Repository navigation
tools: fmisc_diff.py, a differential fuzzer for f32 misc ops and float compares - #2514
Conversation
…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.
|
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 |
Requested by Lucas · project thread
Claimed in the coordination issue as: EGEN-TOOL-FMISC (claim)
What and why
tools/fmisc_diff.pyis a differential fuzzer for the f32 ops thattools/f32_fuzz.pydoes not generate, and for float compares. It follows the shape ofsalu_diff.py, #2336, #2371 and #2431: standard library only,python -I, seeded, shrinking, counted skips, exit codes 0/1/2/77.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.v_cmp_*_f32conditions (e32 into VCC, e64 into s20, s21 or VCC) andv_cmp_class_f32e64, each read back withv_cndmask_b32_e64.neg/abs,mul:2/mul:4/div:2andclamp.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.pyor the other fuzzers. Each program runs on one lane, and the four exported words are compared bit for bit withrdna2spirvrunning intests/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.pymeasures the last two.--oracle hwruns the same programs natively throughtools/hw_oracle. It uses the MODE inferred for the game's shaders (IEEE off, f32 denormals flushed; the same asf32_fuzz.py'sflush). With the assembler's compute default (IEEE on), the hardware ignoresomod. The first hardware run showed this:v_fract_f32_e64 v4, -v16 mul:2with v16 = 0.5 gave 0.5.Finding (posted, not fixed here): on hardware,
v_cmp_class_f32with-v,|v|or-|v|on a signalling NaN (0x7f800001,0xffa00000,0x7fbfffff) still reports bit 0, signalling. The translator applies the modifier withOpFNegate/FAbs, and in the interpreter that quiets the NaN, so it reports bit 1. The tool leaves out modifiers on the class source unless--knownis given (class-snan-modsinKNOWN_DIVERGENCES).tests/test_fmisc_diff.pyhas:-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;It also adds a section to
docs/shader_validation.md.Tested
Windows 11, Python 3.12.
--oracle hwwith 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,frexpof-infand-0,ldexpby 128, by0x80000000and by0x7fffffff,cvt_u32(2^32),cvt_i32(NaN),cvt_off(8) = -0.5, andfmamksingle rounding.--known(seed 13, 1,000 programs), the class finding above shows up as 1 mismatch.v_frexp_exp_i32_f32bias inrdna2spirv.pyfrom 126 to 127 gives300 programs: 50 pass, 241 mismatchwith--ops v_frexp_exp_i32_f32. The change was reverted.python -I tests/test_fmisc_diff.py: 19 tests OK.tests/test_docs_repo_paths.py,test_docs_links.pyandtest_docs_list_items.py: OK.No translator change. AI-assisted.
Checklist
docs/design.md, with how it was confirmed. (No new rule.)