rdna2spirv: s_bfe_u64 / s_bfe_i64 on the dword pair, with no Int64 (SHADER-930) #212

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

@⁠Andretuta on GitHub · 2026-11-24 02:45 UTC · original
ubiquitarianism:old-pr/9947 → main · +53 −37 · 3 files · 1 commits · draft

Carried over from old PR 9947 by fromthemoonx in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9947, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
fromthemoonx: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Item: SHADER-930 (translator part; claimed in #9677). The gfx1036 hardware measurement in the row stays up for grabs.
Depends on: nothing

What. s_bfe_u64 / s_bfe_i64 were the last 64-bit scalar data ops that built a %ulong and set uses_psb (Int64). The others in the row (s_brev_b64, s_bitset*_b64, s_flbit_i32_*64) already use 32-bit ops only. The extract is now lowered on the (lo, hi) dword pair:

  • Shift the pair right by the offset with 32-bit shifts only. The bits coming down from the high dword are written (b << 1) << (31 - s), so no shift amount reaches 32 and s = 0 needs no select.
  • Extract min(w, 32) bits of the low dword and w - 32 of the high one with OpBitField[U|S]Extract. A count of 0 extracts 0, so width 0 still gives D = 0 and SCC = 0.
  • s_bfe_i64 with w ≤ 32 sign-fills the high dword from the low field's top bit.
  • The semantics are unchanged: offset = S1[5:0], width = S1[22:16], cut at bit 63 (LLVM constantFoldBFE), SCC = D ≠ 0.

Tests (Linux, CPU).

  • test_salu_bfe_64.py: the two emission tests no longer pin %ulong / %long; they assert no 64-bit type and uses_psb False (both fail on main, as intended). A new test checks every offset 0-63 × widths 0, 1, 2, 15, 16, 31-34, 47, 62-65, 127 × both ops × a value with the top bit set and one with it clear, against the file's reference model: 3,840 cases, all pass.
  • All 17 test_salu*64* files pass, including test_salu64_fixture.py. The translated cs_w32_salu64 passes spirv-val --target-env vulkan1.2. That module still declares Int64 for its buffer addressing, not for s_bfe.
  • Full semantic suite: 6,047 tests. 3 files fail on main as well, unchanged by this PR: test_exec_computed (SHADER-1264), test_image_atomics_guard and test_int32_to_f64.
  • docs/design.md: the 64-bit scalar data ops row says how they are lowered and how that was checked.

GPU. cs_w32_salu64 (it runs s_bfe_u64 and s_bfe_i64 against the hardware-verified words in the row) on an NVIDIA RTX 3060 / Windows 11: result to follow in a comment.

AI-assisted (Claude).

🤖 Generated with Claude Code

https://claude.ai/code/session_01FXR27ZYP9qtZtN8SG7QPWW

**@⁠Andretuta** on GitHub · 2026-11-24 02:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/212) `ubiquitarianism:old-pr/9947` → `main` · +53 −37 · 3 files · 1 commits · draft > Carried over from **old PR 9947** by `fromthemoonx` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9947`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `fromthemoonx`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Item: SHADER-930 (translator part; claimed in `#9677`). The gfx1036 hardware measurement in the row stays up for grabs. Depends on: nothing **What.** `s_bfe_u64` / `s_bfe_i64` were the last 64-bit scalar data ops that built a `%ulong` and set `uses_psb` (Int64). The others in the row (`s_brev_b64`, `s_bitset*_b64`, `s_flbit_i32_*64`) already use 32-bit ops only. The extract is now lowered on the (lo, hi) dword pair: - Shift the pair right by the offset with 32-bit shifts only. The bits coming down from the high dword are written `(b << 1) << (31 - s)`, so no shift amount reaches 32 and s = 0 needs no select. - Extract `min(w, 32)` bits of the low dword and `w - 32` of the high one with `OpBitField[U|S]Extract`. A count of 0 extracts 0, so width 0 still gives D = 0 and SCC = 0. - `s_bfe_i64` with w ≤ 32 sign-fills the high dword from the low field's top bit. - The semantics are unchanged: offset = S1[5:0], width = S1[22:16], cut at bit 63 (LLVM `constantFoldBFE`), SCC = D ≠ 0. **Tests (Linux, CPU).** - `test_salu_bfe_64.py`: the two emission tests no longer pin `%ulong` / `%long`; they assert no 64-bit type and `uses_psb` False (both fail on main, as intended). A new test checks **every offset 0-63** × widths 0, 1, 2, 15, 16, 31-34, 47, 62-65, 127 × both ops × a value with the top bit set and one with it clear, against the file's reference model: 3,840 cases, all pass. - All 17 `test_salu*64*` files pass, including `test_salu64_fixture.py`. The translated `cs_w32_salu64` passes `spirv-val --target-env vulkan1.2`. That module still declares Int64 for its buffer addressing, not for `s_bfe`. - Full semantic suite: 6,047 tests. 3 files fail on main as well, unchanged by this PR: `test_exec_computed` (SHADER-1264), `test_image_atomics_guard` and `test_int32_to_f64`. - `docs/design.md`: the 64-bit scalar data ops row says how they are lowered and how that was checked. **GPU.** `cs_w32_salu64` (it runs `s_bfe_u64` and `s_bfe_i64` against the hardware-verified words in the row) on an NVIDIA RTX 3060 / Windows 11: result to follow in a comment. AI-assisted (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FXR27ZYP9qtZtN8SG7QPWW
s_bfe_u64 and s_bfe_i64 were the last 64-bit scalar data ops that built a
%ulong and needed the Int64 capability; s_brev_b64, s_bitset*_b64 and
s_flbit_i32_*64 already use 32-bit ops only. Shift the (lo, hi) pair right by
the offset with 32-bit shifts (every amount below 32), then extract min(w, 32)
bits of the low dword and w - 32 of the high one; s_bfe_i64 sign-fills the high
dword from the low field when w <= 32. A count of 0 extracts 0, so width 0
needs no select. SCC is unchanged (D != 0).

test_salu_bfe_64: the emission tests now assert no 64-bit type and no
uses_psb, and a new test checks every offset against the reference at widths
around both dword edges and past bit 63, for a value with the top bit set and
clear.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FXR27ZYP9qtZtN8SG7QPWW
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:48:56 +00:00
This pull request has changes conflicting with the target branch.
  • docs/design.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/212/head:github-bot/gh-212'
git switch 'github-bot/gh-212'

Merge

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