shader: lower 64-bit scalar bit counts and bit scans in the direct compute path #3073

Manually merged
github merged 1 commit from github-bot/gh-3073 into gh-pr/3073/base 2026-11-27 15:55:14 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 14:12 UTC · original
legacy-code-archaeologist:shader/direct-salu-bitscan64 → main · +345 −3 · 5 files · 1 commits · merged 2026-11-27 15:52 UTC

Change

src/gfx1013_direct_compute.inl lowers the six 64-bit-source SOP1 scalar bit-count and bit-scan instructions s_bcnt0_i32_b64, s_bcnt1_i32_b64, s_ff0_i32_b64, s_ff1_i32_b64, s_flbit_i32_b64 and s_flbit_i32_i64 in the direct C++ compute path using 32-bit DXIL unaryBits.i32 (31 Countbits, 32 FirstbitLo, 33 FirstbitHi), matching tools/startup/gfx2hlsl.py. Fixes #3072 (part of #2935; 64-bit counterparts of #3050/#3051).

  • Operands & semantics: general SGPR (s0..s105) destination; aligned SGPR pair (s0..s104 even), inline integer (-16..64), or 32-bit literal S0 (sign-extended for s_flbit_i32_i64, zero-extended for _b64). s_bcnt0_i32_b64 and s_bcnt1_i32_b64 write SCC = (D != 0); the four scans preserve SCC and return 0xffffffff when no qualifying bit exists. No Int64Ops needed.
  • Symbolic transfer & SCC liveness: transfer() in src/gfx1013_compute_native.cpp checks i.name.find(_i32_) == Name::npos before clearing s[dst + 1] on _b64 SOP1/SOP2 instructions so 32-bit-destination _i32_b64 ops do not clobber adjacent descriptors (tested with s_ff1_i32_b64 s31, s[22:23] right below s[32:35]). uses_scc_after() marks s_bcnt0_i32_b64 and s_bcnt1_i32_b64 as overwriting SCC.
  • Tests & docs: tests/native_salu_bitscan64_check.py, tests/cmake/native_salu_bitscan64.cmake, docs/experiments/native-direct-salu-bitscan64.md.

Verification

Tested on upstream/main e1ea515d, Windows 10.0.26100, dev preset:

  • cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump: ok.
  • ctest --preset dev --no-tests=error -R '^(native_salu_bitscan64_|native_bitscan_)' -V: native_bitscan_controls (0.57 s) and native_salu_bitscan64_controls (0.93 s) passed; native_bitscan_hardware and native_salu_bitscan64_hardware skipped (77 — Quadro M1000M lacks shader model 6.6 with wave32, so GPU readback is unmeasured).
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 4: 25/25 passed (18.39 s).
  • python -B tests/docs_links_check.py: passed (76 Markdown files and 585 links).

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 14:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3073) `legacy-code-archaeologist:shader/direct-salu-bitscan64` → `main` · +345 −3 · 5 files · 1 commits · merged 2026-11-27 15:52 UTC ## Change `src/gfx1013_direct_compute.inl` lowers the six 64-bit-source SOP1 scalar bit-count and bit-scan instructions `s_bcnt0_i32_b64`, `s_bcnt1_i32_b64`, `s_ff0_i32_b64`, `s_ff1_i32_b64`, `s_flbit_i32_b64` and `s_flbit_i32_i64` in the direct C++ compute path using 32-bit DXIL `unaryBits.i32` (`31` Countbits, `32` FirstbitLo, `33` FirstbitHi), matching `tools/startup/gfx2hlsl.py`. Fixes #3072 (part of #2935; 64-bit counterparts of #3050/#3051). - **Operands & semantics:** general SGPR (`s0..s105`) destination; aligned SGPR pair (`s0..s104` even), inline integer (`-16..64`), or 32-bit literal `S0` (sign-extended for `s_flbit_i32_i64`, zero-extended for `_b64`). `s_bcnt0_i32_b64` and `s_bcnt1_i32_b64` write `SCC = (D != 0)`; the four scans preserve `SCC` and return `0xffffffff` when no qualifying bit exists. No `Int64Ops` needed. - **Symbolic transfer & SCC liveness:** `transfer()` in `src/gfx1013_compute_native.cpp` checks `i.name.find(_i32_) == Name::npos` before clearing `s[dst + 1]` on `_b64` SOP1/SOP2 instructions so 32-bit-destination `_i32_b64` ops do not clobber adjacent descriptors (tested with `s_ff1_i32_b64 s31, s[22:23]` right below `s[32:35]`). `uses_scc_after()` marks `s_bcnt0_i32_b64` and `s_bcnt1_i32_b64` as overwriting `SCC`. - **Tests & docs:** `tests/native_salu_bitscan64_check.py`, `tests/cmake/native_salu_bitscan64.cmake`, `docs/experiments/native-direct-salu-bitscan64.md`. ## Verification Tested on `upstream/main` `e1ea515d`, Windows 10.0.26100, `dev` preset: - `cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump`: ok. - `ctest --preset dev --no-tests=error -R '^(native_salu_bitscan64_|native_bitscan_)' -V`: `native_bitscan_controls` (`0.57 s`) and `native_salu_bitscan64_controls` (`0.93 s`) passed; `native_bitscan_hardware` and `native_salu_bitscan64_hardware` skipped (`77` — Quadro M1000M lacks shader model 6.6 with wave32, so GPU readback is **unmeasured**). - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 4`: **25/25 passed** (`18.39 s`). - `python -B tests/docs_links_check.py`: passed (`76` Markdown files and `585` links). AI-assisted.
Lower SOP1 s_bcnt0_i32_b64, s_bcnt1_i32_b64, s_ff0_i32_b64, s_ff1_i32_b64, s_flbit_i32_b64 and s_flbit_i32_i64 in the direct compute path using 32-bit DXIL unaryBits.i32 (no Int64Ops required). Counts write SCC = (D != 0); scans preserve SCC and return 0xffffffff when no bit qualifies.

