shader: lower binary64 comparisons on their source words #1349

Manually merged
github merged 2 commits from gh-pr/1349/head into gh-pr/1349/base 2026-11-26 23:00:13 +00:00
Owner

@⁠archielcqp-a11y on GitHub · 2026-11-24 08:54 UTC · original
archielcqp-a11y:shader/cmp-f64 → main · +414 −12 · 5 files · 2 commits · merged 2026-11-24 09:51 UTC

Change

Lowers the binary64 comparisons: v_cmp_*_f64 for all 16 predicates and v_cmp_class_f64, each in the e32 and e64 encodings (34 forms). The comparison works on the two 32-bit words of each source, so the shader uses no HLSL double. That matters because the Windows 10 in-box WARP faults on some double comparisons; see the v_div_fmas_f32 helper.

Three helpers do the work, and class64 adds the class test:

  • num64 detects NaN from the encoding. That includes a signaling NaN whose payload is only in the low word.
  • key64 maps every other encoding to an unsigned key with the same order as its value. It inverts negative encodings, sets the sign bit of positive ones, and gives -0 and +0 one key.
  • Relations: the ordered relations compare keys word by word. The n* predicates negate them, so they are true on NaN.
  • class64 reads the ten classes of class32 from the encoding.

Operand rules:

  • Accepted sources: VGPR pairs, aligned SGPR pairs, 0, and the binary64 inline constants ±0.5, ±1.0, ±2.0 and ±4.0.
  • e64 modifiers: -x and |x| are allowed on the comparison sources (they act on the sign bit), but not on the class source.
  • Refused: other integer inline constants, 1/(2*pi), literals, the suffix-less spelling, and the v_cmpx_*_f64 forms.
  • Denormal mode: MODE[7:6] also controls binary64 denormals. These forms therefore require the declared half_denorm="preserve" entry state, the same declaration the binary16 arithmetic uses.

Verification

Commit 46d20ea on upstream 0f09ca9. I also checked a trial merge with current d6cbd5d: the binary mode, the controls and the 8 comparison draws all pass, and git reported no conflicts.

Environment: Windows 10 build 19045.6466. NVIDIA GeForce RTX 3080 (10de:2216), driver 32.0.15.9174, and WARP 1.0.22 (Agility SDK 1.620.2), with the debug layer enabled.

  • ctest --test-dir out/build/w10 --no-tests=error -R '^pixel_aot_cmp_f64_(warp|hardware)$': 2/2 passed, with no skips.
  • python -B tests/pixel_aot_check.py binary <llvm-mc 15> <llvm-objcopy 15> <LLVM-C.dll 15>: exit 0. This runs the controls and the LLVM 15 gfx1013 round trip of the ten new programs.
  • All 40 pure-Python checks from AGENTS.md pass.
  • ctest over the 155 record-writing tests with --output-junit: 155/155 passed. tools/form_coverage.py on that run puts gfx1013 coverage at 960 → 994 of 1968 (+34), with no v_cmp_*_f64 gap left. gfx1030 coverage is 984 of 1863.

Fixtures and negative controls

  • Draws (pixel_aot_cmp_f64_{warp,hardware}):
    • Eight predicate groups and two class groups.
    • Sources: register pairs, SGPR pairs, swapped pairs or modifiers, and inline constants.
    • 16 word pairs: values decided by the low word (positive and negative), reversed integer order on negatives, +0 against -0, denormals of both signs, quiet and signaling NaNs, the infinities against the largest finite values, and the inline constants.
    • The CPU reference decodes the words as Python floats.
  • Mutations: each change below is applied to the lowered shader and must produce a mismatch on the GPU:
    • keys in raw integer order;
    • separate keys for -0 and +0;
    • denormals keyed as zero;
    • NaN tested on the high word only;
    • a misplaced quiet bit in class64.
  • Translator controls:
    • the exact lowering text;
    • refusal without the entry-state declaration;
    • destination and operand rules: e32 src1 must be a VGPR pair, no modifiers on e32, the refused constants and literals, and the e32 class mask must be a VGPR;
    • untracked sources, masked regions and pending loads;
    • a Python pre-check that the word rows separate each wrong model.
  • Existing controls updated: check_cmp64_controls and form_coverage_check listed v_cmp_lt_f64 and v_cmp_class_f64 as refused neighbours. Those forms now have their own controls, and v_cmpx_lt_f64 and v_cmpx_class_f64 are asserted as uncovered instead.

