rdna2spirv: handle mixed mask pairs, wave32 VCC, and mask bit indices in s_bitcmp0/1_b32/b64 (SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS) #2360

Open
github-bot wants to merge 1 commit from github-bot/gh-2360 into main AGit
Owner

@⁠ShotTechOp on GitHub · 2026-11-26 15:22 UTC · original
ShotTechOp:fix/bitcmp64-mixed-and-special-srcs → main · +290 −16 · 3 files · 1 commits · open

Item ID: SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS

Summary

Fixes Gen.bitcmp (s_bitcmp0/1_b32 and s_bitcmp0/1_b64) in tools/rdna2spirv.py for five broken lane-mask operand combinations (matching the per-dword word-materialization model used by s_cmp_eq/lg_u64):

  1. Mixed mask/data SGPR pairs in s_bitcmp0/1_b64: when one dword of s[r:r+1] holds a lane mask and the other holds plain scalar data, holds_lane_mask returned False, so the mask dword was loaded raw (0 / 0xFFFFFFFF per lane) instead of materializing the wave's 32-bit mask word.
  2. Wave32 (mask, -1) (EITHER) pairs in s_bitcmp0/1_b64: holds_lane_mask returned True and called wave_mask(s[r:r+1]), which returned (lo, 0) in wave32 and dropped the high -1 word to 0.
  3. Swapped or duplicated wave64 half-mask SGPR pairs in s_bitcmp0/1_b64 (e.g. s10 = vcc_hi, s11 = vcc_lo): holds_lane_mask returned True and wave_mask collapsed them to canonical (lo, hi). Now only canonical wave64 (MASK_LO, MASK_HI) keeps a single wave_mask; all other SGPR pairs materialize each dword independently (lane_mask_word when tracked as a mask, else load_reg).
  4. Wave32 FSPX s_bitcmp0/1_b64 vcc, bit: in wave32, vcc is {vcc_hi, vcc_lo} where vcc_lo can hold a lane mask while vcc_hi holds scalar data (or a separate mask). Previously wave_mask(vcc) zeroed bits 32..63; now vcc_lo and vcc_hi are materialized independently.
  5. Lane-mask bit-index operand a[1] on s_bitcmp0/1_b32 and s_bitcmp0/1_b64: previously self.src_u(a[1]) read per-lane 0 / 0xFFFFFFFF instead of self.lane_mask_word(a[1]).

Also simplifies _b32 to use self.lane_mask_word(src0) and replaces the non-mask 64-bit fallback self.mask_src(src0) with self.src_u(src0). Updates the contract table in docs/design.md and adds tests/semantic/test_bitcmp64_mixed_and_special.py.

Verification

  • AI-assisted: yes
  • Environment: Windows 11, Python 3.12.10 (CPU semantic interpreter spirv_mini_interp; no local GPU/Vulkan/spirv-val installed)
  • GREEN checks:
    • python -I tests/semantic/test_bitcmp64_mixed_and_special.py -v -> 6/6 OK (wave32, FSPX wave32, native wave64, --wave64-emulate)
    • python -I tests/semantic/test_scalar_bitcmp.py -> 23/23 OK
    • python -I tests/test_text_write_line_endings.py -> 3/3 OK
    • python -m compileall -q tools/rdna2spirv.py tests/semantic/test_bitcmp64_mixed_and_special.py -> exit 0
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_bitcmp64_mixed_and_special.py docs/design.md -> exit 0
    • git diff --check -> clean
  • RED control against origin/main (tools/ extracted from origin/main):
    • tests/semantic/test_bitcmp64_mixed_and_special.py fails 5 of 6 tests (6 failures across wave32, FSPX wave32, native wave64, and --wave64-emulate; test_wave64_bitcmp32_high_half_mask is a parity regression guard).
