shader: lower binary64 add and multiply #3652

Open
github-bot wants to merge 3 commits from github-bot/gh-3650 into main AGit
Owner

@⁠lambirou on GitHub · 2026-11-30 21:15 UTC · original
lambirou:shader/f64-add-mul → main · +1461 −6 · 7 files · 3 commits · open

Stacked on #3645 (shader/f64-rounding, head 9601449e after the origin/main merge). Do not merge this change before #3645.

Problem

v_add_f64 and v_mul_f64 are VOP3 gfx1013/gfx1030 forms that were still unobserved in both coverage references. No open pull request lowers either form; #3645 lists them among the forms it explicitly leaves uncovered.

Change

Add the two unmodified VOP3 forms to the pixel AOT translator. The destination is a VGPR pair. Each source is an unmodified VGPR pair or an aligned SGPR pair. The implementation operates on the low and high 32-bit words and uses no HLSL binary64 type:

  • add aligns the smaller 53-bit significand under the larger biased exponent, adds or subtracts in two's-complement carries, normalizes a 128-bit integer, and rounds once to nearest even;
  • multiply forms the exact 53x53-bit product from four 32x32 partial products, combines the exponents, normalizes, and rounds once to nearest even;
  • both paths preserve signed zeros, encode subnormal results under the declared denormal-preserving entry profile, overflow to signed infinity, and quiet NaNs. The first NaN keeps its payload; (+inf) + (-inf) and zero times infinity produce 0x7ff8000000000000.

The existing f64 rounding helpers do not provide the 128-bit alignment, exact product, carries, or subnormal-result rounding, so this change adds the r64a_* integer helpers. It leaves v_fma_f64, divide/reciprocal/square root/trigonometric f64, min/max/ldexp, frexp, conversions, and DS f64 forms unchanged. Modifiers, clamp, omod, op_sel, DPP, SDWA, literals, inline constants, malformed or untracked pairs, pending SGPR loads, sample results, partial source/destination overlap, and non-entry masks are refused; an identical source and destination pair is accepted after both source words are captured.

Tests

  • python -B tests/pixel_aot_check.py: passed.
  • python -B tests/form_coverage_check.py: passed.
  • python -B tests/rdna2_tools_check.py: 163 tests passed, 19 skipped.
  • cmake --preset dev -DINTAKE_PYTHON=<repo>/out/pe-env/Scripts/python.exe; cmake --build --preset dev -- -j 4: passed. The final build was rerun at -j4 after a default-parallel rc.exe failure in unrelated targets.
  • ctest --preset dev --no-tests=error -R '^pixel_aot_f64_arith_' --output-junit out/f64_arith_junit.xml: 2 passed, 0 failed, 0 skipped. pixel_aot_f64_arith_hardware passed on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010, Windows build 26300.10075, debug layer unavailable) and pixel_aot_f64_arith_warp passed on the Microsoft Basic Render Driver.
  • Each FORM_COVERAGE_RECORD contains exactly v_add_f64 and v_mul_f64.
  • tools/form_coverage.py out/build/dev/out/f64_arith_junit.xml --records out/build/dev/form_coverage: 2 of 1968 gfx1013 forms and 2 of 1863 gfx1030 forms from this fixture. The measured delta is +2 gfx1013 and +2 gfx1030.
  • The draw covers 39 rows: signed zeros, normal values, subnormal inputs and outputs, normal/subnormal boundaries, exponent transitions, catastrophic cancellation, exact rounding ties, significand carry, overflow to infinity, infinities, and quiet/signaling NaNs. Five mutations (truncated rounding, ignored sign, unbiased exponent, lost significand carry, non-quiet NaN) each report pixel_mismatch. An additional local 256-pair randomized draw pass matched the Python reference.

Limits

This is desktop DXIL translation evidence only. It does not establish the console's NaN payload selection, subnormal behavior, or rounding behavior. Only the two named VOP3 forms are covered; dependent f64 arithmetic remains out of scope.

AI-assisted change.

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

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

