Skip to content

mem_diff: export result words in 16-bit halves (fixes test_mem_diff on Python < 3.14 / CI) - #567

Closed
LouisRiverstone wants to merge 1 commit into
ItsNotRexed:mainfrom
LouisRiverstone:mem-diff-export-halves
Closed

LouisRiverstone wants to merge 1 commit into
ItsNotRexed:mainfrom
LouisRiverstone:mem-diff-export-halves

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

tests/test_mem_diff.py fails on main in CI (the check job, on every PR since d9e6292):

FAIL: test_every_family_runs_clean (family='s_load')
AssertionError: 1 != 0 : ps_mem_00008 (seed 20261122 program 8): export word 1: expected 0x7f8295f4, translated 0x7fc295f4

The translator is right here. 0x7f8295f4 is a signalling-NaN bit pattern, and the word leaves through exp mrt0, which is a float channel. On Python before 3.14, struct.pack("<f", …) quiets a signalling NaN (bit 22 set), so the interpreter's float export changes the word. Python 3.14 keeps the payload. That's why the test passes locally on 3.14 (@Spaghetih's run in #442 and mine) and fails on the CI runners. A GPU export may quiet such a word too. The same thing happened to test_alu_shift_b64 (see the review on #454).

Change

  • tools/mem_diff.py:
    • The four result words (v8..v11) now leave as eight 16-bit halves in v12..v19. Each half is ORed into 0x40000000, which is always a normal float, and goes out through mrt0 and mrt1.
    • _exported_words puts them back together. It reports a mismatch if any half doesn't come back with the 0x4000 tag.
    • v12..v19 aren't used by any generator (they use v2..v11).
    • Memory comparison isn't affected: memory never goes through a float.

Tested

  • python -I tests/test_mem_diff.py: OK on Python 3.14.
  • I ran it again with spirv_mini_interp's bits↔float conversions forced to quiet signalling NaNs, the way older Pythons do:
    • On main, that reproduces the CI failure exactly (ps_mem_00008, 0x7f8295f4 → 0x7fc295f4).
    • With this change, it passes.
  • python -I tools/mem_diff.py --programs 1500 --seed 7: 1500 pass, 0 mismatch, both normally and with the forced quieting.
  • python -I -m unittest discover -s tests/semantic OK, and compileall passes. CPU only, no game files.

#548 also edits tools/mem_diff.py, near run_one. If it lands first I'll rebase this.

AI-assisted (Claude Code): it found the cause, wrote the change, and ran the checks listed above.

On Python before 3.14, struct's float packing quiets a signalling NaN, so a
result word like 0x7f8295f4 came back from the interpreter's float export as
0x7fc295f4. tests/test_mem_diff.py (seed 20261122, program 8, s_load) failed
that way on the CI runners, while it passes on Python 3.14. A GPU export may
quiet such a word too.

The words now leave as eight 16-bit halves ORed into 0x40000000 (always a
normal float) through mrt0 and mrt1, and are reassembled before comparing.
@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Closing this: the root cause is TEST-67 (#509), the interpreter quieting signalling-NaN bit patterns in its float conversions, and #533 / #543 fix that at the source, which makes test_mem_diff pass without changing the harness. No need for a second fix of the same symptom. (The halves export is still an option if the GPU path of mem_diff ever needs it.)

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.

1 participant