shader: lower s_cmov_b32, s_cmov_b64 and s_cmovk_i32 #92

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

@⁠lcg007xd-c on GitHub · 2026-11-25 22:26 UTC · original
lcg007xd-c:shader-s-cmov → main · +95 −0 · 2 files · 1 commits · open

What is broken

The scalar conditional moves decode, but a program using one fails to translate with s_cmov_b32 is not supported (or the matching name):

Instruction Encoding
s_cmov_b32 SOP1 0x05
s_cmov_b64 SOP1 0x06
s_cmovk_i32 SOPK 0x02

The rest of the pipeline already handles them:

  • the IR reads SCC and the old destination for them (ir.rs, "These change (or may keep) the destination's old value");
  • resource tracking follows a descriptor picked by s_cmov (resource.rs).

Only the lowering was missing. I found the gap with a scalar sweep through the CPU harness of #62, the same sweep as #89 and #91.

Semantics

AMD's RDNA2 ISA (§12.2 opcodes 5–6, §12.4 opcode 2): if (SCC) D = S0. For s_cmovk_i32 the value is signext(SIMM16). Otherwise D keeps its value. They write no SCC.

The change (emit/lower.rs, in sop)

  • 32-bit forms: a select on SCC between the new value and the destination's old value.
  • s_cmov_b64: the same select for each dword, beside s_cselect_b64.

Tests

  • emit::lower::tests::scalar_conditional_moves_translate (every host): after s_mov into s[12:13] and s_cmp_eq_u32 s0, s1, each conditional move decodes, and a program that moves s12 to v0 and stores it translates. Without the lower.rs change it fails: s_cmov_b32 [be8c0502]: GFX10 code at 0x30: s_cmov_b32 is not supported.
  • valu_tests::scalar_conditional_moves_keep_the_destination_when_scc_is_clear (Windows/GPU): each form with SCC set and clear, reading both dwords for s_cmov_b64. The sign-extended 0x8000 checks s_cmovk_i32.
  • CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's lli: four input sets per form, SCC both ways. All match.

Run here (Linux, Rust 1.98.1):

  • cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.
  • Portable clippy and CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.

Not run here: the GPU case, since I have no Windows machine.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 22:26 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/92) `lcg007xd-c:shader-s-cmov` → `main` · +95 −0 · 2 files · 1 commits · open ## What is broken The scalar conditional moves decode, but a program using one fails to translate with `s_cmov_b32 is not supported` (or the matching name): | Instruction | Encoding | |---|---| | `s_cmov_b32` | SOP1 0x05 | | `s_cmov_b64` | SOP1 0x06 | | `s_cmovk_i32` | SOPK 0x02 | The rest of the pipeline already handles them: - the IR reads SCC and the old destination for them (`ir.rs`, "These change (or may keep) the destination's old value"); - resource tracking follows a descriptor picked by `s_cmov` (`resource.rs`). Only the lowering was missing. I found the gap with a scalar sweep through the CPU harness of #62, the same sweep as #89 and #91. ## Semantics AMD's RDNA2 ISA (§12.2 opcodes 5–6, §12.4 opcode 2): `if (SCC) D = S0`. For `s_cmovk_i32` the value is `signext(SIMM16)`. Otherwise D keeps its value. They write no SCC. ## The change (`emit/lower.rs`, in `sop`) - **32-bit forms:** a select on SCC between the new value and the destination's old value. - **`s_cmov_b64`:** the same select for each dword, beside `s_cselect_b64`. ## Tests - **`emit::lower::tests::scalar_conditional_moves_translate`** (every host): after `s_mov` into `s[12:13]` and `s_cmp_eq_u32 s0, s1`, each conditional move decodes, and a program that moves `s12` to `v0` and **stores** it translates. Without the `lower.rs` change it fails: `s_cmov_b32 [be8c0502]: GFX10 code at 0x30: s_cmov_b32 is not supported`. - **`valu_tests::scalar_conditional_moves_keep_the_destination_when_scc_is_clear`** (Windows/GPU): each form with SCC set and clear, reading both dwords for `s_cmov_b64`. The sign-extended `0x8000` checks `s_cmovk_i32`. - **CPU run:** I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's `lli`: four input sets per form, SCC both ways. All match. **Run here** (Linux, Rust 1.98.1): - `cargo test -p victory-shader --lib --locked`: 188 passed, 0 failed, 2 ignored. - Portable clippy and `CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. **Not run here:** the GPU case, since I have no Windows machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
SOP1 0x05/0x06 and SOPK 0x02 decoded but failed to translate
("s_cmov_b32 is not supported"). AMD's RDNA2 ISA: if SCC, D = S0 (for
s_cmovk_i32 the sign-extended 16-bit immediate); otherwise D keeps its
value. The IR already reads SCC and the old destination for them, and
resource tracking already follows descriptors through s_cmov; only the
lowering was missing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:44 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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