feat(shader): implement s_cmovk_i32, s_version and s_setreg_imm32_b32 #333

Merged
adriadam10 merged 2 commits from upstream-pr/333 into main 2026-10-04 22:41:48 +00:00
adriadam10 commented 2026-10-02 06:52:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T06:52:46Z.


What

Three SOPK opcodes threw unsupported SOPK opcode. The ISA sweep found them.

  • s_cmovk_i32 (0x02): if (SCC) D = sext(simm16). Measured on an RDNA2 GPU: 0x8001 writes 0xffff8001, and with SCC clear the register is unchanged.
  • s_version (0x01): marker for the ISA version, no effect.
  • s_setreg_imm32_b32 (0x15): like s_setreg_b32, but the value is a literal dword that follows the instruction. The decoder now consumes that literal, so the next instruction decodes from the right word. Like s_setreg_b32, it is translated as a no-op.

s_setreg_b32 already ignored its writes without being listed. Both are now listed under silent stubs in docs/dev/TechnicalDebt.md: writes to MODE (rounding/denormals) and the other hardware registers have no effect.

Test agc_driver_scalar_sopk_misc: s_cmovk_i32 taken (negative and positive immediates) and not taken, plus an s_mov_b32 right after s_setreg_imm32_b32 to check the literal is skipped. Expected values were measured on the RDNA2 GPU.

Tested

Linux, full ctest (99) passes.

  • RADV (Radeon 660M) and lavapipe: the test passes.
  • Writing without checking SCC: cmovk_not_taken is 0x00007fff, expected 0x22222222.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #251 (test harness); review only the last commit
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4713586192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/333). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T06:52:46Z. --- ### What Three SOPK opcodes threw `unsupported SOPK opcode`. The ISA sweep found them. - `s_cmovk_i32` (0x02): `if (SCC) D = sext(simm16)`. Measured on an RDNA2 GPU: `0x8001` writes `0xffff8001`, and with SCC clear the register is unchanged. - `s_version` (0x01): marker for the ISA version, no effect. - `s_setreg_imm32_b32` (0x15): like `s_setreg_b32`, but the value is a literal dword that follows the instruction. The decoder now consumes that literal, so the next instruction decodes from the right word. Like `s_setreg_b32`, it is translated as a no-op. `s_setreg_b32` already ignored its writes without being listed. Both are now listed under silent stubs in `docs/dev/TechnicalDebt.md`: writes to MODE (rounding/denormals) and the other hardware registers have no effect. Test `agc_driver_scalar_sopk_misc`: `s_cmovk_i32` taken (negative and positive immediates) and not taken, plus an `s_mov_b32` right after `s_setreg_imm32_b32` to check the literal is skipped. Expected values were measured on the RDNA2 GPU. ### Tested Linux, full ctest (99) passes. - RADV (Radeon 660M) and lavapipe: the test passes. - Writing without checking SCC: `cmovk_not_taken is 0x00007fff, expected 0x22222222`. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #251 (test harness); review only the last commit - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-02 07:02:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T07:02:17Z.


Progress report (cd61f15 → eff7af9)

📈 GPU shader instructions: 73.41% (+0.25%, +3 implemented instructions)

✅ 3 implemented
Encoding Name
SOPK S_CMOVK_I32
SOPK S_SETREG_IMM32_B32
SOPK S_VERSION
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5947077409 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/333#issuecomment-5947077409). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T07:02:17Z. --- <!-- progress-report --> ### Progress report (cd61f15 → eff7af9) 📈 **GPU shader instructions**: 73.41% (+0.25%, +3 implemented instructions) <details> <summary>✅ 3 implemented</summary> | Encoding | Name | | - | - | | SOPK | `S_CMOVK_I32` | | SOPK | `S_SETREG_IMM32_B32` | | SOPK | `S_VERSION` | </details>
oneandonlydean commented 2026-10-04 05:41:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:41:37Z.


