fmisc_diff: do not judge the class bits of a NaN whose quiet bit is unmodelled #1659

Open
github-bot wants to merge 1 commit from github-bot/gh-1659 into main AGit
Owner

@⁠whoalin1 on GitHub · 2026-11-25 07:24 UTC · original
whoalin1:snan-fma-cmpclass → main · +88 −8 · 3 files · 1 commits · open

Fuzz-campaign follow-up (coordination issue #14; its comment thread is at the cap so context lives here): fmisc_diff reported a divergence where an sNaN through v_fmamk_f32 flipped the v_cmp_class_f32 result bit on both AMD gfx1036 and NVIDIA RTX 4070 SUPER.

Root cause is not the translator: hardware itself does not deterministically preserve the NaN quiet bit — measured on gfx1036 under the game'''s MODE (IEEE off, denormal flush), an sNaN operand mostly passes through v_fmamk_f32 unchanged but is quieted in edge cases. The translator'''s output matched what the hardware produces on both GPUs; the fuzzer'''s reference model simply had no way to express "this NaN'''s quiet bit is unknown".

What

tools/fmisc_diff.py gains st["nanf"] — a set of VGPRs holding a computed NaN whose quiet bit is not modelled. It is set when v_fmamk_f32 sees a signalling-NaN (or already-fuzzy NaN) operand and propagates through the pass-through ops (v_fract_f32, v_frexp_mant_f32, v_frexp_exp_i32_f32, v_ldexp_f32, the NAN_PASSTHROUGH set) and v_mov_b32/v_cndmask_b32_e64; it clears on any fully-modelled result. v_cmp_class_f32 on a nanf register raises Uncertain (a Skip subclass) instead of producing a false mismatch. docs/shader_validation.md records the measurement and the conclusion.

Verification

  • tests/test_fmisc_diff.py: 35 tests pass, including the new test_class_of_a_computed_nan (sNaN→fmamk→class raises Uncertain; fuzzy NaN surviving a pass-through still raises; quiet-NaN and exact-sNaN cases are still judged — guards against over-skipping).
  • tools/fmisc_diff.py --programs 3000 --seed 11 --max-ops 8 (translator oracle): 2512 pass, 0 mismatch, 488 skipped; a targeted 2000-program run produced 4 skips with the new reason and 0 mismatches.
  • Python-only fuzzer change; no translator or runtime code touched.

Independent review: APPROVE — nanf coverage is complete for the ops this fuzzer models (v_fmamk_f32 is the only NaN-minting op in its set; other producers raise RefError), Uncertain flows through the skip path correctly, and the tests fail without the fix. Non-blocking notes left for a possible follow-up: v_cmp_class could skip only when mask & 3 is exactly one of the NaN class bits (masks 00/11 are deterministic either way), and one copy/cndmask propagation case could be added to the test.

AI-assisted (Devin).

**@⁠whoalin1** on GitHub · 2026-11-25 07:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1659) `whoalin1:snan-fma-cmpclass` → `main` · +88 −8 · 3 files · 1 commits · open Fuzz-campaign follow-up (coordination issue #14; its comment thread is at the cap so context lives here): `fmisc_diff` reported a divergence where an sNaN through `v_fmamk_f32` flipped the `v_cmp_class_f32` result bit on both AMD gfx1036 and NVIDIA RTX 4070 SUPER. Root cause is **not** the translator: hardware itself does not deterministically preserve the NaN quiet bit — measured on gfx1036 under the game'\''s MODE (IEEE off, denormal flush), an sNaN operand mostly passes through `v_fmamk_f32` unchanged but is quieted in edge cases. The translator'\''s output matched what the hardware produces on both GPUs; the fuzzer'\''s reference model simply had no way to express "this NaN'\''s quiet bit is unknown". ## What `tools/fmisc_diff.py` gains `st["nanf"]` — a set of VGPRs holding a computed NaN whose quiet bit is not modelled. It is set when `v_fmamk_f32` sees a signalling-NaN (or already-fuzzy NaN) operand and propagates through the pass-through ops (`v_fract_f32`, `v_frexp_mant_f32`, `v_frexp_exp_i32_f32`, `v_ldexp_f32`, the `NAN_PASSTHROUGH` set) and `v_mov_b32`/`v_cndmask_b32_e64`; it clears on any fully-modelled result. `v_cmp_class_f32` on a `nanf` register raises `Uncertain` (a `Skip` subclass) instead of producing a false mismatch. `docs/shader_validation.md` records the measurement and the conclusion. ## Verification - `tests/test_fmisc_diff.py`: 35 tests pass, including the new `test_class_of_a_computed_nan` (sNaN→fmamk→class raises `Uncertain`; fuzzy NaN surviving a pass-through still raises; quiet-NaN and exact-sNaN cases are still judged — guards against over-skipping). - `tools/fmisc_diff.py --programs 3000 --seed 11 --max-ops 8` (translator oracle): 2512 pass, 0 mismatch, 488 skipped; a targeted 2000-program run produced 4 skips with the new reason and 0 mismatches. - Python-only fuzzer change; no translator or runtime code touched. Independent review: APPROVE — `nanf` coverage is complete for the ops this fuzzer models (`v_fmamk_f32` is the only NaN-minting op in its set; other producers raise `RefError`), `Uncertain` flows through the skip path correctly, and the tests fail without the fix. Non-blocking notes left for a possible follow-up: `v_cmp_class` could skip only when `mask & 3` is exactly one of the NaN class bits (masks `00`/`11` are deterministic either way), and one copy/`cndmask` propagation case could be added to the test. AI-assisted (Devin).
A fuzzed sNaN through v_fmamk_f32 into v_cmp_class_f32 flipped a result
bit on both Vulkan GPUs against the reference model. The model returns a
canonical quiet NaN for v_fmamk_f32, but on gfx1036 under the game's MODE
the hardware mostly returns the NaN source's word and only sometimes
quiets a signalling one (f32_hw_s5.log), so whether the result tests as
signalling or quiet is not something the model can know. Track registers
holding such a computed NaN (st["nanf"], set by v_fmamk_f32 with a
signalling or already-fuzzy NaN operand and propagated through the
pass-through ops and register moves) and raise Uncertain when
v_cmp_class_f32 reads one, instead of reporting a mismatch that is a
model gap, not a translator bug.

Co-Authored-By: Devin <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:43 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 07:51 UTC · original

Tested 36f2621ae on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 3f81d46ac (Python differential tool; no GPU run):

  • pytest 9.2.0 on tests/test_fmisc_diff.py: 35 passed, 49 subtests passed at this head.
  • The same file on main: 1 failed (Reference::test_class_of_a_computed_nan), 34 passed, 49 subtests — that is the sNaN class-bit judgement the PR changes; the rest of the file is unchanged.
  • Not run: the hardware oracle on gfx1036 / RTX 4070 SUPER; only the synthetic unit tests. This is a "do not judge an unmodelled bit" change, so a hardware run would not add a pass/fail beyond the existing campaign data.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 07:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1659#issuecomment-7156328316) Tested `36f2621ae` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `3f81d46ac` (Python differential tool; no GPU run): - pytest 9.2.0 on `tests/test_fmisc_diff.py`: **35 passed, 49 subtests passed** at this head. - The same file on `main`: **1 failed** (`Reference::test_class_of_a_computed_nan`), 34 passed, 49 subtests — that is the sNaN class-bit judgement the PR changes; the rest of the file is unchanged. - Not run: the hardware oracle on gfx1036 / RTX 4070 SUPER; only the synthetic unit tests. This is a "do not judge an unmodelled bit" change, so a hardware run would not add a pass/fail beyond the existing campaign data. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 20:30 UTC · original

Rebased cleanly onto current main (db1a22d29) as fc3342fd2 to refresh the stale CI baseline; no conflicts. The branch is unchanged: fmisc_diff no longer judges the class bits of a NaN whose quiet bit the translator does not model. AI-assisted with Devin.

**@⁠whoalin1** on GitHub · 2026-11-25 20:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1659#issuecomment-7173768811) Rebased cleanly onto current main (`db1a22d29`) as `fc3342fd2` to refresh the stale CI baseline; no conflicts. The branch is unchanged: `fmisc_diff` no longer judges the class bits of a NaN whose quiet bit the translator does not model. AI-assisted with Devin.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1659/head:github-bot/gh-1659'
git switch 'github-bot/gh-1659'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1659'
git switch 'github-bot/gh-1659'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1659'
git switch 'github-bot/gh-1659'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1659'
git switch 'main'
git merge --squash 'github-bot/gh-1659'
git switch 'main'
git merge --ff-only 'github-bot/gh-1659'
git switch 'main'
git merge 'github-bot/gh-1659'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.