[PR #1973] rdna2spirv: read %vcc and %vcc_hi for plain 64-bit scalar data in s_bcnt/s_ff/s_flbit _b64/_i64 (SHADER-B64-BITOPS-VCC-DATA) #1979

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

📋 Pull Request Information

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

Base: main ← Head: fix/b64-bitops-vcc-data


📝 Commits (1)

  • a186754 rdna2spirv: read %vcc and %vcc_hi for plain 64-bit scalar data in s_bcnt/s_ff/s_flbit

📊 Changes

3 files changed (+242 additions, -1 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_b64_bitops_vcc_data.py (+222 -0)
📝 tools/rdna2spirv.py (+19 -0)

📄 Description

Claimed in #1608 as SHADER-B64-BITOPS-VCC-DATA.

What and why

When vcc holds plain 64-bit scalar data (not tracked as a lane mask by tools/lane_masks.py, e.g., written via s_mov_b32 vcc_lo, ...; s_mov_b32 vcc_hi, ...), the 64-bit scalar bit-count and bit-scan instructions mishandled vcc (and s_flbit_i32_{b64,i64} also rejected null):

  1. s_bcnt1_i32_b64 / s_bcnt0_i32_b64 (tools/rdna2spirv.py): when self.holds_lane_mask(a[1]) was False, vcc fell through to lo, hi = (self.mask_src(a[1]), self.cu(0)), dropping %vcc_hi completely (hi = 0). For example, vcc = (0x3, 0xF) returned 2 instead of 6 on s_bcnt1_i32_b64, and vcc = (0xFFFFFFFF, 0xFFFFFFFF) returned 32 (SCC = 1) instead of 0 (SCC = 0) on s_bcnt0_i32_b64.
  2. s_ff1_i32_b64 / s_ff0_i32_b64 (tools/rdna2spirv.py): same fallthrough (lo, hi = self.mask_src(a[1]), self.cu(0)), dropping %vcc_hi so vcc = (0, 0x8) returned -1 instead of 35 on s_ff1_i32_b64, and vcc = (0xFFFFFFFF, 0xFFFFFFFF) returned 32 instead of -1 on s_ff0_i32_b64.
  3. s_flbit_i32_b64 / s_flbit_i32_i64 (tools/rdna2spirv.py): only accepted SGPR pairs and immediates on the non-mask path, raising Unsupported on plain-data vcc and null.

Both s_bitcmp[01]_b64 (bitcmp) and s_cmp_eq/lg_u64 already handle plain-data vcc by loading %vcc and %vcc_hi, and null as (0, 0).

Changes

  • tools/rdna2spirv.py:
    • Handle a[1] / x == vcc (when holds_lane_mask(...) is False) by loading (%vcc, %vcc_hi) and null as (0, 0) in s_bcnt[01]_i32_b64, s_flbit_i32_{b64,i64}, and s_ff[01]_i32_b64.
    • Lane-mask vcc (holds_lane_mask(...) == True) continues to take the existing wave_mask() path unchanged.
  • docs/design.md:
    • Documented the plain-data vcc and null handling in the Wave64 mask ballot row of the translator contract table.
  • tests/semantic/test_b64_bitops_vcc_data.py:
    • Covers all 6 ops (s_bcnt1_i32_b64 + SCC, s_bcnt0_i32_b64 + SCC, s_ff1_i32_b64, s_ff0_i32_b64, s_flbit_i32_b64, s_flbit_i32_i64) on plain-data vcc across 9 edge-case (lo, hi) pairs in native wave64, --wave64-emulate, and FSPX wave32 (s_flbit_i32_{b64,i64}), plus lane-mask-to-plain-data transitions, null sources, and a real lane-mask vcc control.

Verification

  • AI-assisted: yes.
  • Environment: Windows 11 (Python 3.12.10, CPU-only / spirv_mini_interp; no GPU, LLVM, or SPIRV-Tools installed locally).
  • Tests run (all GREEN):
    • python -I tests/semantic/test_b64_bitops_vcc_data.py -v
    • python -m unittest discover -s tests/semantic -p test_scalar_bitcmp.py
    • python -m unittest discover -s tests/semantic -p test_salu_flbit_lane_mask.py
    • python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py
    • python -m unittest discover -s tests/semantic -p test_scmp_u64_mask_pairs.py
    • python -m unittest discover -s tests -p "test_docs_*.py"
    • python -I tests/test_text_write_line_endings.py
    • python -m compileall -q tools/rdna2spirv.py tests/semantic/test_b64_bitops_vcc_data.py
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_b64_bitops_vcc_data.py
    • git diff --check
  • Negative control against origin/main (tools/rdna2spirv.py at fe15534): tests/semantic/test_b64_bitops_vcc_data.py fails on origin/main — test_bcnt_and_ff_plain_vcc_data_reads_high_word silently miscompiles all 4 (lo, hi) cases (%vcc_hi dropped to 0, e.g. returning [2, 1, 62, 1, 0, 2] instead of [6, 1, 58, 1, 0, 2] for (0x3, 0xF) and [0, 0, 64, 1, 0xffffffff, 0] instead of [1, 1, 63, 1, 35, 0] for (0, 0x8)), and all 5 s_flbit_i32_{b64,i64} tests raise Unsupported: s_flbit_i32_b64 source; the lane-mask control passes.

🔄 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/1973 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/b64-bitops-vcc-data` --- ### 📝 Commits (1) - [`a186754`](https://github.com/ubiquitarianism/leonida/commit/a186754ab572bc991c7083154b6bc5dbecafc0d9) rdna2spirv: read %vcc and %vcc_hi for plain 64-bit scalar data in s_bcnt/s_ff/s_flbit ### 📊 Changes **3 files changed** (+242 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_b64_bitops_vcc_data.py` (+222 -0) 📝 `tools/rdna2spirv.py` (+19 -0) </details> ### 📄 Description Claimed in #1608 as `SHADER-B64-BITOPS-VCC-DATA`. ### What and why When `vcc` holds plain 64-bit scalar data (not tracked as a lane mask by `tools/lane_masks.py`, e.g., written via `s_mov_b32 vcc_lo, ...; s_mov_b32 vcc_hi, ...`), the 64-bit scalar bit-count and bit-scan instructions mishandled `vcc` (and `s_flbit_i32_{b64,i64}` also rejected `null`): 1. **`s_bcnt1_i32_b64` / `s_bcnt0_i32_b64`** (`tools/rdna2spirv.py`): when `self.holds_lane_mask(a[1])` was `False`, `vcc` fell through to `lo, hi = (self.mask_src(a[1]), self.cu(0))`, dropping `%vcc_hi` completely (`hi = 0`). For example, `vcc = (0x3, 0xF)` returned `2` instead of `6` on `s_bcnt1_i32_b64`, and `vcc = (0xFFFFFFFF, 0xFFFFFFFF)` returned `32` (`SCC = 1`) instead of `0` (`SCC = 0`) on `s_bcnt0_i32_b64`. 2. **`s_ff1_i32_b64` / `s_ff0_i32_b64`** (`tools/rdna2spirv.py`): same fallthrough (`lo, hi = self.mask_src(a[1]), self.cu(0)`), dropping `%vcc_hi` so `vcc = (0, 0x8)` returned `-1` instead of `35` on `s_ff1_i32_b64`, and `vcc = (0xFFFFFFFF, 0xFFFFFFFF)` returned `32` instead of `-1` on `s_ff0_i32_b64`. 3. **`s_flbit_i32_b64` / `s_flbit_i32_i64`** (`tools/rdna2spirv.py`): only accepted SGPR pairs and immediates on the non-mask path, raising `Unsupported` on plain-data `vcc` and `null`. Both `s_bitcmp[01]_b64` (`bitcmp`) and `s_cmp_eq/lg_u64` already handle plain-data `vcc` by loading `%vcc` and `%vcc_hi`, and `null` as `(0, 0)`. ### Changes - **`tools/rdna2spirv.py`**: - Handle `a[1]` / `x` == `vcc` (when `holds_lane_mask(...)` is `False`) by loading `(%vcc, %vcc_hi)` and `null` as `(0, 0)` in `s_bcnt[01]_i32_b64`, `s_flbit_i32_{b64,i64}`, and `s_ff[01]_i32_b64`. - Lane-mask `vcc` (`holds_lane_mask(...) == True`) continues to take the existing `wave_mask()` path unchanged. - **`docs/design.md`**: - Documented the plain-data `vcc` and `null` handling in the `Wave64 mask ballot` row of the translator contract table. - **`tests/semantic/test_b64_bitops_vcc_data.py`**: - Covers all 6 ops (`s_bcnt1_i32_b64` + SCC, `s_bcnt0_i32_b64` + SCC, `s_ff1_i32_b64`, `s_ff0_i32_b64`, `s_flbit_i32_b64`, `s_flbit_i32_i64`) on plain-data `vcc` across 9 edge-case `(lo, hi)` pairs in native wave64, `--wave64-emulate`, and FSPX wave32 (`s_flbit_i32_{b64,i64}`), plus lane-mask-to-plain-data transitions, `null` sources, and a real lane-mask `vcc` control. ### Verification - **AI-assisted**: yes. - **Environment**: Windows 11 (Python 3.12.10, CPU-only / `spirv_mini_interp`; no GPU, LLVM, or SPIRV-Tools installed locally). - **Tests run (all GREEN)**: - `python -I tests/semantic/test_b64_bitops_vcc_data.py -v` - `python -m unittest discover -s tests/semantic -p test_scalar_bitcmp.py` - `python -m unittest discover -s tests/semantic -p test_salu_flbit_lane_mask.py` - `python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py` - `python -m unittest discover -s tests/semantic -p test_scmp_u64_mask_pairs.py` - `python -m unittest discover -s tests -p "test_docs_*.py"` - `python -I tests/test_text_write_line_endings.py` - `python -m compileall -q tools/rdna2spirv.py tests/semantic/test_b64_bitops_vcc_data.py` - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_b64_bitops_vcc_data.py` - `git diff --check` - **Negative control against `origin/main` (`tools/rdna2spirv.py` at `fe15534`)**: `tests/semantic/test_b64_bitops_vcc_data.py` fails on `origin/main` — `test_bcnt_and_ff_plain_vcc_data_reads_high_word` silently miscompiles all 4 `(lo, hi)` cases (`%vcc_hi` dropped to 0, e.g. returning `[2, 1, 62, 1, 0, 2]` instead of `[6, 1, 58, 1, 0, 2]` for `(0x3, 0xF)` and `[0, 0, 64, 1, 0xffffffff, 0]` instead of `[1, 1, 63, 1, 35, 0]` for `(0, 0x8)`), and all 5 `s_flbit_i32_{b64,i64}` tests raise `Unsupported: s_flbit_i32_b64 source`; the lane-mask control passes. --- <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#1979
No description provided.