shader: lower s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64 and s_bitcmp1_b64 in the direct compute path #3081

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3081 into main 2026-11-27 20:35:22 +00:00
legacy-code-archaeologist commented 2026-11-27 14:35:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T14:35:23Z.


Lowers s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64, and s_bitcmp1_b64 in the direct C++ compute path (src/gfx1013_direct_compute.inl) to pure 32-bit DXIL writes of SCC.

Verification

Measured on Windows 10.0.26100 (dev preset) on upstream/main 88cddb09 + cc7a8fbe:

  • ctest --preset dev --no-tests=error -R '^native_salu_cmp64_' -V:
    • native_salu_cmp64_ir (passed): dumps DXIL IR via native_compute_ir_dump for all 22 cases (aligned pairs, null, negative inline -1, 32-bit literal 0x80000001, bits 0/31/32/63, wrapped SGPR indices 65/96), asserts pure 32-bit IR (no i64 ops), evaluates lane 0 to verify s[22:23] is untouched and exact SCC is stored, verifies 7 operand refusals, and catches 6 oracle mutants.
    • native_salu_cmp64_controls (passed): compiles all 22 cases together via compile_dxil to pure 32-bit DXIL, verifies the 7 operand refusals and 6 oracle mutants.
    • native_salu_cmp64_hardware (skipped, exit 77): NVIDIA Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback is not measured locally.
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 47/47 passed (51.67s).
  • python -B tests/docs_links_check.py: passed (102 Markdown files, 589 links).
  • Broken-lowering sensitivity check: 5 deliberate broken builds (low_word_only_cmp, high_word_only_cmp, swap_and_or, ignore_bit5, invert_bitcmp) each failed native_salu_cmp64_ir (exit 1).

Fixes #3078
Refs #2935

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5528382301 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3081). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T14:35:23Z. --- Lowers `s_cmp_eq_u64`, `s_cmp_lg_u64`, `s_bitcmp0_b64`, and `s_bitcmp1_b64` in the direct C++ compute path (`src/gfx1013_direct_compute.inl`) to pure 32-bit DXIL writes of `SCC`. ## Verification Measured on Windows `10.0.26100` (`dev` preset) on `upstream/main` `88cddb09` + `cc7a8fbe`: - `ctest --preset dev --no-tests=error -R '^native_salu_cmp64_' -V`: - `native_salu_cmp64_ir` (**passed**): dumps DXIL IR via `native_compute_ir_dump` for all 22 cases (aligned pairs, `null`, negative inline `-1`, 32-bit literal `0x80000001`, bits `0`/`31`/`32`/`63`, wrapped SGPR indices `65`/`96`), asserts pure 32-bit IR (no `i64` ops), evaluates lane 0 to verify `s[22:23]` is untouched and exact `SCC` is stored, verifies 7 operand refusals, and catches 6 oracle mutants. - `native_salu_cmp64_controls` (**passed**): compiles all 22 cases together via `compile_dxil` to pure 32-bit DXIL, verifies the 7 operand refusals and 6 oracle mutants. - `native_salu_cmp64_hardware` (**skipped**, exit `77`): NVIDIA Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback is not measured locally. - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **47/47 passed** (`51.67s`). - `python -B tests/docs_links_check.py`: **passed** (102 Markdown files, 589 links). - Broken-lowering sensitivity check: 5 deliberate broken builds (`low_word_only_cmp`, `high_word_only_cmp`, `swap_and_or`, `ignore_bit5`, `invert_bitcmp`) each failed `native_salu_cmp64_ir` (exit `1`). Fixes #3078 Refs #2935 AI-assisted.
tedin7 commented 2026-11-27 18:09:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T18:09:37Z.

Review: COMMENTED


Review of bc6dc3b5 (comment only).

The lowering reads correctly to me: 64-bit equality as two 32-bit compares joined with and/or, and the bit test picking the high word for index bit 5 with the shift masked to the word.

What holds me back from merging: the semantics are not checked by anything that runs. controls asserts only that icmp eq i32, icmp ne i32 and lshr i32 appear in the DXIL dump, which other instructions in the same program could also produce, and native_salu_cmp64_hardware skipped on your machine and skips on WARP. Could you add either an IR-level control that pins the compare operands and the high-word selection (like native_f16_alu_check.py ir with native_compute_ir_dump), or a hardware run on an SM 6.6 wave32 GPU, reported with adapter, driver and commit? The same gap was pointed out on #3071.

