cpp-migration: lower v_mad_f32, v_mad_legacy_f32, v_mac_f32 and v_mac_legacy_f32 in the direct C++ compute path #3005

Closed
opened 2026-11-27 04:18:18 +00:00 by github-bot · 0 comments
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 04:13 UTC · original

Target branch cpp-migration. Part of #2935 (instruction coverage: f32 ALU). I am taking this; please say if you already have it locally and I will drop it.

Gap: the direct compute path lowers the fused v_fma_f32 family (DXIL FMad) but refuses the unfused multiply-adds. v_mad_f32 and v_mad_legacy_f32 fail with direct DXIL lowering for <name> in the per-opcode VOP3 probe of #2985 (cpp-migration 05438d65). The VOP2 accumulators v_mac_f32 and v_mac_legacy_f32 have no lowering either.

gfx2hlsl.py lowers all four through mad32(a, b, c, legacy), which matches pixel_aot:

  • flush denormal inputs to signed zero;
  • round the product on its own (for the legacy form, 0 * anything is 0);
  • add the flushed S2;
  • flush the sum.

Plan:

  • Lower the same sequence with plain fmul/fadd, which carry no fast-math flags, so no contraction is allowed. The flush is an integer mask on the sign bit.

  • v_mac_* reads the destination as its addend.

  • Fixture: a source-built dispatch against a CPU reference, with:

    • a product that needs more than 24 bits ((1 + 2^-12)^2 - 1), so fused and unfused results differ;
    • denormal inputs and a denormal sum;
    • 0 * inf for the legacy and plain forms;
    • signed zeros.

    References that fuse, skip the flush, or treat the legacy form like the plain one must differ.

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 04:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/3005) Target branch `cpp-migration`. Part of #2935 (instruction coverage: f32 ALU). I am taking this; please say if you already have it locally and I will drop it. **Gap:** the direct compute path lowers the fused `v_fma_f32` family (DXIL `FMad`) but refuses the unfused multiply-adds. `v_mad_f32` and `v_mad_legacy_f32` fail with `direct DXIL lowering for <name>` in the per-opcode VOP3 probe of #2985 (`cpp-migration` `05438d65`). The VOP2 accumulators `v_mac_f32` and `v_mac_legacy_f32` have no lowering either. `gfx2hlsl.py` lowers all four through `mad32(a, b, c, legacy)`, which matches `pixel_aot`: - flush denormal inputs to signed zero; - round the product on its own (for the legacy form, 0 * anything is 0); - add the flushed S2; - flush the sum. **Plan:** - Lower the same sequence with plain `fmul`/`fadd`, which carry no fast-math flags, so no contraction is allowed. The flush is an integer mask on the sign bit. - `v_mac_*` reads the destination as its addend. - Fixture: a source-built dispatch against a CPU reference, with: - a product that needs more than 24 bits ((1 + 2^-12)^2 - 1), so fused and unfused results differ; - denormal inputs and a denormal sum; - 0 * inf for the legacy and plain forms; - signed zeros. References that fuse, skip the flush, or treat the legacy form like the plain one must differ. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:18:18 +00:00
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#3005
No description provided.