Thanks, s_cmovk_i32 and s_version look right to me (I checked the SOPK encodings with llvm-mc for gfx1013, and the literal skip is a good catch).
One thing I can't merge as is: s_setreg_imm32_b32 becomes a silent no-op and is listed under silent stubs. CONTRIBUTING limits silent stubs to UI-only behaviour that unblocks a title, and a MODE write changes rounding and denormal results. Since the value here is a literal, could the translation accept only writes that leave what the recompiler models unchanged and throw for anything else (or leave the opcode throwing for now)? The existing s_setreg_b32 no-op is worth recording, but under "Functional" in TechnicalDebt.md rather than "Silent stubs". With that split, the rest is ready from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977013505 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/333#issuecomment-5977013505). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:41:37Z. --- Thanks, `s_cmovk_i32` and `s_version` look right to me (I checked the SOPK encodings with llvm-mc for gfx1013, and the literal skip is a good catch). One thing I can't merge as is: `s_setreg_imm32_b32` becomes a silent no-op and is listed under silent stubs. CONTRIBUTING limits silent stubs to UI-only behaviour that unblocks a title, and a MODE write changes rounding and denormal results. Since the value here is a literal, could the translation accept only writes that leave what the recompiler models unchanged and throw for anything else (or leave the opcode throwing for now)? The existing `s_setreg_b32` no-op is worth recording, but under "Functional" in TechnicalDebt.md rather than "Silent stubs". With that split, the rest is ready from my side.
adriadam10 commented 2026-10-04 06:28:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T06:28:55Z.


Thanks, agreed. Rebased onto main and changed it:

  • s_setreg_imm32_b32 is a no-op only when it writes 0 (round to nearest even) inside MODE's FP_ROUND bits [3:0]. Any other register, a field that reaches the denormal bits, or a nonzero value throws.
  • The test now writes RNE, and it checks that a round-toward-zero write (hwreg(MODE, 0, 4), 0xf) is refused. The refusal check fails if the guard is removed.
  • TechnicalDebt: the silent stubs line is gone, and the existing s_setreg_b32 no-op is recorded under "Functional".
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977316965 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/333#issuecomment-5977316965). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T06:28:55Z. --- Thanks, agreed. Rebased onto main and changed it: - `s_setreg_imm32_b32` is a no-op only when it writes 0 (round to nearest even) inside MODE's FP_ROUND bits [3:0]. Any other register, a field that reaches the denormal bits, or a nonzero value throws. - The test now writes RNE, and it checks that a round-toward-zero write (`hwreg(MODE, 0, 4), 0xf`) is refused. The refusal check fails if the guard is removed. - TechnicalDebt: the silent stubs line is gone, and the existing `s_setreg_b32` no-op is recorded under "Functional".
oneandonlydean commented 2026-10-04 22:37:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:37:53Z.


Thanks, that's exactly the split I meant. s_setreg_imm32_b32 is now a no-op only for a write of 0 into MODE's FP_ROUND bits (hwreg id 1, offset plus size within bits 3:0), which is round to nearest even and what the recompiler assumes; any other register, a field that reaches the denormal bits, or a nonzero value throws. The refusal test covers the round toward zero case, and the existing s_setreg_b32 no-op now sits under "Functional" in TechnicalDebt.md. agc_driver_scalar_sopk_misc passes on my NVIDIA machine on current main, and fails on main's code.

All three are opcodes main refused, so this is ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985218185 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/333#issuecomment-5985218185). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T22:37:53Z. --- Thanks, that's exactly the split I meant. `s_setreg_imm32_b32` is now a no-op only for a write of 0 into MODE's FP_ROUND bits (hwreg id 1, offset plus size within bits 3:0), which is round to nearest even and what the recompiler assumes; any other register, a field that reaches the denormal bits, or a nonzero value throws. The refusal test covers the round toward zero case, and the existing `s_setreg_b32` no-op now sits under "Functional" in TechnicalDebt.md. `agc_driver_scalar_sopk_misc` passes on my NVIDIA machine on current main, and fails on main's code. All three are opcodes main refused, so this is ready to merge from my side.
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
boykopovar/AnyPS5!333
No description provided.