shader: lower v_ldexp_f64 in the direct compute path #3531

Manually merged
github merged 1 commit from github-bot/gh-3529 into gh-pr/3529/base 2026-11-30 09:03:52 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-29 23:23 UTC · original
legacy-code-archaeologist:shader/direct-ldexp-f64 → main · +397 −1 · 4 files · 1 commits · merged 2026-11-30 09:01 UTC

Summary

Lowers v_ldexp_f64 in the direct C++ compute path. It was refused with direct DXIL lowering for v_ldexp_f64 (VOP3 probe, see #3520). The lowering follows tools/pixel_aot.py's ldexp32 rules, carried over to binary64, and uses 32-bit integer operations only. The module needs no double-precision and no 64-bit integer shader operations, so this does not depend on the approach #3520 settles for binary64 arithmetic.

  • Zero, Inf and NaN pass unchanged, NaN payload included.
  • A subnormal S0 is normalized by six conditional shifts of the two-word mantissa.
  • S1 is clamped to [-4096, 4096]. Every larger magnitude overflows or underflows exactly as ±4096 does, so the clamp only keeps the exponent sum from wrapping.
  • A result below the normal range rounds to nearest even from the round and sticky bits, with the carry into the high word. Overflow gives a signed Inf.
  • Abs/neg on S0 act on bit 63.
  • The op is accepted only under the default MODE for the fields gfx10 shares between f16 and f64 (denormals kept). The existing binary16 MODE tracking now also covers it.
  • Refused: clamp, omod, op_sel, S1/S2 modifiers, a src2 field, a constant or literal S0.

Refs #3520, refs #2935

Tests

tests/native_ldexp_f64_check.py (ir, controls, hardware), tests/cmake/native_ldexp_f64.cmake, docs/experiments/native-direct-ldexp-f64.md. The VOP3 words were assembled with LLVM 15.0.7. The references do not transcribe the algorithm: each is the exact S0 * 2^S1, rounded once by Python's correctly rounded integer division.

On main 2ff74a6a plus this change, Windows 10.0.26100:

  • ctest --preset dev --no-tests=error -R '^native_ldexp_f64_' -V:
    • ir passed: 243 cases, 972 words bit for bit through the IR interpreter of native_f16_alu_check.py. The cases are 8 readback cases, 3 carry cases (one rounds a subnormal up to 2^-1022) and a seeded sweep of 232.
    • controls passed: no double, no i64 and no float op in the module; 5 refusals; flushing, truncating, half-away and wrapping-exponent references each differ.
    • hardware skipped (77). This machine's only D3D12 FL 12_0 adapter does not report SM 6.6 with wave32, so the readback is unmeasured.
  • Source mutants of native_compute_ir_dump, each rebuilt and then restored: dropping the sticky bits, the carry into the high word, or the subnormal normalization each fails ir.
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 2: 139/139 passed.
  • A fresh read-only review also checked a 32-bit transcription of the block against the exact reference on 1.66 M cases (0 mismatches). It found the subnormal-to-normal carry case that was missing; that case is now in EXTRA.

AI-assisted: written with Claude Code. I reviewed it and ran the commands above.

🤖 Generated with Claude Code

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-29 23:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3529) `legacy-code-archaeologist:shader/direct-ldexp-f64` → `main` · +397 −1 · 4 files · 1 commits · merged 2026-11-30 09:01 UTC ## Summary Lowers `v_ldexp_f64` in the direct C++ compute path. It was refused with `direct DXIL lowering for v_ldexp_f64` (VOP3 probe, see #3520). The lowering follows `tools/pixel_aot.py`'s `ldexp32` rules, carried over to binary64, and uses **32-bit integer operations only**. The module needs no double-precision and no 64-bit integer shader operations, so this does not depend on the approach #3520 settles for binary64 arithmetic. - Zero, Inf and NaN pass unchanged, NaN payload included. - A subnormal S0 is normalized by six conditional shifts of the two-word mantissa. - S1 is clamped to [-4096, 4096]. Every larger magnitude overflows or underflows exactly as ±4096 does, so the clamp only keeps the exponent sum from wrapping. - A result below the normal range rounds to nearest even from the round and sticky bits, with the carry into the high word. Overflow gives a signed Inf. - Abs/neg on S0 act on bit 63. - The op is accepted only under the default MODE for the fields gfx10 shares between f16 and f64 (denormals kept). The existing binary16 MODE tracking now also covers it. - Refused: clamp, omod, op_sel, S1/S2 modifiers, a src2 field, a constant or literal S0. Refs #3520, refs #2935 ## Tests `tests/native_ldexp_f64_check.py` (`ir`, `controls`, `hardware`), `tests/cmake/native_ldexp_f64.cmake`, `docs/experiments/native-direct-ldexp-f64.md`. The VOP3 words were assembled with LLVM 15.0.7. The references do not transcribe the algorithm: each is the exact `S0 * 2^S1`, rounded once by Python's correctly rounded integer division. On `main` `2ff74a6a` plus this change, Windows 10.0.26100: - `ctest --preset dev --no-tests=error -R '^native_ldexp_f64_' -V`: - `ir` **passed**: 243 cases, 972 words bit for bit through the IR interpreter of `native_f16_alu_check.py`. The cases are 8 readback cases, 3 carry cases (one rounds a subnormal up to 2^-1022) and a seeded sweep of 232. - `controls` **passed**: no double, no i64 and no float op in the module; 5 refusals; flushing, truncating, half-away and wrapping-exponent references each differ. - `hardware` **skipped (77)**. This machine's only D3D12 FL 12_0 adapter does not report SM 6.6 with wave32, so the readback is unmeasured. - Source mutants of `native_compute_ir_dump`, each rebuilt and then restored: dropping the sticky bits, the carry into the high word, or the subnormal normalization each fails `ir`. - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 2`: 139/139 passed. - A fresh read-only review also checked a 32-bit transcription of the block against the exact reference on 1.66 M cases (0 mismatches). It found the subnormal-to-normal carry case that was missing; that case is now in `EXTRA`. AI-assisted: written with Claude Code. I reviewed it and ran the commands above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Exact binary64 scaling after pixel_aot.py's ldexp32 rules with 32-bit
integer operations only: zero, Inf and NaN unchanged, subnormal inputs
normalized, results below the normal range rounded to nearest even with
the carry into the high word, S1 clamped to [-4096, 4096]. Only under the
default MODE for the shared f16/f64 fields. An ir mode checks 243 cases
bit for bit against exact rational references.

