compute: lower v_bcnt_u32_b32 in compute_store_aot #2083

Merged
archielcqp-a11y merged 1 commit from upstream-pr/2090 into main 2026-11-25 01:40:11 +00:00
archielcqp-a11y commented 2026-11-25 00:07:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by archielcqp-a11y on 2026-11-25T00:07:30Z.


Refs #2022 (item D)

Summary

compute_store_aot refused v_bcnt_u32_b32, item D of #2022. It now lowers v_bcnt_u32_b32 vD, a, b as (countbits(a) + b).

Semantics: D = CountOneBits(a) + b, with the addend wrapping modulo 2^32.

  • RDNA2 ISA: D.u = CountOneBits(S0.u) + S1.u.
  • LLVM: V_BCNT_U32_B32_e64 is ctpop(src0) + src1.
  • Mesa ACO selects this instruction for bit_count.

Encoding: gfx10 has only the VOP3 encoding. LLVM 15 (llvm-mc -mcpu=gfx1013) prints it without a suffix, refuses _e32, and refuses source negation and clamp. The instruction joins the existing two-source VOP3 group (v_mul_lo_u32, v_add_nc_i32, v_sub_nc_i32), on known words only.

Refused:

  • the _e32 and _e64 spellings;
  • source modifiers (-v, |v|, neg()) and clamp;
  • a register range and a third source;
  • an unknown source and a destination past v255, as Unverified ALU operand.

v_mbcnt_lo/hi_u32_b32 and s_bcnt1_i32_b32 are unchanged.

Fixture

compute_store_aot_alu_bcnt_{warp,hardware} (tests/compute_alu_bcnt_check.py) follows the v_xor3_b32 check. It replaces the umin of the read-compute-write fixture with four v_bcnt_u32_b32, hand-edited in LLVM 15 spelling:

out = bcnt(-16) + bcnt(0x2c5a96e1) + bcnt(gid) + bcnt(p) + key      // p = (v & 0xffff) * (v >> 16) + gid
  • Counted sources: a result, the dispatch index, a 32-bit literal and a negative inline constant.
  • Addends: an SGPR constant word (params[0].y) and the running result.
  • Reference: expected words come from a Python model of the instruction definition. Lane 0 is also worked by hand (0xa5c30fd0).
  • Readback: three dispatches, each comparing all 320 words.

Negative controls:

  • Nine wrong references must fail at their first differing word:

    • a plain add, or a count of zero bits, in place of the bit count;
    • the operands swapped;
    • each of the five sources dropped;
    • +16 for -16.

    So must one word off and lane 150 also writing.

  • Six mutated HLSL sources must fail on the GPU: firstbitlow for a count, a count dropped, the key from params[0].z, the dispatch index dropped, the literal off by one bit, and +16 for the inline constant.

  • The translation controls pin the exact store. They reject every refused form above, and a result used as a store address, read address or lane-guard operand.

  • With the lowering removed, or with its template operands swapped, the controls fail.

Results

Run on 2fd3f69 (main) with this change, Windows 10 build 19045, debug layer enabled, 0 debug errors and 0 debug warnings on both adapters.

Command WARP 1.0.22 (app-local) NVIDIA GeForce RTX 3080, driver 32.0.15.9174
tests/compute_alu_bcnt_check.py draw pass pass

Other checks:

  • tests/compute_alu_bcnt_check.py controls: pass.
  • tests/compute_store_check.py binary with LLVM 15, which also runs the existing controls: pass.
  • tests/compute_alu_xor3_check.py draw on WARP: pass.
  • form_coverage_check, docs_links_check, bidi_controls_check and shader_census_check: pass.

No capability skips.

cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^compute_store_aot_alu_bcnt_(warp|hardware)$' -V

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594039091 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2090). Originally posted by [archielcqp-a11y](https://github.com/archielcqp-a11y) on 2026-11-25T00:07:30Z. --- Refs #2022 (item D) ## Summary `compute_store_aot` refused `v_bcnt_u32_b32`, item D of #2022. It now lowers `v_bcnt_u32_b32 vD, a, b` as `(countbits(a) + b)`. **Semantics:** `D = CountOneBits(a) + b`, with the addend wrapping modulo 2^32. - RDNA2 ISA: `D.u = CountOneBits(S0.u) + S1.u`. - LLVM: `V_BCNT_U32_B32_e64` is `ctpop(src0) + src1`. - Mesa ACO selects this instruction for `bit_count`. **Encoding:** gfx10 has only the VOP3 encoding. LLVM 15 (`llvm-mc -mcpu=gfx1013`) prints it without a suffix, refuses `_e32`, and refuses source negation and `clamp`. The instruction joins the existing two-source VOP3 group (`v_mul_lo_u32`, `v_add_nc_i32`, `v_sub_nc_i32`), on known words only. **Refused:** - the `_e32` and `_e64` spellings; - source modifiers (`-v`, `|v|`, `neg()`) and `clamp`; - a register range and a third source; - an unknown source and a destination past `v255`, as `Unverified ALU operand`. `v_mbcnt_lo/hi_u32_b32` and `s_bcnt1_i32_b32` are unchanged. ## Fixture `compute_store_aot_alu_bcnt_{warp,hardware}` (`tests/compute_alu_bcnt_check.py`) follows the `v_xor3_b32` check. It replaces the `umin` of the read-compute-write fixture with four `v_bcnt_u32_b32`, hand-edited in LLVM 15 spelling: ``` out = bcnt(-16) + bcnt(0x2c5a96e1) + bcnt(gid) + bcnt(p) + key // p = (v & 0xffff) * (v >> 16) + gid ``` - **Counted sources:** a result, the dispatch index, a 32-bit literal and a negative inline constant. - **Addends:** an SGPR constant word (`params[0].y`) and the running result. - **Reference:** expected words come from a Python model of the instruction definition. Lane 0 is also worked by hand (`0xa5c30fd0`). - **Readback:** three dispatches, each comparing all 320 words. **Negative controls:** - Nine wrong references must fail at their first differing word: - a plain add, or a count of zero bits, in place of the bit count; - the operands swapped; - each of the five sources dropped; - `+16` for `-16`. So must one word off and lane 150 also writing. - Six mutated HLSL sources must fail on the GPU: `firstbitlow` for a count, a count dropped, the key from `params[0].z`, the dispatch index dropped, the literal off by one bit, and `+16` for the inline constant. - The translation controls pin the exact store. They reject every refused form above, and a result used as a store address, read address or lane-guard operand. - With the lowering removed, or with its template operands swapped, the controls fail. ## Results Run on `2fd3f69` (main) with this change, Windows 10 build 19045, debug layer enabled, 0 debug errors and 0 debug warnings on both adapters. | Command | WARP 1.0.22 (app-local) | NVIDIA GeForce RTX 3080, driver 32.0.15.9174 | |---|---|---| | `tests/compute_alu_bcnt_check.py draw` | pass | pass | Other checks: - `tests/compute_alu_bcnt_check.py controls`: pass. - `tests/compute_store_check.py binary` with LLVM 15, which also runs the existing controls: pass. - `tests/compute_alu_xor3_check.py draw` on WARP: pass. - `form_coverage_check`, `docs_links_check`, `bidi_controls_check` and `shader_census_check`: pass. No capability skips. ```powershell cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^compute_store_aot_alu_bcnt_(warp|hardware)$' -V ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-25 01:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:48:20Z.

Review: COMMENTED


Review of head 6924fb784a (compute: lower v_bcnt_u32_b32 in compute_store_aot).

Result: no P1, no P2.

Commands executed locally:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • gh pr checks 2090: Linux Python checks, gfx1013 fixtures and Windows build/test pass (the /O2 job shows "skipping").
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/bidi_controls_check.py: pass.
  • python3 tests/docs_links_check.py: pass (18 files, 393 links).
  • python3 -B tests/compute_alu_bcnt_check.py controls: pass.
  • python3 x2w_pipe.py win2025 2090 --wait 900: Win2025 WARP pass at this exact head, Debug (--preset dev) and Release /O2 (--preset release), including compute_store_aot_alu_bcnt_warp (about 5.3 s). The pipeline reported a result already recorded for this head, so it did not rebuild.

Mutation: in tools/compute_store_aot.py I changed the template (countbits({0}) + {1}) to (countbits({0}) - {1}). The controls test failed on the exact-output assertion, as it should. I restored the file with git checkout -- ..

Reading notes:

  • The template, the VOP3 regex group, the CMake test and the docs match each other. The test uses an independent CPU model, rejects each unsupported form, and mutates the translated HLSL (firstbitlow, dropped count, wrong key, dropped source, off-by-one literal, +16 for -16), so the coverage looks real.

P3 (minor):

  • tests/compute_alu_bcnt_check.py: the hardware adapter run was not executed by me. Only WARP was.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049828841 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2090#pullrequestreview-6049828841). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:48:20Z. **Review:** COMMENTED --- Review of head 6924fb784a31c24efa9266ad7487321d22b06285 (compute: lower v_bcnt_u32_b32 in compute_store_aot). Result: no P1, no P2. Commands executed locally: - `git merge-tree --write-tree --name-only origin/main HEAD`: clean, no conflicts. - `gh pr checks 2090`: Linux Python checks, gfx1013 fixtures and Windows build/test pass (the /O2 job shows "skipping"). - `git diff --check origin/main...HEAD`: clean. - `python3 tests/bidi_controls_check.py`: pass. - `python3 tests/docs_links_check.py`: pass (18 files, 393 links). - `python3 -B tests/compute_alu_bcnt_check.py controls`: pass. - `python3 x2w_pipe.py win2025 2090 --wait 900`: Win2025 WARP pass at this exact head, Debug (`--preset dev`) and Release /O2 (`--preset release`), including `compute_store_aot_alu_bcnt_warp` (about 5.3 s). The pipeline reported a result already recorded for this head, so it did not rebuild. Mutation: in `tools/compute_store_aot.py` I changed the template `(countbits({0}) + {1})` to `(countbits({0}) - {1})`. The `controls` test failed on the exact-output assertion, as it should. I restored the file with `git checkout -- .`. Reading notes: - The template, the VOP3 regex group, the CMake test and the docs match each other. The test uses an independent CPU model, rejects each unsupported form, and mutates the translated HLSL (firstbitlow, dropped count, wrong key, dropped source, off-by-one literal, +16 for -16), so the coverage looks real. P3 (minor): - tests/compute_alu_bcnt_check.py: the hardware adapter run was not executed by me. Only WARP was. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 02:01:43 +00:00
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!2083
No description provided.