Assumed, not sourced:

  • An integer inline constant other than 0 on a binary64 operand reads as raw bits. It is refused rather than modeled.
  • The comparisons and v_cmp_class_f64 follow MODE[7:6] the way the arithmetic does.

No gfx1013 hardware run checks either assumption. The draws pin the translator's model on desktop adapters only.

This touches lines near #1335 in tools/pixel_aot.py and tests/form_coverage_check.py, but the two PRs are independent. If one merges first, the other may need a rebase.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

🤖 Generated with Claude Code

**@⁠archielcqp-a11y** on GitHub · 2026-11-24 08:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1349) `archielcqp-a11y:shader/cmp-f64` → `main` · +414 −12 · 5 files · 2 commits · merged 2026-11-24 09:51 UTC ## Change Lowers the binary64 comparisons: `v_cmp_*_f64` for all 16 predicates and `v_cmp_class_f64`, each in the e32 and e64 encodings (34 forms). The comparison works on the two 32-bit words of each source, so the shader uses no HLSL `double`. That matters because the Windows 10 in-box WARP faults on some double comparisons; see the `v_div_fmas_f32` helper. Three helpers do the work, and `class64` adds the class test: - **`num64`** detects NaN from the encoding. That includes a signaling NaN whose payload is only in the low word. - **`key64`** maps every other encoding to an unsigned key with the same order as its value. It inverts negative encodings, sets the sign bit of positive ones, and gives -0 and +0 one key. - **Relations:** the ordered relations compare keys word by word. The `n*` predicates negate them, so they are true on NaN. - **`class64`** reads the ten classes of `class32` from the encoding. Operand rules: - **Accepted sources:** VGPR pairs, aligned SGPR pairs, `0`, and the binary64 inline constants ±0.5, ±1.0, ±2.0 and ±4.0. - **e64 modifiers:** `-x` and `|x|` are allowed on the comparison sources (they act on the sign bit), but not on the class source. - **Refused:** other integer inline constants, `1/(2*pi)`, literals, the suffix-less spelling, and the `v_cmpx_*_f64` forms. - **Denormal mode:** MODE[7:6] also controls binary64 denormals. These forms therefore require the declared `half_denorm="preserve"` entry state, the same declaration the binary16 arithmetic uses. ## Verification Commit `46d20ea` on upstream `0f09ca9`. I also checked a trial merge with current `d6cbd5d`: the binary mode, the controls and the 8 comparison draws all pass, and git reported no conflicts. Environment: Windows 10 build 19045.6466. NVIDIA GeForce RTX 3080 (10de:2216), driver 32.0.15.9174, and WARP 1.0.22 (Agility SDK 1.620.2), with the debug layer enabled. - `ctest --test-dir out/build/w10 --no-tests=error -R '^pixel_aot_cmp_f64_(warp|hardware)$'`: 2/2 passed, with no skips. - `python -B tests/pixel_aot_check.py binary <llvm-mc 15> <llvm-objcopy 15> <LLVM-C.dll 15>`: exit 0. This runs the controls and the LLVM 15 gfx1013 round trip of the ten new programs. - All 40 pure-Python checks from AGENTS.md pass. - `ctest` over the 155 record-writing tests with `--output-junit`: 155/155 passed. `tools/form_coverage.py` on that run puts gfx1013 coverage at 960 → 994 of 1968 (+34), with no `v_cmp_*_f64` gap left. gfx1030 coverage is 984 of 1863. ## Fixtures and negative controls - **Draws (`pixel_aot_cmp_f64_{warp,hardware}`):** - Eight predicate groups and two class groups. - Sources: register pairs, SGPR pairs, swapped pairs or modifiers, and inline constants. - 16 word pairs: values decided by the low word (positive and negative), reversed integer order on negatives, +0 against -0, denormals of both signs, quiet and signaling NaNs, the infinities against the largest finite values, and the inline constants. - The CPU reference decodes the words as Python floats. - **Mutations:** each change below is applied to the lowered shader and must produce a mismatch on the GPU: - keys in raw integer order; - separate keys for -0 and +0; - denormals keyed as zero; - NaN tested on the high word only; - a misplaced quiet bit in `class64`. - **Translator controls:** - the exact lowering text; - refusal without the entry-state declaration; - destination and operand rules: e32 src1 must be a VGPR pair, no modifiers on e32, the refused constants and literals, and the e32 class mask must be a VGPR; - untracked sources, masked regions and pending loads; - a Python pre-check that the word rows separate each wrong model. - **Existing controls updated:** `check_cmp64_controls` and `form_coverage_check` listed `v_cmp_lt_f64` and `v_cmp_class_f64` as refused neighbours. Those forms now have their own controls, and `v_cmpx_lt_f64` and `v_cmpx_class_f64` are asserted as uncovered instead. **Assumed, not sourced:** - An integer inline constant other than 0 on a binary64 operand reads as raw bits. It is refused rather than modeled. - The comparisons and `v_cmp_class_f64` follow MODE[7:6] the way the arithmetic does. No gfx1013 hardware run checks either assumption. The draws pin the translator's model on desktop adapters only. This touches lines near #1335 in `tools/pixel_aot.py` and `tests/form_coverage_check.py`, but the two PRs are independent. If one merges first, the other may need a rebase. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. This change was AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Lower v_cmp_*_f64 (all 16 predicates) and v_cmp_class_f64 in the e32
and e64 encodings, 34 forms, without an HLSL double. num64 detects NaN
from the encoding, key64 maps the other encodings to an unsigned key
with the order of their value (-0 and +0 share one key), and class64
reads the ten classes. Sources are VGPR or SGPR pairs, 0 and the
binary64 inline constants; e64 takes neg and abs on the comparison
sources. MODE[7:6] also governs binary64 denormals, so the forms
require the declared half_denorm="preserve" entry state.

