Repository navigation
tests/semantic: OpBitcast keeps signalling-NaN bits in the mini interpreter (TEST-67) - #533
Conversation
…preter (TEST-67) 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 ItsNotRexed#509. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 3fe9203 on Windows 11, Python 3.12 (no GPU): I opened #543 for the same item with the same approach (a float subclass that carries the 32-bit pattern), so I'm closing it and this PR continues. If they aren't covered here yet, three cheap extra cases are in #543's tests: OpCopyObject and OpSelect on a signalling NaN, a float Output variable, and arithmetic on a signalling NaN (the result must still be the quiet NaN, 0xFFA3A095 + 1.0 gives 0xFFE3A095). Copy them if you want them. |
|
Independent Windows x64 / Python 3.12.10 CPU validation on detached commit
I also ran the failing cases in a separate clean worktree of main at
Both failures disappear with this exact PR head. This independently confirms that the two interpreter-related failures inherited by #388 are addressed. These are synthetic CPU-only tests; no GPU or game data was used. This report does not claim the whole project CI is green: the separate llvmpipe subgroup issue is TEST-78. I tested both current TEST-67 proposals under the same environment and am reporting exact-head evidence on each, without proposing a third fix or changing either author's code. The choice/coordination between them remains with the authors and maintainer. |
IAmNotSiob
left a comment
There was a problem hiding this comment.
Verified: with this interpreter, #454's original seeded case (v_ashrrev_i64, n=0x3e32dea5, x=0xf47412b2f2e132ea, which exports 0xffa3a095) passes unchanged, and test_interp.py is OK. That's the same approach I had drafted as part of #575, a float subclass carrying the bits with arithmetic dropping them. I've removed my copy from #575 in favour of this one. LGTM. AI-assisted review (Claude Code).
test_preview_with_no_fitting_layout_reports_the_problem runs the tool, which imports numpy before it parses its arguments, so without numpy the test sees a ModuleNotFoundError traceback instead of "no layout" and fails. Its neighbours that run the CLI already skip without numpy. CI's Windows check job has no numpy, so this is its next failure once the mem_diff one (#533) is fixed. The pytest wrapper of the same test skips too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 3fe9203 on Windows 11, Python 3.11.0, CPU only (no GPU, no game data): pass.
About the red checks: neither one comes from this change.
Two small things, neither blocking:
|
spirv_mini_interp.py: keep main's _F32 (sNaN bits, ItsNotRexed#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>
…533) u2f()/f2u() went through struct's binary32 <-> double conversion, which quiets a signalling NaN (sets bit 22), so a word in 0x7f800001.. 0x7fbfffff / 0xff800001..0xffbfffff that passed through an OpBitcast came back changed: 0xffa3a095 became 0xffe3a095. This is the second interpreter (test_values, test_f16_op_sel_values, test_f16_hw_words, test_interp_p1_p2); #533 fixed the same bug in spirv_mini_interp. Same fix: u2f() returns a float subclass that keeps the pattern and f2u() returns it; copies, selects, composites and stores pass it on, and arithmetic gives a plain float. New test_spirv_interp_bits.py checks four sNaN words through every pass-through path, OpIsNan, and that arithmetic still gives a NaN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #509 (TEST-67 in #374).
What and why
bits_f32/f32_bitsintests/semantic/spirv_mini_interp.pywent through struct's binary32 ↔ double conversion, and that conversion quiets a signalling NaN by setting bit 22. Every word in0x7f800001..0x7fbfffff/0xff800001..0xffbfffffthat passed through a float came back changed. That covers anOpBitcastround trip and an integer exported through a float output. SPIR-VOpBitcastis bit-exact, so this was an interpreter bug and the translator was not at fault. About 0.4% of random words hit it. Two seeded tests fail on main because of it:test_alu_shift_b64v_ashrrev_i64(n=0x3e32dea5, x=0xf47412b2f2e132ea), the case from spirv_mini_interp: OpBitcast and float outputs quiet signalling-NaN bit patterns (bit 22 flips) #509tests/test_mem_diff.py::Harness::test_every_family_runs_clean,s_loadfamilyFix. A float made by
OpBitcastis now a smallfloatsubclass (_F32) that keeps its exact 32-bit pattern, which is the wrapper #509 suggests.OpCopyObject, composites,OpSelect,OpPhi, variables and outputs pass the value on unchanged, andf32_bitsreturns the kept pattern. Arithmetic on it returns a plainfloat, so the pattern is dropped there, because SPIR-V leaves NaN result bits open. Float operations still see an ordinary NaN (OpIsNanis true,OpFOrdEqualis false).Tested
Three new tests in
tests/semantic/test_interp.py:OpBitcast→OpCopyObject→ composite →OpSelect→ Function variable → both a uint and a float Output. Each comes out unchanged. Against main's interpreter exactly the four sNaN words fail.OpIsNan/OpFOrdEqualon a bitcast sNaN.OpFAdd/OpFMul/OpFNegateof one still give a NaN. Only "a NaN" is asserted, not its bits.Results:
python -m unittest discover -s tests/semantic: 711 tests OK. Main has 708 tests with 1 failure, the seededv_ashrrev_i64case.pytest tests/test_rdna2spirv_pixelinput.py tests/test_shader_diff.py tests/test_mem_diff.py tests/test_salu_diff.py: 35 passed. These are the other users of the interpreter. On main thes_loadsubtest fails.python -m compileall -q make_game.py tools tests: clean.Python 3.12.15 on macOS arm64. CPU only with hand-written modules, no game data. This change doesn't involve a GPU or driver.
AI-assisted (Claude Code).
Checklist
🤖 Generated with Claude Code