**@⁠ShotTechOp** on GitHub · 2026-11-26 15:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2360) `ShotTechOp:fix/bitcmp64-mixed-and-special-srcs` → `main` · +290 −16 · 3 files · 1 commits · open Item ID: `SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS` ## Summary Fixes `Gen.bitcmp` (`s_bitcmp0/1_b32` and `s_bitcmp0/1_b64`) in `tools/rdna2spirv.py` for five broken lane-mask operand combinations (matching the per-dword word-materialization model used by `s_cmp_eq/lg_u64`): 1. **Mixed mask/data SGPR pairs in `s_bitcmp0/1_b64`**: when one dword of `s[r:r+1]` holds a lane mask and the other holds plain scalar data, `holds_lane_mask` returned `False`, so the mask dword was loaded raw (`0` / `0xFFFFFFFF` per lane) instead of materializing the wave's 32-bit mask word. 2. **Wave32 `(mask, -1)` (`EITHER`) pairs in `s_bitcmp0/1_b64`**: `holds_lane_mask` returned `True` and called `wave_mask(s[r:r+1])`, which returned `(lo, 0)` in wave32 and dropped the high `-1` word to `0`. 3. **Swapped or duplicated wave64 half-mask SGPR pairs in `s_bitcmp0/1_b64`** (e.g. `s10 = vcc_hi`, `s11 = vcc_lo`): `holds_lane_mask` returned `True` and `wave_mask` collapsed them to canonical `(lo, hi)`. Now only canonical wave64 `(MASK_LO, MASK_HI)` keeps a single `wave_mask`; all other SGPR pairs materialize each dword independently (`lane_mask_word` when tracked as a mask, else `load_reg`). 4. **Wave32 FSPX `s_bitcmp0/1_b64 vcc, bit`**: in wave32, `vcc` is `{vcc_hi, vcc_lo}` where `vcc_lo` can hold a lane mask while `vcc_hi` holds scalar data (or a separate mask). Previously `wave_mask(vcc)` zeroed bits 32..63; now `vcc_lo` and `vcc_hi` are materialized independently. 5. **Lane-mask bit-index operand `a[1]` on `s_bitcmp0/1_b32` and `s_bitcmp0/1_b64`**: previously `self.src_u(a[1])` read per-lane `0` / `0xFFFFFFFF` instead of `self.lane_mask_word(a[1])`. Also simplifies `_b32` to use `self.lane_mask_word(src0)` and replaces the non-mask 64-bit fallback `self.mask_src(src0)` with `self.src_u(src0)`. Updates the contract table in `docs/design.md` and adds `tests/semantic/test_bitcmp64_mixed_and_special.py`. ## Verification - **AI-assisted**: yes - **Environment**: Windows 11, Python 3.12.10 (CPU semantic interpreter `spirv_mini_interp`; no local GPU/Vulkan/`spirv-val` installed) - **GREEN checks**: - `python -I tests/semantic/test_bitcmp64_mixed_and_special.py -v` -> 6/6 OK (wave32, FSPX wave32, native wave64, `--wave64-emulate`) - `python -I tests/semantic/test_scalar_bitcmp.py` -> 23/23 OK - `python -I tests/test_text_write_line_endings.py` -> 3/3 OK - `python -m compileall -q tools/rdna2spirv.py tests/semantic/test_bitcmp64_mixed_and_special.py` -> exit 0 - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_bitcmp64_mixed_and_special.py docs/design.md` -> exit 0 - `git diff --check` -> clean - **RED control against `origin/main` (`tools/` extracted from `origin/main`)**: - `tests/semantic/test_bitcmp64_mixed_and_special.py` fails 5 of 6 tests (6 failures across wave32, FSPX wave32, native wave64, and `--wave64-emulate`; `test_wave64_bitcmp32_high_half_mask` is a parity regression guard).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:26:58 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 15:35 UTC · original · reviewed

Windows 11: 6/6 targeted bitcmp semantic tests passed with synthetic inputs. These cover mixed SGPR pairs, the wave32 high word, wave64 swapped halves, and a lane-mask bit index. No findings from these checks.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 15:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2360#pullrequestreview-6076850749) · **reviewed** Windows 11: 6/6 targeted bitcmp semantic tests passed with synthetic inputs. These cover mixed SGPR pairs, the wave32 high word, wave64 swapped halves, and a lane-mask bit index. No findings from these checks. AI-assisted.
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 15:49 UTC · original

