feat(shader): implement S_SWAPPC_B64 and S_RFE_B64 #901

Closed
Kikoarl wants to merge 1 commit from upstream-pr/901 into main
Kikoarl commented 2026-10-06 14:26:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-06T14:26:47Z.


What

Implement the remaining RDNA 2 SOP1 control flow instructions: S_SWAPPC_B64 (opcode 0x21) and S_RFE_B64 (opcode 0x22), completing the SOP1 instruction category (65/65).

  • Decodes S_SWAPPC_B64 with destination 64-bit SGPR pair sdst (dataDwordCount = 2) and 64-bit scalar target ssrc0, preserving existing alias to S_SETPC_B64 when sdst is the null register (125).
  • Decodes S_RFE_B64 with null destination and 64-bit scalar target ssrc0.
  • Updates GraphBuilder basic block boundary discovery and control-flow barriers.
  • Throws on IR translation until indirect subroutine call frames are modelled in the backend.

Tested

Linux x86_64, unit test scalar_sop1 verifying decoding, 64-bit destination pair, null-destination aliasing, graph builder boundaries, and translation throw path.

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: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4760172898 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/901). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-06T14:26:47Z. --- ### What Implement the remaining RDNA 2 SOP1 control flow instructions: `S_SWAPPC_B64` (opcode `0x21`) and `S_RFE_B64` (opcode `0x22`), completing the SOP1 instruction category (65/65). - Decodes `S_SWAPPC_B64` with destination 64-bit SGPR pair `sdst` (`dataDwordCount = 2`) and 64-bit scalar target `ssrc0`, preserving existing alias to `S_SETPC_B64` when `sdst` is the null register (`125`). - Decodes `S_RFE_B64` with null destination and 64-bit scalar target `ssrc0`. - Updates `GraphBuilder` basic block boundary discovery and control-flow barriers. - Throws on IR translation until indirect subroutine call frames are modelled in the backend. ### Tested Linux x86_64, unit test `scalar_sop1` verifying decoding, 64-bit destination pair, null-destination aliasing, graph builder boundaries, and translation throw path. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-06 14:28:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T14:28:22Z.


Progress report (68010df → 7fe92f9)

📈 GPU shader instructions: 97.86% (+0.18%, +2 implemented instructions)

✅ 2 implemented
Encoding Name
SOP1 S_RFE_B64
SOP1 S_SWAPPC_B64
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6018462062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/901#issuecomment-6018462062). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T14:28:22Z. --- <!-- progress-report --> ### Progress report (68010df → 7fe92f9) 📈 **GPU shader instructions**: 97.86% (+0.18%, +2 implemented instructions) <details> <summary>✅ 2 implemented</summary> | Encoding | Name | | - | - | | SOP1 | `S_RFE_B64` | | SOP1 | `S_SWAPPC_B64` | </details>
adriadam10 commented 2026-10-07 08:29:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T08:29:13Z.

Review: CHANGES_REQUESTED


