Skip to content

Translator: wave64 32-bit ops on one half of EXEC/VCC (FUZZ-8) - #663

Open
tunczzz wants to merge 3 commits into
ItsNotRexed:mainfrom
tunczzz:fuzz-8-masks
Open

tunczzz wants to merge 3 commits into
ItsNotRexed:mainfrom
tunczzz:fuzz-8-masks

Conversation

@tunczzz

@tunczzz tunczzz commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Item: FUZZ-8 finding, posted in #374: #374 (comment)

Depends on: #615 (stacked on it; only the last commit, eb89f82, is new here).
Overlaps #293 in three lines of dst() (the exec_lo destination). #293 already conflicts with main; whichever lands second keeps both: this adds a wave64-only case in front of that code.

Findings (fixed here)

Found by tools/cf_diff.py with new mask shapes, reduced:

  1. A register written to exec_lo changed all 64 lanes. v_cmp_gt_u32 vcc, 8, v1; s_and_b32 exec_lo, exec_lo, vcc_lo must leave lanes 32-63 alone, but dst() stored %active for every lane, so lanes 32-63 switched off. s_mov_b32 exec_lo, s0 did the same. Any op but s_mov_b32 into exec_hi was rejected (Unsupported: destination exec_hi). Now dst() writes exec_lo/exec_hi in wave64 through exec_half_write, the helper the constant moves and s_wqm already use.
  2. SCC of a 32-bit op on one half of a mask took the lane's own bit. s_and_b32 s50, vcc_hi, exec_hi; s_cbranch_scc0 must vote over lanes 32-63 only. scc_logic now uses scc_any_half in wave64, with the half taken from the sources (or from an EXEC/VCC destination). An SGPR destination's old half is ignored: the fuzzer hit one whose earlier contents were the low half of a 64-bit mask.

Cost guard: a program in which nothing reads SCC (s_cbranch_scc*, s_cselect, s_addc/s_subb, s_cmov*, an scc/src_scc operand) skips the vote in scc_logic, so --wave64-emulate doesn't pay an exchange (a round and a barrier) for an SCC nobody reads. That keeps test_wave64_emulate_reuses_a_mask_exchange at its counts. A program that reads SCC anywhere still votes.

Fuzzer

  • tools/cf_ref.py: every _b32 op is a 32-bit word op (exec_lo/hi, vcc_lo/hi, SGPRs), which is what the hardware does in both wave sizes. It also adds s_cmp_eq/lg_u64 and s_cselect_b64.
  • tools/cf_diff.py, new shapes: v_cmp_*_e64 into an SGPR mask feeding s_and_saveexec and v_cndmask_b32_e64; constant EXEC (s_mov_b32 exec_lo/exec_hi, literal); s_and_b32 on one EXEC half; SCC of half-mask ops; s_cmp of masks against 0; s_cselect between masks. Instruction sizes now count literals.
  • Before the fix: seed 80 gave 17 mismatches and 21 skips (destination exec_hi) in 600 cases, all wave64. After: 0 and 0. Another 2,000+ cases pass after rebasing, including 800 with --spirv-val.
  • tests/test_cf_diff.py: five half-mask regression cases in both forms. All 10 fail on the old translator.

GPU test

runtime/test/shaders/cs_w64_exec_half.asm is a wave64 dump (one wave64, 64 threads) registered in check.py and run_gpu_tests.py. Expected out[0..7] = 1 0 1 1 0 3 9 9. With the old translator, (A) gives out[2] = 0, (B) does not translate, and (C) gives out[5] = 7 and out[6] = 4. It needs a 64-wide subgroup or LEONIDA_W64_EMULATE=1; it builds and passes spirv-val both ways. Not run on a GPU by me (no Vulkan SDK here).

Tests

Ubuntu (WSL), llvm-mc 21, SPIRV-Tools 2026.1, on c432cdc: pytest tests --ignore=tests/semantic gives 1940 passed, 44 skipped, 1 xfailed; unittest discover -s tests/semantic OK. Not counted over the corpus (no copy of the game here).

AI-assisted (Claude Code). No game data.

🤖 Generated with Claude Code

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

tunczzz's cf_diff sweep already shows main's 43 mismatches go to 0 with this plus #615, and tests pass with main here (805). lgtm \o/ AI-assisted review (Claude Code).

@Pierre-Kookis

Copy link
Copy Markdown

GPU run of #663 (eb89f82), which asks for a 64-wide subgroup or LEONIDA_W64_EMULATE=1. I ran both, on one machine.