On an RTX 4090, all 136 synthetic bit-comparison dispatches at c26efd297 matched an independent scalar reference. The same fixture and runtime inputs matched in 89 of 136 dispatches on parent fbf100b1b.

Mode Parent PR
Native wave32 32/48 48/48
Wave64 emulated on two 32-lane subgroups 57/88 88/88

For example, I gave the low half of an SGPR pair a lane mask of 0x80000001 and the high half ordinary scalar data. Testing bit 0 of that pair should set SCC for the whole wave. On the parent, lane 1 reported zero. On the PR, every lane reported one.

The matrix covered mixed mask/data pairs, all-ones and ordinary scalar controls, duplicate and swapped halves, direct VCC operands, and mask-derived indices. I included wave32 FSPX metadata for the full-VCC case. Each lane wrote the results for both bit polarities and both operand widths. All 28,672 output words on the PR matched, the output-buffer guards stayed intact, and all 17 PR modules passed SPIR-V validation for Vulkan 1.2. The six committed CPU semantic tests also passed.

Windows 11, NVIDIA 616.64, Vulkan validation enabled. The GPU ran synthetic shader listings through the common parent’s vk_compute_test. AI-assisted verification by OpenAI Codex (GPT-6).

**@⁠ecox982745** on GitHub · 2026-11-26 15:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2360#issuecomment-7196791654) On an RTX 4090, all 136 synthetic bit-comparison dispatches at `c26efd297` matched an independent scalar reference. The same fixture and runtime inputs matched in 89 of 136 dispatches on parent `fbf100b1b`. | Mode | Parent | PR | | --- | ---: | ---: | | Native wave32 | 32/48 | 48/48 | | Wave64 emulated on two 32-lane subgroups | 57/88 | 88/88 | For example, I gave the low half of an SGPR pair a lane mask of `0x80000001` and the high half ordinary scalar data. Testing bit 0 of that pair should set SCC for the whole wave. On the parent, lane 1 reported zero. On the PR, every lane reported one. The matrix covered mixed mask/data pairs, all-ones and ordinary scalar controls, duplicate and swapped halves, direct VCC operands, and mask-derived indices. I included wave32 FSPX metadata for the full-VCC case. Each lane wrote the results for both bit polarities and both operand widths. All 28,672 output words on the PR matched, the output-buffer guards stayed intact, and all 17 PR modules passed SPIR-V validation for Vulkan 1.2. The six committed CPU semantic tests also passed. Windows 11, NVIDIA 616.64, Vulkan validation enabled. The GPU ran synthetic shader listings through the common parent’s `vk_compute_test`. AI-assisted verification by OpenAI Codex (GPT-6).
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 18:21 UTC · original · reviewed

macOS arm64 check of #2360 (SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS). Translator-only plus one semantic test; the GPU part is MoltenVK/KosmicKrisp, and it does not reach the changed combinations (see the finding).

Tested head c26efd297 merged onto main bdbc7e923 as merge d59a3d6e6 (clean; branch 21 commits behind, git merge-tree clean).

Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.

