startup: lower s_bitcmp0_b64 and s_bitcmp1_b64 in gfx2hlsl #2880

Manually merged
github merged 1 commit from github-bot/gh-2880 into gh-pr/2880/base 2026-11-27 04:45:56 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-26 16:19 UTC · original
R0D4X:feat/gfx2hlsl-s-bitcmp64 → main · +441 −0 · 4 files · 1 commits · merged 2026-11-27 04:45 UTC

Summary

Lower the 64-bit scalar bit-compare SOPC instructions s_bitcmp0_b64 and s_bitcmp1_b64 in tools/startup/gfx2hlsl.py:

  • ISA semantics (RDNA 2 SOPC): SCC = (S0.u64[S1.u[5:0]] == 0) for s_bitcmp0_b64 and == 1 for s_bitcmp1_b64. Bit 5 of S1 selects the high vs. low 32-bit word ((idx & 32u) != 0u ? hi : lo), and idx & 31u selects the bit within that word.
  • 64-bit source (S0) handling: Supports even-aligned SGPR pairs (s[0:1]..s[104:105]), null (0u, 0u), inline integers -16..64 (sign-extended to 64 bits via Stage.i64_words), and 32-bit hex literals (zero-extended to 64 bits).
  • Refusals & uniformity: Refuses wrong operand counts, modifiers, lane masks (including masks and mask_high on either register of an SGPR pair or on S1), VGPRs, single/odd/out-of-range SGPRs, float inline constants, m0/src_scc as S0, and unverified src_scc as S1. Updates scc_uniform via Stage.set_scc.

Before / After

  • Before: s_bitcmp0_b64 and s_bitcmp1_b64 were decoded by tools/disasm_rdna2.py and handled in pixel_aot / mesh_entry_aot, but refused as unlowered in tools/startup/gfx2hlsl.py.
  • After: Both instructions lower to HLSL SCC assignments with full operand validation, uniformity propagation, pure-Python controls, and FXC ps_5_1 + DXC ps_6_0 GPU draw verification.

Verification

Commit under test: 43b0aa33 (based on upstream/main b505c32b)
Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0, FXC + DXC 1.9.2602.17, D3D12 debug layer enabled.
Adapters:

  • WARP: Microsoft Basic Render Driver (1414:008c, driver 10.0.26100.9818)
  • Hardware: NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2124)

Commands & observed results:

  • ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_bitcmp64' -V -> 3/3 passed, 0 skipped (startup_gfx2hlsl_s_bitcmp64_controls, startup_gfx2hlsl_s_bitcmp64_warp, startup_gfx2hlsl_s_bitcmp64_hardware; debug_errors=0 debug_warnings=0 on every draw, negative-control mismatch rejected on both FXC and DXC).
  • ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_s_bitcmp64' --output-on-failure -> 3/3 passed, 0 skipped.
  • ctest --preset dev --no-tests=error -R '^startup_tools_lint$' -> 1/1 passed.
  • Neighbor & repo checks (docs_links_check.py, bidi_controls_check.py, startup_gfx2hlsl_s_bitcmp_check.py, startup_gfx2hlsl_handler_arity_check.py, startup_gfx2hlsl_scalar_arity_check.py, startup_gfx2hlsl_scalar_table_arity_check.py, startup_gfx2hlsl_scalar_null_check.py, startup_gfx2hlsl_refusals_check.py, git diff --check) -> all passed.
  • Live self-mutations on tools/startup/gfx2hlsl.py (swap_lo_hi, drop_bit5, drop_vgpr_guard, drop_mask_high, sext_literal) -> 5/5 killed (rc=1) by tests/startup_gfx2hlsl_s_bitcmp64_check.py.

Evidence Scope

Verified on synthetic gfx1013 SOPC fixtures decoded via G.decode() and executed on WARP and NVIDIA GeForce RTX 5080 with FXC ps_5_1 and DXC ps_6_0. This establishes the s_bitcmp0_b64 / s_bitcmp1_b64 lowering in gfx2hlsl.py; it does not establish full-title execution or frame rate.