New draw pixel_aot_cmp_f64_{warp,hardware}: eight predicate groups and
two class groups over 16 word pairs (signed zeros, denormals, quiet and
signaling NaNs, infinities, low-word-decided values) against a Python
float reference. Helper mutations (integer order, separate signed
zeros, flushed denormals, high-word-only NaN test, misplaced quiet bit)
must each mismatch. The controls check the lowering, the entry state
and the refused operands; the binary round trip covers all programs.

gfx1013 form coverage: 960 -> 994 of 1968 (+34).

AI-assisted (Claude Code); reviewed and run locally.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:00:11 +00:00
github manually merged commit a1a0c14960 into gh-pr/1349/base 2026-11-26 23:00:13 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 09:49 UTC · original

I pushed a1a0c149 to resolve the overlap with the integer CMPX regions. The merge preserves both comparison helpers and the existing CMPX region controls. On Windows 11 build 26200.9974, form coverage and the integer/binary64 translator controls passed. Both draw-cmp-f64 and draw-cmpx-regions passed on RTX 4060 Laptop (32.0.16.1656) and WARP (10.0.26100.9818) using SDK 26100 DXC and the source-built renderer. GitHub checks are running on the new head.

**@⁠R0Y00** on GitHub · 2026-11-24 09:49 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1349#issuecomment-7127945560) I pushed a1a0c149 to resolve the overlap with the integer CMPX regions. The merge preserves both comparison helpers and the existing CMPX region controls. On Windows 11 build 26200.9974, form coverage and the integer/binary64 translator controls passed. Both `draw-cmp-f64` and `draw-cmpx-regions` passed on RTX 4060 Laptop (32.0.16.1656) and WARP (10.0.26100.9818) using SDK 26100 DXC and the source-built renderer. GitHub checks are running on the new head.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 09:20 UTC · original · reviewed

Technical peer-review at commit 46d20eab85e464266755096feea7402b4fb58919.

