Skip to content

tests: keep f32 bits exact through the interpreter (OpBitcast / sNaN) - #545

Closed
luisbaker wants to merge 1 commit into
ItsNotRexed:mainfrom
luisbaker:test-67-spirv-interp
Closed

luisbaker wants to merge 1 commit into
ItsNotRexed:mainfrom
luisbaker:test-67-spirv-interp

Conversation

@luisbaker

Copy link
Copy Markdown
Contributor

Item: TEST-67 (claimed in #374). Fixes #509.

What

tests/semantic/spirv_mini_interp.py kept float values as Python floats, and the
<f <-> double conversion quiets signalling NaNs (it sets bit 22). So OpBitcast
int->float->int and any float output changed an sNaN word like 0xffa3a095 into
0xffe3a095. Any semantic test that exports a random integer through a float
hits this about 0.4% of the time, and the fuzzers report false mismatches.

Float values are now an _F32 wrapper holding the 32-bit pattern, widened to a
Python float only inside arithmetic ops (where sNaN is undefined anyway).
OpBitcast, loads/stores and outputs read .bits directly, so they are
bit-exact. Caller-supplied inputs and the float zero value are coerced through
the same wrapper.

Tested

  • New tests/semantic/test_float_bits.py: round-trips sNaN words through
    bits_f32/f32_bits and through a uint -> float -> uint OpBitcast shader.
  • python -m unittest discover -s tests/semantic (subset): test_float_bits,
    test_float_compares, test_float_to_int, test_value_semantics,
    test_ps_semantics, test_interp*, test_alu_subrev_f16, test_salu_pack,
    test_int*, test_scalar*, test_alu_* -> all pass.

Notes

  • AI-assisted (Cline).
  • CPU only, no game files, no GPU.

…tsNotRexed#509)

spirv_mini_interp kept float values as Python floats, and the <f <-> double
conversion quiets signalling NaNs (it sets bit 22), so OpBitcast and float
outputs changed sNaN words like 0xffa3a095 into 0xffe3a095. Any semantic test
that exports a random integer through a float hits this about 0.4% of the time.

Represent float values as an _F32 wrapper holding the 32-bit pattern, and widen
to a Python float only inside arithmetic ops (where sNaN is undefined anyway).
OpBitcast, loads/stores and outputs read the bits directly. Caller-supplied
inputs and the float zero value are coerced through the same wrapper.

test_float_bits.py round-trips sNaN words through bits_f32/f32_bits and through
a uint->float->uint OpBitcast shader, bit-exactly.

AI-assisted (Cline).
@IAmNotSiob

Copy link
Copy Markdown
Contributor

Heads-up: #533 (also TEST-67, fixing #509 with the same _F32 wrapper idea) was merged at 01:00 UTC, and this now conflicts in spirv_mini_interp.py. If there's anything here #533 doesn't cover, a small follow-up on top of main might be easiest. Otherwise this one can probably be closed. AI-assisted review (Claude Code).

@luisbaker

Copy link
Copy Markdown
Contributor Author

Closing as redundant: #533 (the same _F32 wrapper fix for #509) was already merged and covers the same sNaN round-trip tests. Thanks @IAmNotSiob.

@luisbaker luisbaker closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spirv_mini_interp: OpBitcast and float outputs quiet signalling-NaN bit patterns (bit 22 flips)

2 participants