rdna2spirv, lane_masks: extract per-lane bits for m0 and scc/src_scc in mask_src and _maskable_b32 (SHADER-MASK-SRC-M0-SCC) #1996

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

@⁠ShotTechOp on GitHub · 2026-11-25 17:52 UTC · original
ShotTechOp:fix/mask-src-m0-scc → main · +252 −2 · 4 files · 1 commits · open

Claimed in #1608 as SHADER-MASK-SRC-M0-SCC.

What and why

  • _maskable_b32 in both tools/rdna2spirv.py and tools/lane_masks.py previously accepted only sgpr, imm, exec*, vcc*, and null, omitting m0 and scc/src_scc.
    • When a 32-bit bitwise or select op targeted exec_lo/exec_hi or vcc_lo/vcc_hi with m0 or src_scc (e.g., s_and_b32 exec_lo, exec_lo, m0, s_andn2_b32 exec_lo, exec_lo, m0, s_and_b32 vcc_lo, vcc_lo, m0, s_not_b32 vcc_lo, m0), sop2_b32_srcs / s_not_b32 fell back to raw src_u() instead of _mask_b32_src():
      1. On exec_lo/exec_hi destinations, r held raw non-zero bitmasks on active lanes whose bit in m0/src_scc was 0, so scc_logic (scc_any_half(r)) set SCC = 1 even when the resulting EXEC half was 0 (e.g., exec_lo = 0x2, m0 = 0x5 -> exec_lo & m0 == 0 still set SCC = 1).
      2. On vcc_lo/vcc_hi destinations, put_mask / dst stored that raw non-zero word into %vcc on lanes whose bit in m0 was 0 (corrupting subsequent v_cndmask_b32 and s_cbranch_vccz), and lane_masks.step dropped vcc from the mask state.
  • Gen.mask_src also raised Unsupported("mask operand") for m0 and scc/src_scc, breaking s_*_saveexec_b32 / s_*_wrexec_b32 / s_*_saveexec_b64 with m0 or src_scc.
  • Adding m0, scc, and src_scc to _maskable_b32 (both modules) and to Gen.mask_src (zero-extending bits 32..63 to 0 when wide and self.wave64) fixes both the silent miscompilations and the saveexec/wrexec rejections.
  • Added the contract row for m0 and scc/src_scc lane-mask sources in docs/design.md.

Testing

  • AI-assisted: yes.
  • Environment: Windows 11, Python 3.12 (no GPU / LLVM / SPIRV-Tools installed locally).
  • New regression suite: tests/semantic/test_mask_src_m0_scc.py — tests s_and_b32, s_andn2_b32, s_or_b32, s_xor_b32, s_not_b32 into exec_lo, exec_hi, vcc_lo, vcc_hi (wave32 and wave64), and s_and_saveexec_b32 / s_and_saveexec_b64 with m0 and src_scc, checking both per-lane mask values and SCC.
  • RED control on origin/main (b9320a1): tests/semantic/test_mask_src_m0_scc.py fails with FAILED (failures=19, errors=1) (proving wrong SCC on exec_lo/exec_hi, corrupted vcc_lo/vcc_hi lane bits, and Unsupported("mask operand") on s_and_saveexec_b32/b64).
  • GREEN checks on branch:
    • python -I tests/semantic/test_mask_src_m0_scc.py -v (3/3 OK)
    • python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py (9 ran, OK, 1 skipped)
    • python -m unittest discover -s tests/semantic -p test_mask_src_sgpr_const.py (7/7 OK)
    • python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py (7/7 OK)
    • python -m unittest discover -s tests -p "test_docs_*.py" (50/50 OK)
    • python -I tests/test_text_write_line_endings.py (3/3 OK)
    • python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_mask_src_m0_scc.py
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tools/lane_masks.py docs/design.md tests/semantic/test_mask_src_m0_scc.py
    • git diff --check
