spirv_mini_interp.py: keep main's _F32 (sNaN bits, #533) and its vector-aware
RoundEven/Floor/Ceil/Trunc; keep this branch's fma_f32, OpFDiv and
Exp2/Log2/Sqrt/InverseSqrt. regen_fixtures.py: both sides' shaders.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI-assisted. Addresses IAmNotSiob's review on #512 (he is taking the
arithmetic sites under SHADER-56/#513; f16_roundtrip stays here).
SPIR-V's OpQuantizeToF16 returns +0/-0 when the magnitude is too small for a
normal f16, and it pins no rounding mode. The docstring, the design row and the
test's rule text now say "round to nearest, f16 denormals flushed to signed
zero" and warn against reusing the helper where denormals or a rounding mode
matter.
The mini-interpreter used struct.pack('<e'), which keeps f16 subnormals: it was
more precise than any conforming driver, so a test could pass here and fail on a
GPU. It now flushes after float_to_half, and the test's independent oracle does
the same. A new case pins 1e-6 -> +0.0 and -1e-6 -> -0.0 through a translated
flagged shader (PS input 1e-6 is an f16 subnormal, 6.1e-5 is the smallest
normal); without the interpreter flush that test is red.
Existing 1.1 -> 1.099609375 pin and the opcode pin are unchanged.
v_fma_f16, v_fmac_f16 and v_pk_fma_f16 used GLSL Fma (rounded to f32) and then narrowed, a double rounding;
an RX 6700 matches a correctly rounded f16 FMA in 12,612/12,612 cases (#374). fma_f16_odd: exact f32 product,
TwoSum, round-to-odd at f32, then f16_bits. Design row for f16 rounding.
Drivers fold PackHalf2x16 -> UnpackHalf2x16 to a no-op, so a following f16 op saw the unrounded f32 (#513:
v_pk_add_f16 -> v_pk_mul_f16 1 ulp off under --wave64-emulate on NVIDIA; v_cvt_pkrtz_f16_f32 rounding to
nearest on llvmpipe). Gen.f16_bits converts with integer ops (RTE, or RTZ with +-65504 for pkrtz) and is used
by f16_out, v_cvt_f16_f32, v_pk_*_f16, f16 sin/cos, v_interp_p2_f16, v_fma_mix* and f16_rtz.
tests/spirv_interp.py gains OpU{Less,Greater}ThanEqual and OpFUnordNotEqual.
v_lerp_u8 raised Unsupported. Per byte it gives (S0.b + S1.b + bit 0 of
S2.b) >> 1, the unsigned average rounded by S2 (RDNA ISA pseudocode). clamp
is rejected, not guessed.
tests/semantic/test_alu_lerp_u8.py checks it against a plain-Python
reference.
v_add_nc_i32 and v_sub_nc_i32 raised Unsupported. The VOP3 clamp bit on
v_add_nc_u32 / v_sub_nc_u32 / v_subrev_nc_u32 was silently ignored, so a
saturating add came out wrapped. On GFX9+ an integer add/sub with clamp
saturates (LLVM selects uaddsat/usubsat and saddsat/ssubsat to these ops):
unsigned to [0, 0xFFFFFFFF], signed to [INT_MIN, INT_MAX].
tests/semantic/test_alu_add_nc_clamp.py checks all five ops with and without
clamp against a plain-Python reference; docs/design.md gets a contract row.
All three raised Unsupported. s_sext_i32_i8/i16 sign-extend the low byte /
half (OpBitFieldSExtract); s_flbit_i32 is the scalar form of v_ffbh_i32 and
shares its code. None writes SCC.
tests/semantic/test_salu_sext_flbit.py checks all three against a
plain-Python reference, with SCC kept from 0 and 1.
Both raised Unsupported. {sdst, D} = S0 * S1 + S2 as a 65-bit result (RDNA ISA
pseudocode): a 32 x 32 -> 64-bit product, unsigned or signed, plus the 64-bit
S2, built from OpUMulExtended/OpSMulExtended and an OpIAddCarry chain. sdst
gets bit 64 as a lane mask: the carry out for u64, the sign of the exact sum
for i64. clamp is rejected.
tests/semantic/test_alu_mad64.py checks D and the sdst bit against a
plain-Python reference, a null sdst, an inline accumulator, and the carry
feeding v_add_co_ci_u32; docs/design.md gets a contract row.
All five raised Unsupported. They add the sum of absolute differences of the
sources' bytes / halves / words to S2 (unsigned, wrapping at 32 bits), as in
the RDNA ISA pseudocode; v_sad_hi_u8 shifts the byte sum left by 16 and
v_msad_u8 skips the bytes where S1's byte is 0. clamp is rejected, not
guessed.
tests/semantic/test_alu_sad.py checks all five against a plain-Python
reference. test_translate.py and test_f16_op_sel.py used v_sad_u8 as their
example of an unsupported instruction; they now use v_mqsad_u32_u8.
VGPR[D + M0[25:16]] = VGPR[S0 + M0[9:0]] (RDNA2 ISA VOP1 opcode 72; same
fields in the RDNA3 ISA). It raised Unsupported before (noted in #496).
- tools/rdna2spirv.py: masks M0 per side on the existing movrel path.
- tests/semantic/test_alu_movrelsd_2.py: 7 hand-computed cases through the
translator and the interpreter, including ignored M0 bits set, the _e32
spelling and a check that it differs from v_movrelsd_b32.
- runtime/test/shaders/cs_movrelsd_2.asm: GPU test (wave32 dump) with the
ISA's own example; registered in check.py and run_gpu_tests.py.
- docs/design.md: contract row for the v_movrel* forms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bits_f32/f32_bits went through struct's binary32 <-> double conversion,
which quiets a signalling NaN (sets bit 22). Any word in
0x7f800001..0x7fbfffff or 0xff800001..0xffbfffff that passed through a
float (an OpBitcast round trip, or an integer exported through a float
output) came back changed, although OpBitcast is bit-exact in SPIR-V.
About 0.4% of random words hit it, so seeded tests failed by chance:
test_alu_shift_b64's v_ashrrev_i64 case and test_mem_diff's s_load
family both fail on main.
A float made by OpBitcast is now a float subclass that keeps its exact
pattern; copies, composites, selects, variables and outputs pass it on,
and arithmetic returns a plain float, which drops it (SPIR-V leaves NaN
result bits open). Tests cover four sNaN words through every pass-through
path, OpIsNan/OpFOrdEqual on one, and that arithmetic still gives a NaN.
Fixes#509.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI-assisted. Follow-up to merged #274, per Vonsek RTX 5080 review on it.
Pack/Unpack round-trip is folded to a no-op (expected 0x3f802000, observed 0x3f801800, not f16); emit one OpQuantizeToF16, teach mini-interp, pin value and opcode in tests.
tests/semantic/README.md: keep all three new bullets, and drop the conflict markers that
main itself carries from the #421 merge.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
need used to be ceil(size/4) and only the first dword was shifted, so a
4-byte format at byte 3 (or an 8-byte format at byte 6) took its tail
from dword 0. Load ceil((byte_shift + size) / 4) dwords and shift the
whole window so the packed stream starts at the element. Found by the
FUZZ-5 fuzzer; left open in #234.