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:13:30 +00:00 by legacy-code-archaeologist · 0 comments
legacy-code-archaeologist commented 2026-11-27 04:13:30 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T04:13:30Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6639830178 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3005). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T04:13:30Z. --- 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.
Sign in to join this conversation.
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
R0Y00/Xbox2Windows#3005
No description provided.