Skip to content

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

Done

Description

@pigalot

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.

Activity

  1. added a commit that references this issue on Nov 27, 2026
    eff2dd7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions