Skip to content

wave64_halves: a VALU mask destination printed as one SGPR is the SGPR pair (new SHADER item) - #4794

Open
shdann wants to merge 3 commits into
ItsNotRexed:mainfrom
shdann:wave64-halves-sdst-pair
Open

shdann wants to merge 3 commits into
ItsNotRexed:mainfrom
shdann:wave64-halves-sdst-pair

Conversation

@shdann

@shdann shdann commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new SHADER item (claim)

Depends on: #2231

This branch is main 98fa503f with #2231 (8276a25c) merged in, and one commit on top (cdea51c1). #2231 conflicts with main in three files at this time; the merge commit 7aacc969 has my resolution (see "The merge of #2231"). The change of this pull request is the last commit only: tools/wave64_halves.py, one new test file, one sentence in docs/design.md and one in tests/semantic/README.md.

What and why

The corpus listings are disassembled for wave32. Thus the 64-bit mask destination of a wave64 v_cmp_*_e64 or carry-out prints as one register: v_cmp_gt_f32_e64 s0, ... writes s[0:1]. #2231 found this (284,353 compares in 18,866 wave64 shaders) and corrects the translator and tools/lane_masks.py.

tools/wave64_halves.py has the same defect in its own operand table, and #2231 does not change that file. operands() takes the destination as s0 only. Then s1 keeps what the analysis knew about its old value:

  • its taint (a lane count, a first-lane copy, ...),
  • its tag,
  • its reaching definitions (for the stale-scalar check).

A later 64-bit read of s[0:1] as a mask (s_and_saveexec_b64, s_and_b64, ...) gets that old state, and an exact shader is tier C tainted-exec or stale-scalar.

The census of #4686 shows the size of the problem. @Kev-Ball ran --census --why on the corpus at a head without #2231. The largest rows are a vcc_branch whose producer is a SALU instruction and whose sources are a v_cmp and one more writer (s_load, input, salu): that is a 64-bit mask instruction on a pair whose low register a v_cmp wrote and whose high register still has an older value. A hand-written listing in the one-register spelling gives these same lines at main, and the pair spelling of the same listing is tier A (details in my comment on #4686). About 3,700 of the 8,245 first reasons have a source of that form. #2231 removes the main part (the pair becomes a mask for lane_masks). This pull request removes the part that stays in the tier analysis after #2231.