Setup: Windows 11. AMD Radeon Graphics (Ryzen 7 7800X3D iGPU, RDNA2), driver 32.0.21043.5001, native wave64 (subgroup 32..64). RTX 4070 Ti SUPER, driver 610.88, subgroup 32. Test programs from main c432cdc (llvm-mingw clang), llvm-mc 23.1.6.

cs_w64_exec_half cs_scc_mask32 suite
AMD native wave64 PASS 1 0 1 1 0 3 9 9 PASS 7 0 0 9 11 13 7 13 82/87, 5 skipped (mesh)
NVIDIA, no emulation SKIP (no 64-wide subgroup) PASS 60/87, 27 skipped
NVIDIA LEONIDA_W64_EMULATE=1 PASS 1 0 1 1 0 3 9 9 PASS 87/87

Native wave64 and emulated give the same words. tests/test_run_gpu_tests.py: 18 OK. python -m unittest discover -s tests/semantic: 805 OK. I didn't run tests/test_cf_diff.py because it imports pytest. GitHub now shows a conflict with main, so this run is from before any rebase.

(AI-assisted run, counts only.)

@matheuskshn

Copy link
Copy Markdown
Contributor

Ran python -I tools/cf_diff.py --programs 12 --seed 17 at eb89f82 on Windows 11 / Python 3.12.14. The structured campaign gave 24 passes across wave32 and wave64, 0 mismatches, 0 skips and 0 harness errors. This was CPU differential validation; the dedicated hardware coverage remains separate. AI-assisted.

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested eb89f82 on RTX 4090 (driver 621.14, 32-wide subgroups), Windows 11 26200: pass (32-wide half)

  • RelWithDebInfo Ninja build of runtime/ (MSVC, Vulkan SDK 1.4.363.0); ctest: 27/27
  • python -I scripts/run_gpu_tests.py: 60/87 passed, 27 skipped; with LEONIDA_W64_EMULATE=1: 87/87. main c432cdc on the same machine: 59/85 (26 skipped) and 85/85
    • cs_w64_exec_half: skipped without emulation (no 64-wide subgroup here), 1 0 1 1 0 3 9 9 with LEONIDA_W64_EMULATE=1
    • cs_scc_mask32: 7 0 0 9 11 13 7 13 in both modes
  • python -m unittest discover -s tests/semantic: 805 OK
  • python -m pytest tests --ignore=tests/semantic: 2029 passed, 5 skipped, 1 xfailed

This still needs a native wave64 (AMD) run. No game files used. AI-assisted run (Claude Code).

@realmalikov

Copy link
Copy Markdown

Tested #663 (eb89f82) on an NVIDIA GTX 1060 6GB (Pascal, subgroup 32..32, NVIDIA 582.78,
Windows 11 10.0.26200). No game files.

With LEONIDA_W64_EMULATE=1 (this device has no 64-wide subgroup, so native wave64 skips as expected):
cs_w64_exec_half (1 group x 64): 0 mismatches, out[0..7] = 1 0 1 1 0 3 9 9
cs_scc_mask32 (1 group x 64): 0 mismatches, out[0..7] = 7 0 0 9 11 13 7 13
AI-assisted.

…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>
tunczzz and others added 2 commits November 22, 2026 22:36
…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>
@tunczzz

tunczzz commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the rebased #615 (now a07e9e0b, on main aa2988cc). The translator change is the same. What the merge changed:

  • rdna2spirv.py: main now reads the wave size from the FSSM header. That code is kept, and g.reads_scc is set right after it.
  • cf_ref.py: main's new 32-bit mask path and its s_mov_b32 width check are kept; they read a _b32 op as a 32-bit word too, as this PR did. s_cselect_b64 and s_cmp_eq/lg_u64 are added next to them.
  • cf_diff.py: main's new saveexec shape and this PR's mask shapes are both generated.
  • tests/test_cf_ref.py: main expects s_cmp_eq_u64 s[0:1], s[2:3] to be rejected as unmodelled. This PR models it in wave64, so that case now checks wave32, where it is still rejected.
  • docs/design.md: the Wave64 and SCC rows now cite the cs_w64_exec_half results from this thread (native wave64 on a 7800X3D iGPU; emulated on an RTX 4070 Ti SUPER, 4090 and GTX 1060).

