shader: lower v_cvt_f32_f64 for exact static pairs in pixel_aot #1653

Merged
JB2WIN merged 1 commit from upstream-pr/1660 into main 2026-11-24 17:36:59 +00:00
JB2WIN commented 2026-11-24 16:39:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-24T16:39:16Z.


Refs #1606

Change

This is the mode-independent slice agreed in #1606. tools/pixel_aot.py lowers v_cvt_f32_f64 on a binary64 pair whose provenance is the static record from #1575 (v_cvt_f64_f32 of a known source), using f64_words and the existing join rule.

  • Accepted values: only a value that is exactly a normal binary32 or a signed zero. cvt_f32_f64_exact_bits narrows the value with struct, widens it again with cvt_f64_f32_words, and requires the same two words bit for bit. The binary32 word is emitted as a constant, so the shader uses no HLSL double, and the result depends neither on the rounding field (MODE[1:0] vs MODE[3:2]) nor on the denorm field. Which field governs the narrowing stays open, as requested.
  • Refused:
    • both infinities and NaNs (is not finite)
    • subnormals
    • any value that needs rounding, including overflow and underflow (requires rounding)
    • pairs of integer origin (v_cvt_f64_i32/_u32, even where the integer would fit)
    • unknown pairs, a pair with either word clobbered, words of two pairs, swapped or offset words, and unequal joins
    • use inside a masked region, _e64, clamp, omod, neg, abs, DPP and SDWA
  • Spelling: LLVM 15 prints the unmodified form as _e32 (v_cvt_f32_f64_e32 v13, v[20:21] = 141f1a7e). The plain and _e32 spellings are accepted, as for the neighbouring forms.
  • Changed control: in check_cvt_f64_f32_lowering, v_cvt_f32_f64_e32 of the 1.0 pair used to be listed as a refused consumer. It is now a positive check, as in #1575. The integer-pair control and the round-toward-zero refusal are unchanged.
  • How the rounding refusal is tested: no path in the translator brings a pair that needs rounding to this conversion, because static records only come from the exact widening. The refusal is therefore covered twice:
    • A helper-level check requires requires rounding for 1 + 2^-24, 2^24 + 1, ±0.1, 1e300, FLT_MAX * 2, FLT_MAX + 2^102/2^103, 1e-50 and two values just below the smallest normal.
    • A lowering control refuses the v_cvt_f64_i32 pair of the known source 16777217 as integer origin.

Test

  • Mode: draw-cvt-f32-f64, registered as pixel_aot_cvt_f32_f64_hardware and _warp, with a 60 s timeout, skip code 77 and its own FORM_COVERAGE_RECORD. The LLVM 15 round trip covers the fixture.
  • Rows: ±0, 0x00800000, 0x80800000, 0x7f7fffff, 0xff7fffff, ±1.0 and 0x3f800001/0xbf800001. The results are exported raw through the uint target with xor masks and compared bit for bit with the original binary32 pattern.
  • Wrong references: a lost sign of -0, a flipped mantissa bit and the high word exported instead of the low word must each report pixel_mismatch.
  • Mutations: accepting infinity, losing the sign of -0, and not noticing a high-word clobber each turn the checks red.
  • Against main: with the tools/pixel_aot.py from main, the mode fails with ValueError: Unsupported instruction 23: v_cvt_f32_f64_e32 v13, v[16:17].

The semantics come from LLVM 15 and are not checked against the ISA document or measured on a console.

On commit d6624c0e (rebased on f0c0ed86), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200, debug layer unavailable:

ctest --preset dev --no-tests=error -R '^pixel_aot_cvt_(f32_f64|int_f64|f64_)' -V   # 8/8 passed, none skipped
ctest --preset dev --no-tests=error                                               # 1040/1040 passed; 25 capability skips, none from this change

