shader: lower the remaining binary16 VOP2 and VOP3 arithmetic #3594

Merged
lambirou merged 5 commits from upstream-pr/3594 into main 2026-12-03 00:09:45 +00:00
lambirou commented 2026-11-30 12:11:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-30T12:11:22Z.


Part of the f16 slice (Refs #839).

This adds the remaining binary16 VOP2 and VOP3 arithmetic forms: v_dot2c_f32_f16, v_fmaak_f16, v_fmamk_f16 (VOP2) and v_fma_f16, v_fmac_f16_e64, v_ldexp_f16_e64, v_div_fixup_f16 (VOP3).

The multiply-add forms use fma16_rne and round once; v_fmac_f16_e64 reads the destination as the accumulator; v_ldexp_f16_e64 keeps the e32 exponent range [-64, 64] and its overflow rule; v_dot2c_f32_f16 requires two proven finite half words and a proven finite binary32 accumulator, follows the direct-compute model and the subnormal correction; v_div_fixup_f16 prefers the S2 NaN and returns 0xfe00 for 0/0 and Inf/Inf. The existing guards stay: entry EXEC, destination 0..255, no outstanding sample, half_denorm="preserve", refusal under round-toward-zero, and refusal of modifiers, clamp, omod, op_sel, DPP and SDWA.

Tests

  • pixel_aot_f16_vop23_warp and _hardware pass: 46 programmes plus 20 -denorm ftz repeats over exact/inexact values, negatives, signed zeros, subnormals, binary32 ties both ways, fused-vs-unfused discriminants, subnormal binary32 accumulators, destination aliasing, the div_fixup special cases, four readers and two chains. Seven mutations each report pixel_mismatch (fused made unfused, accumulator dropped, high-half read, dot2c accumulator read as a half lane, div_fixup sign reduced to S1, 0xfe00 cases removed, ldexp exponent negated) on WARP and on the RX 9060 XT (driver 32.0.32029.2010).
  • check_f16_vop23_controls covers spelling, operand kinds, proofs, ranges, mode, scheduling, readers and exact refusal messages; form_coverage_check.py pins exactly the seven forms and leaves conversions, packs, interpolation and SDWA uncovered.
  • rdna2_tools_check.py passes 162 tests (19 LLVM-dependent skips); draw-f16-arith and draw-f16-fmac-ldexp still pass on both adapters.
  • Expected full table after the merge: 1,627/1,968 gfx1013 and 1,581/1,863 gfx1030 (measured baseline 1,579/1,564, plus #3586 +10, #3592 +31 and this +7).

Limits

The high half of the destination is not observed; runtime operands stay refused by the static proof, including the dot2c accumulator; arithmetic NaN/infinity sources other than v_div_fixup_f16 are refused; dot2c routing under a partial EXEC mask and hardware overflow beyond the translator's refusal are not measured. No title is known to execute these forms.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5565013711 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3594). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-30T12:11:22Z. --- Part of the f16 slice (Refs #839). This adds the remaining binary16 VOP2 and VOP3 arithmetic forms: `v_dot2c_f32_f16`, `v_fmaak_f16`, `v_fmamk_f16` (VOP2) and `v_fma_f16`, `v_fmac_f16_e64`, `v_ldexp_f16_e64`, `v_div_fixup_f16` (VOP3). The multiply-add forms use `fma16_rne` and round once; `v_fmac_f16_e64` reads the destination as the accumulator; `v_ldexp_f16_e64` keeps the e32 exponent range [-64, 64] and its overflow rule; `v_dot2c_f32_f16` requires two proven finite half words and a proven finite binary32 accumulator, follows the direct-compute model and the subnormal correction; `v_div_fixup_f16` prefers the S2 NaN and returns `0xfe00` for 0/0 and Inf/Inf. The existing guards stay: entry EXEC, destination 0..255, no outstanding sample, `half_denorm="preserve"`, refusal under round-toward-zero, and refusal of modifiers, `clamp`, `omod`, `op_sel`, DPP and SDWA. ## Tests - `pixel_aot_f16_vop23_warp` and `_hardware` pass: 46 programmes plus 20 `-denorm ftz` repeats over exact/inexact values, negatives, signed zeros, subnormals, binary32 ties both ways, fused-vs-unfused discriminants, subnormal binary32 accumulators, destination aliasing, the `div_fixup` special cases, four readers and two chains. Seven mutations each report `pixel_mismatch` (fused made unfused, accumulator dropped, high-half read, dot2c accumulator read as a half lane, `div_fixup` sign reduced to S1, `0xfe00` cases removed, ldexp exponent negated) on WARP and on the RX 9060 XT (driver 32.0.32029.2010). - `check_f16_vop23_controls` covers spelling, operand kinds, proofs, ranges, mode, scheduling, readers and exact refusal messages; `form_coverage_check.py` pins exactly the seven forms and leaves conversions, packs, interpolation and SDWA uncovered. - `rdna2_tools_check.py` passes 162 tests (19 LLVM-dependent skips); `draw-f16-arith` and `draw-f16-fmac-ldexp` still pass on both adapters. - Expected full table after the merge: **1,627/1,968** gfx1013 and **1,581/1,863** gfx1030 (measured baseline 1,579/1,564, plus #3586 +10, #3592 +31 and this +7). ## Limits The high half of the destination is not observed; runtime operands stay refused by the static proof, including the dot2c accumulator; arithmetic NaN/infinity sources other than `v_div_fixup_f16` are refused; dot2c routing under a partial EXEC mask and hardware overflow beyond the translator's refusal are not measured. No title is known to execute these forms. AI-assisted.
lukaslw-lab commented 2026-11-30 20:44:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T20:44:24Z.

Review: APPROVED


Reviewed 8d1e8bbc by reading the diff; not built or run.

Verdict: approve. The seven lowerings match their stated models, and every operand is static and proven. No MUST. The SHOULD is a docs conflict and can follow.

  • SHOULD This removes the v_fma_f16 refusal that #704 added on purpose ("Unverified v_fma_f16 binary16 FMA semantics"). The #704 paragraph in docs/experiments.md is still in place and says that pixel_aot "rejects v_div_scale_f32 and v_fma_f16 (including explicit _e64 spellings)… until verified by source-built native RDNA readbacks". After this PR the docs contradict the code. The single-rounding half of #704's condition is now covered: the 0x3c69·0x3faa + 0x89d1 row pins 0x4039 against the unfused 0x403a. High-half preservation is handled by the half16 reader contract. But the readbacks are desktop, not RDNA. Please rewrite that paragraph, keeping v_div_scale_f32 rejected, and state that the native-readback condition is being lifted for v_fma_f16. That last part is the maintainer's call.
  • Checked, no finding:
    • v_div_fixup_f16 matches the ISA order: S2 NaN, then S1 NaN (quieted with | 0x200), then 0/0 and Inf/Inf giving 0xfe00, then S1 = 0 or S2 = Inf giving ±Inf, then S1 = Inf or S2 = 0 giving ±0, else |S0| with sign(S1) ^ sign(S2). The helper's overwrite order produces exactly that precedence, and the HLSL and Python copies are identical.
    • fmamk is S0·K + S1 and fmaak is S0·S1 + K, which matches LLVM's printed operand order. Only K's low half is read, and it must be finite. fmac_e64 reads D before writing it.
    • dot2c: both products are exact in binary32, including subnormal halves (2^-48 is normal), with one rounding for the sum and one for the accumulator add. Desktop flushing of a subnormal accumulator only matters when the sum is ±0, and dk covers that. precise prevents fusion.
    • ldexp_f16_e64: the exponent is limited to [−64, 64], so widen16·2^e stays a normal, exact binary32 before narrow16.

Tests: 46 programs plus 20 -denorm ftz repeats, and seven mutations including fused→unfused and the div_fixup special cases. The controls run in the Linux LLVM job (passed). pixel_aot_f16_vop23_{warp,hardware} are not in the Windows pr preset filter.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6120247353 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3594#pullrequestreview-6120247353). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T20:44:24Z. **Review:** APPROVED --- Reviewed `8d1e8bbc` by reading the diff; not built or run. **Verdict: approve.** The seven lowerings match their stated models, and every operand is static and proven. No MUST. The SHOULD is a docs conflict and can follow. - **SHOULD** This removes the `v_fma_f16` refusal that #704 added on purpose (`"Unverified v_fma_f16 binary16 FMA semantics"`). The #704 paragraph in `docs/experiments.md` is still in place and says that `pixel_aot` "rejects `v_div_scale_f32` and `v_fma_f16` (including explicit `_e64` spellings)… until verified by source-built native RDNA readbacks". After this PR the docs contradict the code. The single-rounding half of #704's condition is now covered: the `0x3c69·0x3faa + 0x89d1` row pins `0x4039` against the unfused `0x403a`. High-half preservation is handled by the `half16` reader contract. But the readbacks are desktop, not RDNA. Please rewrite that paragraph, keeping `v_div_scale_f32` rejected, and state that the native-readback condition is being lifted for `v_fma_f16`. That last part is the maintainer's call. - Checked, no finding: - `v_div_fixup_f16` matches the ISA order: S2 NaN, then S1 NaN (quieted with `| 0x200`), then 0/0 and Inf/Inf giving `0xfe00`, then S1 = 0 or S2 = Inf giving ±Inf, then S1 = Inf or S2 = 0 giving ±0, else `|S0|` with `sign(S1) ^ sign(S2)`. The helper's overwrite order produces exactly that precedence, and the HLSL and Python copies are identical. - `fmamk` is `S0·K + S1` and `fmaak` is `S0·S1 + K`, which matches LLVM's printed operand order. Only K's low half is read, and it must be finite. `fmac_e64` reads `D` before writing it. - `dot2c`: both products are exact in binary32, including subnormal halves (2^-48 is normal), with one rounding for the sum and one for the accumulator add. Desktop flushing of a subnormal accumulator only matters when the sum is ±0, and `dk` covers that. `precise` prevents fusion. - `ldexp_f16_e64`: the exponent is limited to [−64, 64], so `widen16·2^e` stays a normal, exact binary32 before `narrow16`. Tests: 46 programs plus 20 `-denorm ftz` repeats, and seven mutations including fused→unfused and the `div_fixup` special cases. The controls run in the Linux LLVM job (passed). `pixel_aot_f16_vop23_{warp,hardware}` are not in the Windows `pr` preset filter.
R0Y00 commented 2026-12-02 23:54:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T23:54:55Z.

Review: COMMENTED


Independent exact-head Windows checks passed for c48f4dd9: the pixel translator, form coverage, and draw-f16-vop2-vop3-arith on both WARP and RTX 4060 Laptop. All seven built-in mutations mismatched on each adapter. Since #3651 merged, git merge-tree against main 72cc7c7f shows one conflict in the CLI dispatch tuple at the end of tests/pixel_aot_check.py. Please retain both draw-sopp-denorm-mode and draw-f16-vop2-vop3-arith when merging current main.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6161209911 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3594#pullrequestreview-6161209911). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T23:54:55Z. **Review:** COMMENTED --- Independent exact-head Windows checks passed for `c48f4dd9`: the pixel translator, form coverage, and `draw-f16-vop2-vop3-arith` on both WARP and RTX 4060 Laptop. All seven built-in mutations mismatched on each adapter. Since #3651 merged, `git merge-tree` against `main` `72cc7c7f` shows one conflict in the CLI dispatch tuple at the end of `tests/pixel_aot_check.py`. Please retain both `draw-sopp-denorm-mode` and `draw-f16-vop2-vop3-arith` when merging current main.
R0Y00 commented 2026-12-02 23:58:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T23:58:05Z.


I tested that merge resolution locally against 72cc7c7f. Keeping both CLI entries passes the Python translator and form-coverage checks. draw-f16-vop2-vop3-arith and draw-sopp-denorm-mode both pass on WARP and RTX 4060 Laptop, 4/4 across the two selectors, with all seven f16 arithmetic mutations still caught on each adapter. The PR branch still needs the conflict resolution so GitHub can run the integrated checks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7362641435 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3594#issuecomment-7362641435). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T23:58:05Z. --- I tested that merge resolution locally against `72cc7c7f`. Keeping both CLI entries passes the Python translator and form-coverage checks. `draw-f16-vop2-vop3-arith` and `draw-sopp-denorm-mode` both pass on WARP and RTX 4060 Laptop, 4/4 across the two selectors, with all seven f16 arithmetic mutations still caught on each adapter. The PR branch still needs the conflict resolution so GitHub can run the integrated checks.
R0Y00 commented 2026-12-03 00:05:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T00:05:01Z.

Review: APPROVED


Re-reviewed 2cdb4381. The conflict resolution keeps both CLI modes. I compared this head with the independently tested merge tree onto 72cc7c7f: its only difference is one blank line in the dispatch list. The Python translator and form-coverage checks passed on that tree. Both draw modes passed on WARP and RTX 4060 Laptop (4/4), with all seven binary16 arithmetic mutations caught on each adapter. This head merges cleanly.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6161317190 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3594#pullrequestreview-6161317190). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T00:05:01Z. **Review:** APPROVED --- Re-reviewed `2cdb4381`. The conflict resolution keeps both CLI modes. I compared this head with the independently tested merge tree onto `72cc7c7f`: its only difference is one blank line in the dispatch list. The Python translator and form-coverage checks passed on that tree. Both draw modes passed on WARP and RTX 4060 Laptop (4/4), with all seven binary16 arithmetic mutations caught on each adapter. This head merges cleanly.
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
R0Y00/Xbox2Windows!3594
No description provided.