feat(shader): implement legacy float multiply-add ops #308

Merged
asimplestray merged 1 commit from upstream-pr/308 into main 2026-10-02 20:29:06 +00:00
asimplestray commented 2026-10-02 03:12:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by asimplestray on 2026-10-02T03:12:10Z.


What

Implements 2 VOP3 opcodes:

  • V_MAD_LEGACY_F32 (0x140) reuses the FMA translation; V_MULLIT_F32 (0x150) reuses the multiply translation.
  • Encodings verified against LLVM's GFX10 disassembler tests.

Note: the integer multiply-add family from the original revision (V_MAD_I16/U16, V_MAD_I32_I16/U32_U16, V_MUL_LO_U16, V_ADD/SUB_NC_I32, V_ASHRREV_I64) has since landed in main via other work, so this PR keeps only the two remaining float ops.

Tested

Linux (GCC, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=OFF): full build, ctest 110/110 pass, including the new vector_mad_legacy test (decode opcode + family + ALU classification plus translation emitting the expected IR op for both encodings).

Checklist

  • Based on current main; no other open PR implements the same opcodes (checked open shader PRs)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (decoding unknown opcodes still throws)
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4712245766 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/308). Originally posted by [asimplestray](https://github.com/asimplestray) on 2026-10-02T03:12:10Z. --- ### What Implements 2 VOP3 opcodes: - `V_MAD_LEGACY_F32` (`0x140`) reuses the FMA translation; `V_MULLIT_F32` (`0x150`) reuses the multiply translation. - Encodings verified against LLVM's GFX10 disassembler tests. Note: the integer multiply-add family from the original revision (`V_MAD_I16/U16`, `V_MAD_I32_I16/U32_U16`, `V_MUL_LO_U16`, `V_ADD/SUB_NC_I32`, `V_ASHRREV_I64`) has since landed in `main` via other work, so this PR keeps only the two remaining float ops. ### Tested Linux (GCC, `BUILD_TESTING=ON`, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`): full build, `ctest` 110/110 pass, including the new `vector_mad_legacy` test (decode opcode + family + ALU classification plus translation emitting the expected IR op for both encodings). ### Checklist - [x] Based on current `main`; no other open PR implements the same opcodes (checked open shader PRs) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (decoding unknown opcodes still throws) - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-02 03:12:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T03:12:35Z.


Progress report (313de1c → 20f12cc)

📈 GPU shader instructions: 59.78% (+0.17%, +2 implemented instructions)

✅ 2 implemented
Encoding Name
VOP3 V_MAD_LEGACY_F32
VOP3 V_MULLIT_F32
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5944933055 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/308#issuecomment-5944933055). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T03:12:35Z. --- <!-- progress-report --> ### Progress report (313de1c → 20f12cc) 📈 **GPU shader instructions**: 59.78% (+0.17%, +2 implemented instructions) <details> <summary>✅ 2 implemented</summary> | Encoding | Name | | - | - | | VOP3 | `V_MAD_LEGACY_F32` | | VOP3 | `V_MULLIT_F32` | </details>
adriadam10 commented 2026-10-02 04:44:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T04:44:54Z.


Heads-up on overlap: #257 (opened 2026-10-01) already implements v_add_nc_i32 / v_sub_nc_i32 (including clamp as signed saturation), v_mul_lo_u16, v_mad_u16, v_mad_i16, v_mad_u32_u16, v_mad_i32_i16 and v_ashrrev_i64. It has an execution test comparing every lane on RADV/lavapipe. One thing it caught: the u32_u16 / i32_i16 forms must not take the 16-bit destination select in applyNativeVop3I16TernarySelectors, or the result gets truncated to 16 bits. Worth checking here too.

On v_mad_legacy_f32, two semantic details that FPFma32 misses:

  • It is a legacy multiply: if either factor is ±0 the product is +0, even when the other is inf or NaN. I measured that for v_mul_legacy_f32 on an RDNA2 GPU, and it's the defining property of the legacy family.
  • It is a mad, not an fma: the product is rounded before the add, like v_mad_f32. #263 adds an unfused FPMad32 for exactly that.

I had v_mad_legacy_f32 in an upcoming PR next to v_mul/mac_legacy_f32, and I've dropped it there since yours came first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5945753945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/308#issuecomment-5945753945). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T04:44:54Z. --- Heads-up on overlap: #257 (opened 2026-10-01) already implements `v_add_nc_i32` / `v_sub_nc_i32` (including clamp as signed saturation), `v_mul_lo_u16`, `v_mad_u16`, `v_mad_i16`, `v_mad_u32_u16`, `v_mad_i32_i16` and `v_ashrrev_i64`. It has an execution test comparing every lane on RADV/lavapipe. One thing it caught: the `u32_u16` / `i32_i16` forms must not take the 16-bit destination select in `applyNativeVop3I16TernarySelectors`, or the result gets truncated to 16 bits. Worth checking here too. On `v_mad_legacy_f32`, two semantic details that `FPFma32` misses: - It is a *legacy* multiply: if either factor is ±0 the product is +0, even when the other is inf or NaN. I measured that for `v_mul_legacy_f32` on an RDNA2 GPU, and it's the defining property of the legacy family. - It is a mad, not an fma: the product is rounded before the add, like `v_mad_f32`. #263 adds an unfused `FPMad32` for exactly that. I had `v_mad_legacy_f32` in an upcoming PR next to `v_mul/mac_legacy_f32`, and I've dropped it there since yours came first.
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!308
No description provided.