fix(shader): translate v_fma_mix_f32 as a fused multiply-add #1878

Merged
adriadam10 merged 1 commit from upstream-pr/1878 into main 2026-10-08 22:46:53 +00:00
adriadam10 commented 2026-10-08 22:40:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T22:40:18Z.


What

v_fma_mix_f32 (VOP3P 0x20) decodes to VFmaF32 but was translated as a separately rounded multiply-add (FPMad32). roundsProductSeparately only looks at the opcode id, and 0x20 is also v_madmk_f32's VOP2 id. VOP3P instructions now never take the separately rounded path.

On RDNA2 (gfx1035), measured with the HW oracle, v_fma_mix_f32 with f32 sources is fused. It gives the same bits as v_fma_f32, while v_mul_f32 followed by v_add_f32 differs:

a, b, c v_fma_mix_f32 v_fma_f32 mul + add
0x3f800001, 0x3f7ffffe, 0xbf800000 0xa8800000 0xa8800000 0x00000000
0x3fa00001, 0x40400001, 0xc0700001 0x34e00001 0x34e00001 0x35000000

v_fma_mixlo_f16/v_fma_mixhi_f16 already used FPFma32.

This also makes the f32 denormal flush from #1850 apply to v_fma_mix_f32, as its TechnicalDebt line already says: the flush classification also skips the separately rounded forms.

Tested

Linux (CachyOS, GCC), full Release ctest 493/493. vector_fused_multiply_add now also decodes and translates v_fma_mix_f32 with f32 sources and with op_sel_hi:[1,0,1], and requires one FPFma32 and no FPMad32. It fails without the fix. That test pins the IR routing rather than values, like its existing VOP2 cases, because a value test can't tell fused from split: Vulkan lets a driver split Fma into a multiply and an add.

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:4793643866 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1878). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T22:40:18Z. --- ### What `v_fma_mix_f32` (VOP3P 0x20) decodes to `VFmaF32` but was translated as a separately rounded multiply-add (`FPMad32`). `roundsProductSeparately` only looks at the opcode id, and 0x20 is also `v_madmk_f32`'s VOP2 id. VOP3P instructions now never take the separately rounded path. On RDNA2 (gfx1035), measured with the HW oracle, `v_fma_mix_f32` with f32 sources is fused. It gives the same bits as `v_fma_f32`, while `v_mul_f32` followed by `v_add_f32` differs: | a, b, c | `v_fma_mix_f32` | `v_fma_f32` | mul + add | |---|---|---|---| | `0x3f800001`, `0x3f7ffffe`, `0xbf800000` | `0xa8800000` | `0xa8800000` | `0x00000000` | | `0x3fa00001`, `0x40400001`, `0xc0700001` | `0x34e00001` | `0x34e00001` | `0x35000000` | `v_fma_mixlo_f16`/`v_fma_mixhi_f16` already used `FPFma32`. This also makes the f32 denormal flush from #1850 apply to `v_fma_mix_f32`, as its TechnicalDebt line already says: the flush classification also skips the separately rounded forms. ### Tested Linux (CachyOS, GCC), full Release ctest 493/493. `vector_fused_multiply_add` now also decodes and translates `v_fma_mix_f32` with f32 sources and with `op_sel_hi:[1,0,1]`, and requires one `FPFma32` and no `FPMad32`. It fails without the fix. That test pins the IR routing rather than values, like its existing VOP2 cases, because a value test can't tell fused from split: Vulkan lets a driver split `Fma` into a multiply and an add. ### 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
Deftera186 commented 2026-10-09 02:19:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Deftera186 on 2026-10-09T02:19:02Z.


This duplicates #1445, opened 16 hours earlier with the same fix (roundsProductSeparately skipping VOP3P) on the same branch name. pr-overlap missed it because tools/pr_overlap.py only lists the 200 newest open PRs (gh pr list -L 200). At the 22:42 UTC run, 326 newer PRs were open, so #1445 was never compared. Merging both heads on that run's base (42e91486) conflicts in VectorInstructions.cpp, so the pair would have been reported otherwise. #1325 removes that cap.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072910126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1878#issuecomment-6072910126). Originally posted by [Deftera186](https://github.com/Deftera186) on 2026-10-09T02:19:02Z. --- This duplicates #1445, opened 16 hours earlier with the same fix (`roundsProductSeparately` skipping VOP3P) on the same branch name. pr-overlap missed it because `tools/pr_overlap.py` only lists the 200 newest open PRs (`gh pr list -L 200`). At the 22:42 UTC run, 326 newer PRs were open, so #1445 was never compared. Merging both heads on that run's base (42e91486) conflicts in `VectorInstructions.cpp`, so the pair would have been reported otherwise. #1325 removes that cap.
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!1878
No description provided.