feat(shader): implement s_bfe_i64 #838

Closed
ebosido444-ai wants to merge 1 commit from upstream-pr/838 into main
ebosido444-ai commented 2026-10-06 08:38:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T08:38:33Z.


What

s_bfe_i64 (SOP2 0x2a) is the last SOP2 hole — shaders using a signed 64-bit bitfield extract die at translation with unsupported SOP2 opcode. Implemented as the sign twin of the existing s_bfe_u64, exactly the pairing of s_bfe_u32/s_bfe_i32: sBfeU64 widens to sBfeU64(inst, bool sign) over a shared extractBits64 (the clamp-and-mask the unsigned path already had, plus the sign-extension idiom the 32-bit pair uses), so the unsigned path is byte-equivalent for its callers and the two 32/64 families now read symmetrically. Shader progress: 1125 to 1126 out of 1166 on top of current main (1127 combined with #821).

Encoding sourced from LLVM's AMDGPU backend table SOP2_Real_gfx6_gfx7_gfx10_gfx13<0x02a> — the PS5 generation (gfx11/gfx12 renumber this family, so the row is generation-specific). Field descriptor layout (offset in bits 5:0, size in bits 22:16) is the one the existing s_bfe_u64 already decodes; sizes are clamped to the bits remaining above the offset as before, and the extracted field sign-extends from its top bit.

Tested

Windows 11: core/libs/tests/ScalarBfe64.cpp (registered as scalar_bfe64) decodes both 0x2a and 0x29 through DecodeRdnaSop2, asserts family and the two-dword destination bookkeeping (IsScalarAluOpcode accepted), translates both, and distinguishes them in the IR: ShiftRightArithmetic64 is present exactly for the signed form and the shared BitwiseAnd64 clamp present for both. Standalone run passes. Scoped CMake/CTest suite (winlibs GCC 15.2.0 per BUILD.md): scalar_bfe64, scalar_bitcount64, scalar_saveexec, guest_rtc — 4/4 passed. tools/progress.py: shaders 1125 -> 1126 out of 1166 on this branch.

Checklist

  • Based on current main; no other open PR implements the same functions (checked open-PR titles and diffs for BFE/bitfield — none)
  • 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
  • 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:4756279003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/838). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-06T08:38:33Z. --- ### What `s_bfe_i64` (SOP2 0x2a) is the last SOP2 hole — shaders using a signed 64-bit bitfield extract die at translation with `unsupported SOP2 opcode`. Implemented as the sign twin of the existing `s_bfe_u64`, exactly the pairing of `s_bfe_u32`/`s_bfe_i32`: `sBfeU64` widens to `sBfeU64(inst, bool sign)` over a shared `extractBits64` (the clamp-and-mask the unsigned path already had, plus the sign-extension idiom the 32-bit pair uses), so the unsigned path is byte-equivalent for its callers and the two 32/64 families now read symmetrically. Shader progress: 1125 to 1126 out of 1166 on top of current `main` (1127 combined with #821). Encoding sourced from LLVM's AMDGPU backend table `SOP2_Real_gfx6_gfx7_gfx10_gfx13<0x02a>` — the PS5 generation (gfx11/gfx12 renumber this family, so the row is generation-specific). Field descriptor layout (`offset` in bits 5:0, `size` in bits 22:16) is the one the existing `s_bfe_u64` already decodes; sizes are clamped to the bits remaining above the offset as before, and the extracted field sign-extends from its top bit. ### Tested Windows 11: `core/libs/tests/ScalarBfe64.cpp` (registered as `scalar_bfe64`) decodes both 0x2a and 0x29 through `DecodeRdnaSop2`, asserts family and the two-dword destination bookkeeping (`IsScalarAluOpcode` accepted), translates both, and distinguishes them in the IR: `ShiftRightArithmetic64` is present exactly for the signed form and the shared `BitwiseAnd64` clamp present for both. Standalone run passes. Scoped CMake/CTest suite (winlibs GCC 15.2.0 per BUILD.md): `scalar_bfe64`, `scalar_bitcount64`, `scalar_saveexec`, `guest_rtc` — 4/4 passed. `tools/progress.py`: shaders 1125 -> 1126 out of 1166 on this branch. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (checked open-PR titles and diffs for BFE/bitfield — none) - [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 - [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 08:59:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T08:59:21Z.


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
#234 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:6012900205 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/838#issuecomment-6012900205). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T08:59:21Z. --- <!-- 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 | |---|---|---|---| | #234 | `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) | | |
ebosido444-ai commented 2026-10-06 09:41:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T09:41:51Z.


Closing in favour of #234, which implements the same function and predates this by five days (both converged on the same sBfeU64(inst, bool sign) widening and shift-align sign extension). #234 is complete with full-suite evidence. One process note for the record: my duplicate check missed #234 because a capped PR listing never reached it — the pr-overlap report above caught it. No functional difference worth merging here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6013577219 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/838#issuecomment-6013577219). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-06T09:41:51Z. --- Closing in favour of #234, which implements the same function and predates this by five days (both converged on the same sBfeU64(inst, bool sign) widening and shift-align sign extension). #234 is complete with full-suite evidence. One process note for the record: my duplicate check missed #234 because a capped PR listing never reached it — the pr-overlap report above caught it. No functional difference worth merging here.

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