Skip to content

spirv_mini_interp: OpBitcast and float outputs keep signalling-NaN patterns (TEST-67) - #543

Closed
NWX10 wants to merge 1 commit into
ProjectLeonida:mainfrom
NWX10:test-67-snan
Closed

NWX10 wants to merge 1 commit into
ProjectLeonida:mainfrom
NWX10:test-67-snan

Conversation

@NWX10

@NWX10 NWX10 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in #374 as: TEST-67

Fixes #509.

What and why

tests/semantic/spirv_mini_interp.py keeps float values as Python floats, and Python quiets a signalling NaN (sets bit 22) when it goes through struct <f or a double. A word in 0x7f800001..0x7fbfffff or 0xff800001..0xffbfffff therefore came back changed after OpBitcast int -> float -> int or an export of an integer result: 0xffa3a095 became 0xffe3a095, about 0.4% of random words. It broke the seeded v_ashrrev_i64 case in #454, and it breaks tests/test_mem_diff.py today: family='s_load' with the date-based seed 20261122 expects 0x7f8295f4 and got 0x7fc295f4.

bits_f32 now returns a SignallingNaN for such a pattern: a float subclass whose value is the quiet NaN Python makes of the pattern, plus the original 32-bit pattern. f32_bits returns that pattern. So OpBitcast, OpCopyObject, OpSelect, stores and outputs carry the word exactly, while arithmetic is unchanged (the result is the quiet NaN with the same sign and payload, as IEEE 754 says). Nothing else in the interpreter or the translator changes.

The copy of f32_bits in test_ballot_votes.py (the wave interpreter) has the same property; it is a separate interpreter and not part of #509, so I left it alone.

Tested

  • tests/semantic/test_interp.py (the interpreter's own self-tests) gets three tests: int -> float -> int, through OpCopyObject and OpSelect as well, for 0xffa3a095, 0x7f800001, 0x7fbfffff, a quiet NaN, infinity and 0xffffffff; a float Output variable; and an OpFAdd on a signalling NaN, which must still return the quiet NaN (0xffe3a095). With the interpreter from main the new tests fail (6 failing cases); with this change all 31 tests pass.
  • python -I -m unittest discover -s tests/semantic -p "test_*.py": 711 tests OK. python -I tests/semantic/regen_fixtures.py --check: OK.
  • Full suite (python -I -m unittest discover -s tests -p "test_*.py"): 1326 tests, no failures; the only errors are 14 modules that need pytest, which isn't installed here. On main the same run has the test_mem_diff s_load failure above.
  • Windows 11, Python 3.12. No GPU involved, no game files.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…tterns (TEST-67)

The interpreter keeps floats as Python floats, and struct '<f' / a double quiets a
signalling NaN (bit 22), so a word in 0x7f800001..0x7fbfffff or 0xff800001..0xffbfffff
came back changed after OpBitcast int->float->int or an export (ProjectLeonida#509: 0xffa3a095
became 0xffe3a095, about 0.4% of random words).

bits_f32 now returns a SignallingNaN for such a pattern: a float subclass whose value
is the quiet NaN Python makes of it, so arithmetic is unchanged, and f32_bits returns
the original pattern. OpBitcast, OpCopyObject, OpSelect, stores and outputs carry the
word exactly; an operation on it still gives the quiet NaN, as IEEE 754 says.

test_interp.py covers int->float->int, copies, selects, a float output and the
arithmetic case; they fail with the interpreter from main. The seeded
test_mem_diff s_load case (seed 20261122), which failed on main with 0x7fc295f4
for 0x7f8295f4, passes again.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@73N1X

73N1X commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows x64 / Python 3.12.10 CPU validation on detached commit 842a9d835afe0ed7e2f3370b0ca17e6d37e2144b: pass.

  • python -I -m unittest discover -s tests/semantic: 711 tests OK.
  • python -I tests/test_mem_diff.py: 9 tests OK, including the s_load family and its negative-control canaries.

I also ran the failing cases in a separate clean worktree of main at 91b36cf, without either TEST-67 proposal:

  • python -I -m unittest discover -s tests/semantic -p test_alu_shift_b64.py: 4 tests, 1 failure; the seeded v_ashrrev_i64 case returns 18446744073707692181 rather than 18446744073703497877.
  • python -I tests/test_mem_diff.py: 9 tests, 1 failure; s_load seed 20261122 program 8 expects 0x7f8295f4 and observes 0x7fc295f4.

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.

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