tombox-xshader: VOP2 0x36-0x38 are the fused f16 forms on GFX10 (v_fmac_f16, v_fmamk_f16, v_fmaak_f16) #45
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator#45
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@realkodr on GitHub · 2026-11-21 19:14 UTC · original
rdna2/mnem.rsnames VOP2 opcodes 0x36, 0x37 and 0x38v_mac_f16,v_madmk_f16andv_madak_f16. LLVM's AMDGPU backend has these three opcodes as the fused forms on GFX10. The unfused names exist only on GFX8/9, at other opcodes.Evidence
llvm/lib/Target/AMDGPU/VOP2Instructions.tdat LLVM commit901520f:V_FMAC_F16,V_FMAMK_F16,V_FMAAK_F16VOP2_Real_gfx10<0x036>,<0x037>,<0x038>(lines 2401-2403)V_MAC_F16,V_MADMK_F16,V_MADAK_F16_vi<0x23>,<0x24>,<0x25>(lines 2819-2821)LLVM's assembler tests agree. From
llvm/test/MC/AMDGPU/gfx10_asm_vop2.s:0x6c0a0501 >> 25is 0x36.I found this by running the decoder over every GFX10 encoding in LLVM's MC tests (40,984 vectors, PR to follow). These are the only three names that disagree with LLVM across all of GFX10. Opcodes 0x06 and 0x140 also differ, but only between gfx10.1 and gfx10.3, so I left those alone.
Why it matters
The translator has two paths for these opcodes, and they give different results:
hlsl.rs, the default path:tb_hz(a * b) + kin f32, then one conversion to f16. Apart from flushing the product, this behaves like a fused operation.hlsl/mode.rs(mode_own, taken when a shader changes the half/double rounding or denormal mode):tb_h_madrounds the product to f16 withtb_h_mul, then rounds again intb_h_add. This is unfused.An input that separates fused from unfused (exact arithmetic, round to nearest even):
So
v_fmac_f16 v0, v1, v2with v1 = v2 = 0x3e01 and v0 = 0xc080 leaves 0x1a00 in v0[15:0] if the hardware fuses, and 0x1c00 if it does not.Not checked
Nothing here was executed. I have no RDNA2 hardware and no Windows machine, so this comes from reading the translator and LLVM. The
rdna2-hwprobetool from #41 could settle it with the input above.If the hardware agrees with LLVM, the fix is to rename the three opcodes and route them through
tb_h_fma, whichv_fma_mixlo_f16already uses. I can send that once someone confirms the measurement.@realkodr on GitHub · 2026-11-21 21:10 UTC · original
#49 covers this, so nobody needs to pick it up separately. It renames VOP2 0x36-0x38 to
v_fmac_f16/v_fmamk_f16/v_fmaak_f16, sends them down the fused path, and adds exec cases where fused and unfused results differ. It also handles the VOP3 form at 0x136, which I missed here.As of
1159c96main still has the old names, so this stays open until #49 (or an equivalent) lands. I won't send a competing PR.@omonkeyz on GitHub · 2026-11-22 13:20 UTC · original
Fixed on main in
b72625c: VOP2 0x36-0x38 are v_fmac_f16 / v_fmamk_f16 / v_fmaak_f16 (mnem.rs, hlsl.rs, mode.rs), with fused lowering. Thanks!