Skip to content

cf_diff: mask reads (s_bcnt1/s_ff1, v_readfirstlane waterfall) and vote-driven loops in the FUZZ-8 fuzzer - #4077

Open
tunczzz wants to merge 5 commits into
ItsNotRexed:mainfrom
tunczzz:fuzz-8-mread
Open

tunczzz wants to merge 5 commits into
ItsNotRexed:mainfrom
tunczzz:fuzz-8-mread

Conversation

@tunczzz

@tunczzz tunczzz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #3918 (comment) (FUZZ-8 follow-up).

Depends on: #663 (and through it #615). The first three commits here are those PRs; review the last two.

What

Two commits that extend tools/cf_diff.py (FUZZ-8) to translator rules it didn't reach. Fuzzer and reference only; no translator change.

cf_diff: vote-driven loops and wrexec (was on my fork without a PR)

  • vccloop: per-lane trip counts, back edge s_cbranch_vccnz (the wave goes round while any lane wants to).
  • cmpxloop: v_cmpx drops finished lanes, back edge s_cbranch_execnz.

cf_diff: scalar reads of a whole lane mask

  • mread: s_bcnt1 / s_ff1 of EXEC, VCC or an SGPR compare mask into a uniform SGPR (wave64: _b64, or _b32 on one half), added to every active lane, optionally followed by s_cmp on it and an SCC branch.
  • waterfall: v_readfirstlane of a lane value → v_cmp_eq → s_and_saveexec → body → s_xor exec, closed by s_cbranch_execnz or by the SCC of the s_xor. This is the loop compilers emit to pick a descriptor per group of lanes.
  • cf_ref models v_readfirstlane_b32 (lowest active lane, or lane 0 when none is active), s_bcnt1_i32_b32/b64 (SCC = count ≠ 0) and s_ff1_i32_b32/b64 (-1 when no bit is set). A _b32 form reads one 32-bit word, which in wave64 is one half of the mask.

Single-op cross-lane semantics stay with #3592 (wave_diff.py). These shapes test the ops where they decide control flow.

Sensitivity

With two old bugs put back by hand (not committed), seed 3 (--programs 60, 120 runs):

  • v_readfirstlane read per lane (the translation before 2026-11-21): 5 mismatches;
  • s_bcnt1 of a mask counting the lane's own bit: 4 mismatches.

Tested

  • CPU campaigns with the new shapes, seeds 201–206: depth 4 structured (150 programs) and depth 3 --dispatch-loop (120 programs), wave32 and wave64: 0 mismatches. The only skips were waterfalls over v8 (one value per lane, 64 rounds) nested in other loops, which ran past the wave interpreter's 2M-step limit. With a 20M limit they match in both forms. The generator now takes waterfall values from v1/v2/v3 (8 or 16 distinct values), and the reruns are clean.
  • New tests: tests/test_cf_diff.py::test_mask_reads / test_wave64_mask_reads (both forms, both waves) and tests/test_cf_ref.py::MaskReadTests (exact counts, first lanes and readfirstlane values in wave32 and wave64).
  • tests/test_cf_ref.py: main expects s_andn1_wrexec_b32 to be rejected as unmodelled. The loops commit models the wrexec family (ISA SOP1: EXEC = ~S0 & EXEC or S0 & ~EXEC, D = the new EXEC, SCC = EXEC != 0, the same as the docs/design.md row), so that case now uses s_quadmask_b32, which is still unmodelled.
  • In WSL Ubuntu (Python 3.14, llvm-mc 21): pytest tests/test_cf_diff.py tests/test_cf_ref.py tests/test_cf_ref_edge_fixes.py gives 118 passed. The rest of the suite is the same as on Translator: wave64 32-bit ops on one half of EXEC/VCC (FUZZ-8) #663, where pytest tests --ignore=tests/semantic gives 6434 passed and 1 failed (test_u16_high_half, which fails the same way on plain main).

No GPU test: this PR changes only the CPU fuzzer and its reference. My GPU is an RTX 5070 Ti, but this PC has no Vulkan SDK.

AI-assisted (Claude Code). No game files were used.

Notes

tunczzz and others added 5 commits November 22, 2026 22:36
…low-up to ItsNotRexed#477)

s_not_b32 has its own handler and still set SCC from the lane's own bit
after ItsNotRexed#477 moved the SOP2 forms to the wave vote. It now goes through
scc_logic too (one or two sources). Reported by @kotorvr in ItsNotRexed#477.

- tools/cf_ref.py models s_not_b32/b64; tools/cf_diff.py generates s_not
  in the sccmask/csel shapes; tests/test_cf_diff.py has the two s_not
  regression cases (and they fail with the old per-lane SCC).
- runtime/test/shaders/cs_scc_mask32.asm: @kotorvr's compute test for
  s_and + s_cselect, s_andn2 + s_cbranch_scc1, s_not, s_or, s_xnor,
  registered as a wave32 dump in check.py and run_gpu_tests.py.
- docs/design.md: s_not_b32 in the rule, the ItsNotRexed#477 GPU results and
  @kotorvr's corpus count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es, as main's new rule)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two wave64 findings of tools/cf_diff.py with new mask shapes:

- A register written to exec_lo (s_and_b32 exec_lo, exec_lo, vcc_lo;
  s_mov_b32 exec_lo, s0) set all 64 lanes, and any op but s_mov_b32
  into exec_hi was rejected ("destination exec_hi"). dst() now writes
  one half through exec_half_write; the other half keeps its lanes.
- The SCC of a 32-bit op on one half of a mask (vcc_lo/hi, exec_lo/hi,
  a half-mask SGPR) took the lane's own bit. scc_logic now votes over
  that half (scc_any_half). The half comes from the sources, or from an
  EXEC/VCC destination; an SGPR destination's old half is ignored.

A program with no SCC reader (s_cbranch_scc*, s_cselect, s_addc/subb,
s_cmov*, an scc operand) skips the vote, so --wave64-emulate does not
pay an exchange for an SCC nobody reads (keeps
test_wave64_emulate_reuses_a_mask_exchange at its counts).

Fuzzer: cf_ref treats every _b32 op as a 32-bit word op (halves
included) and models s_cmp_eq/lg_u64 and s_cselect_b64; cf_diff adds
e64 compares into SGPR masks (saveexec, v_cndmask), constant EXEC,
half-EXEC ops, half-mask SCC, s_cmp on masks and s_cselect between
masks, and counts literals in instruction sizes. GPU test
cs_w64_exec_half (wave64 dump; expected 1 0 1 1 0 3 9 9).

Depends on: ItsNotRexed#615

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two loop shapes: per-lane trip counts closed by s_cbranch_vccnz (the
wave loops while any lane wants to, EXEC unchanged), and loops that drop
finished lanes with v_cmpx and close on s_cbranch_execnz. cf_ref models
s_andn1/andn2_wrexec (EXEC = ~S0 & EXEC / S0 & ~EXEC, D = EXEC, SCC).

No new findings: 2,600 cases with the loop shapes (structured, dispatch
loop, depth 4) and s_andn2_wrexec in both wave sizes and forms match.
s_andn1_wrexec and the xor/orn2/nand/nor/xnor/andn1/orn1 saveexec forms
are not translated (Unsupported); every corpus shader translates, so the
game does not use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two new program shapes cover translator rules the fuzzer did not reach:

- mread: s_bcnt1 / s_ff1 of EXEC, VCC or an SGPR compare mask into a
  uniform SGPR (wave64: _b64, or _b32 on one half), added to every
  active lane, optionally followed by s_cmp on it and a branch.
- waterfall: v_readfirstlane of a lane value -> v_cmp_eq ->
  s_and_saveexec -> body -> s_xor exec, closed by s_cbranch_execnz or
  by the SCC of the s_xor (the descriptor-per-group-of-lanes loop).

cf_ref models v_readfirstlane_b32 (lowest active lane, lane 0 when
none), s_bcnt1_i32_b32/b64 (SCC = count != 0) and s_ff1_i32_b32/b64
(-1 when no bit is set); a _b32 form reads one 32-bit word, one half of
the mask in wave64.

Both shapes are sensitive: with v_readfirstlane read per lane (the
pre-2026-11-21 translation) or s_bcnt1 counting the lane's own bit,
seed 3 gives 5 and 4 mismatches of 120. Waterfalls take v1/v2/v3
(8 or 16 distinct values); v8 (one value per lane) nested inside other
loops ran past the wave interpreter's step limit.

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

@Kam471 Kam471 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.

Ran this at d3240b25 on Windows 11: pytest tests/test_cf_diff.py tests/test_cf_ref.py tests/test_run_gpu_tests.py -q -> 153 passed, 110 subtests passed; compileall (cf_diff/cf_ref/rdna2spirv) and git diff --check clean.

The new coverage is in the fuzzer/reference only: scalar mask reads (s_bcnt1/s_ff1, v_readfirstlane waterfall) and vote-driven loops/wrexec produce the same reference as the interpreted SPIR-V, with the existing program suite unchanged. The branch carries #663/#615's commits; only its last commits are new, as the description says. No blocking issue.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested d3240b2 on Windows 11, AMD Radeon iGPU gfx1036 (RDNA2, driver 26.10.1, subgroup 32..64) and RTX 5080 (driver 616.92, subgroup 32), translator and runtime from this head (MSVC, RelWithDebInfo), LEONIDA_VK_DEVICE set per run with the device line confirmed, VK_LOADER_LAYERS_DISABLE=~implicit~ (no validation layer installed):

  • run_gpu_tests.py --filter cs_scc_mask32: pass on both, 7 0 0 9 11 13 7 13.
  • run_gpu_tests.py --filter cs_w64_exec_half: Radeon pass at native wave64, 1 0 1 1 0 3 9 9; RTX 5080 skipped (no 64-wide compute subgroup).
  • pytest tests/test_cf_diff.py tests/test_cf_ref.py tests/test_cf_ref_edge_fixes.py tests/test_run_gpu_tests.py (Windows, Python 3.12): 158 passed, 117 subtests passed.

No negative control run.

AI-assisted.

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested d3240b2 on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036, RDNA2), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

No game files. AI-assisted.

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