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

Open
opened 2026-11-26 21:19:42 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1996
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/mask-src-m0-scc


📝 Commits (1)

  • 01cd084 rdna2spirv, lane_masks: handle m0 and scc/src_scc in mask_src and _maskable_b32

📊 Changes

4 files changed (+252 additions, -2 deletions)

View changed files

📝 docs/design.md (+1 -0)
➕ tests/semantic/test_mask_src_m0_scc.py (+238 -0)
📝 tools/lane_masks.py (+1 -1)
📝 tools/rdna2spirv.py (+12 -1)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1996 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/mask-src-m0-scc` --- ### 📝 Commits (1) - [`01cd084`](https://github.com/ubiquitarianism/leonida/commit/01cd084222a375ea975da8241c79e4305f442869) rdna2spirv, lane_masks: handle m0 and scc/src_scc in mask_src and _maskable_b32 ### 📊 Changes **4 files changed** (+252 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) ➕ `tests/semantic/test_mask_src_m0_scc.py` (+238 -0) 📝 `tools/lane_masks.py` (+1 -1) 📝 `tools/rdna2spirv.py` (+12 -1) </details> ### 📄 Description 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2002
No description provided.