Refs #3518

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 23:26:39 +00:00
Author
Owner

@⁠Alexofbulgaria on GitHub · 2026-11-30 04:13 UTC · original

Intel Arc A770 readback passed for v_ldexp_f64

Tested on my Intel Arc A770 (8086:56a0), driver 32.0.101.9175, Windows build 26300.10075. Release build with MSVC 14.44.35207 and DXC 1.9.2602.17. I used the repository's synthetic fixtures. Source commit 1601d5cc663f7fb4da9ed20789b9590b784ef154.

I ran ctest --test-dir <release-build> --no-tests=error -R '^native_ldexp_f64_(ir|controls|hardware)$' -V. All three tests passed with zero skips.

  • IR: 972 words matched bit for bit across 243 cases.
  • DXIL controls: Passed, including the invalid-form checks.
  • A770 hardware: All 2,064 readback words matched the reference across the eight-case fixture, including guard words. NaNs matched by class.

WARP: The same fixture and reference, run with --direct-warp, skipped with exit 77 at the Shader Model 6.6 and wave32 capability check. WARP arithmetic remains unverified.

AI assisted with setup and reporting. The test runs executed locally.

**@⁠Alexofbulgaria** on GitHub · 2026-11-30 04:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3529#issuecomment-7268578540) ### Intel Arc A770 readback passed for `v_ldexp_f64` Tested on my Intel Arc A770 (`8086:56a0`), driver `32.0.101.9175`, Windows build `26300.10075`. Release build with MSVC `14.44.35207` and DXC `1.9.2602.17`. I used the repository's synthetic fixtures. Source commit `1601d5cc663f7fb4da9ed20789b9590b784ef154`. I ran `ctest --test-dir <release-build> --no-tests=error -R '^native_ldexp_f64_(ir|controls|hardware)$' -V`. All three tests passed with zero skips. - **IR:** 972 words matched bit for bit across 243 cases. - **DXIL controls:** Passed, including the invalid-form checks. - **A770 hardware:** All 2,064 readback words matched the reference across the eight-case fixture, including guard words. NaNs matched by class. **WARP:** The same fixture and reference, run with `--direct-warp`, skipped with exit 77 at the Shader Model 6.6 and wave32 capability check. WARP arithmetic remains unverified. AI assisted with setup and reporting. The test runs executed locally.
github-bot changed target branch from main to gh-pr/3529/base 2026-11-30 09:03:50 +00:00
github manually merged commit 1601d5cc66 into gh-pr/3529/base 2026-11-30 09:03:52 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.