Skip to content

rdna2spirv: every saveexec kind and s_andn1_wrexec - #1657

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
LouisRiverstone:salu-saveexec-variants
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
LouisRiverstone:salu-saveexec-variants

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

Only s_and/or/andn2_saveexec_b32/b64 and s_andn2_wrexec_b32/b64 were translated. The other saveexec kinds (xor, andn1, orn1, orn2, nand, nor, xnor) and s_andn1_wrexec raised Unsupported; #1562's ISA coverage lists them as unknown. s_xor_saveexec is the one LLVM's SI_ELSE lowering uses.

Change: one table, Gen.EXEC_LOGIC, gives f(S0, EXEC) for the whole family as (op, NOT S0, NOT EXEC, NOT result).

  • saveexec: D = EXEC; EXEC = f(S0, EXEC); SCC = (EXEC != 0)
  • wrexec: EXEC = f(S0, EXEC); D = EXEC
  • The definitions are those of tools/cf_ref.py _SAVEEXEC, the FUZZ-8 ISA model. andn1 complements S0 and andn2 complements EXEC.
  • Each invocation holds its own lane's bit (0 or ~0), so f is the bitwise op on that bit. A lane EXEC had off becomes active when f gives 1 for it, as on hardware (nand, nor, orn1, orn2, xnor, ...). SCC is the wave vote, as before.
  • The three existing kinds emit the same code as before.

Tests:

  • tests/semantic/test_saveexec_variants.py runs translated pixel shaders in spirv_wave_interp. EXEC starts partial (v_cmpx) and S0 is a different lane range. Every lane's saved bit, new EXEC bit and SCC are checked against cf_ref._SAVEEXEC:
    • all ten saveexec kinds in wave32 (3 layouts, one with an empty result) and wave64 (2 layouts)
    • both wrexec kinds
  • Without the change the file fails (38 errors); with it, 3/3 pass.
  • python -I tools/cf_diff.py --self-test passes, and --programs 300 --seed 7 --wave both gives 600 pass, 0 mismatch.
  • python -I -m unittest discover -s tests/semantic: 1341 tests OK (2 skipped).

docs/design.md: new row after "EXEC".

This doesn't touch the existing tests for the and/or/andn2 kinds (#1299, #1326, @Vonsek's GPU test claim), or #663. Tested on CPU only; no GPU run for the seven new kinds. No game files.

AI-assisted (Claude Code): I reviewed and ran the change and the tests.

Only and/or/andn2_saveexec and andn2_wrexec were translated; xor, andn1,
orn1, orn2, nand, nor and xnor_saveexec (b32/b64) and andn1_wrexec were
rejected. One table (Gen.EXEC_LOGIC, the definitions of tools/cf_ref.py
_SAVEEXEC) now gives f(S0, EXEC) for the whole family; the existing three
kinds emit the same code as before.

tests/semantic/test_saveexec_variants.py checks every lane's saved bit,
new EXEC and SCC against cf_ref._SAVEEXEC in wave32 and wave64; cf_diff
(300 programs x wave32/64) still passes. docs/design.md row added.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 6cfcf7c on NVIDIA GeForce RTX 5080 (616.92) and AMD Radeon RDNA2 iGPU (26.10.1), Windows 11: pass

I ran all seven new saveexec kinds (xor, andn1, orn1, orn2, nand, nor, xnor) and s_andn1_wrexec on the GPU with two ad-hoc compute shaders that are not in the tree, cs_w32_saveexec_kinds.asm (_b32) and cs_w64x_saveexec_kinds.asm (_b64). Both went through scripts/run_gpu_tests.py (llvm-mc, then rdna2spirv.py, all pass spirv-val) and ran with vk_compute_test ... 1 dump and VKC_DUMP.

run device result
wave32 (VKC_SUBGROUP_SIZE=32) RTX 5080 16/16 cases exact
wave32 (VKC_SUBGROUP_SIZE=32) Radeon 16/16 cases exact
wave64 native (--require-wave64, subgroup 64 confirmed) Radeon 16/16 cases exact
wave64 emulated (LEONIDA_W64_EMULATE=1) RTX 5080 16/16 cases exact