**@⁠R0D4X** on GitHub · 2026-11-26 16:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2880) `R0D4X:feat/gfx2hlsl-s-bitcmp64` → `main` · +441 −0 · 4 files · 1 commits · merged 2026-11-27 04:45 UTC ## Summary Lower the 64-bit scalar bit-compare SOPC instructions `s_bitcmp0_b64` and `s_bitcmp1_b64` in `tools/startup/gfx2hlsl.py`: - **ISA semantics (RDNA 2 SOPC):** `SCC = (S0.u64[S1.u[5:0]] == 0)` for `s_bitcmp0_b64` and `== 1` for `s_bitcmp1_b64`. Bit 5 of `S1` selects the high vs. low 32-bit word (`(idx & 32u) != 0u ? hi : lo`), and `idx & 31u` selects the bit within that word. - **64-bit source (`S0`) handling:** Supports even-aligned SGPR pairs (`s[0:1]`..`s[104:105]`), `null` (`0u, 0u`), inline integers `-16..64` (sign-extended to 64 bits via `Stage.i64_words`), and 32-bit hex literals (zero-extended to 64 bits). - **Refusals & uniformity:** Refuses wrong operand counts, modifiers, lane masks (including `masks` and `mask_high` on either register of an SGPR pair or on `S1`), VGPRs, single/odd/out-of-range SGPRs, float inline constants, `m0`/`src_scc` as `S0`, and unverified `src_scc` as `S1`. Updates `scc_uniform` via `Stage.set_scc`. ## Before / After - **Before:** `s_bitcmp0_b64` and `s_bitcmp1_b64` were decoded by `tools/disasm_rdna2.py` and handled in `pixel_aot` / `mesh_entry_aot`, but refused as unlowered in `tools/startup/gfx2hlsl.py`. - **After:** Both instructions lower to HLSL SCC assignments with full operand validation, uniformity propagation, pure-Python controls, and FXC `ps_5_1` + DXC `ps_6_0` GPU draw verification. ## Verification Commit under test: `43b0aa33` (based on `upstream/main` `b505c32b`) Environment: Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0`, FXC + DXC `1.9.2602.17`, D3D12 debug layer enabled. Adapters: - WARP: `Microsoft Basic Render Driver` (`1414:008c`, driver `10.0.26100.9818`) - Hardware: `NVIDIA GeForce RTX 5080` (`10de:2c02`, driver `32.0.16.2124`) Commands & observed results: - `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_bitcmp64' -V` -> **3/3 passed, 0 skipped** (`startup_gfx2hlsl_s_bitcmp64_controls`, `startup_gfx2hlsl_s_bitcmp64_warp`, `startup_gfx2hlsl_s_bitcmp64_hardware`; `debug_errors=0 debug_warnings=0` on every draw, negative-control mismatch rejected on both FXC and DXC). - `ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_s_bitcmp64' --output-on-failure` -> **3/3 passed, 0 skipped**. - `ctest --preset dev --no-tests=error -R '^startup_tools_lint$'` -> **1/1 passed**. - Neighbor & repo checks (`docs_links_check.py`, `bidi_controls_check.py`, `startup_gfx2hlsl_s_bitcmp_check.py`, `startup_gfx2hlsl_handler_arity_check.py`, `startup_gfx2hlsl_scalar_arity_check.py`, `startup_gfx2hlsl_scalar_table_arity_check.py`, `startup_gfx2hlsl_scalar_null_check.py`, `startup_gfx2hlsl_refusals_check.py`, `git diff --check`) -> **all passed**. - Live self-mutations on `tools/startup/gfx2hlsl.py` (`swap_lo_hi`, `drop_bit5`, `drop_vgpr_guard`, `drop_mask_high`, `sext_literal`) -> **5/5 killed (`rc=1`)** by `tests/startup_gfx2hlsl_s_bitcmp64_check.py`. ## Evidence Scope Verified on synthetic gfx1013 SOPC fixtures decoded via `G.decode()` and executed on WARP and NVIDIA GeForce RTX 5080 with FXC `ps_5_1` and DXC `ps_6_0`. This establishes the `s_bitcmp0_b64` / `s_bitcmp1_b64` lowering in `gfx2hlsl.py`; it does not establish full-title execution or frame rate.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:27:45 +00:00
Author
Owner

@⁠RonLogic on GitHub · 2026-11-26 16:40 UTC · original

Independent Windows check at 43b0aa33d647566e04bc952ce0c30f44888ca9c2: the pure-Python controls and direct startup_gfx2hlsl_s_bitcmp64_check.py draw passed on in-box WARP 10.0.26100.10068 and RTX 4070 32.0.16.2124, with both SDK FXC and DXC. The wrong-expectation controls failed as intended, with no debug errors, warnings or skips. Windows build 26300.10075, using the existing MSVC Release offscreen runner.

**@⁠RonLogic** on GitHub · 2026-11-26 16:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2880#issuecomment-7197951119) Independent Windows check at `43b0aa33d647566e04bc952ce0c30f44888ca9c2`: the pure-Python controls and direct `startup_gfx2hlsl_s_bitcmp64_check.py draw` passed on in-box WARP `10.0.26100.10068` and RTX 4070 `32.0.16.2124`, with both SDK FXC and DXC. The wrong-expectation controls failed as intended, with no debug errors, warnings or skips. Windows build `26300.10075`, using the existing MSVC Release offscreen runner.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-26 21:48 UTC · original