**@⁠ShotTechOp** on GitHub · 2026-11-25 17:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1996) `ShotTechOp:fix/mask-src-m0-scc` → `main` · +252 −2 · 4 files · 1 commits · open Claimed in #1608 as `SHADER-MASK-SRC-M0-SCC`. ## What and why - `_maskable_b32` in both `tools/rdna2spirv.py` and `tools/lane_masks.py` previously accepted only `sgpr`, `imm`, `exec*`, `vcc*`, and `null`, omitting `m0` and `scc`/`src_scc`. - When a 32-bit bitwise or select op targeted `exec_lo`/`exec_hi` or `vcc_lo`/`vcc_hi` with `m0` or `src_scc` (e.g., `s_and_b32 exec_lo, exec_lo, m0`, `s_andn2_b32 exec_lo, exec_lo, m0`, `s_and_b32 vcc_lo, vcc_lo, m0`, `s_not_b32 vcc_lo, m0`), `sop2_b32_srcs` / `s_not_b32` fell back to raw `src_u()` instead of `_mask_b32_src()`: 1. On `exec_lo`/`exec_hi` destinations, `r` held raw non-zero bitmasks on active lanes whose bit in `m0`/`src_scc` was `0`, so `scc_logic` (`scc_any_half(r)`) set `SCC = 1` even when the resulting `EXEC` half was `0` (e.g., `exec_lo = 0x2`, `m0 = 0x5` -> `exec_lo & m0 == 0` still set `SCC = 1`). 2. On `vcc_lo`/`vcc_hi` destinations, `put_mask` / `dst` stored that raw non-zero word into `%vcc` on lanes whose bit in `m0` was `0` (corrupting subsequent `v_cndmask_b32` and `s_cbranch_vccz`), and `lane_masks.step` dropped `vcc` from the mask state. - `Gen.mask_src` also raised `Unsupported("mask operand")` for `m0` and `scc`/`src_scc`, breaking `s_*_saveexec_b32` / `s_*_wrexec_b32` / `s_*_saveexec_b64` with `m0` or `src_scc`. - Adding `m0`, `scc`, and `src_scc` to `_maskable_b32` (both modules) and to `Gen.mask_src` (zero-extending bits `32..63` to `0` when `wide and self.wave64`) fixes both the silent miscompilations and the `saveexec`/`wrexec` rejections. - Added the contract row for `m0` and `scc`/`src_scc` lane-mask sources in `docs/design.md`. ## Testing - **AI-assisted**: yes. - **Environment**: Windows 11, Python 3.12 (no GPU / LLVM / SPIRV-Tools installed locally). - **New regression suite**: `tests/semantic/test_mask_src_m0_scc.py` — tests `s_and_b32`, `s_andn2_b32`, `s_or_b32`, `s_xor_b32`, `s_not_b32` into `exec_lo`, `exec_hi`, `vcc_lo`, `vcc_hi` (wave32 and wave64), and `s_and_saveexec_b32` / `s_and_saveexec_b64` with `m0` and `src_scc`, checking both per-lane mask values and `SCC`. - **RED control on `origin/main` (`b9320a1`)**: `tests/semantic/test_mask_src_m0_scc.py` fails with `FAILED (failures=19, errors=1)` (proving wrong `SCC` on `exec_lo`/`exec_hi`, corrupted `vcc_lo`/`vcc_hi` lane bits, and `Unsupported("mask operand")` on `s_and_saveexec_b32/b64`). - **GREEN checks on branch**: - `python -I tests/semantic/test_mask_src_m0_scc.py -v` (3/3 OK) - `python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py` (9 ran, OK, 1 skipped) - `python -m unittest discover -s tests/semantic -p test_mask_src_sgpr_const.py` (7/7 OK) - `python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py` (7/7 OK) - `python -m unittest discover -s tests -p "test_docs_*.py"` (50/50 OK) - `python -I tests/test_text_write_line_endings.py` (3/3 OK) - `python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_mask_src_m0_scc.py` - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tools/lane_masks.py docs/design.md tests/semantic/test_mask_src_m0_scc.py` - `git diff --check`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:14:14 +00:00
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/1996/head:github-bot/gh-1996'
git switch 'github-bot/gh-1996'

Merge

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