Skip to content

spirv_mini_interp: f32 and f32_bits give one NaN word on every Python - #7200

Closed
paratustra wants to merge 1 commit into
ItsNotRexed:mainfrom
paratustra:test-mini-interp-f32-nan-pin
Closed

paratustra wants to merge 1 commit into
ItsNotRexed:mainfrom
paratustra:test-mini-interp-f32-nan-pin

Conversation

@paratustra

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new item

What and why

The CPU oracle in tests/semantic/spirv_mini_interp.py rounds through struct's <f. Its answer for a signalling NaN depends on the Python version. CPython 3.12, 3.13 and 3.15 quiet it, but 3.14 keeps it signalling (gh-130317). So OpFNegate or OpFAbs on a bitcast signalling NaN gave 0xFF800001 on 3.14 and 0xFFC00001 on CI's 3.12.

That is how #6293's test_f32_three_input_all_nan_keeps_src0 passed for its author on 3.14.6 and is red on 3.12 on main. A contributor on 3.14 sees a different suite from CI.

This pins CI's rule in f32 and f32_bits, as half_to_float and float_to_half already do for f16: a NaN comes back quiet, with its sign and the top 22 payload bits kept. Non-NaN values take the same struct path as before. _F32 values from a bitcast still return their exact bits.

Tested

macOS arm64, with CPython from uv, on main fd335571.

3.12.13 3.14.7 3.15.2
scripts/run_semantic_tests.py tests/semantic, this PR 5,891 tests, 3 files fail same 3 files same 3 files
same on main 5,889 tests, same 3 files fail 3.14 differs: test_float_nan_fract passes same as 3.12

AI-assisted: yes

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. (Not applicable: no translator change. This is the test oracle.)

struct's '<f' quiets a signalling NaN on 3.12, 3.13 and 3.15 but keeps it
signalling on 3.14 (CPython gh-130317), so OpFNegate or OpFAbs on a bitcast
signalling NaN gave a different word on 3.14 than on CI's 3.12. Pin CI's
rule, as half_to_float already does for f16: the result is quiet, with its
sign and the top 22 payload bits kept.
@dadsmallbuk1

Copy link
Copy Markdown

Tested 6cb9980 on CPython 3.12.10 (CI's quieting rule), Windows 11: pass for the change itself.

AI-assisted (Claude Code).

@hcampbell98

Copy link
Copy Markdown

Tested 6cb9980 merged with main 8575d36ed on Linux (WSL2, CPython 3.12.13 / 3.13.14 / 3.14.4, CPU only, no game files): pass.

  • git diff --check, compileall, and python3 -I scripts/check_no_game_data.py: clean.
  • python3 -I -m unittest discover -s tests/semantic -p test_interp.py: 54/54 OK on CPython 3.12.13, 3.13.14, and 3.14.4.
  • python3 -I -m unittest discover -s tests/semantic -p "test_interp*.py" (3.14.4): 203/203 OK.
  • Cross-version NaN parity (test_float_nan_fract.py): with this PR, CPython 3.12.13, 3.13.14, and 3.14.4 all produce identical results — 31 run, 3 failed (test_f32_three_input_all_nan_keeps_src0 on v_min3_f32/v_max3_f32/v_med3_f32, 1 skipped).
  • Negative control (origin/main tests/semantic/spirv_mini_interp.py): on 3.14.4, test_interp.py fails 4 subtests in Float32NanRuleTests.test_negated_signalling_nan_comes_back_quiet (54 run, 4 failed) while test_float_nan_fract.py passes (31 run, 1 skipped); on 3.12.13, test_interp.py passes 54/54 and test_float_nan_fract.py fails the same 3 subtests. This confirms the 3.14 signalling-NaN divergence is resolved.

AI-assisted.

@paratustra

Copy link
Copy Markdown
Contributor Author

Closing. #7302 (merged) negates a binary32 operand on its sign bit, which is the hardware's rule. With it, main 6b421e6b gives the same tests/semantic result on CPython 3.12 and 3.14: 5,902 tests, with only test_image_atomics_guard and test_image_store_d16 failing on both. Merged on top of that, this PR changes no result on 3.12, 3.14 or 3.15. Its rule, which quiets every NaN, also points the other way from #7302's, which keeps the bits. So it no longer fixes anything and would only disagree with the model main chose. Thanks to everyone who tested it.

AI-assisted.

@paratustra paratustra closed this Nov 23, 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.

3 participants