Skip to content

tools: fmisc_diff.py, a differential fuzzer for f32 misc ops and float compares - #2514

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:fuzz/fmisc-diff
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:fuzz/fmisc-diff

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-TOOL-FMISC (claim)

What and why

tools/fmisc_diff.py is a differential fuzzer for the f32 ops that tools/f32_fuzz.py does not generate, and for float compares. It follows the shape of salu_diff.py, #2336, #2371 and #2431: standard library only, python -I, seeded, shrinking, counted skips, exit codes 0/1/2/77.

  • Ops: v_fract_f32, v_frexp_mant_f32, v_frexp_exp_i32_f32, v_ldexp_f32, v_cvt_u32_f32, v_cvt_i32_f32, v_cvt_off_f32_i4, v_fmamk_f32.
  • Compares: the 16 v_cmp_*_f32 conditions (e32 into VCC, e64 into s20, s21 or VCC) and v_cmp_class_f32 e64, each read back with v_cndmask_b32_e64.
  • Modifiers: VOP3 neg/abs, mul:2/mul:4/div:2 and clamp.
  • Sources: VGPRs, SGPRs, integer and float inline constants, and literals, within the constant-bus limits. Integer and float values live in separate registers, so few float reads hit a denormal.

The reference is its own exact-rational model of the ISA pseudocode, with one rounding per op. It shares no code with the translator, cpu_ref.py or the other fuzzers. Each program runs on one lane, and the four exported words are compared bit for bit with rdna2spirv running in tests/semantic/spirv_mini_interp.py. Any NaN matches any NaN.

These cases are not judged and are counted as skips with the reason: a denormal operand or result (the MODE question, SHADER-35), a computed NaN read as an integer, the clamp of a NaN, and an output modifier that gives a zero. f32_fuzz.py measures the last two.

--oracle hw runs the same programs natively through tools/hw_oracle. It uses the MODE inferred for the game's shaders (IEEE off, f32 denormals flushed; the same as f32_fuzz.py's flush). With the assembler's compute default (IEEE on), the hardware ignores omod. The first hardware run showed this: v_fract_f32_e64 v4, -v16 mul:2 with v16 = 0.5 gave 0.5.

Finding (posted, not fixed here): on hardware, v_cmp_class_f32 with -v, |v| or -|v| on a signalling NaN (0x7f800001, 0xffa00000, 0x7fbfffff) still reports bit 0, signalling. The translator applies the modifier with OpFNegate/FAbs, and in the interpreter that quiets the NaN, so it reports bit 1. The tool leaves out modifiers on the class source unless --known is given (class-snan-mods in KNOWN_DIVERGENCES).

tests/test_fmisc_diff.py has:

  • hand-worked reference values: the fract cap and -0, frexp/ldexp specials and overflow, saturating conversions, one rounding in fmamk, omod then clamp, ordered and unordered compares, class bits, and what is not judged;
  • generator checks: every op in every form, every modifier, the encoding and constant-bus rules, clamp written before the omod (the GFX10 assembler rejects the other order), and the known form off by default;
  • the self-test canaries;
  • a short seeded translator run;
  • 11 hand op cases and 32 compare cases checked against the translator;
  • checks that a wrong translation is caught (including a NaN where a number is expected), that shrinking works, and that the exit codes are right, including 77 without the oracle tools.

It also adds a section to docs/shader_validation.md.

Tested

Windows 11, Python 3.12.

  • Hardware: AMD Radeon RDNA2 iGPU (gfx1036, Ryzen 9 9950X3D, driver 26.10.1), --oracle hw with the known form included. Seeds 1, 2 and 3 ran 500 programs each (seed 3 restricted to the compares, ldexp, fmamk and fract). Seed 4 ran 300 programs with --oracle translator,hw --no-literals. Result: 1,800 programs, 1,563 judged, 0 mismatches, 237 counted skips (denormal operands 85, omod on a zero 95, clamp of a NaN 32, denormal results 24, a computed NaN read as an integer 1). A hand probe also matched: fract(-0) = +0, fract(-2^-24) = 0x3f7fffff, frexp of -inf and -0, ldexp by 128, by 0x80000000 and by 0x7fffffff, cvt_u32(2^32), cvt_i32(NaN), cvt_off(8) = -0.5, and fmamk single rounding.
  • Translator:
    • Seed 11, 3,000 programs (up to 8 ops): 2,517 match, 0 mismatch, 483 counted skips (all "uncertain").
    • Seed 12, 1,000 compare/class programs: 944 match, 0 mismatch.
    • Seed 14, 1,000 programs without literals: 888 match, 0 mismatch.
    • With --known (seed 13, 1,000 programs), the class finding above shows up as 1 mismatch.
  • Negative control: changing the v_frexp_exp_i32_f32 bias in rdna2spirv.py from 126 to 127 gives 300 programs: 50 pass, 241 mismatch with --ops v_frexp_exp_i32_f32. The change was reverted.
  • Unit tests: python -I tests/test_fmisc_diff.py: 19 tests OK. tests/test_docs_repo_paths.py, test_docs_links.py and test_docs_list_items.py: OK.

No translator change. AI-assisted.

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. (No new rule.)

…t compares

A separate exact-rational ISA model for v_fract_f32, v_frexp_mant/exp_f32, v_ldexp_f32, v_cvt_u32/i32_f32, v_cvt_off_f32_i4, v_fmamk_f32, the 16 v_cmp_*_f32 conditions and v_cmp_class_f32, with neg/abs, omod and clamp and every source kind within the constant-bus rules, compared one lane at a time with rdna2spirv run in tests/semantic/spirv_mini_interp.py, optionally with the hardware through tools/hw_oracle (run under IEEE off, f32 denormals flushed). Denormals, NaN payloads read as integers, clamp of a NaN and omod giving a zero are counted skips. v_cmp_class_f32 with neg/abs on a signalling NaN only with --known.

AI-assisted.
@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent check of the SHADER-457 finding on Windows 11 build 26300, RTX 5070 driver 621.24, at 94955e1. All 19 fuzzer tests passed. A synthetic compute fixture read 512 float bit patterns from memory and recovered all ten class bits for each of plain, neg, abs and neg-abs.

On this driver, plain and neg matched the bitwise reference on all inputs. Both abs forms quieted all 203 signaling NaNs. They also reported no class bit for each of +inf and -inf, where the expected bit is positive infinity for abs and negative infinity for neg-abs. For example, positive infinity produced the four masks (512, 4, 0, 0) instead of (512, 4, 512, 4).

With a temporary change confined to Gen.cmp_class to use the raw source word, clear the sign with integer AND for abs, then toggle it with integer XOR for neg, all 2,048 checks matched. Both modules passed Vulkan 1.2 validation. The fuzzer's known-divergence run (seed 13) then had 889 passes, 111 counted skips, and zero mismatches. I restored the source afterward. Synthetic inputs only. AI-assisted review.

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.

3 participants