The pure checks and the LLVM 15.0.7 binary round trip pass.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6586716341 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1660). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-24T16:39:16Z. --- Refs #1606 ## Change This is the mode-independent slice agreed in #1606. `tools/pixel_aot.py` lowers `v_cvt_f32_f64` on a binary64 pair whose provenance is the static record from #1575 (`v_cvt_f64_f32` of a known source), using `f64_words` and the existing join rule. - **Accepted values:** only a value that is exactly a normal binary32 or a signed zero. `cvt_f32_f64_exact_bits` narrows the value with `struct`, widens it again with `cvt_f64_f32_words`, and requires the same two words bit for bit. The binary32 word is emitted as a constant, so the shader uses no HLSL `double`, and the result depends neither on the rounding field (`MODE[1:0]` vs `MODE[3:2]`) nor on the denorm field. Which field governs the narrowing stays open, as requested. - **Refused:** - both infinities and NaNs (`is not finite`) - subnormals - any value that needs rounding, including overflow and underflow (`requires rounding`) - pairs of integer origin (`v_cvt_f64_i32`/`_u32`, even where the integer would fit) - unknown pairs, a pair with either word clobbered, words of two pairs, swapped or offset words, and unequal joins - use inside a masked region, `_e64`, `clamp`, `omod`, `neg`, `abs`, DPP and SDWA - **Spelling:** LLVM 15 prints the unmodified form as `_e32` (`v_cvt_f32_f64_e32 v13, v[20:21]` = `141f1a7e`). The plain and `_e32` spellings are accepted, as for the neighbouring forms. - **Changed control:** in `check_cvt_f64_f32_lowering`, `v_cvt_f32_f64_e32` of the 1.0 pair used to be listed as a refused consumer. It is now a positive check, as in #1575. The integer-pair control and the round-toward-zero refusal are unchanged. - **How the rounding refusal is tested:** no path in the translator brings a pair that needs rounding to this conversion, because static records only come from the exact widening. The refusal is therefore covered twice: - A helper-level check requires `requires rounding` for `1 + 2^-24`, `2^24 + 1`, ±0.1, `1e300`, `FLT_MAX * 2`, `FLT_MAX + 2^102/2^103`, `1e-50` and two values just below the smallest normal. - A lowering control refuses the `v_cvt_f64_i32` pair of the known source 16777217 as integer origin. ## Test - **Mode:** `draw-cvt-f32-f64`, registered as `pixel_aot_cvt_f32_f64_hardware` and `_warp`, with a 60 s timeout, skip code 77 and its own `FORM_COVERAGE_RECORD`. The LLVM 15 round trip covers the fixture. - **Rows:** ±0, `0x00800000`, `0x80800000`, `0x7f7fffff`, `0xff7fffff`, ±1.0 and `0x3f800001`/`0xbf800001`. The results are exported raw through the uint target with xor masks and compared bit for bit with the original binary32 pattern. - **Wrong references:** a lost sign of -0, a flipped mantissa bit and the high word exported instead of the low word must each report `pixel_mismatch`. - **Mutations:** accepting infinity, losing the sign of -0, and not noticing a high-word clobber each turn the checks red. - **Against `main`:** with the `tools/pixel_aot.py` from `main`, the mode fails with `ValueError: Unsupported instruction 23: v_cvt_f32_f64_e32 v13, v[16:17]`. The semantics come from LLVM 15 and are not checked against the ISA document or measured on a console. On commit `d6624c0e` (rebased on `f0c0ed86`), with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200, debug layer unavailable: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_cvt_(f32_f64|int_f64|f64_)' -V # 8/8 passed, none skipped ctest --preset dev --no-tests=error # 1040/1040 passed; 25 capability skips, none from this change ``` The pure checks and the LLVM 15.0.7 binary round trip pass. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-24 17:01:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:47:22Z.

Review: COMMENTED


Peer review at head_sha: d6624c0eba9c624c96b9b1901ad45e947b9b058c

Findings

No defects found.

  • tools/pixel_aot.py: cvt_f32_f64_exact_bits cleanly restricts lowering to exact normal binary32 values and signed zeros (round-tripping through struct and cvt_f64_f32_words, rejecting non-finite, subnormal, and rounding cases), and lower() enforces ("static", low, high) provenance, entry-mask execution, register bounds, and non-pending/non-sample-dest operands without emitting HLSL double.
  • tests/pixel_aot_check.py, tests/form_coverage_check.py, CMakeLists.txt, docs/experiments.md: thorough negative controls, wrong-reference pixel mismatch checks, and coverage records; 100% title-neutral.