The GPU results above still apply. CPU, in WSL Ubuntu (Python 3.14, llvm-mc 21):

  • pytest tests --ignore=tests/semantic: 6434 passed, 1 failed. The failure is test_u16_high_half, which fails the same way on plain main.
  • cf_diff.py --programs 250 --seed 100: main gives 464 pass / 18 mismatch / 18 skipped; this branch gives 500 pass, 0 mismatch, 0 skipped.
  • seeds 101–104 at depth 4: 2,000 runs, structured and dispatch-loop, 0 mismatches.

AI-assisted (Claude Code).

@tunczzz

tunczzz commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Semantic suite on a07e9e0b: pytest tests/semantic fails only test_mutations (the v_mul_legacy_f32 anchor) and two test_cmp_class_f64::test_rejected_forms subtests. Plain main aa2988cc fails exactly those in the same WSL setup, so this PR adds no failures. AI-assisted (Claude Code).

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a07e9e0 on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran run_gpu_tests.py --filter for the two shaders this PR adds, plus pytest tests/test_cf_diff.py tests/test_run_gpu_tests.py (93 passed). Radeon (subgroup 32..64, native wave64): cs_w64_exec_half PASS (1 0 1 1 0 3 9 9) and cs_scc_mask32 PASS (7 0 0 9 11 13 7 13), 2/2. RTX 5080: cs_scc_mask32 PASS (same words); cs_w64_exec_half SKIP as designed (no 64-wide subgroup), and with LEONIDA_W64_EMULATE=1 it PASSES with 1 0 1 1 0 3 9 9. No game files.

AI-assisted.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested a07e9e0 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

No game files. AI-assisted.

@lunarminus

Copy link
Copy Markdown

Tested a07e9e0b merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • The merge is clean. The PR changes no C++/CMake, so the test programs are from a d0835dd9 build. llvm-mc 23.1.5.
  • python -I scripts/run_gpu_tests.py: 198/212 passed, 14 skipped without emulation, and 198/212 passed, 14 skipped with LEONIDA_W64_EMULATE=1.
    • d0835dd9 without the PR on the same machine gives 196/210 with 14 skipped in both modes.
    • Compared test by test (PASS/FAIL/SKIP and name), the only difference in either mode is the two new fixtures.
    • cs_w64_exec_half: PASS 1 0 1 1 0 3 9 9 in both modes. Without emulation this ran on a native 64-wide subgroup, so it adds a native wave64 run on RDNA3/RADV to the RDNA2/Windows runs above.
    • cs_scc_mask32: PASS 7 0 0 9 11 13 7 13 in both modes.
  • python -I runtime/test/shaders/check.py on the same work folders: 186 of 186 pass, 0 skipped, in both modes. Both new fixtures are ok.
  • pytest tests/test_cf_diff.py tests/test_cf_ref.py tests/test_run_gpu_tests.py: 119 passed, 110 subtests passed. pytest tests/test_translate.py: 585 passed, 4 skipped.
  • python -m unittest discover -s tests/semantic: 7456 tests, 7 failures and 2 errors.
    • They are in test_loop_ballot_barrier (emulate subtests), test_cmp_class_f64::test_rejected_forms and test_mutations (v_mul_legacy_f32).
    • Rerunning those three modules on d0835dd9 without the PR gives exactly the same failures, so the PR adds none.
  • tools/cf_diff.py --programs 250 --seed 100 (CPU):
    • This branch: 500 pass, 0 mismatch, 0 skipped.
    • The PR's cf_diff.py/cf_ref.py over the d0835dd9 translator: 458 pass, 21 mismatch, 21 skipped (destination exec_hi).

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

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

Review of the wave64 EXEC-half write path.

Comment thread tools/rdna2spirv.py
if a["k"] == "special" and a["t"] == "null":
return # result discarded
if a["k"] == "special" and a["t"] in ("exec_lo", "exec_hi") and self.wave64:
# One half of a wave64 EXEC: the lanes of the other half keep their state. Until 2026-11-22 a register

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.

[P2] Preserve scalar mask bits when writing EXEC halves

val is not always a per-lane mask. For example, s_mov_b32 exec_hi, s0 with scalar s0 = 1 (or an arithmetic SALU result of 1) means only bit 0 of EXEC_HI should be set. Every wave lane sees that same nonzero SGPR, so exec_half_write turns val != 0 into true for all 32 lanes in the selected half. Please distinguish scalar/constant mask words from lane-mask values and select the bit for each lane; the current fixture only exercises mask-shaped values.

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.

10 participants