[PR #224] rdna2spirv: 64-bit scalar data ops lower to 2x32-bit, no Int64 (SHADER-930) #276

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/224
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9958


📝 Commits (1)

  • 135d44b rdna2spirv: 64-bit scalar data ops lower to 2x32-bit, no Int64 (SHADER-930)

📊 Changes

11 files changed (+566 additions, -39 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 runtime/test/shaders/check.py (+4 -1)
➕ runtime/test/shaders/cs_w32_salu64_bfe.asm (+84 -0)
➕ runtime/test/shaders/cs_w32_salu64_bits.asm (+64 -0)
📝 scripts/run_gpu_tests.py (+5 -2)
➕ tests/semantic/fixtures/disasm/cs_w32_salu64_bfe.s (+64 -0)
➕ tests/semantic/fixtures/disasm/cs_w32_salu64_bits.s (+49 -0)
➕ tests/semantic/test_salu64_2x32.py (+227 -0)
📝 tests/semantic/test_salu_bfe_64.py (+8 -5)
📝 tools/int_hw_probe.py (+25 -0)
📝 tools/rdna2spirv.py (+35 -30)

📄 Description

Carried over from old PR 9958 by slipperysquid in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9958, 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.
slipperysquid: 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 (up for grabs in the coordination issue; the earlier claim by abnalstlll-byte on #5156 had no code)

What and why

SHADER-930 asks for a pure 2x32-bit lowering, with no Int64 capability, of the 64-bit scalar data ops s_brev_b64, s_bfe_u64, s_bfe_i64, s_bitset0_b64, s_bitset1_b64, s_flbit_i32_b64 and s_flbit_i32_i64, plus a hardware measurement.

I checked each op on main first. Five of the seven were already pure 2x32-bit. s_bfe_u64/s_bfe_i64 were not: they joined the pair into an OpTypeInt 64 value, did 64-bit shifts and set uses_psb. That put OpCapability Int64 and the PSB declarations into every module that used them, including a pixel shader that touches no memory.

op before (main) after
s_brev_b64 2x32 (OpBitReverse on each dword, swapped) unchanged; new edge tests and GPU fixture
s_bfe_u64 64-bit: OpTypeInt 64, OpShiftLeft/RightLogical %ulong, sets uses_psb, so Int64 + PSB 2x32: funnel shift right by the offset (all shift amounts 0..31), then OpBitFieldUExtract on each dword, count min(w,32) / w-min(w,32)
s_bfe_i64 64-bit: as above plus OpShiftRightArithmetic %long 2x32: same funnel, OpBitFieldSExtract on each dword; the high dword takes the low dword's sign when w <= 32
s_bitset0_b64 2x32 (bit S0 & 63, selected into one dword) unchanged; new edge tests and GPU fixture
s_bitset1_b64 2x32 unchanged; new no-Int64 test
s_flbit_i32_b64 2x32 (FindUMsb per dword) unchanged; new edge tests and GPU fixture
s_flbit_i32_i64 2x32 (~S0 when negative, then as b64) unchanged; new edge tests and GPU fixture

The semantics stay as before (RDNA2 ISA SOP1/SOP2, and the docs/design.md row): offset = S1[5:0], width = S1[22:16], a field past bit 63 stops there (width = min(width, 64 - offset)), s_bfe_i64 sign-extends from the top bit it keeps, and SCC = D != 0. The other six ops don't write SCC. In the new lowering no shift amount reaches 32, including on the discarded side of an OpSelect, because SPIR-V leaves that undefined.

Changes

  • tools/rdna2spirv.py: a new s_bfe_u64/s_bfe_i64 lowering. It no longer sets uses_psb.
  • tests/semantic/test_salu64_2x32.py (new):
    • None of the seven ops emits OpCapability Int64 or OpTypeInt 64, with SGPR-pair or constant sources.
    • s_bfe_u64/s_bfe_i64 value and SCC over offsets {0, 1, 31, 32, 33, 63} × widths {0, 1, 31, 32, 33, 63, 64, 65, 127} × 2 sources, with SCC preset to the opposite value.
    • Control bits S1[31:23] and S1[15:6] are ignored.
    • Both new GPU fixtures give their header words through spirv_mini_interp, and their header, check.py and run_gpu_tests.py expect the same words.
  • tests/semantic/test_salu_bfe_64.py: the two emission tests checked for %ulong/%long and uses_psb. They now check for the 32-bit ops and for no 64-bit type.
  • runtime/test/shaders/cs_w32_salu64_bfe.asm, cs_w32_salu64_bits.asm (new hand-written GPU fixtures; derivations in their headers) and their translator inputs in tests/semantic/fixtures/disasm/ (from regen_fixtures.py). Both are wired into runtime/test/shaders/check.py and scripts/run_gpu_tests.py.
  • tools/int_hw_probe.py: 11 more salu_64_data cases with the same edges, ready for a native run.
  • docs/design.md: the contract row for the 64-bit scalar data ops now covers the 2x32 lowering and how it was confirmed.

Tested

Linux, AMD Radeon RX 6800 XT and NVIDIA GeForce RTX 3070 in the same machine:

  • python -I scripts/run_gpu_tests.py --llvm-mc /usr/lib/llvm-21/bin/llvm-mc --filter cs_w32_salu64 (cs_w32_salu64, cs_w32_salu64_bfe, cs_w32_salu64_bits): 3 translated, 3 pass spirv-val, 3/3 PASS on each of:
    • AMD Radeon RX 6800 XT (RADV NAVI21, RDNA2 gfx1030), Mesa 26.2.7 (kisak-mesa PPA), Vulkan 1.4.354
    • NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329
    • llvmpipe, Mesa 26.2.7, LLVM 21.1.8
  • Negative control on the RX 6800 XT: making the funnel treat offset 32 as below 32 fails cs_w32_salu64_bfe with out[7] = 0x5CC0000E, the word its header predicts. Swapping the w <= 32 sign select fails 76 checks in test_salu64_2x32.py. Both were reverted.
  • python -m unittest discover -s tests/semantic -p test_salu64_2x32.py: 8 tests OK. test_salu*64*.py: all OK.
  • python -I scripts/run_semantic_tests.py tests/semantic: 460 files, 6054 tests in 77 s on 16 jobs. Two files fail: test_exec_computed (2 failures) and test_image_atomics_guard (47 failures). Both fail the same way on unmodified upstream/main (e56d9795), so this PR does not cause them. (Separately, python -I tests/test_shader_checks.py has 15 errors on main from a test harness stub that doesn't take cwd=; also not from this PR.)
  • python -I tools/int_hw_probe.py --group salu_64_data (translator side): 21/21 match. --self-test: OK. python -I tests/test_int_hw_probe.py: OK.
  • python -I tests/semantic/regen_fixtures.py --check: clean. python -m compileall -q make_game.py tools tests: clean. python -I scripts/check_no_game_data.py on every new file: clean.

The 64-bit SALU instructions have not been run natively in this PR; the GPU runs above run the translated SPIR-V. They were already measured natively on gfx1100 and gfx1035 (see the design.md row). tools/hw_oracle works on this machine (llvm-21 clang with amdgcn, ld.lld, libdrm_amdgpu 2.4.134, gcc), but the RX 6800 XT drives the desktop displays, and the DRM launcher refuses such a GPU unless LEONIDA_HW_DRM_ALLOW_DISPLAY=1 is set, because a hung kernel resets the GPU. To measure natively on gfx1030 with the new edge cases:

LEONIDA_HW_DRM_NODE=/dev/dri/renderD129 LEONIDA_HW_DRM_ALLOW_DISPLAY=1 LEONIDA_AMD_CLANG=/usr/lib/llvm-21/bin/clang \
  python -I tools/int_hw_probe.py --oracle both --wave both --group salu_64_data

The item names gfx1036. gfx1030 has the same RDNA2 ISA.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The fixtures are small hand-written .asm.
  • The changed translator rule is in the contract table of docs/design.md, with how it was confirmed.

AI-assisted (Claude Code).

🤖 Generated with Claude Code


🔄 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/224 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9958` --- ### 📝 Commits (1) - [`135d44b`](https://github.com/ubiquitarianism/leonida/commit/135d44bee33909164cc693cc6689c7ab356b98f5) rdna2spirv: 64-bit scalar data ops lower to 2x32-bit, no Int64 (SHADER-930) ### 📊 Changes **11 files changed** (+566 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `runtime/test/shaders/check.py` (+4 -1) ➕ `runtime/test/shaders/cs_w32_salu64_bfe.asm` (+84 -0) ➕ `runtime/test/shaders/cs_w32_salu64_bits.asm` (+64 -0) 📝 `scripts/run_gpu_tests.py` (+5 -2) ➕ `tests/semantic/fixtures/disasm/cs_w32_salu64_bfe.s` (+64 -0) ➕ `tests/semantic/fixtures/disasm/cs_w32_salu64_bits.s` (+49 -0) ➕ `tests/semantic/test_salu64_2x32.py` (+227 -0) 📝 `tests/semantic/test_salu_bfe_64.py` (+8 -5) 📝 `tools/int_hw_probe.py` (+25 -0) 📝 `tools/rdna2spirv.py` (+35 -30) </details> ### 📄 Description > Carried over from **old PR 9958** by `slipperysquid` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9958`, 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. > `slipperysquid`: 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 (up for grabs in the coordination issue; the earlier claim by `abnalstlll-byte` on `#5156` had no code) ### What and why SHADER-930 asks for a pure 2x32-bit lowering, with no `Int64` capability, of the 64-bit scalar data ops `s_brev_b64`, `s_bfe_u64`, `s_bfe_i64`, `s_bitset0_b64`, `s_bitset1_b64`, `s_flbit_i32_b64` and `s_flbit_i32_i64`, plus a hardware measurement. I checked each op on main first. Five of the seven were already pure 2x32-bit. `s_bfe_u64`/`s_bfe_i64` were not: they joined the pair into an `OpTypeInt 64` value, did 64-bit shifts and set `uses_psb`. That put `OpCapability Int64` and the PSB declarations into every module that used them, including a pixel shader that touches no memory. | op | before (main) | after | |---|---|---| | `s_brev_b64` | 2x32 (`OpBitReverse` on each dword, swapped) | unchanged; new edge tests and GPU fixture | | `s_bfe_u64` | **64-bit**: `OpTypeInt 64`, `OpShiftLeft/RightLogical %ulong`, sets `uses_psb`, so `Int64` + PSB | **2x32**: funnel shift right by the offset (all shift amounts 0..31), then `OpBitFieldUExtract` on each dword, count min(w,32) / w-min(w,32) | | `s_bfe_i64` | **64-bit**: as above plus `OpShiftRightArithmetic %long` | **2x32**: same funnel, `OpBitFieldSExtract` on each dword; the high dword takes the low dword's sign when w <= 32 | | `s_bitset0_b64` | 2x32 (bit `S0 & 63`, selected into one dword) | unchanged; new edge tests and GPU fixture | | `s_bitset1_b64` | 2x32 | unchanged; new no-Int64 test | | `s_flbit_i32_b64` | 2x32 (`FindUMsb` per dword) | unchanged; new edge tests and GPU fixture | | `s_flbit_i32_i64` | 2x32 (`~S0` when negative, then as b64) | unchanged; new edge tests and GPU fixture | The semantics stay as before (RDNA2 ISA SOP1/SOP2, and the `docs/design.md` row): offset = S1[5:0], width = S1[22:16], a field past bit 63 stops there (width = min(width, 64 - offset)), `s_bfe_i64` sign-extends from the top bit it keeps, and SCC = D != 0. The other six ops don't write SCC. In the new lowering no shift amount reaches 32, including on the discarded side of an `OpSelect`, because SPIR-V leaves that undefined. ### Changes - `tools/rdna2spirv.py`: a new `s_bfe_u64`/`s_bfe_i64` lowering. It no longer sets `uses_psb`. - `tests/semantic/test_salu64_2x32.py` (new): - None of the seven ops emits `OpCapability Int64` or `OpTypeInt 64`, with SGPR-pair or constant sources. - `s_bfe_u64`/`s_bfe_i64` value and SCC over offsets {0, 1, 31, 32, 33, 63} × widths {0, 1, 31, 32, 33, 63, 64, 65, 127} × 2 sources, with SCC preset to the opposite value. - Control bits S1[31:23] and S1[15:6] are ignored. - Both new GPU fixtures give their header words through `spirv_mini_interp`, and their header, `check.py` and `run_gpu_tests.py` expect the same words. - `tests/semantic/test_salu_bfe_64.py`: the two emission tests checked for `%ulong`/`%long` and `uses_psb`. They now check for the 32-bit ops and for no 64-bit type. - `runtime/test/shaders/cs_w32_salu64_bfe.asm`, `cs_w32_salu64_bits.asm` (new hand-written GPU fixtures; derivations in their headers) and their translator inputs in `tests/semantic/fixtures/disasm/` (from `regen_fixtures.py`). Both are wired into `runtime/test/shaders/check.py` and `scripts/run_gpu_tests.py`. - `tools/int_hw_probe.py`: 11 more `salu_64_data` cases with the same edges, ready for a native run. - `docs/design.md`: the contract row for the 64-bit scalar data ops now covers the 2x32 lowering and how it was confirmed. ### Tested Linux, AMD Radeon RX 6800 XT and NVIDIA GeForce RTX 3070 in the same machine: - `python -I scripts/run_gpu_tests.py --llvm-mc /usr/lib/llvm-21/bin/llvm-mc --filter cs_w32_salu64` (`cs_w32_salu64`, `cs_w32_salu64_bfe`, `cs_w32_salu64_bits`): 3 translated, 3 pass spirv-val, 3/3 PASS on each of: - AMD Radeon RX 6800 XT (RADV NAVI21, RDNA2 gfx1030), Mesa 26.2.7 (kisak-mesa PPA), Vulkan 1.4.354 - NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329 - llvmpipe, Mesa 26.2.7, LLVM 21.1.8 - Negative control on the RX 6800 XT: making the funnel treat offset 32 as below 32 fails `cs_w32_salu64_bfe` with out[7] = 0x5CC0000E, the word its header predicts. Swapping the w <= 32 sign select fails 76 checks in `test_salu64_2x32.py`. Both were reverted. - `python -m unittest discover -s tests/semantic -p test_salu64_2x32.py`: 8 tests OK. `test_salu*64*.py`: all OK. - `python -I scripts/run_semantic_tests.py tests/semantic`: 460 files, 6054 tests in 77 s on 16 jobs. Two files fail: `test_exec_computed` (2 failures) and `test_image_atomics_guard` (47 failures). Both fail the same way on unmodified `upstream/main` (e56d9795), so this PR does not cause them. (Separately, `python -I tests/test_shader_checks.py` has 15 errors on main from a test harness stub that doesn't take `cwd=`; also not from this PR.) - `python -I tools/int_hw_probe.py --group salu_64_data` (translator side): 21/21 match. `--self-test`: OK. `python -I tests/test_int_hw_probe.py`: OK. - `python -I tests/semantic/regen_fixtures.py --check`: clean. `python -m compileall -q make_game.py tools tests`: clean. `python -I scripts/check_no_game_data.py` on every new file: clean. The 64-bit SALU instructions have not been run natively in this PR; the GPU runs above run the translated SPIR-V. They were already measured natively on gfx1100 and gfx1035 (see the design.md row). `tools/hw_oracle` works on this machine (llvm-21 clang with amdgcn, ld.lld, libdrm_amdgpu 2.4.134, gcc), but the RX 6800 XT drives the desktop displays, and the DRM launcher refuses such a GPU unless `LEONIDA_HW_DRM_ALLOW_DISPLAY=1` is set, because a hung kernel resets the GPU. To measure natively on gfx1030 with the new edge cases: ```sh LEONIDA_HW_DRM_NODE=/dev/dri/renderD129 LEONIDA_HW_DRM_ALLOW_DISPLAY=1 LEONIDA_AMD_CLANG=/usr/lib/llvm-21/bin/clang \ python -I tools/int_hw_probe.py --oracle both --wave both --group salu_64_data ``` The item names gfx1036. gfx1030 has the same RDNA2 ISA. ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The fixtures are small hand-written `.asm`. - [x] The changed translator rule is in the contract table of `docs/design.md`, with how it was confirmed. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#276
No description provided.