Verification

  • Linux:
    • python3 -B -c "... pixel_aot_check.check_cvt_f32_f64_lowering()": PASS (exit 0).
    • python3 -B -c "... pixel_aot_check.check_cvt_f32_f64_binary(Path(d), 'llvm-mc-19', 'llvm-objcopy-19', '/usr/lib/llvm-19/lib/libLLVM-19.so')": PASS (exit 0).
    • Local mutation check: temporarily replaced if record[0] != "static": with if False: in tools/pixel_aot.py and ran check_cvt_f32_f64_lowering() — failed as expected (IndexError on integer-origin pair test, exit 1); restored cleanly (git status --short clean).
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • tests/form_coverage_check.py: PASS (16.6s, exit 0).
    • Debug (--preset dev): cmake --build --preset dev --target offscreen_check -- -j 6 (10.32s); ctest --preset dev -R '^(pixel_aot_cvt_f32_f64_warp|pixel_aot_cvt_f64_f32_warp|pixel_aot_cvt_int_f64_warp)$' --parallel 4 --no-tests=error --output-on-failure: 3/3 passed (7.06s: pixel_aot_cvt_f32_f64_warp 2.26s, pixel_aot_cvt_int_f64_warp 4.37s, pixel_aot_cvt_f64_f32_warp 6.98s).
    • Release /O2 (--preset release): cmake --build --preset release --target offscreen_check -- -j 6 (7.86s); ctest --preset release -R '^(pixel_aot_cvt_f32_f64_warp|pixel_aot_cvt_f64_f32_warp|pixel_aot_cvt_int_f64_warp)$' --parallel 4 --no-tests=error --output-on-failure: 3/3 passed (6.96s: pixel_aot_cvt_f32_f64_warp 2.28s, pixel_aot_cvt_int_f64_warp 4.79s, pixel_aot_cvt_f64_f32_warp 6.88s).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043548284 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1660#pullrequestreview-6043548284). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T16:47:22Z. **Review:** COMMENTED --- Peer review at `head_sha`: `d6624c0eba9c624c96b9b1901ad45e947b9b058c` ### Findings No defects found. - `tools/pixel_aot.py`: `cvt_f32_f64_exact_bits` cleanly restricts lowering to exact normal binary32 values and signed zeros (round-tripping through `struct` and `cvt_f64_f32_words`, rejecting non-finite, subnormal, and rounding cases), and `lower()` enforces `("static", low, high)` provenance, entry-mask execution, register bounds, and non-pending/non-sample-dest operands without emitting HLSL `double`. - `tests/pixel_aot_check.py`, `tests/form_coverage_check.py`, `CMakeLists.txt`, `docs/experiments.md`: thorough negative controls, wrong-reference pixel mismatch checks, and coverage records; 100% title-neutral. ### Verification - **Linux**: - `python3 -B -c "... pixel_aot_check.check_cvt_f32_f64_lowering()"`: **PASS** (exit 0). - `python3 -B -c "... pixel_aot_check.check_cvt_f32_f64_binary(Path(d), 'llvm-mc-19', 'llvm-objcopy-19', '/usr/lib/llvm-19/lib/libLLVM-19.so')"`: **PASS** (exit 0). - **Local mutation check**: temporarily replaced `if record[0] != "static":` with `if False:` in `tools/pixel_aot.py` and ran `check_cvt_f32_f64_lowering()` — failed as expected (`IndexError` on integer-origin pair test, exit 1); restored cleanly (`git status --short` clean). - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - `tests/form_coverage_check.py`: **PASS** (`16.6s`, exit 0). - **Debug (`--preset dev`)**: `cmake --build --preset dev --target offscreen_check -- -j 6` (`10.32s`); `ctest --preset dev -R '^(pixel_aot_cvt_f32_f64_warp|pixel_aot_cvt_f64_f32_warp|pixel_aot_cvt_int_f64_warp)$' --parallel 4 --no-tests=error --output-on-failure`: **3/3 passed** (`7.06s`: `pixel_aot_cvt_f32_f64_warp` `2.26s`, `pixel_aot_cvt_int_f64_warp` `4.37s`, `pixel_aot_cvt_f64_f32_warp` `6.98s`). - **Release `/O2` (`--preset release`)**: `cmake --build --preset release --target offscreen_check -- -j 6` (`7.86s`); `ctest --preset release -R '^(pixel_aot_cvt_f32_f64_warp|pixel_aot_cvt_f64_f32_warp|pixel_aot_cvt_int_f64_warp)$' --parallel 4 --no-tests=error --output-on-failure`: **3/3 passed** (`6.96s`: `pixel_aot_cvt_f32_f64_warp` `2.28s`, `pixel_aot_cvt_int_f64_warp` `4.79s`, `pixel_aot_cvt_f64_f32_warp` `6.88s`). AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 18:02:22 +00:00
tedin7 commented 2026-11-24 18:02:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:36:18Z.

Review: COMMENTED


Verified at head_sha: d6624c0eba9c624c96b9b1901ad45e947b9b058c (0 P1, 0 P2).