What the shaders do. For each case, S0 comes from a v_cmp_ne_u32_e64 with all lanes on: the lane tests bit lane & 31 of a constant, and in wave64 the constant is different for each half. Old EXEC is then set with s_mov_b32 exec_lo (and exec_hi), the op runs (D in s20 / s[20:21]), and s_cselect takes SCC right away. Lanes under the new EXEC set bit 0 of a VGPR. With EXEC back to all lanes, bit 1 = D's lane bit (v_cndmask_b32_e64 on D) and bit 2 = SCC. Every lane stores its word to out[case*wave + lane]. A small script packs bits 0 and 1 back into EXEC and D masks, checks that SCC is the same in every lane, and compares all three with constants derived by hand from the ISA (andn1 = ~S0 & EXEC, orn1 = ~S0 | EXEC, orn2 = S0 | ~EXEC, nand/nor/xnor = the negated and/or/xor; D = old EXEC for saveexec and the new EXEC for wrexec; SCC = EXEC != 0).

Main pattern: low 32 lanes S0 = 0x00ff0f0f, EXEC = 0x0f0f00ff. In each 16-lane half, the four 4-lane groups cover all four (S0, EXEC) combinations, in a different order in the two halves. In wave64 the high half has S0 = 0x3c3c00ff, EXEC = 0x0ff0f00f, so every result's high word differs from its low word and a swapped or truncated half would show. Expected = got in every run:

op new EXEC (hi_lo for b64) D SCC
s_xor_saveexec 33ccf0f0_0ff00ff0 old EXEC 0ff0f00f_0f0f00ff 1
s_andn1_saveexec 03c0f000_0f0000f0 old EXEC 1
s_orn1_saveexec cff3ff0f_ff0ff0ff old EXEC 1
s_orn2_saveexec fc3f0fff_f0ffff0f old EXEC 1
s_nand_saveexec f3cffff0_fff0fff0 old EXEC 1
s_nor_saveexec c0030f00_f000f000 old EXEC 1
s_xnor_saveexec cc330f0f_f00ff00f old EXEC 1
s_andn1_wrexec 03c0f000_0f0000f0 new EXEC 03c0f000_0f0000f0 1

The _b32 runs use the low word only. orn1, orn2, nand, nor and xnor turn on lanes that were off in the old EXEC, and those lanes did execute the following VALU write on both GPUs.

Each op also has a second case whose result is empty, so SCC must be 0: xor and andn1 with S0 = EXEC = the pattern, nor and xnor with EXEC = ~S0, nand with both all ones, orn1 with S0 = all and EXEC = 0, orn2 with S0 = 0 and EXEC = all, and andn1_wrexec with S0 = EXEC (D = 0). In every run all eight gave EXEC 0, SCC 0, and D equal to the old EXEC (or 0 for wrexec).

Negative control: I changed orn2 in Gen.EXEC_LOGIC to complement S0 instead of EXEC. The wave32 run on the 5080 then failed both orn2 cases (EXEC ff0ff0ff instead of f0ffff0f, and SCC 1 instead of 0 in the empty case). I reverted the change afterwards.

The shaders are about 290 and 320 lines (16 cases each), too long to paste here. If you want them as GPU fixtures in this PR or a follow-up, I can post them or open a small PR that registers them in run_gpu_tests.py. They would need a dump of more than 8 words (VKC_OUT_WORDS / VKC_DUMP) or a split into 8-word dumps.

AI-assisted.

@Doorriiaann

Copy link
Copy Markdown

Tested 6cfcf7c on NVIDIA GeForce RTX 3070 (Ampere, subgroup 32..32), driver 610.57.04 (Vulkan 1.4.341), Debian 13 (kernel 6.12.115): pass, no regression. Adds Linux and a negative control to @Vonsek's GPU run above.

Base is main 41f4482; llvm-mc 21.1.8, SPIRV-Tools v2025.5, GCC 14.2.0.

main 41f4482 this PR
tests/semantic/test_saveexec_variants.py 38 errors (21 test_saveexec_wave32, 14 test_saveexec_wave64, 3 test_wrexec) 3 tests OK
python -I -m unittest discover -s tests/semantic 1338 tests OK 1341 tests OK
scripts/run_gpu_tests.py 115/145 passed, 30 skipped (wave64) 115/145 passed, 30 skipped (wave64)
LEONIDA_W64_EMULATE=1 scripts/run_gpu_tests.py 145/145 passed 145/145 passed

AI-assisted: yes

@ItsNotRexed
ItsNotRexed merged commit f30fd95 into ItsNotRexed:main Nov 22, 2026
3 of 4 checks passed
@Spaghetih

