feat(shader): implement S_CALL_B64 #895

Merged
Kikoarl merged 1 commit from upstream-pr/895 into main 2026-10-08 17:24:59 +00:00
Kikoarl commented 2026-10-06 13:47:24 +00:00 (Migrated from github.com)

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


What

Implement the remaining RDNA 2 SOPK subroutine call instruction: S_CALL_B64 (opcode 0x16), completing the SOPK instruction category (27/27).

  • Decodes destination 64-bit SGPR pair sdst (dataDwordCount = 2) and relative target address (PC + 4 + simm16 * 4).
  • Handles direct branch block linking in GraphBuilder.
  • Throws on IR translation until subroutine call graphs / call frames are modelled in the backend.

Tested

Linux x86_64, unit test scalar_call verifying decoding, 64-bit destination pair, positive/negative relative branch targets, 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:4759655836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/895). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-06T13:47:24Z. --- ### What Implement the remaining RDNA 2 SOPK subroutine call instruction: `S_CALL_B64` (opcode `0x16`), completing the SOPK instruction category (27/27). - Decodes destination 64-bit SGPR pair `sdst` (`dataDwordCount = 2`) and relative target address (`PC + 4 + simm16 * 4`). - Handles direct branch block linking in `GraphBuilder`. - Throws on IR translation until subroutine call graphs / call frames are modelled in the backend. ### Tested Linux x86_64, unit test `scalar_call` verifying decoding, 64-bit destination pair, positive/negative relative branch targets, 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 13:48:02 +00:00 (Migrated from github.com)

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


Progress report (e79c971 → f5619c4)

📈 GPU shader instructions: 97.77% (+0.09%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
SOPK S_CALL_B64
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6017677138 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/895#issuecomment-6017677138). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T13:48:02Z. --- <!-- progress-report --> ### Progress report (e79c971 → f5619c4) 📈 **GPU shader instructions**: 97.77% (+0.09%, +1 implemented instructions) <details> <summary>✅ 1 implemented</summary> | Encoding | Name | | - | - | | SOPK | `S_CALL_B64` | </details>
adriadam10 commented 2026-10-07 08:16:52 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Measured on gfx1035: sdst gets the address of the s_call_b64 + 4 (high dword = PC high), and forward/backward targets are PC + 4 + simm16 * 4. The decoder matches that.

  • GraphBuilder.cpp:590 and RdnaOpcode.cpp:907 link s_call_b64 as a plain s_branch: no return edge to PC + 4, and sdst is never written. With a real call/return (s_call_b64 s[4:5], callee ... callee: s_setpc_b64 s[4:5]), decode + GraphBuilder::Build now fails with unsupported dynamic s_setpc_b64 at program counter 0x0000000c. The new throw in ScalarInstructions.cpp:33 is never reached, and the error names the wrong instruction. It still throws, so nothing silently goes wrong, but the CFG model is wrong for a call and anyone implementing calls later would build on it.
  • Suggested direction: leave s_call_b64 out of IsDirectBranchOpcode and linkBlocks for now, so it stays an ordinary instruction and throws at its own translation. Model it in the CFG (call + return edge) only once calls are actually implemented.
  • ScalarCall.cpp only exercises DecodeRdnaSopk and TranslateInstruction. None of the tests reach GraphBuilder. Please add a case that decodes and builds a small call/return program and checks that it fails on the s_call_b64 throw.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5439493830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/895#pullrequestreview-5439493830). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T08:16:52Z. **Review:** CHANGES_REQUESTED --- Measured on gfx1035: sdst gets the address of the `s_call_b64` + 4 (high dword = PC high), and forward/backward targets are PC + 4 + simm16 * 4. The decoder matches that. - `GraphBuilder.cpp:590` and `RdnaOpcode.cpp:907` link `s_call_b64` as a plain `s_branch`: no return edge to PC + 4, and sdst is never written. With a real call/return (`s_call_b64 s[4:5], callee` ... `callee: s_setpc_b64 s[4:5]`), decode + `GraphBuilder::Build` now fails with `unsupported dynamic s_setpc_b64 at program counter 0x0000000c`. The new throw in `ScalarInstructions.cpp:33` is never reached, and the error names the wrong instruction. It still throws, so nothing silently goes wrong, but the CFG model is wrong for a call and anyone implementing calls later would build on it. - Suggested direction: leave `s_call_b64` out of `IsDirectBranchOpcode` and `linkBlocks` for now, so it stays an ordinary instruction and throws at its own translation. Model it in the CFG (call + return edge) only once calls are actually implemented. - `ScalarCall.cpp` only exercises `DecodeRdnaSopk` and `TranslateInstruction`. None of the tests reach `GraphBuilder`. Please add a case that decodes and builds a small call/return program and checks that it fails on the `s_call_b64` throw.
Kikoarl commented 2026-10-07 13:02:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-07T13:02:50Z.


@adriadam10 Thanks for the guidance! Rebased on latest main, left s_call_b64 out of IsDirectBranchOpcode and linkBlocks so it remains an ordinary instruction and throws at its own translation, and added a test case in ScalarCall.cpp that decodes and builds a small call program with GraphBuilder and verifies that translation fails on the s_call_b64 throw. Ready for review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6038486859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/895#issuecomment-6038486859). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-07T13:02:50Z. --- @adriadam10 Thanks for the guidance! Rebased on latest main, left `s_call_b64` out of `IsDirectBranchOpcode` and `linkBlocks` so it remains an ordinary instruction and throws at its own translation, and added a test case in `ScalarCall.cpp` that decodes and builds a small call program with `GraphBuilder` and verifies that translation fails on the `s_call_b64` throw. Ready for review.
adriadam10 commented 2026-10-08 17:24:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T17:24:41Z.


Rechecked on the merge with current main: build and full ctest green (467/467, scalar_call included). s_call_b64 now stays out of the CFG branch model and throws at its own translation, which is what the last review asked for. Merging, thanks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065359319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/895#issuecomment-6065359319). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T17:24:41Z. --- Rechecked on the merge with current `main`: build and full ctest green (467/467, `scalar_call` included). `s_call_b64` now stays out of the CFG branch model and throws at its own translation, which is what the last review asked for. Merging, thanks.
adriadam10 commented 2026-10-08 17:24:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T17:24:56Z.

Review: APPROVED


Requested changes addressed; build and full ctest green on the merge with main.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5460462533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/895#pullrequestreview-5460462533). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T17:24:56Z. **Review:** APPROVED --- Requested changes addressed; build and full ctest green on the merge with main.
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!895
No description provided.