Review of head 43b0aa33, from reading the diff (not run). The lowering of the 64-bit bit test reads as correct:

  • bit 32-63 picks the high word;
  • the index is masked to 6 bits;
  • lane masks are refused for both words of the pair.

Two test notes, the same pattern as on #2891:

  1. The draw only evaluates constants. ps_words() loads s4..s6 with s_mov_b32 of literals, which Stage.scalar tracks as ('const', value), and S() emits them as hex literals. Every draw expression is therefore constant, for example ((0x00000025u & 32u) != 0u ? <hi> : <lo>), and the compiler can fold it. No draw case reads a run-time SGPR. This matters more here because eval_scc_expr strips the u suffixes and evaluates with Python's unbounded integers, so a lowering that relied on more than 32 bits, for example (hi << 32) | lo, would pass the Python grid; only the draw checks that. One case with a non-constant s[4:5]/s6 would close that.
  2. Section 10 does not exercise the translator. Its five checks compare ref_bitcmp64(...) with itself and never patch the handler, so they pass with any lowering. Section 9, which deletes the handlers, is a real control; a patched handler (index masked with 31, high word ignored) asserted to fail would make section 10 one too.

Optional follow-up, outside this diff: the calculated-PC check in gfx2hlsl.py (s_cmpk?_..._[iu]32|s_bitcmp[01]_b32) does not list s_bitcmp[01]_b64. After the GETPC add/addc sequence the SCC is marked unusable until a listed compare rewrites it. s_bitcmp[01]_b64 is not listed, so an SCC reader after it (s_cbranch_scc*, s_cselect, ...) is refused with "calculated PC SCC escapes". This is fail-closed, not a miscompile.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-26 21:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2880#issuecomment-7204079920) Review of head `43b0aa33`, from reading the diff (not run). The lowering of the 64-bit bit test reads as correct: - bit 32-63 picks the high word; - the index is masked to 6 bits; - lane masks are refused for both words of the pair. Two test notes, the same pattern as on #2891: 1. **The draw only evaluates constants.** `ps_words()` loads `s4`..`s6` with `s_mov_b32` of literals, which `Stage.scalar` tracks as `('const', value)`, and `S()` emits them as hex literals. Every draw expression is therefore constant, for example `((0x00000025u & 32u) != 0u ? <hi> : <lo>)`, and the compiler can fold it. No draw case reads a run-time SGPR. This matters more here because `eval_scc_expr` strips the `u` suffixes and evaluates with Python's unbounded integers, so a lowering that relied on more than 32 bits, for example `(hi << 32) | lo`, would pass the Python grid; only the draw checks that. One case with a non-constant `s[4:5]`/`s6` would close that. 2. **Section 10 does not exercise the translator.** Its five checks compare `ref_bitcmp64(...)` with itself and never patch the handler, so they pass with any lowering. Section 9, which deletes the handlers, is a real control; a patched handler (index masked with 31, high word ignored) asserted to fail would make section 10 one too. Optional follow-up, outside this diff: the calculated-PC check in `gfx2hlsl.py` (`s_cmpk?_..._[iu]32|s_bitcmp[01]_b32`) does not list `s_bitcmp[01]_b64`. After the GETPC add/addc sequence the SCC is marked unusable until a listed compare rewrites it. `s_bitcmp[01]_b64` is not listed, so an SCC reader after it (`s_cbranch_scc*`, `s_cselect`, ...) is refused with "calculated PC SCC escapes". This is fail-closed, not a miscompile. AI-assisted.
github-bot changed target branch from main to gh-pr/2880/base 2026-11-27 04:45:53 +00:00
github manually merged commit 43b0aa33d6 into gh-pr/2880/base 2026-11-27 04:45:56 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 04:44 UTC · original · approved these changes

Reviewed 43b0aa33d647566e04bc952ce0c30f44888ca9c2. The lowering uses index bit 5 to select the word and the low five bits for the intra-word shift. The control suites preserve the lane-mask refusals. I built the clean integration tree with current main 50488e1c in Release on Windows 11 26200.9974, then ran ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx2hlsl_s_bitcmp64_'. Its portable, WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656) tests all passed. D3D12 debug-layer output showed zero errors or warnings. Required Windows CI passed.

**@⁠R0Y00** on GitHub · 2026-11-27 04:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2880#pullrequestreview-6083585725) · **approved these changes** Reviewed `43b0aa33d647566e04bc952ce0c30f44888ca9c2`. The lowering uses index bit 5 to select the word and the low five bits for the intra-word shift. The control suites preserve the lane-mask refusals. I built the clean integration tree with current main `50488e1c` in Release on Windows 11 26200.9974, then ran `ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx2hlsl_s_bitcmp64_'`. Its portable, WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656) tests all passed. D3D12 debug-layer output showed zero errors or warnings. Required Windows CI passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.