pixel_aot: lower 25 exact binary16 min, max, fract, and frexp forms #2570

Merged
KomaGuy merged 2 commits from upstream-pr/2578 into main 2026-11-25 22:18:24 +00:00
KomaGuy commented 2026-11-25 21:37:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KomaGuy on 2026-11-25T21:37:10Z.


Summary

Lowers 25 exact binary16 forms across all 5 GFX10/RDNA 2 encodings (VOP1/VOP2, VOP3 _e64, DPP16, DPP8, SDWA) in tools/pixel_aot.py (counted in both docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv), with static contract controls, pixel_aot_f16_exact_extra_{warp,hardware} draw tests, LLVM 15 check_binary fixtures, and form_coverage_check coverage assertions:

  • v_min_f16, v_max_f16 (10 forms): VOP2 (_e32/bare), VOP3 _e64, DPP16, DPP8, SDWA
  • v_fract_f16 (5 forms): VOP1 (_e32/bare), VOP3 _e64, DPP16, DPP8, SDWA
  • v_frexp_mant_f16, v_frexp_exp_i16_f16 (10 forms): VOP1 (_e32/bare), VOP3 _e64, DPP16, DPP8, SDWA

Contracts & Semantics

  • Entry profile & rounding: All 25 forms require explicit half_denorm="preserve", refuse HALF_RTZ (via HW_REG_MODE), and enforce the static finite-proof contract (half16_arith_source, half16_dpp_source, half16_sdwa_source).
  • v_min_f16 / v_max_f16: Compare finite 16-bit bit patterns directly in signed integer order (f16_min_bits/f16_max_bits helpers) so subnormals and -0.0 are preserved bit-for-bit even under -denorm ftz, while opposite-signed zeros (+0.0 vs -0.0) are refused statically.
  • v_fract_f16: Computes narrow16(widen16(x) - floor(widen16(x))) and statically refuses tiny negative inputs (-2^-11 < x < 0, bit patterns 0x8001..0x93ff) where 1 + x is not representable on the binary16 grid (so every accepted input is exact in binary16).
  • v_frexp_mant_f16 / v_frexp_exp_i16_f16: Pure 16-bit integer decomposition (frexp_mant_f16/frexp_exp_i16_f16 helpers) preserving subnormals and -0.0. v_frexp_mant_f16 produces ("half16", alu) (with known_half for chaining) and v_frexp_exp_i16_f16 produces ("low16", alu) (or full 32-bit known_ssa_bits words under SDWA WORD_0/WORD_1 UNUSED_PAD/UNUSED_PRESERVE).

