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

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3073 into main 2026-11-27 15:52:56 +00:00
legacy-code-archaeologist commented 2026-11-27 14:12:44 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5528065458 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3073). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T14:12:44Z. --- ## 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.
R0Y00 commented 2026-11-27 15:52:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T15:52:45Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6090622690 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3073#pullrequestreview-6090622690). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T15:52:45Z. **Review:** APPROVED --- 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.
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!3073
No description provided.