Skip to content

Tools: hardware oracle for f32_fuzz — 46,967 f32 VALU programs on real AMD hardware, 0 model mismatches; omod turns -0 into +0 - #1248

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
AlxcBTW:hw-oracle-f32
Nov 22, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
AlxcBTW:hw-oracle-f32

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

This continues the hardware oracle from #1160 (salu_diff) and #1202 (crosslane_fuzz), both merged. The finding it produced is here in #1006.

What and why

tools/f32_fuzz.py (FUZZ-3) gains --oracle hw and --oracle translator,hw. The same seeded VOP1/VOP2/VOP3 f32 programs (neg/abs, clamp, omod) run natively in wave32 on an AMD GPU. The results are compared bit-exactly against F32Model, the model written from the RDNA2 ISA guide, which no one had checked against hardware.

  • Judged MODE: 0x1c0, which is IEEE off, f32 denormals flushed and DX10_CLAMP on. This is the state the corpus implies for the game's shaders (docs/design.md, the omod row). Each mode's MODE word is read back on the hardware (s_getreg), so a float-mode directive that didn't take fails loudly. tools/hw_oracle/asm.py gets per-kernel float MODE for this.
  • Recorded, not judged: where the model declines, the hardware still runs under four MODE settings: flush, f32 denormals kept, DX10_CLAMP off, and IEEE on. The results are recorded in informational tables: denormals (SHADER-35), NaN payloads, clamp of NaN/−0, omod, and the min/max/med3 NaN rules (hardware-only ops).
  • GFX10.1-only opcodes: v_mad_f32, v_mac_f32, v_madak_f32, v_madmk_f32 and v_mad_legacy_f32 exist only on GFX10.1 (gfx1010/1011/1013, the console's family). llvm-mc and AMD clang reject them for gfx1030 and GFX11, and the fused replacements round once, so they would be different instructions. The oracle skips them with a reason and never substitutes. Their unfused semantics cannot be measured on any RDNA2 desktop card either.
  • Known deviations: a hardware result that is already analysed and documented is counted separately, and only where the hardware word equals the documented alternative exactly. Today there is one: omod on −0, and only where omod is active in that MODE.
  • Negative control: --negative-control and --perturb NAME re-judge the same hardware words against six deliberately wrong models, for example an unfused FMA or the DX9 0·x rule removed. cancel and zero_inf probes make sure even the weak ones are caught at small sample sizes.
  • Assembler rejections: they get their own column. A non-zero count is a harness error (exit 2), so a driver or assembler that rejects whole op forms can't produce "0 mismatch".
  • Optional: without the tools, the run exits 77, the same as Tools: hardware oracle for salu_diff — run the fuzz programs natively on an AMD GPU; first finding fixes the s_bfe reference #1160 and Tools: hardware oracle for crosslane_fuzz — 24,000 cross-lane programs on real AMD hardware, wave32 and native wave64, 0 mismatches #1202.

Results: Radeon 880M (gfx1150, RDNA3.5), driver 26.11.2

46,967 programs (seeds 1–6): 0 mismatches where the model has an answer.

programs
match 30,577
mismatch 0
known deviation (omod −0) 57
skipped: GFX10.1-only opcode 5,417
not judged: denormal 5,903
not judged: clamp of NaN/−0, cube of NaN 5,013

"match" accepts any NaN for any NaN. Payload, sign and quiet bit are in the informational tables. The model includes the RDNA2 min/max/med3 NaN rules measured in #634, and they hold on gfx1150.

Finding: VOP3 omod and signed zero. mul:2, mul:4 and div:2 turn a −0 result into +0 on gfx1150, while the model and the translator keep −0. In translator,hw, 6 of 6 such programs follow the model. LLVM notes that omod mishandles signed zeros (SIFoldOperands.cpp), and D30209 describes −0 being forced to +0 before the modifier. RDNA2 is not measured, so this is likely a translator difference but not confirmed. It is not fixed in this PR.

Informational (gfx1150 only; RDNA2 is not measured):

  • omod is ignored with IEEE=1, and for ALU ops also with f32 denormals kept. LLVM's SIFoldOperands.cpp says the same about both cases.
  • With f32 denormals flushed, operands and results read as signed zero. With them kept, results are exact. v_rcp/rsq/sqrt/exp/log_f32 flush in both modes, as Coordinating who works on what (3) (moved to #1006) #634 measured on RDNA2. v_cmp_class_f32 classifies a denormal as a denormal in both modes.
  • Clamp of NaN gives +0 with DX10_CLAMP=1, and the NaN passes through with DX10_CLAMP=0. Clamp of −0 gives +0 in every mode.
  • With IEEE off an sNaN passes through unchanged; with IEEE on it is quieted. With several NaN operands, the first one wins. Invalid operations give 0xffc00000.

Tested

  • py -I tests/test_f32_fuzz.py (25 tests), tests/test_hw_oracle.py and f32_fuzz --self-test: green. Without hardware the hardware tests are skipped and the tool exits 77.
  • The table above comes from seeds 1–6 with 5,000 programs each plus probes, run before the last review-fix commit (ee84578a).
  • After that commit: --oracle hw --programs 400 --seed 31 --probes 12 --negative-control gave 0 mismatches, 1 known deviation and 0 assembler rejections, and caught all six perturbed models. --oracle translator,hw (1,500 programs, seed 3): 0 mismatches.

An independent review checked several things:

  • Counts: the categories sum to the total.
  • Known-deviation check: it is exact and narrowly scoped.
  • Readback: the MODE readback works.
  • Opcode claims: the GFX10.1-only claims hold with llvm-mc and AMD clang.
  • LLVM quotes: they say what is cited.

Its findings are fixed:

  • an assembler-rejection count;
  • omod wording made consistent and hedged;
  • citation precision;
  • the v_min_legacy_f32 claim;
  • the negative control at small sample sizes;
  • the NaN note.

AI-assisted (Claude Code).

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. (There is no translator change. The new row records the measurement.)

🤖 Generated with Claude Code

AlxcBTW and others added 4 commits November 22, 2026 09:55
Kernel(mode=...) writes the .amdhsa_ieee_mode / dx10_clamp / float_denorm_mode / float_round_mode
directives; valu_skip_reason lists the f32 opcodes GFX11 and gfx1030 do not have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runs the FUZZ-3 programs natively wave32 and judges the hardware against F32Model, with MODE
probes, known deviations, denormal/NaN/clamp/omod tables, probes and a negative control.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g, zero_inf probes

- own 'asm rej' column; any rejection outside the GFX11 table exits 2
- known deviation omod_neg_zero only where the omod was active
- omod wording/citations (SIFoldOperands.cpp, D30209), v_min_legacy_f32 is in no GFX10/11 part
- zero_inf probes so the DX9-multiply negative control is caught at small sizes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I confirmed the signed-zero finding for RDNA2 gfx1036 on ee84578afe692de535c1cab17253603cca2c2885. Windows AMD Radeon Graphics, driver 32.0.21045.16010, HIP 6 driver DLL. I used this PR's kernel generator and HIP launcher, built the gfx1036 code objects with LLVM MC and LLD 21.1.8, and compiled the unchanged launcher with MSVC. The oracle's independent lane-ID probes passed for wave32 and wave64. Every measured kernel also returned its own MODE and the two input words.

For v_mul_f32_e64 v8, v4, v5 with v4=−0 and v5=+1, wave32 and wave64 returned identical results:

MODE readback No modifier mul:2 mul:4 div:2
0x1c0 (flush), 0x0c0 (DX10_CLAMP off) 80000000 00000000 00000000 00000000
0x1f0 (denormals kept), 0x3c0 (IEEE on) 80000000 80000000 80000000 80000000

The independent ±1 controls scaled by the specified factors in the first two modes and stayed ±1 in the other two. Placement matters: with v4=0x80800000 (the smallest negative normal in magnitude), v5=+1 and div:2, MODE 0x1c0 returned 0x80000000 on both wave sizes. A zero already present before the modifier and a negative result flushed to zero after scaling therefore need distinct treatment. The matrix covered 192 kernels: two wave sizes × four modes × six inputs (±0, ±1, ±minimum normal) × four modifier settings.

I also drew a source-built translated pixel shader that exports the unmodified/mul:2/mul:4/div:2 results in RGBA, with quadrants containing +0, −0, +1 and −1. Against the measured 0x1c0 expectation, on RTX 5080 and on this Radeon the unmodified channel matched all 4,096 pixels, while each modified channel retained −0 in precisely the 1,024 negative-zero pixels. All other words matched. This covers v_mul_f32_e64 on gfx1036; the console's gfx1013 was not measured. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit e78f607 into ItsNotRexed:main Nov 22, 2026
11 checks passed
@bobcatchris

Copy link
Copy Markdown
Contributor

Tested ee84578 on CPU only (Windows 11; no AMD GPU, no AMD clang or HIP runtime here): pass as a code read, and the two PRs in tools/hw_oracle/asm.py merge and test clean together.

  • python -m pytest tests/test_f32_fuzz.py tests/test_hw_oracle.py -q → 33 passed, 4 skipped (8.9 s; the skips are the hardware cases).
  • Negative control: the same tests/test_f32_fuzz.py against origin/main's tools/f32_fuzz.py → 10 failed, 14 passed, 1 skipped (HardwareOracle::test_verdicts, test_negative_control_detects_each_perturbation, test_omod_deviation_needs_an_active_omod, test_zero_inf_probes_catch_a_plain_multiply, …), so the new tests exercise this PR.
  • Overlap with hw_oracle: run on RDNA4 (gfx12xx); an unknown architecture is unavailable, not a traceback #1228, which I also checked: git merge-tree --write-tree of the two heads is clean (no conflicts), and the merged tree runs test_f32_fuzz, test_hw_oracle, test_salu_diff, test_crosslane_fuzz → 71 passed, 5 skipped. The two changes are additive in different parts of asm.py (family/GFX12_REMOVED/kernel_text there, Kernel.mode/MODE_FIELDS/VALU_REMOVED here).

Code read: Kernel.mode rejects unknown MODE_FIELDS keys, raw_kernel_text emits the .amdhsa_* directives after system_vgpr_workitem_id, VALU_REMOVED removes the four mad opcodes everywhere except gfx101x with the "fused is a different instruction" reason rather than substituting one, and GFX11_VALU_RENAMED keeps the old mnemonic. That last point is the right call: silently mapping v_mad_f32 to v_fma_f32 would compare a different instruction and hide mismatches.

Not verified here: every hardware number in the description — the 46,967 programs, the 57 omod signed-zero programs and the zero_inf probes — and the doc rows in docs/shader_validation.md that rest on them. Those need an AMD card; I only ran the CPU half.

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.

4 participants