The change. operands() widens the mask destination with lane_masks.mask_sdst(a, True) (the helper of #2231; this module analyses wave64 programs only):

  • a v_cmp* with an SGPR destination (not v_cmpx, not the VCC form);
  • the carry-out of the VOP3b instructions (v_*_co_*, v_mad_u64_u32, v_mad_i64_i32, v_div_scale_*), the same list that lane_masks.py has.

A pair that the listing prints as a pair is not changed. Other one-register SGPR destinations (v_readfirstlane_b32, SALU, scalar loads) are not changed.

Why it is exact. The hardware writes the two registers (#2231: the listings are made without +wavefrontsize64; its GPU test cs_w64_sdst_pair passes on native wave64 devices). After the instruction, the two registers hold the new mask, so the old state of the high register cannot reach a later read. The change only makes the analysis of the one-register spelling equal to the analysis of the pair spelling, which was already there.

Tested

Head cdea51c1. Windows 11 Pro (10.0.26200), Python 3.14.7, CPU only. No GPU. No llvm-mc and no SPIRV-Tools on this machine, so I did not build the GPU fixtures and I did not run spirv-val. No game files.

New test file tests/semantic/test_wave64_halves_sdst_pair.py (9 tests). Each program is a hand-written vertex shader, written in the one-register spelling and in the pair spelling. It is translated and run on spirv_wave_interp.py as one 64-lane wave and as two 32-lane waves.

Program Tier, two spellings 64 lanes against 2 x 32 lanes
the high register held s_bcnt1_i32_b64 of EXEC before the compare A equal, 1 for lanes 21 to 63
the high register held v_readfirstlane_b32 of a varying value A equal
the high register was set in a skip region (two reaching definitions, one behind a vote) A equal
a carry-out (v_add_co_u32_e64 v9, s14, ...) after a lane count in the high register A equal, 1 for lanes 16 to 63
the census shapes under a narrowed EXEC: s_and_b64 vcc, exec, s[14:15] and a vote; two compares ANDed; the compare into s_and_saveexec_b64 A equal
near miss: a compare of the lane id C tainted-exec different (lanes 32 to 52)
near miss: the compare is behind a vote and the pair is read after the join C tainted-exec different (lanes 32 to 63)
near miss: the high register read as data after the compare C cross-lane tier only
operands() unit checks: which destinations become pairs and which do not

Negative control: with wave64_halves.py of the merge commit (main and #2231, without this change), 5 of the 9 tests fail: the first four rows are tier C tainted-exec in the one-register spelling, and the unit check fails. The census shapes (row five) are tier A there already; they pin the effect of #2231 on the tier.

Check Result
tests/semantic/test_wave64_halves.py, test_wave64_halves_soundness.py, test_w64_sdst_pair.py (of #2231) 101, 30 and 3 tests, pass
python -I -m unittest discover -s tests/semantic 6,257 tests, 3 failures and 3 errors: test_loop_ballot_barrier (5) and test_vcmp16_opsel (1). These are the same 6 tests, by name, that fail on this machine on main (measured at 2d3369a4, 6,245 tests); none of them is in a file that this pull request or #2231 changes
pytest on tests/test_wave64_halves_fixtures.py, test_lane_masks.py, the docs row tests, test_semantic_translator_use.py, test_text_write_line_endings.py, test_resource_hygiene.py 42 passed, 1 skipped (it needs llvm-mc)
python -I -m compileall -q tools tests, git diff --check, scripts/check_no_game_data.py pass

The merge of #2231

git merge of 8276a25c into main 98fa503f has three conflicts. My resolutions, for the author of #2231 if they are useful:

After the merge, tests/semantic/test_w64_sdst_pair.py (3 tests), tests/test_lane_masks.py and the docs row tests pass.

Not measured: the corpus

I have no copy of the game. @Kev-Ball, or any person with their own copy: please run the tier census three times, counts only, on indexes translated at

  1. main 98fa503f,
  2. the merge commit 7aacc969 (main and Translator: a wave64 VALU mask SDST printed as one SGPR is the SGPR pair #2231),
  3. this head cdea51c1,

with python -I tools/wave64_halves.py --census <spirv>/index.json. The difference between 1 and 2 is the effect of #2231 on the tiers; the difference between 2 and 3 is the effect of this pull request. If #4686 is in your tree, --wave64-why and --census --why on 2 and 3 show what stays.

Limits

Overlap

AI-assisted: yes (Claude Code). It wrote the change and ran all the checks above on this machine.

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.

🤖 Generated with Claude Code

simonbronk and others added 3 commits November 22, 2026 22:04
The corpus is disassembled for gfx1013 without +wavefrontsize64, so the 64-bit
SDST of a wave64 v_cmp_*_e64 or carry-out prints as one register
(v_cmp_gt_f32_e64 s0, ...) while the wave writes s[0:1]. lane_masks.py took it
as s0 alone, so s1 was unknown and a later s_and_b64 / s_or_b64 of two compare
results took the 64-bit data path: SCC was each lane's own bit instead of the
wave's vote, and s_bcnt1_i32_b64 of it counted data bits.

lane_masks.step/analyse take the shader's wave size; mask_sdst widens a
one-register VALU mask destination to the pair in wave64. rdna2spirv's
valu_mask_dst writes both registers: since 804f4ae a pair read as a wave64
mask takes lanes 32-63 from the high register, which the one-register write
left stale.

Corpus (26,503 shaders): one-register SDSTs in 18,866 of 23,839 wave64
shaders; 18,868 translate differently, all wave64; the same 26,501 still
translate and pass spirv-val as on main. New GPU test cs_w64_sdst_pair (corpus form) and
tests/semantic/test_w64_sdst_pair.py.

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

Conflicts: tools/lane_masks.py (main added v_div_scale_* to the VOP3b mask line, ItsNotRexed#2231 the mask_sdst call: both
kept), scripts/run_gpu_tests.py (main's name tuple plus cs_w64_sdst_pair), docs/design.md (main's rows plus the
row ItsNotRexed#2231 adds).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…R pair

The corpus listings print the 64-bit mask destination of a wave64 v_cmp_*_e64 or carry-out as one register.
ItsNotRexed#2231 makes the translator and lane_masks.py write and mark the pair. wave64_halves.py still took it as a
write of one register, so the high register kept the taint, the tag and the reaching definitions of its old
value, and a later 64-bit mask read of the pair was tier C (tainted-exec, stale-scalar) in an exact shader.

operands() now widens that destination with lane_masks.mask_sdst (v_cmp with an SGPR destination, the
carry-out of the VOP3b instructions).

tests/semantic/test_wave64_halves_sdst_pair.py: each hand-written listing in the one-register and in the
pair spelling, as one 64-lane wave and as two 32-lane waves. 5 of its 9 tests fail without the change.

Builds on ItsNotRexed#2231. No game data. The corpus effect is not measured.

Co-Authored-By: Claude Fable 5.2 <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 at cdea51c1d on Windows 11, RTX 5070 Ti:

  • tests/semantic/test_w64_sdst_pair.py -> 3 tests, OK; test_wave64_halves_sdst_pair.py -> 9 tests, OK.
  • test_wave64_halves.py 101 OK, test_wave64_halves_soundness.py 30 OK.
  • GPU emulated: LEONIDA_W64_EMULATE=1 run_gpu_tests.py --filter sdst_pair -> 1/1 passed, cs_w64_sdst_pair -> 4871 4871 4871 70407 70407 4871 4871 4871; translator 1/1 + spirv-val.
  • git diff --check clean.

A VALU mask destination printed as one SGPR now consumes the SGPR pair in lane_masks.py/wave64_halves.py/the translator, and the docs note it; the new semantic and GPU fixture cover the pair write. No blocking issue.

@Atomic258

Copy link
Copy Markdown

Verified cdea51c1d318cb7c6282f804b188c69bcde252c0 on Windows 11 / Python 3.15.2 (CPU). Ran python -I tests/semantic/test_<name>.py for wave64_halves_sdst_pair (9 passed), wave64_halves (101 passed), wave64_halves_soundness (30 passed), and w64_sdst_pair (3 passed). These interpreter tests do not need wave64 hardware; the inherited native GPU fixture was not run. Red control: replaced only tools/wave64_halves.py with the version at 7aacc969 (keeping the #2231 dependency); the new suite failed 5 of 9 as expected, including four tainted-exec regressions and the destination-pair assertion. Restored HEAD; worktree clean. Full semantic discovery was started separately and is not included in these pass counts.

AI-assisted (Devin); no game files.

@theswiss24

Copy link
Copy Markdown

Tested cdea51c1 on Linux (Ubuntu 24.04), HP laptop: NVIDIA GeForce GTX 1650 (595.99.02) and Intel UHD Graphics 630 (CFL GT2, Mesa ANV 25.2.8). Full scripts/run_gpu_tests.py with LEONIDA_W64_EMULATE=1, PR merged onto main 98fa503f, compared with main at the same commit and test programs built from it.

Result: pass; the new fixture passes on both GPUs and nothing else changes.

GPU main PR
GTX 1650 201/217 passed, 16 skipped 202/218 passed, 16 skipped
UHD 630 (Mesa) 184/217 passed, 31 skipped 185/218 passed, 31 skipped

cs_w64_sdst_pair passes on both (4871 4871 4871 70407 70407 4871 4871 4871); every other test has the same result as on main.

Tested and written by Claude (Claude Code), posting from @theswiss24's account.

@kacper-serewis kacper-serewis 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.

Independent operand census at cdea51c: 8,825 of 13,405 wave64 graphics listings contain a candidate single-SGPR mask destination (199,475 compare and 1,049 carry/secondary mask sites). Across all stages we found 18,870 candidates among 23,841 wave64 listings, versus 18,866/23,839 reported on #2231; discrepancy unresolved. Nine synthetic controls passed. The single-register and explicit-pair cases both reach tier A with equal interpreted exports; the lane-ID control remains tier C. Static candidate counts do not measure retail tier changes. AI-assisted CPU/cached inputs only.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

AI-assisted (Claude Code). No game files; I cannot count the corpus, so this is a reading of the code only.

@kacper-serewis about 18,870 of 23,841 against 18,866 of 23,839 on #2231: I see two possible causes in the code, and I cannot tell from here which one applies.

  1. The set of wave64 shaders. Translator: a wave64 VALU mask SDST printed as one SGPR is the SGPR pair #2231 made its count at an earlier main. The count of docs/design.md: wave64 graphics tier census as measured on main f847748c #3570 at f847748c has 23,841 wave64 shaders (from the FSSM header flag), the same total as yours. So two shaders became wave64 for the tools between the two counts, and they can have candidates.
  2. The list of instructions. After the count of Translator: a wave64 VALU mask SDST printed as one SGPR is the SGPR pair #2231, main added v_div_scale_f32 and v_div_scale_f64 to the VOP3b line of tools/lane_masks.py. In the merge of Translator: a wave64 VALU mask SDST printed as one SGPR is the SGPR pair #2231 for this branch I kept the two changes, so the second destination of these two instructions is widened also (mask_sdst), and operands() of tools/wave64_halves.py has the same list. If your "carry/secondary mask sites" include v_div_scale_*, they are sites that the count of Translator: a wave64 VALU mask SDST printed as one SGPR is the SGPR pair #2231 did not have.

A count of the candidates for each mnemonic (counts only) can show it: if v_div_scale_* has a small count other than zero, cause 2 is the answer or a part of it. I see no defect in this pull request behind the difference, so I made no change.

@tupacfan04

Copy link
Copy Markdown
Contributor

VERIFIED, no defects found at head cdea51c1. The last commit touches only the four files it claims (the rest is #2231), new test_wave64_halves_sdst_pair.py 9/9, and reverting tools/wave64_halves.py to 7aacc969 fails 5 of them as claimed. All test_wave64_halves*.py 140 pass; fixtures + lane masks 16 passed/1 skipped (no llvm-mc); full tests/semantic 6257 with only the pre-existing test_loop_ballot_barrier/test_vcmp16_opsel failures, reproduced identically on clean main. compileall and merge-tree clean.

Not a bug: _mask_sdst widens every explicit-SGPR v_cmp destination, including VOP3 32-bit compares, matching lane_masks.mask_sdst (tools/wave64_halves.py:158,185). The corpus tier delta remains unmeasured without game data, as the body says.

Note it depends on #2231. AI-assisted review, no game files, no GPU.

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.

7 participants