Skip to content

tools: wint_diff.py, a whole-wave differential fuzzer for integer VALU under random EXEC - #2336

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:fuzz/wint-diff
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:fuzz/wint-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-WINT-DIFF (claim)

What and why

The repo's ALU fuzzers (shader_diff.py, salu_diff.py, the SDWA one in #2113) run one lane, so they never see which lanes an instruction writes or the lane masks that compares and carries make and read. A scratch whole-wave checker found #2206 (wave32 VCC holding data, read as a mask). This PR makes it a repo tool, tools/wint_diff.py, in the style of tools/salu_diff.py (stdlib only, python -I, --programs/--seed/--max-ops/--ops/--list-ops/--self-test, shrinking on mismatch, skips counted with reasons, exit 0/1/2/77):

  • Seeded programs that run on every lane of a wave32 or wave64 wave (--wave 32|64|both), with s_mov_b32 exec_lo/exec_hi between instructions (edge masks and random words).
  • Covered: VOPC e64 into s20/s21 (s[20:21]/s[22:23] in wave64) or VCC and e32 into VCC, v_cmpx into EXEC, v_cndmask_b32 e64/e32 on those masks, v_add/sub/subrev_co_u32 e64 and _co_ci_u32 e64/e32, v_mad_u64_u32/v_mad_i64_i32 with a mask carry-out, 16-bit e64/VOP3 ops with op_sel writing one half, plain data moved into an SGPR mask, and 23 32-bit VOP1/VOP2/VOP3 ops. Sources are VGPRs, SGPRs and inline constants within the GFX10 constant bus.
  • The reference is a per-lane model in the tool, written from the ISA pseudocode and sharing no code with the translator or cpu_ref.py. The translated side runs in tests/semantic/spirv_wave_interp.py. Every lane's four words are compared.
  • --oracle hw runs each program as one wave (32 or 64 threads) through tools/hw_oracle, each lane storing its own words.
  • Known divergences are left out by default and come back with --known: VCC written with data and read as a mask (rdna2spirv: wave32 VCC holding data, read as a lane mask, gives lane L bit L #2206 for wave32; wave64 is still open, see the Coordinating who works on what (9) (moved to #2078) #1902 finding), and a mask read as VALU data (Translator: a lane mask read as data gives the wave's bits (SHADER-21 part 1, #210) #293). The docstring lists what is modelled and these forms.

tests/test_wint_diff.py (18 tests): hand-worked reference values (carry out/in under EXEC, borrow, inactive lanes clearing mask bits, v_cmpx, both v_mad_*64 carries, 16-bit half writes, wave64 exec_hi and mask pairs, data in a mask SGPR), the translator on hand cases in both wave sizes, a short seeded run, generator coverage (every op in both wave sizes; known forms only with --known), canaries (a faked wrong lane is caught, shrinking keeps the guilty instruction), the hardware kernel shape and the exit codes including 77. docs/shader_validation.md gets a short section.

Tested

Windows 11, Python 3.

  • python -I tools/wint_diff.py --wave both --max-ops 10: seeds 1 and 100, 4000 programs each (half wave32, half wave64), 0 mismatch, 0 skipped.
  • --known --programs 500 --seed 1 --wave both: 128 mismatches from the two known forms (the shrunk first one is s_mov_b32 vcc_lo, 0xdeadbeef then a _co_ci carry-in from VCC; hand probes of s20/vcc_lo read as data give 0xffffffff per lane where the hardware has the wave's bits).
  • Hardware, --oracle hw on the AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, gfx1036, driver 26.10.1, HIP oracle), wave32 and wave64 natively, known forms included: --programs 500 with seeds 1 and 2 (1,000 programs), plus 1,340 programs with an earlier version of the generator (one of them --oracle translator,hw). 0 mismatch between the reference and the hardware on every lane. The NVIDIA RTX 5080 has no part here (CPU tool; the hardware oracle needs AMD).
  • Negative control: making the translator's carry-out mask ignore EXEC (OpLogicalAnd %bool {carry_nz} {self.active_b()} -> carry_nz only, tools/rdna2spirv.py in the _co_ branch) fails test_hand_cases_match_the_translator (lane 1 word 0 (v1): reference 0x00000000, translated 0x00000001) and gives a mismatch in a 400-program run. Reverted.
  • python -I tests/test_wint_diff.py (18 tests, about 3 s) OK, python -m compileall -q tools tests OK, tests/test_docs_links.py, test_docs_repo_paths.py, test_docs_list_items.py, test_tool_startup.py, test_tool_stdout_encoding.py OK.
  • No new translator divergence came out of these runs.

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

AI-assisted.

…U under random EXEC

Seeded integer VALU programs run on every lane of a wave32 or wave64 wave with EXEC rewritten between instructions: compares into SGPR masks and VCC, v_cmpx, v_cndmask on the masks, carry-out/carry-in forms, v_mad_u64/i64 with a mask carry-out, 16-bit op_sel half writes and 32-bit ops. A per-lane ISA model is compared with rdna2spirv run in tests/semantic/spirv_wave_interp.py, optionally with the hardware through tools/hw_oracle. Known divergences (VCC data read as a mask, ItsNotRexed#2206; a mask read as data, ItsNotRexed#293) only with --known.

AI-assisted.
@klarnet2009

Copy link
Copy Markdown
Contributor

Reviewed PR #2336 (b8f2567b).

Files read

  • docs/shader_validation.md (diff)
  • tools/wint_diff.py (lines 1-120)
  • tests/test_wint_diff.py (all 236 lines)

Checks run

  • py -3.12 -I tests/test_wint_diff.py -v: Ran 18 tests in 7.617s — OK (exit code 0)
  • py -3.12 -I tools/wint_diff.py --self-test: self-test: match True, hand values True, unsupported form skipped True (exit code 0)
  • py -3.12 -I -m compileall -q tools/wint_diff.py tests/test_wint_diff.py: exit code 0

Findings

Looks clean. All 18 unit tests (covering reference wave32/wave64 EXEC/mask/carry/16-bit semantics, generator coverage and --known gating, translator differential runs, shrinking, CLI exit codes, and hardware-oracle unavailability/kernel generation) and --self-test passed on CPU without GPU hardware.

@x2Tweek x2Tweek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review — PR #2336

Branch: head of PR #2336
Commit: bbf009f
Author: Vonsek
State: OPEN

What it does

Adds tools/wint_diff.py — a whole-wave differential fuzzer for integer VALU under random EXEC (FUZZ differential testing). Seeded integer VALU programs run on every lane of a wave32/wave64 wave with EXEC rewritten between instructions (compares into SGPR masks and VCC, v_cmpx, v_cndmask on masks, carry-out/carry-in forms, v_mad_u64/i64 with mask carry-out, 16-bit op_sel half writes, 32-bit ops). A per-lane ISA model is compared with rdna2spirv run in tests/semantic/spirv_wave_interp.py, optionally with hardware via tools/hw_oracle. Known divergences (VCC data read as a mask #2206; a mask read as data #293) only with --known.

Also adds tests/test_wint_diff.py (reference oracle against hand-worked values, seeded fuzz canaries) and a doc row in docs/shader_validation.md.

Coverage

New tests:

  • Reference.test_carry_out_and_in_under_exec — v_add_co_u32/v_add_co_ci_u32 under partial EXEC, carry propagation, inactive lanes untouched.
  • Reference.test_borrow — v_sub_co_ci_u32 borrow chains under EXEC.
  • Reference.test_inactive_lanes_get_a_zero_mask_bit — compare producing mask clears inactive lanes.
  • Reference.test_cmpx_writes_exec — v_cmpx writes EXEC, subsequent ops respect it.
  • Reference.test_mad64_carry — v_mad_u64_u32/v_mad_i64_i32 carry-out under mask.
  • Reference.test_16bit_writes_one_half — 16-bit op_sel half writes.
  • Reference.test_wave64_exec_hi_and_pairs — wave64 exec_hi, SGPR pairs.
  • Plus CLI canary tests (test_ops_normalization, unknown/empty ops, self-test).

No translator/runtime changes — the fuzzer compares the ISA model against rdna2spirv output, so mismatches would surface translator bugs. No game data; synthetic seeded programs only. Standard library only.

Code review

The fuzzer is well-architected:

  • Whole-wave model with per-lane VGPRs, SGPRs, VCC, and EXEC mask (lo/hi for wave64).
  • EXEC rewritten between instructions via compares, matching real shader control flow.
  • Known-divergence handling via --known flag (documents open hardware questions without failing the run).
  • Hardware oracle optional via --oracle hw for validation on real RDNA2.
  • Tests use hand-worked expected values, not circular reasoning.

The test file is focused (18 tests, 3 subtests) and covers carry chains, EXEC masking, cmpx, mad64 carry, 16-bit half writes, and wave64 pairs.

Test results

  • tests/test_wint_diff.py: 18 passed, 3 subtests (2.52s)
  • python -m compileall: clean on both changed files

Reviewer recommendation

Approve (CPU tests). Adds a whole-wave integer VALU differential fuzzer with EXEC masking, carry chains, mad64, 16-bit op_sel, and wave64 support, plus reference tests and doc row. All 18 tests / 3 subtests pass; compileall is clean.

AI-assisted. CPU tests only.

@ItsNotRexed
ItsNotRexed merged commit c4ccf4b into ItsNotRexed:main Nov 22, 2026
8 of 10 checks passed
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