The new test passes, and the control bites

  • python -I tests/semantic/test_bitcmp64_mixed_and_special.py: Ran 6 tests ... OK at the head and after merging onto bdbc7e923; tests/semantic/test_scalar_bitcmp.py still 23/23.
  • Negative control (test kept, tools/rdna2spirv.py put back to main's): FAILED (failures=6) - lane-mask bit index, wave32 (mask, -1), wave32 mixed, wave32 FSPX vcc, and wave64 swapped/mixed in both native and --wave64-emulate subtests. The unchanged sixth test (test_wave64_bitcmp32_high_half_mask) is the parity guard, as the description says.

What I checked in the code

  • The canonical (MASK_LO, MASK_HI) wave64 pair still goes through one wave_mask; every other SGPR pair materializes each dword (lane_mask_word for a tracked word, load_reg for data), so (mask, data), (data, mask), swapped and duplicated pairs become the same uniform 64-bit value in every lane. lane_mask_word is uniform: for MASK_LO/MASK_HI it returns that word regardless of the lane, which is what a scalar bit index needs.
  • cur_masks only ever holds MASK, MASK_LO, MASK_HI or EITHER (tools/lane_masks.py:32-35), so the (r + i) in self.cur_masks membership test cannot call lane_mask_word on plain data today. It is a little brittle if a new kind is introduced (the check then means "any tracked kind"), but it is correct now.
  • Wave32 FSPX vcc becomes {vcc_hi, vcc_lo} and each word is materialized on its own; src_u already loads %vcc_hi as an ordinary SGPR in wave32 and %vcc for vcc_lo, so the split is consistent with the rest of the translator.
  • The bit-index operand now goes through lane_mask_word when it is a tracked mask, matching the b32 path.

No regressions

  • Semantic suite: 500 files / 6,367 tests / 0 failed at main bdbc7e923; 501 files / 6,373 tests / 0 failed at the merge (+1 file, +6 tests).
  • GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at main and the merge after normalising the per-run temp directory. Same pre-existing failures (cs_fma_fused, cs_imgatomic_ext, ps_ssharp on MV; cs_bvh, cs_bvh32, cs_imgatomic_ext, ps_cndmask_sign_mods, ps_valu16_mad_sel on KK).

Finding
The GPU fixtures do not exercise this rule at all: the only shader with s_bitcmp is runtime/test/shaders/cs_w32_salu_ext.asm, and it uses s_bitcmp0/1_b32 on plain SGPR data, not _b64 and not a mask/mixed pair. The doc row says "Not yet GPU-verified", which is accurate; all five fixed combinations rest on spirv_mini_interp. A small cs_w64x_bitcmp_mixed.asm (or a few lines added to an existing cs_w64x_* fixture) storing SCC for a (mask, -1) wave32 pair, a swapped wave64 half pair and a mixed pair would give the rule the same kind of hardware check that cs_w64x_partial_scmp.asm gives the compare rules.

python -I scripts/check_no_game_data.py on the changed files: clean. git diff --check: clean.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-26 18:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2360#pullrequestreview-6078919557) · **reviewed** **macOS arm64 check of #2360** (SHADER-BITCMP64-MIXED-AND-SPECIAL-SRCS). Translator-only plus one semantic test; the GPU part is MoltenVK/KosmicKrisp, and it does not reach the changed combinations (see the finding). Tested head `c26efd297` merged onto `main` `bdbc7e923` as merge `d59a3d6e6` (clean; branch 21 commits behind, `git merge-tree` clean). Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0. **The new test passes, and the control bites** - `python -I tests/semantic/test_bitcmp64_mixed_and_special.py`: `Ran 6 tests ... OK` at the head and after merging onto `bdbc7e923`; `tests/semantic/test_scalar_bitcmp.py` still 23/23. - Negative control (test kept, `tools/rdna2spirv.py` put back to `main`'s): `FAILED (failures=6)` - lane-mask bit index, wave32 `(mask, -1)`, wave32 mixed, wave32 FSPX `vcc`, and wave64 swapped/mixed in both native and `--wave64-emulate` subtests. The unchanged sixth test (`test_wave64_bitcmp32_high_half_mask`) is the parity guard, as the description says. **What I checked in the code** - The canonical `(MASK_LO, MASK_HI)` wave64 pair still goes through one `wave_mask`; every other SGPR pair materializes each dword (`lane_mask_word` for a tracked word, `load_reg` for data), so `(mask, data)`, `(data, mask)`, swapped and duplicated pairs become the same uniform 64-bit value in every lane. `lane_mask_word` is uniform: for `MASK_LO`/`MASK_HI` it returns that word regardless of the lane, which is what a scalar bit index needs. - `cur_masks` only ever holds `MASK`, `MASK_LO`, `MASK_HI` or `EITHER` (`tools/lane_masks.py:32-35`), so the `(r + i) in self.cur_masks` membership test cannot call `lane_mask_word` on plain data today. It is a little brittle if a new kind is introduced (the check then means "any tracked kind"), but it is correct now. - Wave32 FSPX `vcc` becomes `{vcc_hi, vcc_lo}` and each word is materialized on its own; `src_u` already loads `%vcc_hi` as an ordinary SGPR in wave32 and `%vcc` for `vcc_lo`, so the split is consistent with the rest of the translator. - The bit-index operand now goes through `lane_mask_word` when it is a tracked mask, matching the b32 path. **No regressions** - Semantic suite: 500 files / 6,367 tests / 0 failed at `main` `bdbc7e923`; 501 files / 6,373 tests / 0 failed at the merge (+1 file, +6 tests). - GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at `main` and the merge after normalising the per-run temp directory. Same pre-existing failures (`cs_fma_fused`, `cs_imgatomic_ext`, `ps_ssharp` on MV; `cs_bvh`, `cs_bvh32`, `cs_imgatomic_ext`, `ps_cndmask_sign_mods`, `ps_valu16_mad_sel` on KK). **Finding** The GPU fixtures do not exercise this rule at all: the only shader with `s_bitcmp` is `runtime/test/shaders/cs_w32_salu_ext.asm`, and it uses `s_bitcmp0/1_b32` on plain SGPR data, not `_b64` and not a mask/mixed pair. The doc row says "Not yet GPU-verified", which is accurate; all five fixed combinations rest on `spirv_mini_interp`. A small `cs_w64x_bitcmp_mixed.asm` (or a few lines added to an existing `cs_w64x_*` fixture) storing SCC for a `(mask, -1)` wave32 pair, a swapped wave64 half pair and a mixed pair would give the rule the same kind of hardware check that `cs_w64x_partial_scmp.asm` gives the compare rules. `python -I scripts/check_no_game_data.py` on the changed files: clean. `git diff --check`: clean. No game files. AI-assisted.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:46 UTC · original · approved these changes

Approving c26efd297.

s_bitcmp* now reads each half of an SGPR pair as what it holds (a tracked mask word as its mask, data as data) unless the pair is a real lo/hi wave mask, a wave32 vcc operand as its two words, and a lane-mask bit index through lane_mask_word; null, immediates and the 32-bit form keep their paths. wavehs' finding stands as a follow-up rather than a blocker: no GPU fixture reaches these combinations yet, and the doc row says so.

test_bitcmp64_mixed_and_special.py 6 passed (4 subtests). Merged onto main d1dff7949 together with #2397, #2416 and the other three of this series below (no conflicts), on Linux with Python 3.13. The full translator suite (run_semantic_tests.py tests/semantic) on that tree has only the 8 failures main has here (7 in test_fspx_dot4_op_sel_disasm, test_int32_to_f64), and tests/test_translate.py only main's own ps_sdwa_f16_const.asm (an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2360#pullrequestreview-6083601877) · **approved these changes** Approving c26efd297. `s_bitcmp*` now reads each half of an SGPR pair as what it holds (a tracked mask word as its mask, data as data) unless the pair is a real lo/hi wave mask, a wave32 `vcc` operand as its two words, and a lane-mask bit index through `lane_mask_word`; null, immediates and the 32-bit form keep their paths. wavehs' finding stands as a follow-up rather than a blocker: no GPU fixture reaches these combinations yet, and the doc row says so. `test_bitcmp64_mixed_and_special.py` 6 passed (4 subtests). Merged onto `main` `d1dff7949` together with #2397, #2416 and the other three of this series below (no conflicts), on Linux with Python 3.13. The full translator suite (`run_semantic_tests.py tests/semantic`) on that tree has only the 8 failures `main` has here (7 in `test_fspx_dot4_op_sel_disasm`, `test_int32_to_f64`), and `tests/test_translate.py` only `main`'s own `ps_sdwa_f16_const.asm` (an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2360/head:github-bot/gh-2360'
git switch 'github-bot/gh-2360'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2360'
git switch 'github-bot/gh-2360'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2360'
git switch 'github-bot/gh-2360'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2360'
git switch 'main'
git merge --squash 'github-bot/gh-2360'
git switch 'main'
git merge --ff-only 'github-bot/gh-2360'
git switch 'main'
git merge 'github-bot/gh-2360'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.