Command: git diff origin/main...pull/3081/head -- src/ tests/ (read).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6091923660 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3081#pullrequestreview-6091923660). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T18:09:37Z. **Review:** COMMENTED --- Review of bc6dc3b5 (comment only). The lowering reads correctly to me: 64-bit equality as two 32-bit compares joined with and/or, and the bit test picking the high word for index bit 5 with the shift masked to the word. What holds me back from merging: the semantics are not checked by anything that runs. `controls` asserts only that `icmp eq i32`, `icmp ne i32` and `lshr i32` appear in the DXIL dump, which other instructions in the same program could also produce, and `native_salu_cmp64_hardware` skipped on your machine and skips on WARP. Could you add either an IR-level control that pins the compare operands and the high-word selection (like `native_f16_alu_check.py ir` with `native_compute_ir_dump`), or a `hardware` run on an SM 6.6 wave32 GPU, reported with adapter, driver and commit? The same gap was pointed out on #3071. Command: `git diff origin/main...pull/3081/head -- src/ tests/` (read). AI-assisted; commands listed were executed locally.
legacy-code-archaeologist commented 2026-11-27 19:17:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T19:17:21Z.


@tedin7 Thanks for catching that gap! Added the IR-level check in rebased commit cc7a8fbe on upstream/main (88cddb09):

  • native_salu_cmp64_ir (tests/cmake/native_salu_cmp64.cmake, tests/native_salu_cmp64_check.py): Dumps DXIL IR via native_compute_ir_dump for all 22 cases across s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64, and s_bitcmp1_b64, asserts no 64-bit integer IR ops appear, and evaluates lane 0 (interpret_pair_stores) to verify both the preserved SGPR pair (s[22:23]) and the exact stored SCC result (pinning the low/high word compares, sign/zero-extension of inline -1 / literal 0x80000001, and bit-5 high-word select in s_bitcmp*), plus all 7 operand refusals.
  • Broken-lowering sensitivity: Verified locally that 5 broken builds (low_word_only_cmp, high_word_only_cmp, swap_and_or, ignore_bit5, invert_bitcmp) each fail native_salu_cmp64_ir (exit 1).
  • Verification (Windows 10.0.26100, dev preset): native_salu_cmp64_ir and native_salu_cmp64_controls pass; native_salu_cmp64_hardware skips with 77 on NVIDIA Quadro M1000M (SM 6.1, no SM 6.6 wave32); ^native_.*_(controls|ir)$ passes 47/47; python -B tests/docs_links_check.py passes (102 files, 589 links). Also updated docs/experiments/native-direct-salu-cmp64.md.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7226378362 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3081#issuecomment-7226378362). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T19:17:21Z. --- @tedin7 Thanks for catching that gap! Added the IR-level check in rebased commit `cc7a8fbe` on `upstream/main` (`88cddb09`): - **`native_salu_cmp64_ir` ([tests/cmake/native_salu_cmp64.cmake](tests/cmake/native_salu_cmp64.cmake), [tests/native_salu_cmp64_check.py](tests/native_salu_cmp64_check.py)):** Dumps DXIL IR via `native_compute_ir_dump` for all 22 cases across `s_cmp_eq_u64`, `s_cmp_lg_u64`, `s_bitcmp0_b64`, and `s_bitcmp1_b64`, asserts no 64-bit integer IR ops appear, and evaluates lane 0 (`interpret_pair_stores`) to verify both the preserved SGPR pair (`s[22:23]`) and the exact stored `SCC` result (pinning the low/high word compares, sign/zero-extension of inline `-1` / literal `0x80000001`, and bit-5 high-word `select` in `s_bitcmp*`), plus all 7 operand refusals. - **Broken-lowering sensitivity:** Verified locally that 5 broken builds (`low_word_only_cmp`, `high_word_only_cmp`, `swap_and_or`, `ignore_bit5`, `invert_bitcmp`) each fail `native_salu_cmp64_ir` (exit `1`). - **Verification (Windows `10.0.26100`, `dev` preset):** `native_salu_cmp64_ir` and `native_salu_cmp64_controls` pass; `native_salu_cmp64_hardware` skips with `77` on NVIDIA Quadro M1000M (SM 6.1, no SM 6.6 wave32); `^native_.*_(controls|ir)$` passes `47/47`; `python -B tests/docs_links_check.py` passes (102 files, 589 links). Also updated [docs/experiments/native-direct-salu-cmp64.md](docs/experiments/native-direct-salu-cmp64.md). AI-assisted.
pigalot commented 2026-11-27 20:35:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T20:35:04Z.

