feat(shader): VOP3 v_add/sub_nc_i32 (clamp), v_mul_lo_u16, 16-bit mads, v_ashrrev_i64 #257

Merged
adriadam10 merged 2 commits from upstream-pr/257 into main 2026-10-02 08:13:31 +00:00
adriadam10 commented 2026-10-01 20:09:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-01T20:09:25Z.


What

These VOP3 opcodes threw "VOP3 opcode is not implemented":

  • v_add_nc_i32, v_sub_nc_i32 (0x37f, 0x376), including clamp: these are what compilers emit for signed saturating add/sub (sadd.sat/ssub.sat), so clamp saturates to [INT32_MIN, INT32_MAX] (overflow from the sign bits, result (a >> 31) ^ 0x7fffffff). Other modifiers stay rejected.
  • v_mul_lo_u16 (0x305): integer16Binary(IMul32), op_sel on sources like the other 16-bit binaries.
  • v_mad_u16, v_mad_i16 (0x340, 0x35e): 16-bit result, op_sel on all three sources and the destination half.
  • v_mad_u32_u16, v_mad_i32_i16 (0x373, 0x375): 16x16 product plus a 32-bit addend, 32-bit result. They share the I16 ternary decode path but applyNativeVop3I16TernarySelectors no longer sets the 16-bit destination select or src2 op_sel for them (with it the result was truncated to 16 bits; the test caught that).
  • v_ashrrev_i64 (0x301): next to the existing v_lshrrev_b64.

Found with an ISA sweep (every gfx1013 opcode from llvm-mc through DecodeRdnaInstruction + TranslateInstruction).

Test agc_driver_vop3_integer: hand-assembled compute shader (words from llvm-mc -mcpu=gfx1013), 64 lanes with edge inputs (INT32_MIN/MAX overflow pairs, -1, 0x8000 halves, shift counts 0/31/32/63/64) and pseudo-random ones, 14 results per lane checked against a C++ model, including the clamp and op_sel forms. 16-bit results are checked on the written half only. No cross-lane ops, so it runs on lavapipe in CI.

Tested

Linux: passes on RADV (Radeon 660M) and lavapipe; without the change it fails with "VOP3 opcode is not implemented". Full ctest (99) passes.

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:4708996082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/257). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-01T20:09:25Z. --- ### What These VOP3 opcodes threw "VOP3 opcode is not implemented": - `v_add_nc_i32`, `v_sub_nc_i32` (0x37f, 0x376), including **clamp**: these are what compilers emit for signed saturating add/sub (`sadd.sat`/`ssub.sat`), so clamp saturates to `[INT32_MIN, INT32_MAX]` (overflow from the sign bits, result `(a >> 31) ^ 0x7fffffff`). Other modifiers stay rejected. - `v_mul_lo_u16` (0x305): `integer16Binary(IMul32)`, op_sel on sources like the other 16-bit binaries. - `v_mad_u16`, `v_mad_i16` (0x340, 0x35e): 16-bit result, op_sel on all three sources and the destination half. - `v_mad_u32_u16`, `v_mad_i32_i16` (0x373, 0x375): 16x16 product plus a **32-bit** addend, 32-bit result. They share the I16 ternary decode path but `applyNativeVop3I16TernarySelectors` no longer sets the 16-bit destination select or src2 op_sel for them (with it the result was truncated to 16 bits; the test caught that). - `v_ashrrev_i64` (0x301): next to the existing `v_lshrrev_b64`. Found with an ISA sweep (every gfx1013 opcode from `llvm-mc` through `DecodeRdnaInstruction` + `TranslateInstruction`). Test `agc_driver_vop3_integer`: hand-assembled compute shader (words from `llvm-mc -mcpu=gfx1013`), 64 lanes with edge inputs (INT32_MIN/MAX overflow pairs, -1, 0x8000 halves, shift counts 0/31/32/63/64) and pseudo-random ones, 14 results per lane checked against a C++ model, including the clamp and op_sel forms. 16-bit results are checked on the written half only. No cross-lane ops, so it runs on lavapipe in CI. ### Tested Linux: passes on RADV (Radeon 660M) and lavapipe; without the change it fails with "VOP3 opcode is not implemented". Full ctest (99) passes. ### 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-01 20:09:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-01T20:09:49Z.


Progress report (709d7fe → e144f43)

📈 GPU shader instructions: 53.34% (+0.68%, +8 implemented instructions)

✅ 8 implemented
Encoding Name
VOP3 V_ADD_NC_I32
VOP3 V_ASHRREV_I64
VOP3 V_MAD_I16
VOP3 V_MAD_I32_I16
VOP3 V_MAD_U16
VOP3 V_MAD_U32_U16
VOP3 V_MUL_LO_U16
VOP3 V_SUB_NC_I32
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5939627344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/257#issuecomment-5939627344). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-01T20:09:49Z. --- <!-- progress-report --> ### Progress report (709d7fe → e144f43) 📈 **GPU shader instructions**: 53.34% (+0.68%, +8 implemented instructions) <details> <summary>✅ 8 implemented</summary> | Encoding | Name | | - | - | | VOP3 | `V_ADD_NC_I32` | | VOP3 | `V_ASHRREV_I64` | | VOP3 | `V_MAD_I16` | | VOP3 | `V_MAD_I32_I16` | | VOP3 | `V_MAD_U16` | | VOP3 | `V_MAD_U32_U16` | | VOP3 | `V_MUL_LO_U16` | | VOP3 | `V_SUB_NC_I32` | </details>
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!257
No description provided.