shader: lower the binary64 rounding and fraction forms #3643

Closed
lambirou wants to merge 0 commits from upstream-pr/3643 into main
lambirou commented 2026-11-30 19:48:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-30T19:48:49Z.


Part of the f64 slice (P5).

This adds the ten binary64 rounding/fraction forms: v_ceil_f64, v_floor_f64, v_trunc_f64, v_rndne_f64 and v_fract_f64 in both the VOP1 _e32 and VOP3 _e64 spellings. The lowering works only on the two 32-bit words, with no HLSL double: r64_round covers trunc/floor/ceil/rndne (ties to even), and r64_fract computes x - floor(x) from the significand, with the below-one ceiling for tiny negative fractions. NaN inputs are quieted and infinities become the canonical qNaN, following the existing binary16/binary32 helpers.

Guards: entry EXEC, destination pair v[d:d+1] with d <= 254, no outstanding sample, preserved entry denormal profile; modifiers, clamp/omod, op_sel, DPP, SDWA, inline constants, literals and unproven pairs are refused.

Tests

  • pixel_aot_f64_round_warp and _hardware pass on WARP and the AMD Radeon RX 9060 XT (driver 32.0.32029.2010).
  • The draw covers integral values, exact rndne ties, positive/negative fractions, signed zeros, values above 2^52, subnormals, infinities and NaNs; five mutations each report pixel_mismatch.
  • form_coverage_check.py pins exactly the ten forms; rdna2_tools_check.py passes 162 tests (19 LLVM-dependent skips); the neighbouring draw-cmp-f64, draw-cvt-f64-* and draw-cvt-*-f64 tests still pass on both adapters.
  • Expected delta: +10 forms on gfx1013 and +10 on gfx1030. After the other open PRs and this one: 1,756/1,968 and 1,652/1,863.

Limits

The draws prove the translated shader on desktop adapters, not gfx1013 or the console. NaN quieting and the fract below-one ceiling are chosen from the existing helpers without a console measurement. No LLVM 15 round-trip of the ten forms was run; the spellings are covered by the controls and draws.

AI-assisted.

Merge with origin/main (2026-12-01)

Merged origin/main at a3bfd019 into this branch; head is 9601449e. The shared CMake, docs and test files keep both the #3607/#3623 additions and the PR additions. Local post-merge: pixel_aot_check.py, form_coverage_check.py and rdna2_tools_check.py pass (163 tests, 19 skips); CTest pixel_aot_f64_round_warp and pixel_aot_f64_minmax_ldexp_warp pass.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5572582611 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3643). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-30T19:48:49Z. --- Part of the f64 slice (P5). This adds the ten binary64 rounding/fraction forms: `v_ceil_f64`, `v_floor_f64`, `v_trunc_f64`, `v_rndne_f64` and `v_fract_f64` in both the VOP1 `_e32` and VOP3 `_e64` spellings. The lowering works only on the two 32-bit words, with no HLSL double: `r64_round` covers trunc/floor/ceil/rndne (ties to even), and `r64_fract` computes x - floor(x) from the significand, with the below-one ceiling for tiny negative fractions. NaN inputs are quieted and infinities become the canonical qNaN, following the existing binary16/binary32 helpers. Guards: entry EXEC, destination pair `v[d:d+1]` with `d <= 254`, no outstanding sample, preserved entry denormal profile; modifiers, clamp/omod, `op_sel`, DPP, SDWA, inline constants, literals and unproven pairs are refused. ## Tests - `pixel_aot_f64_round_warp` and `_hardware` pass on WARP and the AMD Radeon RX 9060 XT (driver 32.0.32029.2010). - The draw covers integral values, exact rndne ties, positive/negative fractions, signed zeros, values above 2^52, subnormals, infinities and NaNs; five mutations each report `pixel_mismatch`. - `form_coverage_check.py` pins exactly the ten forms; `rdna2_tools_check.py` passes 162 tests (19 LLVM-dependent skips); the neighbouring `draw-cmp-f64`, `draw-cvt-f64-*` and `draw-cvt-*-f64` tests still pass on both adapters. - Expected delta: **+10 forms on gfx1013 and +10 on gfx1030**. After the other open PRs and this one: **1,756/1,968** and **1,652/1,863**. ## Limits The draws prove the translated shader on desktop adapters, not gfx1013 or the console. NaN quieting and the fract below-one ceiling are chosen from the existing helpers without a console measurement. No LLVM 15 round-trip of the ten forms was run; the spellings are covered by the controls and draws. AI-assisted. ## Merge with origin/main (2026-12-01) Merged `origin/main` at `a3bfd019` into this branch; head is `9601449e`. The shared CMake, docs and test files keep both the #3607/#3623 additions and the PR additions. Local post-merge: `pixel_aot_check.py`, `form_coverage_check.py` and `rdna2_tools_check.py` pass (163 tests, 19 skips); CTest `pixel_aot_f64_round_warp` and `pixel_aot_f64_minmax_ldexp_warp` pass.
lukaslw-lab commented 2026-11-30 19:57:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T19:57:28Z.

