feat(shader): implement S_BFE_I64 #234

Closed
Digote wants to merge 1 commit from upstream-pr/234 into main
Digote commented 2026-10-01 17:33:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Digote on 2026-10-01T17:33:53Z.


What

  • Decode S_BFE_I64 as SOP2 opcode 0x2A.
  • Sign-extend the selected 64-bit scalar field and update SCC from the result.
  • Add regression coverage for decoding, classification, destination width, and translation.

Tested

Windows 11, MinGW-w64 GCC 16.1.0:

  • cmake --build build-s-bfe-i64-gcc
  • ctest --test-dir build-s-bfe-i64-gcc --output-on-failure --timeout 120 (89/89 passed)
  • python tools/progress.py build-s-bfe-i64-gcc/progress-current (GPU shader instructions: 610/1166, 52.32%)

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:4707266665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/234). Originally posted by [Digote](https://github.com/Digote) on 2026-10-01T17:33:53Z. --- ### What - Decode `S_BFE_I64` as SOP2 opcode `0x2A`. - Sign-extend the selected 64-bit scalar field and update SCC from the result. - Add regression coverage for decoding, classification, destination width, and translation. ### Tested Windows 11, MinGW-w64 GCC 16.1.0: - `cmake --build build-s-bfe-i64-gcc` - `ctest --test-dir build-s-bfe-i64-gcc --output-on-failure --timeout 120` (89/89 passed) - `python tools/progress.py build-s-bfe-i64-gcc/progress-current` (GPU shader instructions: 610/1166, 52.32%) ### 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: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-01 17:34:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-01T17:34:19Z.


Progress report (7384588 → f9f792c)

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

✅ 1 implemented
Encoding Name
SOP2 S_BFE_I64
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5936930150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/234#issuecomment-5936930150). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-01T17:34:19Z. --- <!-- progress-report --> ### Progress report (7384588 → f9f792c) 📈 **GPU shader instructions**: 72.73% (+0.09%, +1 implemented instructions) <details> <summary>✅ 1 implemented</summary> | Encoding | Name | | - | - | | SOP2 | `S_BFE_I64` | </details>
github-actions[bot] commented 2026-10-04 01:13:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T01:13:19Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#295 core/libs/prx/libSceAgcDriver/CMakeLists.txt L806
#381 core/libs/prx/libSceAgcDriver/CMakeLists.txt L806
#838 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp L242
core/shader/recompiler/Translation/src/IntegerInstructions.cpp L675-679, L683-684
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5975292455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/234#issuecomment-5975292455). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T01:13:19Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #295 | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` [L806](https://github.com/boykopovar/AnyPS5/blob/5895ea721a43f48547cc996aee0bb65b603622ac/core/libs/prx/libSceAgcDriver/CMakeLists.txt#L806) | | | | #381 | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` [L806](https://github.com/boykopovar/AnyPS5/blob/5895ea721a43f48547cc996aee0bb65b603622ac/core/libs/prx/libSceAgcDriver/CMakeLists.txt#L806) | | | | #838 | `core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp` [L242](https://github.com/boykopovar/AnyPS5/blob/5895ea721a43f48547cc996aee0bb65b603622ac/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp#L242)<br>`core/shader/recompiler/Translation/src/IntegerInstructions.cpp` [L675-679](https://github.com/boykopovar/AnyPS5/blob/5895ea721a43f48547cc996aee0bb65b603622ac/core/shader/recompiler/Translation/src/IntegerInstructions.cpp#L675-L679), [L683-684](https://github.com/boykopovar/AnyPS5/blob/5895ea721a43f48547cc996aee0bb65b603622ac/core/shader/recompiler/Translation/src/IntegerInstructions.cpp#L683-L684) | | |
oneandonlydean commented 2026-10-04 05:39:12 +00:00 (Migrated from github.com)

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


Thanks for this and for the rebase, the sign extension looks right to me, including the offset + width > 64 case, which comes out as the arithmetic shift the ISA describes. One thing before it can go in: the test only checks that a ShiftRightArithmetic64 appears. Could you turn it into an execution test with values (see core/libs/prx/libSceAgcDriver/tests/execution/ScalarBitCount.cpp for the pattern), covering a negative field, width 0, width 64 and offset + width > 64? That would pin the behaviour rather than the IR shape.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5976998535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/234#issuecomment-5976998535). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:39:12Z. --- Thanks for this and for the rebase, the sign extension looks right to me, including the offset + width > 64 case, which comes out as the arithmetic shift the ISA describes. One thing before it can go in: the test only checks that a `ShiftRightArithmetic64` appears. Could you turn it into an execution test with values (see `core/libs/prx/libSceAgcDriver/tests/execution/ScalarBitCount.cpp` for the pattern), covering a negative field, width 0, width 64 and offset + width > 64? That would pin the behaviour rather than the IR shape.
adriadam10 commented 2026-10-06 08:05:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T08:05:26Z.


@oneandonlydean measured on RDNA2 hardware (gfx1035, same SOP2 encoding as gfx1013): the semantics here match. 512 random rows through s_bfe_i64, including width 0, 1, 63, 64, 65 and 127, offset + width > 64, and garbage in the unused bits of S1, all agree with this PR's model: count = min(S1[22:16], 64 - S1[5:0]), the field sign-extended from bit count - 1, 0 for count 0, SCC = result != 0. Only your pending ask (an execution test) is left.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6012068168 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/234#issuecomment-6012068168). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T08:05:26Z. --- @oneandonlydean measured on RDNA2 hardware (gfx1035, same SOP2 encoding as gfx1013): the semantics here match. 512 random rows through `s_bfe_i64`, including width 0, 1, 63, 64, 65 and 127, offset + width > 64, and garbage in the unused bits of S1, all agree with this PR's model: count = min(S1[22:16], 64 - S1[5:0]), the field sign-extended from bit count - 1, 0 for count 0, SCC = result != 0. Only your pending ask (an execution test) is left.

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