Verification

  • Ran locally on Linux:
    • python3 tests/pixel_aot_check.py (including new check_f16_exact_extra_controls)
    • form_coverage_check: check_f16_exact_extra_forms (+25 forms in gfx1013.tsv and rdna2.tsv, unlowered neighbours excluded, single-opcode removal control) + all existing f16/DPP/SDWA coverage checks
    • Independent Python bit-exact simulation across all 5 fixtures (plain_e32, plain_e64, dpp16, dpp8, sdwa) and all 20 mutations + inspection of generated HLSL
    • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, python3 tests/rdna2_tools_check.py (156 tests OK)
    • git merge-tree --write-tree --name-only origin/main HEAD and git diff --check origin/main
  • Runs in CI:
    • LLVM 15 pixel_aot_binary assembly/disassembly round-trips for all 5 F16_EXACT_EXTRA_PROGRAMS fixtures
    • Windows D3D12 pixel_aot_f16_exact_extra_warp / pixel_aot_f16_exact_extra_hardware draws (both default denorm mode and -denorm ftz + all 20 mutations)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6614249419 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2578). Originally posted by [KomaGuy](https://github.com/KomaGuy) on 2026-11-25T21:37:10Z. --- ## Summary Lowers **25 exact binary16 forms** across all 5 GFX10/RDNA 2 encodings (`VOP1`/`VOP2`, `VOP3` `_e64`, `DPP16`, `DPP8`, `SDWA`) in `tools/pixel_aot.py` (counted in both `docs/coverage/gfx1013.tsv` and `docs/coverage/rdna2.tsv`), with static contract controls, `pixel_aot_f16_exact_extra_{warp,hardware}` draw tests, LLVM 15 `check_binary` fixtures, and `form_coverage_check` coverage assertions: - **`v_min_f16`, `v_max_f16` (10 forms):** `VOP2` (`_e32`/bare), `VOP3` `_e64`, `DPP16`, `DPP8`, `SDWA` - **`v_fract_f16` (5 forms):** `VOP1` (`_e32`/bare), `VOP3` `_e64`, `DPP16`, `DPP8`, `SDWA` - **`v_frexp_mant_f16`, `v_frexp_exp_i16_f16` (10 forms):** `VOP1` (`_e32`/bare), `VOP3` `_e64`, `DPP16`, `DPP8`, `SDWA` ## Contracts & Semantics - **Entry profile & rounding:** All 25 forms require explicit `half_denorm="preserve"`, refuse `HALF_RTZ` (via `HW_REG_MODE`), and enforce the static finite-proof contract (`half16_arith_source`, `half16_dpp_source`, `half16_sdwa_source`). - **`v_min_f16` / `v_max_f16`:** Compare finite 16-bit bit patterns directly in signed integer order (`f16_min_bits`/`f16_max_bits` helpers) so subnormals and `-0.0` are preserved bit-for-bit even under `-denorm ftz`, while opposite-signed zeros (`+0.0` vs `-0.0`) are refused statically. - **`v_fract_f16`:** Computes `narrow16(widen16(x) - floor(widen16(x)))` and statically refuses tiny negative inputs (`-2^-11 < x < 0`, bit patterns `0x8001..0x93ff`) where `1 + x` is not representable on the binary16 grid (so every accepted input is exact in binary16). - **`v_frexp_mant_f16` / `v_frexp_exp_i16_f16`:** Pure 16-bit integer decomposition (`frexp_mant_f16`/`frexp_exp_i16_f16` helpers) preserving subnormals and `-0.0`. `v_frexp_mant_f16` produces `("half16", alu)` (with `known_half` for chaining) and `v_frexp_exp_i16_f16` produces `("low16", alu)` (or full 32-bit `known_ssa_bits` words under SDWA `WORD_0`/`WORD_1` `UNUSED_PAD`/`UNUSED_PRESERVE`). ## Verification - **Ran locally on Linux:** - `python3 tests/pixel_aot_check.py` (including new `check_f16_exact_extra_controls`) - `form_coverage_check`: `check_f16_exact_extra_forms` (+25 forms in `gfx1013.tsv` and `rdna2.tsv`, unlowered neighbours excluded, single-opcode removal control) + all existing f16/DPP/SDWA coverage checks - Independent Python bit-exact simulation across all 5 fixtures (`plain_e32`, `plain_e64`, `dpp16`, `dpp8`, `sdwa`) and all 20 mutations + inspection of generated HLSL - `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`, `python3 tests/rdna2_tools_check.py` (156 tests OK) - `git merge-tree --write-tree --name-only origin/main HEAD` and `git diff --check origin/main` - **Runs in CI:** - LLVM 15 `pixel_aot_binary` assembly/disassembly round-trips for all 5 `F16_EXACT_EXTRA_PROGRAMS` fixtures - Windows D3D12 `pixel_aot_f16_exact_extra_warp` / `pixel_aot_f16_exact_extra_hardware` draws (both default denorm mode and `-denorm ftz` + all 20 mutations)
tedin7 commented 2026-11-25 22:02:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T21:42:43Z.

Review: COMMENTED


Review of head ad6e22fe (main merged into the PR; the PR's own diff is the same 6 files as before). Comment only.

Result: sound. I found no blocking issue.

What I checked:

  • No other open or merged PR covers these 25 binary16 forms (#906 closed, #419 and #537 are different slices).
  • tools/pixel_aot.py: the 25 forms need half_denorm="preserve", refuse HALF_RTZ, and keep the static finite-proof contract. min/max compare the bit patterns, so subnormals and -0.0 are kept. Opposite-sign zeros are refused. fract refuses the tiny-negative range.
  • Tests: check_f16_exact_extra_controls plus the pixel_aot_f16_exact_extra_{warp,hardware} draw tests (real draw readback against a CPU reference, with built-in mutations that must be caught). form_coverage_check has new coverage assertions.
  • Mutation: changing the fract refusal bound 0x9400 to 0x9300 (line 1894) makes check_f16_exact_extra_controls fail.
  • Sibling tables: coverage TSV counts, docs/experiments.md and CMakeLists.txt are all updated.

Not run here: tests/form_coverage_check.py needs iced_x86, which is not installed on this Linux box. The Windows run covers it.

Commands run:

  • python3 tests/pixel_aot_check.py (pass)
  • python3 tests/rdna2_tools_check.py (OK, 19 skipped)
  • python3 tests/docs_links_check.py
  • python3 tests/bidi_controls_check.py
  • git diff --check origin/main...HEAD
  • the mutation above, reverted with git checkout -- .

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6065377788 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2578#pullrequestreview-6065377788). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T21:42:43Z. **Review:** COMMENTED --- Review of head ad6e22fe (main merged into the PR; the PR's own diff is the same 6 files as before). Comment only. Result: sound. I found no blocking issue. What I checked: - No other open or merged PR covers these 25 binary16 forms (#906 closed, #419 and #537 are different slices). - `tools/pixel_aot.py`: the 25 forms need `half_denorm="preserve"`, refuse `HALF_RTZ`, and keep the static finite-proof contract. min/max compare the bit patterns, so subnormals and -0.0 are kept. Opposite-sign zeros are refused. fract refuses the tiny-negative range. - Tests: `check_f16_exact_extra_controls` plus the `pixel_aot_f16_exact_extra_{warp,hardware}` draw tests (real draw readback against a CPU reference, with built-in mutations that must be caught). `form_coverage_check` has new coverage assertions. - Mutation: changing the fract refusal bound `0x9400` to `0x9300` (line 1894) makes `check_f16_exact_extra_controls` fail. - Sibling tables: coverage TSV counts, `docs/experiments.md` and `CMakeLists.txt` are all updated. Not run here: `tests/form_coverage_check.py` needs `iced_x86`, which is not installed on this Linux box. The Windows run covers it. Commands run: - `python3 tests/pixel_aot_check.py` (pass) - `python3 tests/rdna2_tools_check.py` (OK, 19 skipped) - `python3 tests/docs_links_check.py` - `python3 tests/bidi_controls_check.py` - `git diff --check origin/main...HEAD` - the mutation above, reverted with `git checkout -- .` AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 23:01:51 +00:00
tedin7 commented 2026-11-25 23:02:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:18:14Z.


Win2025 WARP receipt for head ad6e22fe after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit ad6e22fed9ec7621392e67b0e995b956ec9c3685:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 707.05s (configure 2.20s)
    • Test (ctest --preset dev -R 'pixel_aot_f16_exact_extra_warp|pixel_aot_check|form_coverage' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (20.72s: pixel_aot_f16_exact_extra_warp 11.32s, form_coverage 20.52s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 947.86s (configure 3.95s)
    • Test (ctest --preset release -R 'pixel_aot_f16_exact_extra_warp|pixel_aot_check|form_coverage' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (16.96s: pixel_aot_f16_exact_extra_warp 8.97s, form_coverage 16.77s)
  • Windows Python checks: tests/form_coverage_check.py ok (17.9s), tests/mesh_clip_cull_check.py ok (9.0s), tests/mesh_dynamic_geometry_check.py ok (0.4s), tests/mesh_heap_sampler_check.py ok (1.1s), tests/pso_readiness_check.py ok (1.4s), tests/rdna2_tools_check.py ok (4.1s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.4s), tests/startup_gfx2hlsl_f32_lg_check.py ok (2.0s), tests/startup_gfx2hlsl_f32_nan_check.py ok (9.6s), tests/startup_gfx2hlsl_fma_mix_check.py ok (0.4s), tests/startup_gfx2hlsl_sop2_complement_check.py ok (14.2s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (9.8s), tests/startup_image_load_d16_check.py ok (1.2s), tests/startup_image_sample_a16_check.py ok (0.1s), tests/startup_ngg_slice_check.py ok (0.3s), tests/vk_offscreen.py ok (1.3s)
  • sccache: 477/4568 hits; wall 1769.9s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7176193412 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2578#issuecomment-7176193412). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T22:18:14Z. --- Win2025 WARP receipt for head ad6e22fe after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `ad6e22fed9ec7621392e67b0e995b956ec9c3685`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `707.05s` (configure `2.20s`) - Test (`ctest --preset dev -R 'pixel_aot_f16_exact_extra_warp|pixel_aot_check|form_coverage' --parallel 2 --no-tests=error --output-on-failure`): **2/2 passed** (`20.72s`: `pixel_aot_f16_exact_extra_warp` `11.32s`, `form_coverage` `20.52s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `947.86s` (configure `3.95s`) - Test (`ctest --preset release -R 'pixel_aot_f16_exact_extra_warp|pixel_aot_check|form_coverage' --parallel 2 --no-tests=error --output-on-failure`): **2/2 passed** (`16.96s`: `pixel_aot_f16_exact_extra_warp` `8.97s`, `form_coverage` `16.77s`) - **Windows Python checks**: `tests/form_coverage_check.py` ok (`17.9s`), `tests/mesh_clip_cull_check.py` ok (`9.0s`), `tests/mesh_dynamic_geometry_check.py` ok (`0.4s`), `tests/mesh_heap_sampler_check.py` ok (`1.1s`), `tests/pso_readiness_check.py` ok (`1.4s`), `tests/rdna2_tools_check.py` ok (`4.1s`), `tests/startup_gfx2hlsl_cmp16_check.py` ok (`0.4s`), `tests/startup_gfx2hlsl_f32_lg_check.py` ok (`2.0s`), `tests/startup_gfx2hlsl_f32_nan_check.py` ok (`9.6s`), `tests/startup_gfx2hlsl_fma_mix_check.py` ok (`0.4s`), `tests/startup_gfx2hlsl_sop2_complement_check.py` ok (`14.2s`), `tests/startup_gfx2hlsl_vopc_sdwa_check.py` ok (`9.8s`), `tests/startup_image_load_d16_check.py` ok (`1.2s`), `tests/startup_image_sample_a16_check.py` ok (`0.1s`), `tests/startup_ngg_slice_check.py` ok (`0.3s`), `tests/vk_offscreen.py` ok (`1.3s`) - `sccache`: 477/4568 hits; wall `1769.9s` AI-assisted; commands listed were executed locally.
alvaroolt commented 2026-11-26 00:01:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alvaroolt on 2026-11-25T23:07:14Z.


Hardware results for the merged change. Until now only WARP had been run.

Tested main at b41f6fca, which contains this PR's merge commit af172024. The machine runs Windows 11 build 26300 with MSVC 14.52, Windows SDK 10.0.26100 and DXC 1.9.2602.17. The D3D12 debug layer is not available (Graphics Tools not installed).

Adapter Driver dev release
NVIDIA GeForce RTX 5080 (default hardware adapter) 32.0.16.2124 pass pass
AMD Radeon(TM) Graphics iGPU (XBOX2WINDOWS_ADAPTER=Radeon) 32.0.11034.2 pass pass
Microsoft WARP in-box pass pass

In every run, pixel_aot_f16_exact_extra_{hardware,warp} passed and all 20 mutations reported mismatch: 120 of 120 across the six runs, none escaped. The other binary16 draws (pixel_aot_f16_{arith,round,fmac_ldexp,cvt_int16,to_int16}_*) also passed on all three adapters in both presets. There were no capability skips. The LLVM 15 round trip (tests/pixel_aot_check.py binary, LLVM 15.0.7) exited 0.

Commands, from a dev shell (.\tools\dev.ps1):

foreach ($p in 'dev', 'release') {
  cmake --preset $p; cmake --build --preset $p
  ctest --preset $p --no-tests=error -R '^pixel_aot_f16_' -V
  $env:XBOX2WINDOWS_ADAPTER = 'Radeon'
  ctest --preset $p --no-tests=error -R '^pixel_aot_f16_.*_hardware$' -V
  Remove-Item Env:XBOX2WINDOWS_ADAPTER
}

As an independent cross-check, I had written a separate lowering of only the VOP2/e64 v_min_f16/v_max_f16 forms before this PR landed. It also refused opposite-signed zeros. Its own draws, with a CPU reference and min/max-swap, unsigned-compare, flush and high-half mutations, passed on the same three adapters. It is not being submitted, because this PR covers it.

This comment was AI-assisted (Claude Code); I reviewed the commands and the results.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177169319 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2578#issuecomment-7177169319). Originally posted by [alvaroolt](https://github.com/alvaroolt) on 2026-11-25T23:07:14Z. --- Hardware results for the merged change. Until now only WARP had been run. Tested `main` at `b41f6fca`, which contains this PR's merge commit `af172024`. The machine runs Windows 11 build 26300 with MSVC 14.52, Windows SDK 10.0.26100 and DXC 1.9.2602.17. The D3D12 debug layer is not available (Graphics Tools not installed). | Adapter | Driver | `dev` | `release` | |---|---|---|---| | NVIDIA GeForce RTX 5080 (default hardware adapter) | 32.0.16.2124 | pass | pass | | AMD Radeon(TM) Graphics iGPU (`XBOX2WINDOWS_ADAPTER=Radeon`) | 32.0.11034.2 | pass | pass | | Microsoft WARP | in-box | pass | pass | In every run, `pixel_aot_f16_exact_extra_{hardware,warp}` passed and all 20 mutations reported `mismatch`: 120 of 120 across the six runs, none escaped. The other binary16 draws (`pixel_aot_f16_{arith,round,fmac_ldexp,cvt_int16,to_int16}_*`) also passed on all three adapters in both presets. There were no capability skips. The LLVM 15 round trip (`tests/pixel_aot_check.py binary`, LLVM 15.0.7) exited 0. Commands, from a dev shell (`.\tools\dev.ps1`): ```powershell foreach ($p in 'dev', 'release') { cmake --preset $p; cmake --build --preset $p ctest --preset $p --no-tests=error -R '^pixel_aot_f16_' -V $env:XBOX2WINDOWS_ADAPTER = 'Radeon' ctest --preset $p --no-tests=error -R '^pixel_aot_f16_.*_hardware$' -V Remove-Item Env:XBOX2WINDOWS_ADAPTER } ``` As an independent cross-check, I had written a separate lowering of only the VOP2/e64 `v_min_f16`/`v_max_f16` forms before this PR landed. It also refused opposite-signed zeros. Its own draws, with a CPU reference and min/max-swap, unsigned-compare, flush and high-half mutations, passed on the same three adapters. It is not being submitted, because this PR covers it. This comment was AI-assisted (Claude Code); I reviewed the commands and the results.
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!2570
No description provided.