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

Open
opened 2026-11-26 20:22:03 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1659
Author: @whoalin1
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: snan-fma-cmpclass


📝 Commits (1)

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

📊 Changes

3 files changed (+88 additions, -8 deletions)

View changed files

📝 docs/shader_validation.md (+8 -2)
📝 tests/test_fmisc_diff.py (+25 -0)
📝 tools/fmisc_diff.py (+55 -6)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1659 **Author:** [@whoalin1](https://github.com/whoalin1) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `snan-fma-cmpclass` --- ### 📝 Commits (1) - [`fc3342f`](https://github.com/ubiquitarianism/leonida/commit/fc3342fd218fe6d73065e08fc937b9d50c8c3873) fmisc_diff: do not judge the class bits of a NaN whose quiet bit is unmodelled ### 📊 Changes **3 files changed** (+88 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/shader_validation.md` (+8 -2) 📝 `tests/test_fmisc_diff.py` (+25 -0) 📝 `tools/fmisc_diff.py` (+55 -6) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1673
No description provided.