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

Merged
leonida/mandy
whoalin1 merged 1 commit from snan-fma-cmpclass into main 2026-12-01 10:31:31 +00:00

Pull request successfully merged and closed

whoalin1 commented 2026-11-25 07:24:29 +00:00

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).

Claimed in the coordination issue as: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7259693905

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). Claimed in the coordination issue as: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7259693905
GeorgiyDemo commented 2026-11-25 07:51:23 +00:00

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.

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.
whoalin1 commented 2026-11-25 20:30:18 +00:00

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.

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.
MoonEyes commented 2026-11-27 22:43:10 +00:00

Hi @whoalin1, thanks for this pull request.

CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post claiming: <ID> there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one.

The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.

Could you post the claim in #1608 and put its ID (or a link to it) on the pull request's "Claimed in the coordination issue as:" line? If you already claimed it in another form, a link to your comment is enough.

AI-assisted (Claude Code, Claude Opus 5.5).

Hi @whoalin1, thanks for this pull request. CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post `claiming: <ID>` there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one. The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time. Could you post the claim in #1608 and put its ID (or a link to it) on the pull request's "Claimed in the coordination issue as:" line? If you already claimed it in another form, a link to your comment is enough. AI-assisted (Claude Code, Claude Opus 5.5).
zmasi commented 2026-11-28 20:31:05 +00:00

#1659 | head fc3342fd218fe6d73065e08fc937b9d50c8c3873 (merged cleanly with main 1bc055e6c2) | python -I tests/test_fmisc_diff.py + python -I tools/fmisc_diff.py --programs 500 --seed 7 | red on main: FAILED (failures=1) (Reference.test_class_of_a_computed_nan did not raise Uncertain when v_fmamk_f32 with an sNaN operand fed v_cmp_class_f32) | green on PR+main: 35 tests OK + 500 programs: 456 pass, 0 mismatch, 44 skipped | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited rebased head fc3342fd21 across tools/fmisc_diff.py, tests/test_fmisc_diff.py, and docs/shader_validation.md on Windows 11, verifying st["nanf"] tracking for unmodelled quiet bits from v_fmamk_f32 (including survival across NAN_PASSTHROUGH ops and v_mov_b32 / v_cndmask_b32, in-place destination aliasing safety, and exact preservation of quiet-NaN and pure pass-through sNaN v_cmp_class_f32 checks). Also verified tests/test_docs_encoding.py (1 OK), tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

#1659 | head fc3342fd218fe6d73065e08fc937b9d50c8c3873 (merged cleanly with main 1bc055e6c2) | `python -I tests/test_fmisc_diff.py` + `python -I tools/fmisc_diff.py --programs 500 --seed 7` | red on main: `FAILED (failures=1)` (`Reference.test_class_of_a_computed_nan` did not raise `Uncertain` when `v_fmamk_f32` with an sNaN operand fed `v_cmp_class_f32`) | green on PR+main: `35 tests OK` + `500 programs: 456 pass, 0 mismatch, 44 skipped` | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited rebased head `fc3342fd21` across `tools/fmisc_diff.py`, `tests/test_fmisc_diff.py`, and `docs/shader_validation.md` on Windows 11, verifying `st["nanf"]` tracking for unmodelled quiet bits from `v_fmamk_f32` (including survival across `NAN_PASSTHROUGH` ops and `v_mov_b32` / `v_cndmask_b32`, in-place destination aliasing safety, and exact preservation of quiet-NaN and pure pass-through sNaN `v_cmp_class_f32` checks). Also verified `tests/test_docs_encoding.py` (`1 OK`), `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
TheGeogeo commented 2026-11-29 00:16:52 +00:00

Tested fc3342fd2 merged (no commit) with main 829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_fmisc_diff.py, 35 tests pass.
  • Red: with tools/fmisc_diff.py back to main, 1 failure (Uncertain not raised).

No blocker from my side.

AI-assisted (Claude Code).