Review: APPROVED


Reviewed 2b3459ed by reading the diff; not built or run.

Verdict: approve. I traced r64_round, r64_one_minus and r64_fract by hand and found no wrong result. No MUST. The SHOULD is draw rows for branches no row reaches today; it can follow.

  • SHOULD Several word-split branches in the f64_round helper (tools/pixel_aot.py:991-1177) are never reached by F64_ROUND_ROWS. The finite non-integral rows have bits = 1075 − exponent of 1, 51 or 52 only. So:

    • r64_round's bits == 32 branch (unit_hi = 1, half_lo = 0x80000000, odd = hi & 1) is never drawn, and neither is r64_fract's bits == 32 mask.
    • In r64_one_minus, no row reaches shift == 32 or shift > 32, i.e. a negative input with magnitude in about [2^-53, 2^-32), or a negative |x| ≥ 1 with such a fractional part. No row takes the down step either: -0.1 has remainder 2 < half 4, and the other negative fractions have remainder 0.

    I read these as correct, but they are where a word-boundary slip would hide. The 64-bit Python references would catch one, so rows are cheap to add. Suggested rows: ±(2^20 + 0.5), ±(2^20 + 1.5), ±(2^20 + 0.75); fract of −2^-40, −(1 + 2^-40) and −0.3; and one r64_one_minus tie, e.g. −(0.25 + 2^-54), which has remainder = half.

  • Checked, no finding:

    • Exponent carry (1.5 ceil → 2.0), the odd bit at bits == 52, the rndne 0.5/1.0 boundary, the length + 969 / length − bits + 1022 exponents and the ≤ 969 clamp.
    • NaN/Inf pass through the four rounding forms, like the direct-compute f16 rounding (exp >= 25). Overlapping destinations are safe.

Tests: check_f64_round_controls (Linux LLVM step, passed) pins the emitted calls and the refusals. pixel_aot_f64_round_{warp,hardware} are not in the Windows pr preset filter, so the draw has only the author's WARP + RX 9060 XT run. The red Linux job is startup_close_guard_check.py, which fails to compile startup code this PR does not touch.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6119518531 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3643#pullrequestreview-6119518531). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T19:57:28Z. **Review:** APPROVED --- Reviewed `2b3459ed` by reading the diff; not built or run. **Verdict: approve.** I traced `r64_round`, `r64_one_minus` and `r64_fract` by hand and found no wrong result. No MUST. The SHOULD is draw rows for branches no row reaches today; it can follow. - **SHOULD** Several word-split branches in the `f64_round` helper (`tools/pixel_aot.py:991-1177`) are never reached by `F64_ROUND_ROWS`. The finite non-integral rows have `bits = 1075 − exponent` of 1, 51 or 52 only. So: - `r64_round`'s `bits == 32` branch (`unit_hi = 1`, `half_lo = 0x80000000`, `odd = hi & 1`) is never drawn, and neither is `r64_fract`'s `bits == 32` mask. - In `r64_one_minus`, no row reaches `shift == 32` or `shift > 32`, i.e. a negative input with magnitude in about [2^-53, 2^-32), or a negative |x| ≥ 1 with such a fractional part. No row takes the `down` step either: `-0.1` has remainder 2 < half 4, and the other negative fractions have remainder 0. I read these as correct, but they are where a word-boundary slip would hide. The 64-bit Python references would catch one, so rows are cheap to add. Suggested rows: ±(2^20 + 0.5), ±(2^20 + 1.5), ±(2^20 + 0.75); fract of −2^-40, −(1 + 2^-40) and −0.3; and one `r64_one_minus` tie, e.g. −(0.25 + 2^-54), which has remainder = half. - Checked, no finding: - Exponent carry (`1.5` ceil → `2.0`), the `odd` bit at `bits == 52`, the rndne 0.5/1.0 boundary, the `length + 969` / `length − bits + 1022` exponents and the ≤ 969 clamp. - NaN/Inf pass through the four rounding forms, like the direct-compute f16 rounding (`exp >= 25`). Overlapping destinations are safe. Tests: `check_f64_round_controls` (Linux LLVM step, passed) pins the emitted calls and the refusals. `pixel_aot_f64_round_{warp,hardware}` are not in the Windows `pr` preset filter, so the draw has only the author's WARP + RX 9060 XT run. The red Linux job is `startup_close_guard_check.py`, which fails to compile startup code this PR does not touch.

Pull request closed

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!3643
No description provided.