Scope & Semantics

  • Touches only tools/pixel_aot.py, tests/pixel_aot_check.py, tests/form_coverage_check.py, CMakeLists.txt (test-only pixel_aot_cvt_f32_f64_{hardware,warp}), and docs/experiments.md.
  • v_cvt_f32_f64 lowers only exact static v_cvt_f64_f32 pairs (normal binary32 or ±0.0), verified by round-trip bit equality in cvt_f32_f64_exact_bits without reading any MODE rounding/denorm field; rejects infinities, NaNs, subnormals, values requiring rounding, integer-origin pairs, unknown/clobbered/divergent pairs, masked regions, _e64, and all modifiers.

Verified

  • Linux:
    • git diff --check origin/main...HEAD -> clean
    • python3 tests/docs_links_check.py -> passed (16 Markdown files, 349 links)
    • python3 tests/bidi_controls_check.py -> passed (1277 tracked files)
    • pixel_aot_check.check_cvt_f32_f64_lowering() and pixel_aot_check.check_cvt_f64_f32_lowering() -> OK
    • llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding: v_cvt_f32_f64 v13, v[20:21] -> 14 1f 1a 7e, v_cvt_f32_f64_e64 v13, v[20:21] -> 0d 00 8f d5 14 01 00 00
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): offscreen_check built (10.40s), ctest --preset dev -R 'pixel_aot_cvt_f32_f64|pixel_aot_cvt_f64_f32' 4/4 passed (7.58s)
    • Release /O2 (--preset release): offscreen_check built (8.32s), ctest --preset release -R 'pixel_aot_cvt_f32_f64|pixel_aot_cvt_f64_f32' 4/4 passed (7.51s)
    • Windows Python check: tests/form_coverage_check.py -> passed (16.96s)
  • Mutation checks (local, reverted cleanly):
    • Disabled subnormal binary32 guard in cvt_f32_f64_exact_bits -> pixel_aot_check.check_cvt_f32_f64_lowering() failed as expected (AssertionError on subnormal diagnostic).
    • Disabled record[0] != "static" integer-origin guard in tools/pixel_aot.py -> pixel_aot_check.check_cvt_f32_f64_lowering() failed as expected.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044299941 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1660#pullrequestreview-6044299941). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:36:18Z. **Review:** COMMENTED --- Verified at `head_sha`: `d6624c0eba9c624c96b9b1901ad45e947b9b058c` (0 P1, 0 P2). ### Scope & Semantics - Touches only `tools/pixel_aot.py`, `tests/pixel_aot_check.py`, `tests/form_coverage_check.py`, `CMakeLists.txt` (test-only `pixel_aot_cvt_f32_f64_{hardware,warp}`), and `docs/experiments.md`. - `v_cvt_f32_f64` lowers only exact static `v_cvt_f64_f32` pairs (normal binary32 or ±0.0), verified by round-trip bit equality in `cvt_f32_f64_exact_bits` without reading any MODE rounding/denorm field; rejects infinities, NaNs, subnormals, values requiring rounding, integer-origin pairs, unknown/clobbered/divergent pairs, masked regions, `_e64`, and all modifiers. ### Verified - **Linux**: - `git diff --check origin/main...HEAD` -> clean - `python3 tests/docs_links_check.py` -> passed (16 Markdown files, 349 links) - `python3 tests/bidi_controls_check.py` -> passed (1277 tracked files) - `pixel_aot_check.check_cvt_f32_f64_lowering()` and `pixel_aot_check.check_cvt_f64_f32_lowering()` -> OK - `llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding`: `v_cvt_f32_f64 v13, v[20:21]` -> `14 1f 1a 7e`, `v_cvt_f32_f64_e64 v13, v[20:21]` -> `0d 00 8f d5 14 01 00 00` - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: `offscreen_check` built (`10.40s`), `ctest --preset dev -R 'pixel_aot_cvt_f32_f64|pixel_aot_cvt_f64_f32'` **4/4 passed** (`7.58s`) - **Release `/O2` (`--preset release`)**: `offscreen_check` built (`8.32s`), `ctest --preset release -R 'pixel_aot_cvt_f32_f64|pixel_aot_cvt_f64_f32'` **4/4 passed** (`7.51s`) - **Windows Python check**: `tests/form_coverage_check.py` -> passed (`16.96s`) - **Mutation checks** (local, reverted cleanly): - Disabled subnormal binary32 guard in `cvt_f32_f64_exact_bits` -> `pixel_aot_check.check_cvt_f32_f64_lowering()` failed as expected (`AssertionError` on subnormal diagnostic). - Disabled `record[0] != "static"` integer-origin guard in `tools/pixel_aot.py` -> `pixel_aot_check.check_cvt_f32_f64_lowering()` failed as expected. AI-assisted; commands listed were 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!1653
No description provided.