feat(shader): implement v_mad_i64_i32 #435

Merged
adriadam10 merged 1 commit from upstream-pr/435 into main 2026-10-04 09:54:50 +00:00
adriadam10 commented 2026-10-03 06:46:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-03T06:46:00Z.


What

v_mad_i64_i32 (VOP3b 0x177) threw "VOP3 opcode is not implemented". Found by the ISA coverage sweep.

  • Decoded like v_mad_u64_u32 (same VOP3b layout: 64-bit vdst, sdst carry-out, 64-bit src2).
  • Translation shares the v_mad_u64_u32 code (vMad64x32(inst, sign)): the high half of the product uses SMulHi
    instead of UMulHi; the low 64 bits of the sum are the same arithmetic.
  • Carry-out: measured on RDNA2 hardware, it is not signed overflow. It is the sign of the exact result, that is
    bit 64 of sext(S0*S1) + sext(S2). Translated as sign(product) xor sign(addend) xor unsigned carry. Out of 1000
    measured vectors, signed overflow mismatched 483 and the unsigned carry 484; this model matched all of them.
  • clamp is still rejected for both VOP3b mads, like on main. On hardware it saturates the 64-bit result to the
    signed range and leaves the carry unchanged; that is a follow-up.

Tested

  • New execution test Vop3MadI64 (32 lanes, expected values captured on an RDNA2 GPU, Radeon 660M): v_mad_i64_i32
    with an SGPR carry-out, with vcc_lo and an inline -1 multiplier, and with an inline 64-bit -1 addend, plus
    v_mad_u64_u32 on the same inputs since its code moved. Inputs cover INT_MIN products, signed and unsigned
    wrap-around, and both carry values.
  • Fails on main ("VOP3 opcode is not implemented"); passes on Linux with RADV and lavapipe.
  • Negative checks: using the unsigned carry for the signed op fails ("i64 add-1 carry"); using UMulHi fails
    ("i64 neg1 hi").
  • Full Release build + ctest: 126/126.

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:4724694528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/435). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-03T06:46:00Z. --- ### What `v_mad_i64_i32` (VOP3b 0x177) threw "VOP3 opcode is not implemented". Found by the ISA coverage sweep. - Decoded like `v_mad_u64_u32` (same VOP3b layout: 64-bit `vdst`, `sdst` carry-out, 64-bit `src2`). - Translation shares the `v_mad_u64_u32` code (`vMad64x32(inst, sign)`): the high half of the product uses `SMulHi` instead of `UMulHi`; the low 64 bits of the sum are the same arithmetic. - Carry-out: measured on RDNA2 hardware, it is **not** signed overflow. It is the sign of the exact result, that is bit 64 of `sext(S0*S1) + sext(S2)`. Translated as `sign(product) xor sign(addend) xor unsigned carry`. Out of 1000 measured vectors, signed overflow mismatched 483 and the unsigned carry 484; this model matched all of them. - `clamp` is still rejected for both VOP3b mads, like on `main`. On hardware it saturates the 64-bit result to the signed range and leaves the carry unchanged; that is a follow-up. ### Tested - New execution test `Vop3MadI64` (32 lanes, expected values captured on an RDNA2 GPU, Radeon 660M): `v_mad_i64_i32` with an SGPR carry-out, with `vcc_lo` and an inline `-1` multiplier, and with an inline 64-bit `-1` addend, plus `v_mad_u64_u32` on the same inputs since its code moved. Inputs cover INT_MIN products, signed and unsigned wrap-around, and both carry values. - Fails on `main` ("VOP3 opcode is not implemented"); passes on Linux with RADV and lavapipe. - Negative checks: using the unsigned carry for the signed op fails ("i64 add-1 carry"); using `UMulHi` fails ("i64 neg1 hi"). - Full Release build + `ctest`: 126/126. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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-03 06:46:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T06:46:23Z.


Progress report (8a64778 → e1b7ecc)

📈 GPU shader instructions: 73.58% (+0.08%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
VOP3 V_MAD_I64_I32
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5966477579 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/435#issuecomment-5966477579). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-03T06:46:23Z. --- <!-- progress-report --> ### Progress report (8a64778 → e1b7ecc) 📈 **GPU shader instructions**: 73.58% (+0.08%, +1 implemented instructions) <details> <summary>✅ 1 implemented</summary> | Encoding | Name | | - | - | | VOP3 | `V_MAD_I64_I32` | </details>
adriadam10 commented 2026-10-04 07:18:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T07:18:14Z.


Rebased onto main after #437: v_mad_i64_i32 now sits next to v_mad_u64_u32 in the 2-register case of embeddedFetchDstSize, which #437 turned into a switch. agc_driver_vop3_mad_i64 passes on RADV and lavapipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977639706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/435#issuecomment-5977639706). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T07:18:14Z. --- Rebased onto main after #437: `v_mad_i64_i32` now sits next to `v_mad_u64_u32` in the 2-register case of `embeddedFetchDstSize`, which #437 turned into a switch. `agc_driver_vop3_mad_i64` passes on RADV and lavapipe.
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!435
No description provided.