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) #1973

Merged
ShotTechOp merged 1 commit from upstream-pr/1973 into main 2026-11-29 00:12:03 +00:00
ShotTechOp commented 2026-11-25 17:08:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ShotTechOp on 2026-11-25T17:08:06Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5495727055 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1973). Originally posted by [ShotTechOp](https://github.com/ShotTechOp) on 2026-11-25T17:08:06Z. --- 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.
zmasi commented 2026-11-28 12:16:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:16:42Z.


Verified on physical gfx906, native subgroup 64 (RADV Mesa 26.0.8), with synchronization validation enabled. Same eight input pairs on main d48a957bb and a186754ab merged with it. For example, with VCC low = 0 and high = 8, main reported a population count of 0 and no set bit; the merge returned 1 and bit index 35.

The count/find shader went from 2/8 to 8/8 matching readbacks (1,664 wrong output words to zero). Main separately refused the shader containing s_flbit_i32_b64 before dispatch; the merge ran both signed and unsigned leading-bit forms correctly on all eight inputs. The genuine VCC lane-mask and ordinary SGPR-pair controls returned byte-identical data on both trees. Overall: 32/32 merge dispatches matched, 19,456 output words correct, all guards intact, no validation errors.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239116362 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1973#issuecomment-7239116362). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:16:42Z. --- Verified on physical gfx906, native subgroup 64 (RADV Mesa 26.0.8), with synchronization validation enabled. Same eight input pairs on main `d48a957bb` and `a186754ab` merged with it. For example, with VCC low = 0 and high = 8, main reported a population count of 0 and no set bit; the merge returned 1 and bit index 35. The count/find shader went from 2/8 to 8/8 matching readbacks (1,664 wrong output words to zero). Main separately refused the shader containing `s_flbit_i32_b64` before dispatch; the merge ran both signed and unsigned leading-bit forms correctly on all eight inputs. The genuine VCC lane-mask and ordinary SGPR-pair controls returned byte-identical data on both trees. Overall: 32/32 merge dispatches matched, 19,456 output words correct, all guards intact, no validation errors. AI-assisted.
TheGeogeo commented 2026-11-29 00:00:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:00:27Z.


Tested a186754ab merged (no commit) with main aa918e5d9. Python 3.12.4, Windows 11 10.0.26300, CPU only, with LLVM_MC (conda-forge llvm-tools) and SPIRV-Tools from the Vulkan SDK 1.4.363.1. check_no_game_data.py is clean.

  • Green: tests/semantic/test_b64_bitops_vcc_data.py, 7 tests pass.
  • Red: with tools/rdna2spirv.py back to main, 4 failures and 5 errors (e.g. [32, 1, 32, 1, 0, 32] != [63, 1, 1, 1, 0, 35]).

Overlap check across #1973, #1977, #1990, #1943, #1994, #1996 and #1803 (same translator area):

  • None is a stack or a duplicate. They are independent single commits, and each covers a different reader:
    • plain 64-bit VCC data: #1973 for the b64 bit ops, #1977 for s_wqm, #1990 for src64_data/is_mask_op;
    • per-lane bits from non-mask sources: #1943 for VCC data, #1994 for s_mov into exec_hi, #1996 for m0/scc;
    • #1803: wave32 lane slots.
  • The only textual conflict is docs/design.md, between #1990, #1943 and #1994.
  • With all 7 merged together on main (docs/design.md taken from main), each PR's own test file passes. The full semantic suite (scripts/run_semantic_tests.py tests/semantic -j 4, 528 files, 6513 tests) fails in 2 files:
    • test_valu_cvt_f16_int16_mods, which fails on plain main too;
    • test_wave64_emulate_opt, which comes from #1990 alone (see #1990).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247807532 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1973#issuecomment-7247807532). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:00:27Z. --- Tested `a186754ab` merged (no commit) with `main` `aa918e5d9`. Python 3.12.4, Windows 11 10.0.26300, CPU only, with `LLVM_MC` (conda-forge llvm-tools) and SPIRV-Tools from the Vulkan SDK 1.4.363.1. `check_no_game_data.py` is clean. - Green: `tests/semantic/test_b64_bitops_vcc_data.py`, 7 tests pass. - Red: with `tools/rdna2spirv.py` back to `main`, 4 failures and 5 errors (e.g. `[32, 1, 32, 1, 0, 32] != [63, 1, 1, 1, 0, 35]`). Overlap check across #1973, #1977, #1990, #1943, #1994, #1996 and #1803 (same translator area): - None is a stack or a duplicate. They are independent single commits, and each covers a different reader: - plain 64-bit VCC data: #1973 for the b64 bit ops, #1977 for `s_wqm`, #1990 for `src64_data`/`is_mask_op`; - per-lane bits from non-mask sources: #1943 for VCC data, #1994 for `s_mov` into `exec_hi`, #1996 for `m0`/`scc`; - #1803: wave32 lane slots. - The only textual conflict is `docs/design.md`, between #1990, #1943 and #1994. - With all 7 merged together on `main` (`docs/design.md` taken from `main`), each PR's own test file passes. The full semantic suite (`scripts/run_semantic_tests.py tests/semantic -j 4`, 528 files, 6513 tests) fails in 2 files: - `test_valu_cvt_f16_int16_mods`, which fails on plain `main` too; - `test_wave64_emulate_opt`, which comes from #1990 alone (see #1990). No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 00:12:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T00:12:05Z.


Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main 829530dbd without conflict, and its test file(s) (tests/semantic/test_b64_bitops_vcc_data.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247945871 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1973#issuecomment-7247945871). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T00:12:05Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1973#issuecomment-7247807532)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 829530dbd without conflict, and its test file(s) (`tests/semantic/test_b64_bitops_vcc_data.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1973
No description provided.