**@⁠lambirou** on GitHub · 2026-11-30 21:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3650) `lambirou:shader/f64-add-mul` → `main` · +1461 −6 · 7 files · 3 commits · open Stacked on #3645 (`shader/f64-rounding`, head `9601449e` after the `origin/main` merge). Do not merge this change before #3645. ## Problem `v_add_f64` and `v_mul_f64` are VOP3 gfx1013/gfx1030 forms that were still `unobserved` in both coverage references. No open pull request lowers either form; #3645 lists them among the forms it explicitly leaves uncovered. ## Change Add the two unmodified VOP3 forms to the pixel AOT translator. The destination is a VGPR pair. Each source is an unmodified VGPR pair or an aligned SGPR pair. The implementation operates on the low and high 32-bit words and uses no HLSL binary64 type: - add aligns the smaller 53-bit significand under the larger biased exponent, adds or subtracts in two's-complement carries, normalizes a 128-bit integer, and rounds once to nearest even; - multiply forms the exact 53x53-bit product from four 32x32 partial products, combines the exponents, normalizes, and rounds once to nearest even; - both paths preserve signed zeros, encode subnormal results under the declared denormal-preserving entry profile, overflow to signed infinity, and quiet NaNs. The first NaN keeps its payload; `(+inf) + (-inf)` and zero times infinity produce `0x7ff8000000000000`. The existing f64 rounding helpers do not provide the 128-bit alignment, exact product, carries, or subnormal-result rounding, so this change adds the `r64a_*` integer helpers. It leaves `v_fma_f64`, divide/reciprocal/square root/trigonometric f64, min/max/ldexp, frexp, conversions, and DS f64 forms unchanged. Modifiers, clamp, omod, op_sel, DPP, SDWA, literals, inline constants, malformed or untracked pairs, pending SGPR loads, sample results, partial source/destination overlap, and non-entry masks are refused; an identical source and destination pair is accepted after both source words are captured. ## Tests - `python -B tests/pixel_aot_check.py`: passed. - `python -B tests/form_coverage_check.py`: passed. - `python -B tests/rdna2_tools_check.py`: 163 tests passed, 19 skipped. - `cmake --preset dev -DINTAKE_PYTHON=<repo>/out/pe-env/Scripts/python.exe`; `cmake --build --preset dev -- -j 4`: passed. The final build was rerun at `-j4` after a default-parallel `rc.exe` failure in unrelated targets. - `ctest --preset dev --no-tests=error -R '^pixel_aot_f64_arith_' --output-junit out/f64_arith_junit.xml`: 2 passed, 0 failed, 0 skipped. `pixel_aot_f64_arith_hardware` passed on an AMD Radeon RX 9060 XT (driver 32.0.32029.2010, Windows build 26300.10075, debug layer unavailable) and `pixel_aot_f64_arith_warp` passed on the Microsoft Basic Render Driver. - Each `FORM_COVERAGE_RECORD` contains exactly `v_add_f64` and `v_mul_f64`. - `tools/form_coverage.py out/build/dev/out/f64_arith_junit.xml --records out/build/dev/form_coverage`: 2 of 1968 gfx1013 forms and 2 of 1863 gfx1030 forms from this fixture. The measured delta is **+2 gfx1013** and **+2 gfx1030**. - The draw covers 39 rows: signed zeros, normal values, subnormal inputs and outputs, normal/subnormal boundaries, exponent transitions, catastrophic cancellation, exact rounding ties, significand carry, overflow to infinity, infinities, and quiet/signaling NaNs. Five mutations (truncated rounding, ignored sign, unbiased exponent, lost significand carry, non-quiet NaN) each report `pixel_mismatch`. An additional local 256-pair randomized draw pass matched the Python reference. ## Limits This is desktop DXIL translation evidence only. It does not establish the console's NaN payload selection, subnormal behavior, or rounding behavior. Only the two named VOP3 forms are covered; dependent f64 arithmetic remains out of scope. AI-assisted change. ## Merge with origin/main (2026-12-01) Merged `origin/main` at `a3bfd019` into this branch; head is `98f1bee0`. The shared CMake, docs and test files keep both the #3609/#3623 additions and the PR additions. Local post-merge: `pixel_aot_check.py`, `form_coverage_check.py` and `rdna2_tools_check.py` pass (164 tests, 19 skips); CTest `pixel_aot_f64_arith_warp`, `pixel_aot_f64_round_warp` and `pixel_aot_f64_minmax_ldexp_warp` pass (3/3).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 21:16:26 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 02:43 UTC · original · approved these changes

Reviewed 98f1bee0 by reading the diff; not built or run. Stacked on #3645, so I read this PR's own change against #3645's head 9601449e.

