Skip to content

tests/semantic: generated NaNs are the x86 default NaN on every host (ARM64 failures) - #4069

Open
Tom1419-git wants to merge 1 commit into
ItsNotRexed:mainfrom
Tom1419-git:tests/semantic-arm64-nan-sign
Open

Tom1419-git wants to merge 1 commit into
ItsNotRexed:mainfrom
Tom1419-git:tests/semantic-arm64-nan-sign

Conversation

@Tom1419-git

Copy link
Copy Markdown

Claimed in the coordination issue as: #3918 (comment)

What and why

The measured words pinned in tests/semantic use 0xFFC00000 for a NaN made from non-NaN operands (inf - inf, 0 * inf), the x86 SSE default NaN. spirv_mini_interp.py left that sign to the host CPU. On ARM64 (Apple Silicon) the host gives 0x7FC00000, so the tests passed on x86-64 only.

ieee_nan() makes the sign explicit for OpFAdd, OpFSub, OpFMul and fma_f32. A NaN that comes from a NaN operand is untouched (both architectures pass it through with its sign). x86-64 results are unchanged by construction.

Tested

macOS 26 arm64, CPython 3.15.2, CPU only, no game data, no GPU. python3 -m unittest discover -s tests/semantic at aa2988c: 39 failures/errors before; after this change test_alu_vop3_mods_hw and test_alu_sdwa_hw pass (30 rows fixed) and the full suite is at 10 failures/errors. Not caused by this change, left alone: test_mutations (already #3883), test_cmp_class_f64 (2 rejected forms are accepted), test_loop_ballot_barrier and test_vcmp16_opsel (not investigated). Not run on x86-64: CI should confirm nothing moved there.

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. (Not applicable: test interpreter only, no translator rule.)

The measured words pinned in the semantic tests use 0xFFC00000 for a NaN made
from non-NaN operands (inf - inf, 0 * inf). The interpreter left that sign to
the host CPU, so 30 rows in test_alu_vop3_mods_hw and test_alu_sdwa_hw failed
on ARM64 (Apple Silicon), where the host gives 0x7FC00000. ieee_nan() makes the
sign explicit for OpFAdd, OpFSub, OpFMul and fma_f32. x86-64 results are
unchanged.

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

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows x86-64 Python check of 8acce97 against aa2988c. Both revisions returned 0xffc00000 for FMA with zero times infinity and with infinity plus negative infinity. Both preserved 0x7fc12345 and 0xffc12345 when those quiet NaNs were inputs. To exercise the normalization directly, I supplied a positive NaN result from non-NaN operands to the new helper and observed 0xffc00000. This confirms the tested x86-64 behavior. ARM64 execution is covered by the author's reported run, which I did not repeat.

AI-assisted.

@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Overlap note: #4100 (@AirKyzzZ) makes the same change in spirv_mini_interp.py: a NaN created from non-NaN operands in OpFAdd/OpFSub/OpFMul/fma_f32 becomes 0xFFC00000, and an operand NaN passes through unchanged. It is SHADER-723, claimed earlier in #3796 (claim), and also pins the cases in test_interp.py. Worth agreeing with them which one goes ahead.

AI-assisted.

@Atlonsky

Copy link
Copy Markdown

Full semantic suite as an A/B on Windows x86-64 (Python 3.15.2, python -I, MinGW g++ 16.2, llvm-mc 23.1.6, SPIRV-Tools v2026.4, RTX 3080 / driver 616.92):

  • main aa2988c: Ran 7456 tests in 616.667s — FAILED (failures=7, errors=2, skipped=1)
  • 8acce97b: Ran 7456 tests in 603.337s — the same 7 failures and 2 errors (test_loop_ballot_barrier, test_cmp_class_f64.test_rejected_forms, test_mutations; all pre-existing on main)

Same count, same failure set, so the change is inert on x86-64 and touches nothing beyond the NaN rows. I cannot run the ARM64 half here, so the actual fix stays unverified on the host it targets.

One detail from the implementation: ieee_nan returns -math.nan, whose word is 0xFFC00000 on any host, and a NaN that came from a NaN operand is returned unchanged (ieee_nan(nan + nan, nan, nan) → 0x7FC00000, ieee_nan(nan + 1.0, nan, 1.0) → 0x7FC00000) — the docstring's two rules hold on this host too.

AI-assisted (Claude). No game files.

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.

4 participants