[PR #2357] rdna2spirv, lane_masks, wave64_halves: fix 3-operand short-form v_*_co_ci_u32 operand classification (SHADER-SHORT-CO-CI-MASK-OPERANDS) #2360

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

📋 Pull Request Information

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

Base: main ← Head: fix/short-co-ci-mask-operands


📝 Commits (1)

  • e1ca6cc rdna2spirv, lane_masks, wave64_halves: fix 3-operand short-form v_*_co_ci_u32 operand classification (SHADER-SHORT-CO-CI-MASK-OPERANDS)

📊 Changes

4 files changed (+177 additions, -4 deletions)

View changed files

➕ tests/semantic/test_short_co_ci_masks.py (+168 -0)
📝 tools/lane_masks.py (+3 -1)
📝 tools/rdna2spirv.py (+3 -2)
📝 tools/wave64_halves.py (+3 -1)

📄 Description

Item: SHADER-SHORT-CO-CI-MASK-OPERANDS

Problem

Gen._insn (tools/rdna2spirv.py) explicitly accepts the 3-operand short VOP2 assembler spelling v_add_co_ci_u32 vD, src0, src1 (and v_sub_co_ci_u32 / v_subrev_co_ci_u32), where carry-out and carry-in are both implicit vcc and operand 1 is the 32-bit source src0. However, four analysis helpers treated operand 1 as the VOP3b carry-out destination:

  1. tools/lane_masks.py (step): Called put(state, a[1], MASK, wave64), falsely marking src0 (e.g. an SGPR holding plain scalar data) as a lane mask and failing to mark implicit vcc as MASK. Downstream scalar ops reading src0 (e.g. s_bcnt1_i32_b32) then read the wave ballot (32 instead of popcnt(src0)).
  2. tools/rdna2spirv.py (widen_wave64_masks): Always used at = (1, 4) for _co_ci_, widening a 32-bit src0 SGPR (a[1]) to n=2 in wave64 shaders, which crashed translation with Unsupported("64-bit operand").
  3. tools/rdna2spirv.py (writes_exec): Treated a[1] as a destination on all VOP3_TWO_DESTS ops, so v_add_co_ci_u32 v1, exec_lo, v0 was falsely flagged as writing EXEC.
  4. tools/wave64_halves.py (operands): Split dests, srcs = [a[0], a[1]], list(a[2:]) when a[1] was an SGPR/special, dropping src0 from srcs, falsely claiming src0 was overwritten, and omitting implicit "vcc" from both defs and uses.

Fix

  • tools/lane_masks.py: For 3-operand v_*_co_ci_u32, put MASK on implicit vcc instead of a[1].
  • tools/rdna2spirv.py: In widen_wave64_masks, only widen (1, 4) when len(a) > 3; in writes_exec, skip the a[1] destination check for 3-operand *_ci_u32.
  • tools/wave64_halves.py: For 3-operand v_*_co_ci_u32, keep dests = [a[0]] and srcs = [a[1], a[2]], and append "vcc" to defs (len(srcs) == 2 then also adds "vcc" to uses).
  • tests/semantic/test_short_co_ci_masks.py: Unit + wave32/wave64 execution regression tests covering all four sites.

Verification

AI-assisted: yes.
Environment: Windows 11, Python 3.12.10, CPU-only (no game files, no spirv-val, not GPU-verified).

  • GREEN (branch):
    • python -I tests/semantic/test_short_co_ci_masks.py -v -> 6/6 OK
    • python -I tests/test_lane_masks.py -> OK
    • python -I tests/semantic/test_wave64_halves.py -> 127/127 OK
    • python -I tests/test_text_write_line_endings.py -> 3/3 OK
    • python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tools/wave64_halves.py tests/semantic/test_short_co_ci_masks.py -> 0
    • python -I scripts/check_no_game_data.py ... -> 0
    • git diff --check -> 0
  • RED control (origin/main fbf100b1):
    • Running tests/semantic/test_short_co_ci_masks.py against origin/main's tools/ fails all 6 tests (14 assertion failures + 1 Unsupported("64-bit operand") crash on wave64).

🔄 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/2357 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/short-co-ci-mask-operands` --- ### 📝 Commits (1) - [`e1ca6cc`](https://github.com/ubiquitarianism/leonida/commit/e1ca6cceac0c76d2ea9de8245d200a83efea2855) rdna2spirv, lane_masks, wave64_halves: fix 3-operand short-form v_*_co_ci_u32 operand classification (SHADER-SHORT-CO-CI-MASK-OPERANDS) ### 📊 Changes **4 files changed** (+177 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `tests/semantic/test_short_co_ci_masks.py` (+168 -0) 📝 `tools/lane_masks.py` (+3 -1) 📝 `tools/rdna2spirv.py` (+3 -2) 📝 `tools/wave64_halves.py` (+3 -1) </details> ### 📄 Description Item: `SHADER-SHORT-CO-CI-MASK-OPERANDS` ### Problem `Gen._insn` (`tools/rdna2spirv.py`) explicitly accepts the 3-operand short VOP2 assembler spelling `v_add_co_ci_u32 vD, src0, src1` (and `v_sub_co_ci_u32` / `v_subrev_co_ci_u32`), where carry-out and carry-in are both implicit `vcc` and operand 1 is the 32-bit source `src0`. However, four analysis helpers treated operand 1 as the VOP3b carry-out destination: 1. **`tools/lane_masks.py` (`step`)**: Called `put(state, a[1], MASK, wave64)`, falsely marking `src0` (e.g. an SGPR holding plain scalar data) as a lane mask and failing to mark implicit `vcc` as `MASK`. Downstream scalar ops reading `src0` (e.g. `s_bcnt1_i32_b32`) then read the wave ballot (`32` instead of `popcnt(src0)`). 2. **`tools/rdna2spirv.py` (`widen_wave64_masks`)**: Always used `at = (1, 4)` for `_co_ci_`, widening a 32-bit `src0` SGPR (`a[1]`) to `n=2` in wave64 shaders, which crashed translation with `Unsupported("64-bit operand")`. 3. **`tools/rdna2spirv.py` (`writes_exec`)**: Treated `a[1]` as a destination on all `VOP3_TWO_DESTS` ops, so `v_add_co_ci_u32 v1, exec_lo, v0` was falsely flagged as writing EXEC. 4. **`tools/wave64_halves.py` (`operands`)**: Split `dests, srcs = [a[0], a[1]], list(a[2:])` when `a[1]` was an SGPR/special, dropping `src0` from `srcs`, falsely claiming `src0` was overwritten, and omitting implicit `"vcc"` from both `defs` and `uses`. ### Fix - **`tools/lane_masks.py`**: For 3-operand `v_*_co_ci_u32`, put `MASK` on implicit `vcc` instead of `a[1]`. - **`tools/rdna2spirv.py`**: In `widen_wave64_masks`, only widen `(1, 4)` when `len(a) > 3`; in `writes_exec`, skip the `a[1]` destination check for 3-operand `*_ci_u32`. - **`tools/wave64_halves.py`**: For 3-operand `v_*_co_ci_u32`, keep `dests = [a[0]]` and `srcs = [a[1], a[2]]`, and append `"vcc"` to `defs` (`len(srcs) == 2` then also adds `"vcc"` to `uses`). - **`tests/semantic/test_short_co_ci_masks.py`**: Unit + wave32/wave64 execution regression tests covering all four sites. ### Verification AI-assisted: yes. Environment: Windows 11, Python 3.12.10, CPU-only (no game files, no `spirv-val`, not GPU-verified). - **GREEN (branch)**: - `python -I tests/semantic/test_short_co_ci_masks.py -v` -> 6/6 OK - `python -I tests/test_lane_masks.py` -> OK - `python -I tests/semantic/test_wave64_halves.py` -> 127/127 OK - `python -I tests/test_text_write_line_endings.py` -> 3/3 OK - `python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tools/wave64_halves.py tests/semantic/test_short_co_ci_masks.py` -> 0 - `python -I scripts/check_no_game_data.py ...` -> 0 - `git diff --check` -> 0 - **RED control (`origin/main` `fbf100b1`)**: - Running `tests/semantic/test_short_co_ci_masks.py` against `origin/main`'s `tools/` fails all 6 tests (14 assertion failures + 1 `Unsupported("64-bit operand")` crash on wave64). --- <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#2360
No description provided.