Native compiler: lower 32-bit bit counts and scans in the direct compute path #3050

Closed
opened 2026-11-27 11:35:55 +00:00 by pigalot · 0 comments
pigalot commented 2026-11-27 11:35:55 +00:00 (Migrated from github.com)
Contributor

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


Part of the instruction-coverage item of #2935. Target branch main (cpp-migration merged in #3039).

Gap. The direct C++ compute path refuses the 32-bit bit counts and bit scans with direct DXIL lowering for <name>:

  • s_bcnt0_i32_b32 and s_bcnt1_i32_b32
  • s_ff0_i32_b32 and s_ff1_i32_b32
  • s_flbit_i32_b32 and s_flbit_i32
  • v_ffbl_b32, v_ffbh_u32 and v_ffbh_i32

gfx2hlsl.py and tools/pixel_aot.py already lower them. They agree on these rules:

  • The bit counts set SCC to D != 0.
  • The scans return 0xffffffff when no bit qualifies, and leave SCC unchanged.
  • ffbh/flbit count from bit 31.
  • The signed forms search for the first bit that differs from the sign bit.

Measured. I ran compile_dxil --refusals (counts only) at main 98007de5 on a local start-up capture of 2,689 compute requests. 12 of them stop first at one of these names: s_bcnt1_i32_b32 5, s_ff1_i32_b32 3, v_ffbl_b32 3 and v_ffbh_i32 1.

Proposed.

  • Lower them to DXIL Countbits, FirstbitLo, FirstbitHi and FirstbitSHi. FirstbitHi and FirstbitSHi already count from bit 31, as dxc shows: HLSL firstbithigh compiles to 31 - FirstbitHi.
  • Keep VOP3 modifiers refused.
  • Leave the 64-bit scalar forms for later.
  • Add a controls/hardware fixture covering negative values, single bits, 0, 0xffffffff and both SCC cases, with mutant references.

I am taking it, and the PR follows. This issue was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6645634622 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3050). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T11:35:55Z. --- Part of the instruction-coverage item of #2935. Target branch `main` (cpp-migration merged in #3039). **Gap.** The direct C++ compute path refuses the 32-bit bit counts and bit scans with `direct DXIL lowering for <name>`: - `s_bcnt0_i32_b32` and `s_bcnt1_i32_b32` - `s_ff0_i32_b32` and `s_ff1_i32_b32` - `s_flbit_i32_b32` and `s_flbit_i32` - `v_ffbl_b32`, `v_ffbh_u32` and `v_ffbh_i32` `gfx2hlsl.py` and `tools/pixel_aot.py` already lower them. They agree on these rules: - The bit counts set SCC to D != 0. - The scans return 0xffffffff when no bit qualifies, and leave SCC unchanged. - `ffbh`/`flbit` count from bit 31. - The signed forms search for the first bit that differs from the sign bit. **Measured.** I ran `compile_dxil --refusals` (counts only) at `main` `98007de5` on a local start-up capture of 2,689 compute requests. 12 of them stop first at one of these names: `s_bcnt1_i32_b32` 5, `s_ff1_i32_b32` 3, `v_ffbl_b32` 3 and `v_ffbh_i32` 1. **Proposed.** - Lower them to DXIL `Countbits`, `FirstbitLo`, `FirstbitHi` and `FirstbitSHi`. `FirstbitHi` and `FirstbitSHi` already count from bit 31, as `dxc` shows: HLSL `firstbithigh` compiles to `31 - FirstbitHi`. - Keep VOP3 modifiers refused. - Leave the 64-bit scalar forms for later. - Add a controls/hardware fixture covering negative values, single bits, 0, 0xffffffff and both SCC cases, with mutant references. I am taking it, and the PR follows. This issue was AI-assisted.
Sign in to join this conversation.
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#3050
No description provided.