Review: APPROVED


I reviewed cc7a8fbe merged into main 671d2f46 (tree 4971b9a6, clean merge; main now includes #3071). This includes the hardware run tedin7 asked for.

What I traced.

  • s_cmp_eq_u64 / s_cmp_lg_u64: two 32-bit compares, joined with and / or.
  • s_bitcmp0_b64 / s_bitcmp1_b64: the word is chosen by index bit 5. shift() masks the amount to 5 bits, so this is exactly bit S1[5:0].
  • Sources: null reads as 0. pair_high() refuses unaligned pairs and wave64 specials, and sign-extends negative inline constants. The new code also refuses vcc and exec.
  • Only SCC is written.

What I ran. I built compile_dxil native_store_replay native_compute_ir_dump in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_salu_(cmp64|cmov)_'

  • 6/6 passed in each preset. I included cmov because the two PRs share uses_scc_after() and the SOPC/SOP1 dispatch.
  • native_salu_cmp64_hardware ran and passed all 22 cases, each reporting preserved pair, SCC and guards matched. These include eq hi differs / eq lo differs, bits 0/31/32/63, null, -1 and the 0x80000001 literal.

Mutants (in src/gfx1013_direct_compute.inl, rebuilt each time):

mutant _ir _hardware
bit test always reads the low word (word = a_lo) fails at ('bitcmp1 bit 32 set', (512, 0, 0), 1) fails at ('bitcmp1 bit 32 set', (0, 1), 1)
s_cmp_eq_u64 joins the halves with or fails at ('eq hi differs', (512, 1, 0), 0) fails

Restored, all pass, and git diff --check is clean.

Still unmeasured (the same caveat as #3071): whether gfx1013 zero-extends the 32-bit literal in a 64-bit compare. The hardware run shows only that the lowering matches the PR's pair_high() reference.

Verdict: approve on cc7a8fbe.

Environment: NVIDIA GeForce RTX 5090 (wave 32..32, SM 6.8), driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10.
CI: Build and test on Windows passes on cc7a8fbe.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093116222 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3081#pullrequestreview-6093116222). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T20:35:04Z. **Review:** APPROVED --- I reviewed `cc7a8fbe` merged into `main` `671d2f46` (tree `4971b9a6`, clean merge; `main` now includes #3071). This includes the hardware run tedin7 asked for. **What I traced.** - **`s_cmp_eq_u64` / `s_cmp_lg_u64`:** two 32-bit compares, joined with `and` / `or`. - **`s_bitcmp0_b64` / `s_bitcmp1_b64`:** the word is chosen by index bit 5. `shift()` masks the amount to 5 bits, so this is exactly bit `S1[5:0]`. - **Sources:** `null` reads as 0. `pair_high()` refuses unaligned pairs and wave64 specials, and sign-extends negative inline constants. The new code also refuses `vcc` and `exec`. - Only SCC is written. **What I ran.** I built `compile_dxil native_store_replay native_compute_ir_dump` in `dev` and `release`, then ran: `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_salu_(cmp64|cmov)_'` - 6/6 passed in each preset. I included `cmov` because the two PRs share `uses_scc_after()` and the SOPC/SOP1 dispatch. - **`native_salu_cmp64_hardware` ran and passed** all 22 cases, each reporting `preserved pair, SCC and guards matched`. These include `eq hi differs` / `eq lo differs`, bits 0/31/32/63, `null`, `-1` and the `0x80000001` literal. **Mutants** (in `src/gfx1013_direct_compute.inl`, rebuilt each time): | mutant | `_ir` | `_hardware` | |---|---|---| | bit test always reads the low word (`word = a_lo`) | fails at `('bitcmp1 bit 32 set', (512, 0, 0), 1)` | fails at `('bitcmp1 bit 32 set', (0, 1), 1)` | | `s_cmp_eq_u64` joins the halves with `or` | fails at `('eq hi differs', (512, 1, 0), 0)` | fails | Restored, all pass, and `git diff --check` is clean. **Still unmeasured** (the same caveat as #3071): whether gfx1013 zero-extends the 32-bit literal in a 64-bit compare. The hardware run shows only that the lowering matches the PR's `pair_high()` reference. **Verdict:** approve on `cc7a8fbe`. Environment: NVIDIA GeForce RTX 5090 (wave 32..32, SM 6.8), driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10. CI: `Build and test on Windows` passes on `cc7a8fbe`. This reply was AI-assisted.
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!3081
No description provided.