shader: lower v_ldexp_f64 in the direct compute path #3529

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3529 into main 2026-11-30 09:01:58 +00:00
legacy-code-archaeologist commented 2026-11-29 23:23:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-29T23:23:43Z.


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 #3518). 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 #3518 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 #3518, 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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5556274754 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3529). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-29T23:23:43Z. --- ## 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 #3518). 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 #3518 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 #3518, 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)
Alexofbulgaria commented 2026-11-30 04:13:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Alexofbulgaria on 2026-11-30T04:13:24Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7268578540 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3529#issuecomment-7268578540). Originally posted by [Alexofbulgaria](https://github.com/Alexofbulgaria) on 2026-11-30T04:13:24Z. --- ### 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.
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!3529
No description provided.