shader: lower the 64-bit integer compares in pixel_aot #797

Merged
JB2WIN merged 4 commits from upstream-pr/803 into main 2026-11-23 08:08:18 +00:00
JB2WIN commented 2026-11-23 06:00:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T06:00:56Z.


Change

tools/pixel_aot.py now lowers the 64-bit integer compares v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i64,u64} in the e32 (VOPC, printed with _e32) and e64 encodings. This is the bounded register-pair slice from #794.

Sources. The new int64_operand helper returns the raw (lo, hi) words of a source. A source may be:

  • a VGPR pair v[a:a+1] with 0 ≤ a ≤ 254. Unaligned pairs are accepted, because LLVM 15 assembles v[3:4]. Both halves must be tracked.
  • an aligned SGPR pair, read through sgpr_pair/scalar_u64.
  • an inline integer from -16 to 64, sign-extended to 64 bits.

Compare. Signed ordering applies to the high word only, and the low words always compare unsigned. Operands are compared as raw bits (asuint), so non-normal binary32 patterns keep their bits. The result is the same per-lane condition the 32-bit compares produce.

Destinations.

  • e32 writes vcc/vcc_lo only.
  • e64 follows the existing lane-mask rules: vcc_lo, vcc, sN or an aligned s[a:a+1].
  • wave32 and wave64 spellings lower to identical HLSL, as for the 16-bit compares.
  • On e32, src1 must be a VGPR pair, as LLVM requires.

Refused.

  • With an exact message: 32-bit literals (their extension rule is not established yet), float inline constants (a translator choice; LLVM accepts 1.0), hex values, out-of-range decimals, v[255:256], s[45:46], untracked halves, SGPR src1 on e32, an SGPR destination on e32, pending scalar loads and outstanding samples.
  • As an unsupported instruction: v_cmpx_*, modifiers, clamp, DPP and SDWA.

Scanner. supports_int64_compare() applies the same operand and destination rules. Six boundary forms the translator refuses are asserted unsupported.

Changed expectations, replaced rather than deleted:

  • The two 64-bit lines in the existing reject list become v_cmp_lt_i64_e64 s52, s[45:46], v[18:19] (odd SGPR pair) and v_cmp_lt_i64_e32 vcc_lo, v[18:19], s[44:45] (SGPR src1 on e32). Both are still refused.
  • In form_coverage_check.py, the 32 forms move into compare_forms. The expected count is now derived from the sets. The uncovered neighbours become v_cmpx_lt_i64/v_cmpx_lt_u64.

Refs #794. AI-assisted (Claude Code).

Verification

Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at d998665.

Draw draw-cmp64 (pixel_aot_cmp64_{hardware,warp}): eight programs, 13 cases each, with v_cndmask_b32 selecting per-predicate words. Readback is full-width and checked against an independent Python reference. The cases include:

  • identical high words with distinct low words;
  • high words that differ only in the sign bit;
  • -1 against 0;
  • 0x7fffffff_ffffffff against 0x80000000_00000000;
  • equal values;
  • a source pair overlapping the other source (v[18:19] against v[19:20]);
  • non-normal bit patterns 0x00000001, 0x7fc00000, 0xffffffff and 0x80000000, compiled with -denorm preserve.

Mutations. Each must mismatch, and each did on both adapters:

  • high and low words swapped;
  • low words only;
  • high words only;
  • lt replaced with le;
  • signed compared as unsigned;
  • the overlapping pair read as v[20:21].

Dev-time checks (not committed). Without the new branch the controls fail. Without the scanner validator rdna2_tools_check.py fails.