Verification

  • Linux / LLVM-19:
    • git diff --check origin/main...HEAD: clean.
    • tests/docs_links_check.py: passed (16 Markdown files, 294 links).
    • tests/bidi_controls_check.py: passed (1108 tracked files).
    • tests/pixel_aot_check.py: passed (138 tests, 18 skipped).
    • tests/rdna2_tools_check.py & tests/form_coverage_check.py: passed.
    • CMPF64_GROUPS binary roundtrip (llvm-mc-19, llvm-objcopy-19, libLLVM-19.so): 10/10 programs passed. (Full pixel_aot_check.py binary on LLVM-19 stops earlier in pre-existing check_f16_cvt_int16_binary on v_cvt_f16_i16_e32 v1, 0xfff0, unrelated to this PR.)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): 4/4 passed (pixel_aot_cmp_f64_{warp,hardware}, pixel_aot_cmp64_{warp,hardware}) in 4.89s.
    • Release /O2 (--preset release): 4/4 passed in 4.94s.
    • tests/form_coverage_check.py: passed (43.4s).

Code Review Notes

  • tools/pixel_aot.py (cmp_f64 helpers): num64, key64, lt64, eq64, and class64 accurately model IEEE 754 binary64 ordering, NaN detection (including signaling NaNs with payload only in the low word), -0.0/+0.0 equivalence, denormal ordering, and all 10 ClassFlags bits without emitting HLSL double.
  • Operand & mode handling: f64_operand restricts inline constants to 0 and ±0.5, ±1.0, ±2.0, ±4.0, applies e64 -x/|x| modifiers on the sign bit (and disallows them on e32 and v_cmp_class_f64), and enforces half_denorm == HALF_DENORM_PRESERVE and v_cmpx_*_f64 refusal consistently with the rest of the translator.
**@⁠tedin7** on GitHub · 2026-11-24 09:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1349#pullrequestreview-6036579304) · **reviewed** Technical peer-review at commit `46d20eab85e464266755096feea7402b4fb58919`. ### Verification - **Linux / LLVM-19**: - `git diff --check origin/main...HEAD`: clean. - `tests/docs_links_check.py`: passed (16 Markdown files, 294 links). - `tests/bidi_controls_check.py`: passed (1108 tracked files). - `tests/pixel_aot_check.py`: passed (`138` tests, `18` skipped). - `tests/rdna2_tools_check.py` & `tests/form_coverage_check.py`: passed. - `CMPF64_GROUPS` binary roundtrip (`llvm-mc-19`, `llvm-objcopy-19`, `libLLVM-19.so`): 10/10 programs passed. *(Full `pixel_aot_check.py binary` on LLVM-19 stops earlier in pre-existing `check_f16_cvt_int16_binary` on `v_cvt_f16_i16_e32 v1, 0xfff0`, unrelated to this PR.)* - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: 4/4 passed (`pixel_aot_cmp_f64_{warp,hardware}`, `pixel_aot_cmp64_{warp,hardware}`) in `4.89s`. - **Release `/O2` (`--preset release`)**: 4/4 passed in `4.94s`. - `tests/form_coverage_check.py`: passed (`43.4s`). ### Code Review Notes - **`tools/pixel_aot.py` (`cmp_f64` helpers)**: `num64`, `key64`, `lt64`, `eq64`, and `class64` accurately model IEEE 754 binary64 ordering, NaN detection (including signaling NaNs with payload only in the low word), `-0.0`/`+0.0` equivalence, denormal ordering, and all 10 `ClassFlags` bits without emitting HLSL `double`. - **Operand & mode handling**: `f64_operand` restricts inline constants to `0` and `±0.5, ±1.0, ±2.0, ±4.0`, applies `e64` `-x`/`|x|` modifiers on the sign bit (and disallows them on `e32` and `v_cmp_class_f64`), and enforces `half_denorm == HALF_DENORM_PRESERVE` and `v_cmpx_*_f64` refusal consistently with the rest of the translator.
This discussion has been locked. Commenting is limited to contributors.
No description provided.