Also fix transfer() in gfx1013_compute_native.cpp so 32-bit-destination _i32_b64 ops do not clear s[dst + 1] and clobber adjacent descriptors, and mark s_bcnt0_i32_b64 / s_bcnt1_i32_b64 in uses_scc_after().

Fixes #3072

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:19:29 +00:00
github-bot force-pushed github-bot/gh-3073 from 14619992be to df32f3d925 2026-11-27 14:47:48 +00:00 Compare
github-bot force-pushed github-bot/gh-3073 from df32f3d925 to b6fde8d0b5 2026-11-27 15:39:08 +00:00 Compare
github-bot changed target branch from main to gh-pr/3073/base 2026-11-27 15:55:13 +00:00
github manually merged commit b6fde8d0b5 into gh-pr/3073/base 2026-11-27 15:55:14 +00:00
Author
Owner

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

Independently reviewed b6fde8d0 integrated over main d71f9ed2 (tree 591f1c0a84165670e0c3af7782fa99db62967113). I traced the low/high selection and no-bit sentinel for the scans, signed leading-bit normalization, SCC writes for the two counts, and preservation of the adjacent SGPR for 32-bit destinations.

Built compile_dxil native_store_replay native_compute_ir_dump with dev and release. Ran ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_bitscan64|bitscan|s_lshl_add_u32|v_xnor_b32)_'. Debug and Release /O2 passed 8/8 each, zero skips. Replay verified the results, neighboring register, SCC and guards, including both SCC-preservation cases, negative literal extension and source/destination overlap. Compile controls passed for adjacent descriptor preservation and invalid operands. git diff --check HEAD^1 HEAD passed.

NVIDIA GeForce RTX 4060 Laptop GPU, driver 32.0.16.1656, Windows 26200.9974, SDK/DXC 10.0.26100.0, wave32, D3D12 debug layer disabled. This supplies independent hardware coverage for the capability skip reported on the Quadro. GitHub Windows, Linux and gfx1013 checks passed; hosted /O2 was skipped.

**@⁠R0Y00** on GitHub · 2026-11-27 15:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3073#pullrequestreview-6090622690) · **approved these changes** Independently reviewed `b6fde8d0` integrated over `main` `d71f9ed2` (tree `591f1c0a84165670e0c3af7782fa99db62967113`). I traced the low/high selection and no-bit sentinel for the scans, signed leading-bit normalization, SCC writes for the two counts, and preservation of the adjacent SGPR for 32-bit destinations. Built `compile_dxil native_store_replay native_compute_ir_dump` with `dev` and `release`. Ran `ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_bitscan64|bitscan|s_lshl_add_u32|v_xnor_b32)_'`. Debug and Release `/O2` passed 8/8 each, zero skips. Replay verified the results, neighboring register, SCC and guards, including both SCC-preservation cases, negative literal extension and source/destination overlap. Compile controls passed for adjacent descriptor preservation and invalid operands. `git diff --check HEAD^1 HEAD` passed. NVIDIA GeForce RTX 4060 Laptop GPU, driver `32.0.16.1656`, Windows `26200.9974`, SDK/DXC `10.0.26100.0`, wave32, D3D12 debug layer disabled. This supplies independent hardware coverage for the capability skip reported on the Quadro. GitHub Windows, Linux and gfx1013 checks passed; hosted `/O2` was skipped.
This discussion has been locked. Commenting is limited to contributors.
No description provided.