Verdict: approve. The integer binary64 add and multiply round once, correctly, in every range I traced. No MUST, no SHOULD. Merge after #3645, as the body says.

  • Checked, no finding:
    • Limbs: r64a_mul32, the add128/sub128 carry chains and the shifts are exact. r64a_bitlen(0) is 0.
    • r64a_round normal path (tools/pixel_aot.py:1372): the exponent base is in units of the integer significand, be for add and ae + be − 1075 for multiply. Guard and sticky give ties-to-even, a carry to 2^53 renormalizes, and overflow before or after rounding gives signed infinity.
    • r64a_round subnormal path: a value with exponent ≤ 0 is below 2^52 after the shift, so hi >= 0x00100000 can only be the rounding carry, and returning the minimum normal is exact.
    • Add (:1427): operands are swapped so that |a| ≥ |b|. The distance >= 64 early return (:1459) is safe, because b < 2^−11 ulp(a), which is below the half-ulp just under a power of two. An exact cancellation gives +0, and −0 + −0 gives −0.
    • Multiply (:1467): four partial products cover all 106 bits. inf·0 gives the canonical NaN.
    • NaNs: the first NaN keeps its payload with bit 51 set. The invalid cases give positive 0x7ff8000000000000.
    • Lowering: the suffix must be empty, a partly overlapping VGPR source/destination is refused (:7832), and an identical pair is safe because the helper call reads both sources first. The CMake delta only adds the two draws.

Tests: the 39 draw rows with five mutations prove the rounding paths against the Python reference. CI ran pixel_aot_check.py, form_coverage_check.py and rdna2_tools_check.py at this head. The draws are outside the pr filter.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 02:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3650#pullrequestreview-6124228484) · **approved these changes** Reviewed `98f1bee0` by reading the diff; not built or run. Stacked on #3645, so I read this PR's own change against #3645's head `9601449e`. **Verdict: approve.** The integer binary64 add and multiply round once, correctly, in every range I traced. No MUST, no SHOULD. Merge after #3645, as the body says. - Checked, no finding: - **Limbs:** `r64a_mul32`, the `add128`/`sub128` carry chains and the shifts are exact. `r64a_bitlen(0)` is 0. - **`r64a_round` normal path** (`tools/pixel_aot.py:1372`): the exponent base is in units of the integer significand, `be` for add and `ae + be − 1075` for multiply. Guard and sticky give ties-to-even, a carry to 2^53 renormalizes, and overflow before or after rounding gives signed infinity. - **`r64a_round` subnormal path:** a value with exponent ≤ 0 is below 2^52 after the shift, so `hi >= 0x00100000` can only be the rounding carry, and returning the minimum normal is exact. - **Add** (`:1427`): operands are swapped so that |a| ≥ |b|. The `distance >= 64` early return (`:1459`) is safe, because b < 2^−11 ulp(a), which is below the half-ulp just under a power of two. An exact cancellation gives +0, and −0 + −0 gives −0. - **Multiply** (`:1467`): four partial products cover all 106 bits. inf·0 gives the canonical NaN. - **NaNs:** the first NaN keeps its payload with bit 51 set. The invalid cases give positive `0x7ff8000000000000`. - **Lowering:** the suffix must be empty, a partly overlapping VGPR source/destination is refused (`:7832`), and an identical pair is safe because the helper call reads both sources first. The CMake delta only adds the two draws. Tests: the 39 draw rows with five mutations prove the rounding paths against the Python reference. CI ran `pixel_aot_check.py`, `form_coverage_check.py` and `rdna2_tools_check.py` at this head. The draws are outside the `pr` filter.
Author
Owner

@⁠lambirou on GitHub · 2026-12-02 18:08 UTC · original

Superseded: main already carries this change as 8b7e0213 (shader: lower binary64 add and multiply). The branch has no non-merge commits outside main, so closing it avoids a duplicate review.

**@⁠lambirou** on GitHub · 2026-12-02 18:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3650#issuecomment-7354003795) Superseded: main already carries this change as 8b7e0213 (shader: lower binary64 add and multiply). The branch has no non-merge commits outside main, so closing it avoids a duplicate review.
This pull request has changes conflicting with the target branch.
  • CMakeLists.txt
  • docs/experiments.md
  • tests/form_coverage_check.py
  • tests/pixel_aot_check.py
  • tests/rdna2_tools_check.py
  • tools/pixel_aot.py
  • tools/scan_unsupported_shaders.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3652/head:github-bot/gh-3650'
git switch 'github-bot/gh-3650'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3650'
git switch 'github-bot/gh-3650'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3650'
git switch 'github-bot/gh-3650'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3650'
git switch 'main'
git merge --squash 'github-bot/gh-3650'
git switch 'main'
git merge --ff-only 'github-bot/gh-3650'
git switch 'main'
git merge 'github-bot/gh-3650'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.