Thanks. Build and ctest are green on top of current main, and the test encodings match llvm-mc -mcpu=gfx1013. One semantic problem before merging:

  • s_rfe_b64 is modelled as the end of the program (TerminatorKind::Return, GraphBuilder.cpp:523 and :571), and ScalarControlFlowSop1.cpp:94 pins that. On hardware (gfx1035, user mode) it doesn't end the wave: it jumps to ssrc0 the same way s_setpc_b64 does. Measured: s_getpc_b64 s[20:21], then s20 += .Ltarget - .Lpc, s_rfe_b64 s[20:21], v_mov_b32 v10, 1, .Ltarget: v_mov_b32 v11, 2 gives v10 = 0, v11 = 2, so the v_mov gets skipped and the wave keeps running at the target. Since translation throws, no wrong output gets through today, but the CFG and the test record the wrong behaviour. Please either throw in splitIntoBlocks as you do for s_swappc_b64, or treat it as s_setpc_b64 (dynamic target), and update the test to match.
  • Minor: the SSwappcB64 translation case (ScalarInstructions.cpp:32) and the findLastWriter clause (GraphBuilder.cpp:325) can't be reached, because splitIntoBlocks already throws for every non-null-destination s_swappc_b64. Up to you whether to keep them.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5439636921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/901#pullrequestreview-5439636921). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T08:29:13Z. **Review:** CHANGES_REQUESTED --- Thanks. Build and ctest are green on top of current `main`, and the test encodings match `llvm-mc -mcpu=gfx1013`. One semantic problem before merging: - `s_rfe_b64` is modelled as the end of the program (`TerminatorKind::Return`, `GraphBuilder.cpp:523` and `:571`), and `ScalarControlFlowSop1.cpp:94` pins that. On hardware (gfx1035, user mode) it doesn't end the wave: it jumps to `ssrc0` the same way `s_setpc_b64` does. Measured: `s_getpc_b64 s[20:21]`, then `s20 += .Ltarget - .Lpc`, `s_rfe_b64 s[20:21]`, `v_mov_b32 v10, 1`, `.Ltarget: v_mov_b32 v11, 2` gives `v10 = 0, v11 = 2`, so the `v_mov` gets skipped and the wave keeps running at the target. Since translation throws, no wrong output gets through today, but the CFG and the test record the wrong behaviour. Please either throw in `splitIntoBlocks` as you do for `s_swappc_b64`, or treat it as `s_setpc_b64` (dynamic target), and update the test to match. - Minor: the `SSwappcB64` translation case (`ScalarInstructions.cpp:32`) and the `findLastWriter` clause (`GraphBuilder.cpp:325`) can't be reached, because `splitIntoBlocks` already throws for every non-null-destination `s_swappc_b64`. Up to you whether to keep them.
Kikoarl commented 2026-10-07 12:52:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-07T12:52:38Z.


@adriadam10 Thanks for the hardware measurement and guidance! Rebased on latest main and updated s_rfe_b64 to throw in splitIntoBlocks matching s_swappc_b64, removed it from TerminatorKind::Return in linkBlocks, and updated ScalarControlFlowSop1.cpp to verify that GraphBuilder::Build throws. Ready for review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6038313698 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/901#issuecomment-6038313698). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-07T12:52:38Z. --- @adriadam10 Thanks for the hardware measurement and guidance! Rebased on latest main and updated `s_rfe_b64` to throw in `splitIntoBlocks` matching `s_swappc_b64`, removed it from `TerminatorKind::Return` in `linkBlocks`, and updated `ScalarControlFlowSop1.cpp` to verify that `GraphBuilder::Build` throws. Ready for review.
adriadam10 commented 2026-10-07 12:58:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T12:58:33Z.


Thanks for following up on the s_rfe_b64 point. With that change, though, the PR no longer changes behaviour: on main both opcodes already stop the recompilation ("unsupported SOP1 opcode 33/34"), and here they stop it in splitIntoBlocks/translation with a different message. What remains is decoding plus a throw, which only moves the progress metric (+2 instructions) without making any shader run that didn't before. We closed #980 and the related PRs for the same reason, and we said in our last review that throwing was one of the options, sorry for not flagging this then.

Closing for that reason. You're welcome to reopen once s_swappc_b64 (call with a return address) and s_rfe_b64 (indirect jump, measured on gfx1035 as behaving like s_setpc_b64) are actually translated, with an execution test that runs through them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6038413928 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/901#issuecomment-6038413928). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T12:58:33Z. --- Thanks for following up on the `s_rfe_b64` point. With that change, though, the PR no longer changes behaviour: on `main` both opcodes already stop the recompilation ("unsupported SOP1 opcode 33/34"), and here they stop it in `splitIntoBlocks`/translation with a different message. What remains is decoding plus a throw, which only moves the progress metric (+2 instructions) without making any shader run that didn't before. We closed #980 and the related PRs for the same reason, and we said in our last review that throwing was one of the options, sorry for not flagging this then. Closing for that reason. You're welcome to reopen once `s_swappc_b64` (call with a return address) and `s_rfe_b64` (indirect jump, measured on gfx1035 as behaving like `s_setpc_b64`) are actually translated, with an execution test that runs through them.

Pull request closed

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!901
No description provided.