Tested `fc3342fd2` merged (no commit) with `main` `829530dbd`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_fmisc_diff.py`, 35 tests pass. - Red: with `tools/fmisc_diff.py` back to `main`, 1 failure (`Uncertain not raised`). No blocker from my side. AI-assisted (Claude Code).
TheGeogeo commented 2026-11-29 11:51:47 +00:00

Tested green here earlier on this same head (see my comment above). The only thing missing for a merge is your claim in the coordination issue #2570.

AI-assisted (Claude Code).

Tested green here earlier on this same head (see my comment above). The only thing missing for a merge is your claim in the coordination issue #2570. AI-assisted (Claude Code).
whoalin1 commented 2026-11-29 17:41:20 +00:00

Added the missing coordination-issue claim and linked it in the PR body: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7259693905. No code changes.

Added the missing coordination-issue claim and linked it in the PR body: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7259693905. No code changes.
MoonEyes commented 2026-11-29 18:31:14 +00:00

Tested fc3342fd2 merged (no commit) with main 4755667f5: Python 3.12, Windows 11 10.0.26300, CPU only. Ran the PR's tests plus every test file that imports the changed tool.

  • Green: python -I tests/test_fmisc_diff.py gives 35 OK.
  • Red with tools/fmisc_diff.py back to main: FAILED (failures=1).
  • I could not find this PR's claim in the coordination issue.
  • Does not force a rebase of #2566 (merge-tree against 8db8335d2).

AI-assisted (Claude Code).

Tested `fc3342fd2` merged (no commit) with `main` `4755667f5`: Python 3.12, Windows 11 10.0.26300, CPU only. Ran the PR's tests plus every test file that imports the changed tool. - Green: `python -I tests/test_fmisc_diff.py` gives 35 OK. - Red with `tools/fmisc_diff.py` back to `main`: `FAILED (failures=1)`. - I could not find this PR's claim in the coordination issue. - Does not force a rebase of #2566 (merge-tree against `8db8335d2`). AI-assisted (Claude Code).
whoalin1 commented 2026-11-29 18:38:04 +00:00

The implementation claim is in the current coordination issue here: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7259693905. I also added the corresponding done: entry linking it back to this PR: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7260636580.

The implementation claim is in the current coordination issue here: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7259693905. I also added the corresponding `done:` entry linking it back to this PR: https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7260636580.
whoalin1 commented 2026-11-30 22:32:03 +00:00

Rebased onto current main as ac58ddc50 to refresh the stale CI baseline; the single-commit branch reapplied cleanly with no conflicts. Validation after rebase: pytest tests/test_fmisc_diff.py passes 35 tests + 49 subtests under Python 3.12; py_compile and git diff --check are clean.

Rebased onto current `main` as `ac58ddc50` to refresh the stale CI baseline; the single-commit branch reapplied cleanly with no conflicts. Validation after rebase: `pytest tests/test_fmisc_diff.py` passes **35 tests + 49 subtests** under Python 3.12; `py_compile` and `git diff --check` are clean.
MoonEyes commented 2026-12-01 08:02:45 +00:00

Verified by MoonEyes (another person than the author) on head ac58ddc50 merged with main 501b3e6c5: Windows 11, Python 3.14, no GPU and no SPIR-V tools used beyond what the tests find here. tests/test_fmisc_diff.py 35 OK; with tools/fmisc_diff.py back to main, 1 failure. I read the diff: the tool and its test (and a docs line for #1659), nothing the game's build uses.

AI-assisted (Claude Code).

Verified by MoonEyes (another person than the author) on head `ac58ddc50` merged with `main` `501b3e6c5`: Windows 11, Python 3.14, no GPU and no SPIR-V tools used beyond what the tests find here. `tests/test_fmisc_diff.py` 35 OK; with `tools/fmisc_diff.py` back to `main`, 1 failure. I read the diff: the tool and its test (and a docs line for #1659), nothing the game's build uses. AI-assisted (Claude Code).
MoonEyes commented 2026-12-01 10:31:28 +00:00

Merging. Head ac58ddc50 merges cleanly with main 653f60d37 and does not force a rebase of #2566. CI green on this head and on main. I ran it on main + PR (Windows, Python 3.14): 35 tests OK, 1 failure without the change. A validation tool, its test and a docs line. Merged by MoonEyes.

AI-assisted (Claude Code).

Merging. Head `ac58ddc50` merges cleanly with `main` `653f60d37` and does not force a rebase of #2566. CI green on this head and on main. I ran it on main + PR (Windows, Python 3.14): 35 tests OK, 1 failure without the change. A validation tool, its test and a docs line. Merged by MoonEyes. AI-assisted (Claude Code).
Sign in to join this conversation.
No description provided.