Commands.

  • ctest --preset dev --no-tests=error -R "^pixel_aot_cmp64_": 2/2 passed. It took 21.8 s on the RTX 3080 and about 6 s on WARP.
  • Full ctest --preset dev --no-tests=error -j4: 371 of 372 passed. The one failure is compute_store_aot_hardware, which hits its 45 s timeout on this adapter on plain main as well (#448). Skipped: bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp.
  • The LLVM 15 binary round trip passes with all eight programs. llvm-mc runs through a local clang -cc1as shim.
  • The controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py pass.

Assumptions and limits

  • Assumed, not measured:
    • Unaligned VGPR pairs are legal on hardware. Only LLVM accepts them.
    • Inline constants are sign-extended for VOPC. This extends the documented SOP b64 rule.
    • Two SGPR-pair sources on e64 respect the constant-bus limit. LLVM assembles this form, but the limit is not sourced.
  • The draws pin the translator's model on desktop adapters. They are not gfx1013 measurements.
  • Reported, not changed: the existing 16- and 32-bit e32 compare branches, and their scanner patterns, still accept an SGPR destination.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6553314938 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/803). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T06:00:56Z. --- ## Change `tools/pixel_aot.py` now lowers the 64-bit integer compares `v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i64,u64}` in the e32 (VOPC, printed with `_e32`) and e64 encodings. This is the bounded register-pair slice from #794. **Sources.** The new `int64_operand` helper returns the raw `(lo, hi)` words of a source. A source may be: - a VGPR pair `v[a:a+1]` with 0 ≤ a ≤ 254. Unaligned pairs are accepted, because LLVM 15 assembles `v[3:4]`. Both halves must be tracked. - an aligned SGPR pair, read through `sgpr_pair`/`scalar_u64`. - an inline integer from -16 to 64, sign-extended to 64 bits. **Compare.** Signed ordering applies to the high word only, and the low words always compare unsigned. Operands are compared as raw bits (`asuint`), so non-normal binary32 patterns keep their bits. The result is the same per-lane condition the 32-bit compares produce. **Destinations.** - e32 writes `vcc`/`vcc_lo` only. - e64 follows the existing lane-mask rules: `vcc_lo`, `vcc`, `sN` or an aligned `s[a:a+1]`. - wave32 and wave64 spellings lower to identical HLSL, as for the 16-bit compares. - On e32, src1 must be a VGPR pair, as LLVM requires. **Refused.** - With an exact message: 32-bit literals (their extension rule is not established yet), float inline constants (a translator choice; LLVM accepts `1.0`), hex values, out-of-range decimals, `v[255:256]`, `s[45:46]`, untracked halves, SGPR src1 on e32, an SGPR destination on e32, pending scalar loads and outstanding samples. - As an unsupported instruction: `v_cmpx_*`, modifiers, `clamp`, DPP and SDWA. **Scanner.** `supports_int64_compare()` applies the same operand and destination rules. Six boundary forms the translator refuses are asserted unsupported. **Changed expectations, replaced rather than deleted:** - The two 64-bit lines in the existing reject list become `v_cmp_lt_i64_e64 s52, s[45:46], v[18:19]` (odd SGPR pair) and `v_cmp_lt_i64_e32 vcc_lo, v[18:19], s[44:45]` (SGPR src1 on e32). Both are still refused. - In `form_coverage_check.py`, the 32 forms move into `compare_forms`. The expected count is now derived from the sets. The uncovered neighbours become `v_cmpx_lt_i64`/`v_cmpx_lt_u64`. Refs #794. AI-assisted (Claude Code). ## Verification Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at `d998665`. **Draw `draw-cmp64`** (`pixel_aot_cmp64_{hardware,warp}`): eight programs, 13 cases each, with `v_cndmask_b32` selecting per-predicate words. Readback is full-width and checked against an independent Python reference. The cases include: - identical high words with distinct low words; - high words that differ only in the sign bit; - -1 against 0; - `0x7fffffff_ffffffff` against `0x80000000_00000000`; - equal values; - a source pair overlapping the other source (`v[18:19]` against `v[19:20]`); - non-normal bit patterns `0x00000001`, `0x7fc00000`, `0xffffffff` and `0x80000000`, compiled with `-denorm preserve`. **Mutations.** Each must mismatch, and each did on both adapters: - high and low words swapped; - low words only; - high words only; - `lt` replaced with `le`; - signed compared as unsigned; - the overlapping pair read as `v[20:21]`. **Dev-time checks (not committed).** Without the new branch the controls fail. Without the scanner validator `rdna2_tools_check.py` fails. **Commands.** - `ctest --preset dev --no-tests=error -R "^pixel_aot_cmp64_"`: 2/2 passed. It took 21.8 s on the RTX 3080 and about 6 s on WARP. - Full `ctest --preset dev --no-tests=error -j4`: 371 of 372 passed. The one failure is `compute_store_aot_hardware`, which hits its 45 s timeout on this adapter on plain `main` as well (#448). Skipped: `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp`. - The LLVM 15 binary round trip passes with all eight programs. `llvm-mc` runs through a local `clang -cc1as` shim. - The controls, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` pass. ## Assumptions and limits - **Assumed, not measured:** - Unaligned VGPR pairs are legal on hardware. Only LLVM accepts them. - Inline constants are sign-extended for VOPC. This extends the documented SOP b64 rule. - Two SGPR-pair sources on e64 respect the constant-bus limit. LLVM assembles this form, but the limit is not sourced. - The draws pin the translator's model on desktop adapters. They are not gfx1013 measurements. - **Reported, not changed:** the existing 16- and 32-bit e32 compare branches, and their scanner patterns, still accept an SGPR destination. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:51 +00:00
JB2WIN commented 2026-11-24 06:49:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T06:05:07Z.


Follow-up commit 899366b: without a suffix, the encoding is now chosen as LLVM 15 does. It is e32 when the destination is vcc/vcc_lo and src1 is a VGPR pair, and e64 otherwise. Checked with llvm-mc on gfx1013: v_cmp_lt_i64 s52, v[1:2], v[3:4] and v_cmp_lt_i64 vcc_lo, v[1:2], s[4:5] both assemble as _e64. Before this, the translator and scanner treated every suffix-less spelling as e32 and refused those two forms. The controls now assert that the suffix-less forms lower to the same HLSL as their _e64 spelling. The controls, rdna2_tools_check.py and docs_links_check.py pass. The draws use explicit suffixes and are unaffected.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7092992334 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/803#issuecomment-7092992334). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T06:05:07Z. --- Follow-up commit `899366b`: without a suffix, the encoding is now chosen as LLVM 15 does. It is e32 when the destination is `vcc`/`vcc_lo` and src1 is a VGPR pair, and e64 otherwise. Checked with llvm-mc on `gfx1013`: `v_cmp_lt_i64 s52, v[1:2], v[3:4]` and `v_cmp_lt_i64 vcc_lo, v[1:2], s[4:5]` both assemble as `_e64`. Before this, the translator and scanner treated every suffix-less spelling as e32 and refused those two forms. The controls now assert that the suffix-less forms lower to the same HLSL as their `_e64` spelling. The controls, `rdna2_tools_check.py` and `docs_links_check.py` pass. The draws use explicit suffixes and are unaffected.
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!797
No description provided.