Copy link
Copy Markdown
Contributor

Tested 6cfcf7ca on NVIDIA GeForce RTX 4070 Ti, driver 621.24, Windows 11 (Vulkan SDK 1.4.363, llvm-mc 21.1.8 in WSL). Corpus: my own 1.0.2.1 package, 26,503 disassembled shaders; only counts are reported. Pass, with one thing a reviewer may want to know.

  • python -m unittest discover -s tests/semantic: 1,341 tests OK.
  • scripts/run_gpu_tests.py: 150 shaders translated, all pass spirv-val; 115/145 passed, 30 skipped, 0 failed (older base than today's main).
  • Corpus: 18,001 of 26,503 shaders use an s_*_saveexec_* or s_andn1_wrexec. On a seeded sample of 400, main and this branch both translate 400/400, and all pass spirv-val. The SPIR-V differs in 376 of the 400. In two of them that I diffed, almost every changed line is id renumbering. The net effect is 760 fewer lines in each (fewer OpIAdd/OpIEqual/OpSelect/OpUConvert), which fits a shorter saveexec lowering. So the change reaches most of the game's shaders. They stay valid, but I haven't run those shaders or compared their results.

AI-assisted (Claude Code).

LouisRiverstone added a commit to LouisRiverstone/Leonida that referenced this pull request Nov 22, 2026
…xed#1657

s_xor/andn1/orn1/orn2/nand/nor/xnor_saveexec_b32 and s_andn1_wrexec_b32
were merged with CPU checks only. cs_w32_saveexec_ext.asm runs each with
EXEC = lanes 0..23 and S0 = lanes 10..29 (from compares) and stores
(s_bcnt1 << 8) | s_ff1 of the new EXEC, a whole-wave word. It is a wave32
lane-mask dump (WAVE32_LANE_DUMPS), skipped below 32 lanes.

tests/semantic/test_saveexec_ext_fixture.py runs the fixture on the CPU
against tools/cf_ref.py's _SAVEEXEC and checks both runners expect the
same words.
@Spaghetih

Copy link
Copy Markdown
Contributor

Correction to my note above: like on #1640, I compared this branch with main at a0acd33d rather than with its base. So the 376/400 and the two diffs came from other translator commits, not from this PR.

Rerun on the same seeded 400 (from the 18,001 corpus shaders with an s_*_saveexec_* or s_andn1_wrexec), base 41f44826 vs 6cfcf7ca: both translate 400/400, all pass spirv-val, and the SPIR-V is identical in 400 of 400. So in this sample the new saveexec kinds and s_andn1_wrexec don't change any shipped shader. The test results above stand. Sorry for the noise.

AI-assisted (Claude Code).

LouisRiverstone added a commit to LouisRiverstone/Leonida that referenced this pull request Nov 22, 2026
…xed#1657

s_xor/andn1/orn1/orn2/nand/nor/xnor_saveexec_b32 and s_andn1_wrexec_b32
were merged with CPU checks only. cs_w32_saveexec_ext.asm runs each with
EXEC = lanes 0..23 and S0 = lanes 10..29 (from compares) and stores
(s_bcnt1 << 8) | s_ff1 of the new EXEC, a whole-wave word. It is a wave32
lane-mask dump (WAVE32_LANE_DUMPS), skipped below 32 lanes.

tests/semantic/test_saveexec_ext_fixture.py runs the fixture on the CPU
against tools/cf_ref.py's _SAVEEXEC and checks both runners expect the
same words.
LouisRiverstone added a commit to LouisRiverstone/Leonida that referenced this pull request Nov 22, 2026
…xed#1657

s_xor/andn1/orn1/orn2/nand/nor/xnor_saveexec_b32 and s_andn1_wrexec_b32
were merged with CPU checks only. cs_w32_saveexec_ext.asm runs each with
EXEC = lanes 0..23 and S0 = lanes 10..29 (from compares) and stores
(s_bcnt1 << 8) | s_ff1 of the new EXEC, a whole-wave word. It is a wave32
lane-mask dump (WAVE32_LANE_DUMPS), skipped below 32 lanes.

tests/semantic/test_saveexec_ext_fixture.py runs the fixture on the CPU
against tools/cf_ref.py's _SAVEEXEC and checks both runners expect the
same words.
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.

5 participants