Skip to content

compute: accept VCC as source in 64-bit scalar bit-count and bit-scan - #3402

Open
Ammmae0x wants to merge 1 commit into
R0Y00:mainfrom
Ammmae0x:compute/salu-bitscan64-vcc
Open

Ammmae0x wants to merge 1 commit into
R0Y00:mainfrom
Ammmae0x:compute/salu-bitscan64-vcc

Conversation

@Ammmae0x

@Ammmae0x Ammmae0x commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Change

Accept VCC (s0 == 106) as the 64-bit source in the direct C++ compute path for the six 64-bit 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 (src/gfx1013_direct_compute.inl, one-line s0_pair change:
s0 == 106 alongside aligned SGPR pairs and EXEC). vcc_lo/vcc_hi are read via operand32(i, s0) and
operand32(i, s0 + 1), exactly as the existing EXEC path reads exec_lo/exec_hi. M0 (124), odd SGPRs
and invalid destinations (i.dst > 105) are still refused with the exact existing error strings.

Refs #3224, #2935. In #3224's refreshed census, invalid s_bcnt1_i32_b64 source blocks 10 wave64 shaders
(16,894 dispatches) and invalid s_ff1_i32_b64 source blocks 7 wave64 shaders (8,236 dispatches). This is a
single cohesive change, independent of #3357 (which added VCC as a destination for s_bfm_b64 and is
already merged in main).

New tests/native_salu_bitscan64_vcc_check.py + tests/cmake/native_salu_bitscan64_vcc.cmake
(native_salu_bitscan64_vcc_controls / native_salu_bitscan64_vcc_hardware): all 6 ops with S0 = VCC in
wave32 and wave64 (102 cases), populating VCC both with explicit s_mov_b32 vcc_lo/vcc_hi pairs (zero,
all-ones, low-half-only, high-half-only, sign-bit, bit 32) and with lane comparisons (v_cmp_lt_u32 against
16, v_cmp_eq_u32 against 0); exact result words and SCC are verified (counts update SCC = (D != 0),
scans preserve SCC), plus M0/odd-SGPR/invalid-destination refusals. The two existing refusal tests that
asserted VCC is refused as a source for these ops now use M0 instead
(tests/native_wave64_exec_salu_check.py BCNT1_B64, tests/native_salu_bitscan64_check.py FLBIT_B64).
docs/experiments/native-direct-salu-bitscan64.md documents VCC as S0 across all 6 ops.

AI-assisted.

Verification

Commit under test: 414874b6ba1ca87852b53b42479bb85abad7ea92 (branch compute/salu-bitscan64-vcc, from
origin/main 8ecd30fe).

Linux (this VM; no Windows toolchain here):

  • Offline harness (/tmp/bitscan64_vcc_harness.py, not in the repo): decodes every case program with
    tools/disasm_rdna2.py (all 6 ops appear as s_*_i32_b64 s24, vcc; v_cmp_lt_u32/v_cmp_eq_u32
    encodings verified; no bare-VGPR vmove() — VGPRs are stored directly, vmove() is only used for SGPRs),
    cross-checks eval_bitscan() against an independent brute-force reference for all 102 cases, verifies the
    hardware expected-layout build (no double-writes, in bounds, store planes at 0 and 16 * wave_size bytes),
    and evaluates the s0_pair guard expression straight from the .inl (accepts 0/2/22/104/106/126, refuses
    105/107/124/127/23). Result: harness OK: 102 cases x wave32/wave64, VCC source encodings, references, layout and s0_pair guard all match.
  • Spot-mutations, each killed by the harness (exit 1) and restored cleanly (git status/git diff show only
    the intended change): M1 VCC source replaced by SGPR pair (72 failures); M2 bare-VGPR vmove(2, 256 + dst)
    (102 failures — the Task 1/5 failure mode); M3 s0 == 106 dropped from the C++ guard (s0=106 refused);
    M4 v_cmp_lt_u32 opcode swapped to ne (decoded as v_cmp_ne_u32); M5 store plane stride halved
    (102 failures). The M2 check itself was fixed during the run: the disassembler prints v_mov_b32_e32,
    which the first version of the check missed.
  • /tmp/pe-env/bin/python -B tests/form_coverage_check.py — form coverage checks passed, exit 0.
  • /tmp/pe-env/bin/python -B tests/docs_links_check.py — Checked 160 Markdown files and 682 links, exit 0.
  • /tmp/pe-env/bin/python -B tests/bidi_controls_check.py — Checked 2578 tracked source, script and build/CI files: no bidirectional controls, exit 0.
  • py_compile on all three touched/related test files — pass. The changed guard expression compiles clean
    under g++ -std=c++20 -Wall -Wextra in a standalone check (accepts 106, refuses 124/23/127); a standalone
    -fsyntax-only of the whole .inl fails identically before and after this change (missing include
    context), so it proves nothing new either way.

Not run here — needs Windows: cmake --build --preset dev --target compile_dxil native_store_replay and
ctest --preset dev --no-tests=error -R '^(native_salu_bitscan64_vcc_|native_wave64_exec_salu|native_salu_bitscan64)' -V,
including native_salu_bitscan64_vcc_hardware on a real adapter (exit 77 is a skip, not a pass). Note the
hardware test has 102 replay cases; if it approaches the 60 s timeout on Windows, split it by wave size.

Evidence and follow-up

  • Fixtures are synthetic: VCC patterns are set with s_mov_b32 immediates or derived from v_cmp_* lane
    comparisons against v0; no game files, dumps or distribution links are involved.
  • Assumption: v_cmp writes VCC through the same ballot path the direct compute path already uses for
    v_cmpx/EXEC; the hardware test is the check for that on a real adapter.
  • The gfx2hlsl text translator and pixel path are untouched; whether they also accept VCC as a source for
    these ops is out of scope here.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

Windows Verification (414874b6)

  • Environment: Windows build 26100, MSVC 19.50.35727.0, adapter NVIDIA GeForce RTX 4050 Laptop GPU (driver 32.0.15.9186, XBOX2WINDOWS_ADAPTER=NVIDIA), D3D12 debug layer off, commit 414874b6ba1ca87852b53b42479bb85abad7ea92.
  • cmake --build --preset dev --target compile_dxil native_store_replay -> exit 0
  • cmake --build --preset release --target compile_dxil native_store_replay -> exit 0
  • ctest --preset dev --no-tests=error -R '^(native_salu_bitscan64_vcc_|native_wave64_exec_salu|native_salu_bitscan64)' --output-on-failure -> 5/5 passed ( skips)
  • ctest --preset release --no-tests=error -R '^(native_salu_bitscan64_vcc_|native_wave64_exec_salu|native_salu_bitscan64)' --output-on-failure -> 5/5 passed ( skips)
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0)
  • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 160 Markdown files and 682 links. (exit 0)
  • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 2580 tracked source, script and build/CI files: no bidirectional controls. (exit 0)
# dev preset (5/5 passed, 0 skips)
2754: compiled 64-bit scalar counts and scans (adjacent s32 descriptor preserved); 6 invalid forms refused; 6 reference mutants differ
1/5 Test #2754: native_salu_bitscan64_controls .......   Passed    1.17 sec
2/5 Test #2755: native_salu_bitscan64_hardware .......   Passed   15.21 sec
2756: compiled 6 ops with VCC source (plus lane-compare VCC); 6 invalid forms refused; 5 reference mutants differ
3/5 Test #2756: native_salu_bitscan64_vcc_controls ...   Passed    0.62 sec
4/5 Test #2757: native_salu_bitscan64_vcc_hardware ...   Passed   28.68 sec
5/5 Test #2803: native_wave64_exec_salu_hardware .....   Passed    2.73 sec
The following tests passed:
	native_salu_bitscan64_controls
	native_salu_bitscan64_hardware
	native_salu_bitscan64_vcc_controls
	native_salu_bitscan64_vcc_hardware
	native_wave64_exec_salu_hardware
100% tests passed, 0 tests failed out of 5
Total Test time (real) =  48.57 sec

# release preset (5/5 passed, 0 skips)
2754: compiled 64-bit scalar counts and scans (adjacent s32 descriptor preserved); 6 invalid forms refused; 6 reference mutants differ
1/5 Test #2754: native_salu_bitscan64_controls .......   Passed    0.46 sec
2/5 Test #2755: native_salu_bitscan64_hardware .......   Passed   11.02 sec
2756: compiled 6 ops with VCC source (plus lane-compare VCC); 6 invalid forms refused; 5 reference mutants differ
3/5 Test #2756: native_salu_bitscan64_vcc_controls ...   Passed    0.44 sec
4/5 Test #2757: native_salu_bitscan64_vcc_hardware ...   Passed   29.35 sec
5/5 Test #2803: native_wave64_exec_salu_hardware .....   Passed    2.43 sec
The following tests passed:
	native_salu_bitscan64_controls
	native_salu_bitscan64_hardware
	native_salu_bitscan64_vcc_controls
	native_salu_bitscan64_vcc_hardware
	native_wave64_exec_salu_hardware
100% tests passed, 0 tests failed out of 5
Total Test time (real) =  43.83 sec

@Ammmae0x

Ammmae0x commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Windows release verification for commit 414874b6ba1ca87852b53b42479bb85abad7ea92:

  • Command: XBOX2WINDOWS_ADAPTER=NVIDIA ctest --preset release --no-tests=error -R '^(native_salu_bitscan64_vcc_|native_wave64_exec_salu|native_salu_bitscan64)' -V
  • Adapter: NVIDIA GeForce RTX 4050 Laptop GPU (driver 32.0.15.9186, D3D12 debug layer off)
2754: compiled 64-bit scalar counts and scans (adjacent s32 descriptor preserved); 6 invalid forms refused; 6 reference mutants differ
1/5 Test #2754: native_salu_bitscan64_controls .......   Passed    0.46 sec
2/5 Test #2755: native_salu_bitscan64_hardware .......   Passed   11.02 sec
2756: compiled 6 ops with VCC source (plus lane-compare VCC); 6 invalid forms refused; 5 reference mutants differ
3/5 Test #2756: native_salu_bitscan64_vcc_controls ...   Passed    0.44 sec
4/5 Test #2757: native_salu_bitscan64_vcc_hardware ...   Passed   29.35 sec
5/5 Test #2803: native_wave64_exec_salu_hardware .....   Passed    2.43 sec
The following tests passed:
	native_salu_bitscan64_controls
	native_salu_bitscan64_hardware
	native_salu_bitscan64_vcc_controls
	native_salu_bitscan64_vcc_hardware
	native_wave64_exec_salu_hardware
100% tests passed, 0 tests failed out of 5
Total Test time (real) =  43.83 sec

AI-assisted.

@Ammmae0x
Ammmae0x marked this pull request as ready for review November 28, 2026 22:10

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes on 414874b.

The guard change itself is correct. Outside the graphics path operand32 already reads 106/107 as VCC (src/gfx1013_direct_compute.inl:175-191 on main), the handler is gated on compute, and the existing count/scan lowering does not depend on which pair is the source.

Blocking: tests/native_scalar_mask64_check.py:90-92 (added in #3335, not touched by this PR) still asserts the old refusal:

        # VCC stays refused as a 64-bit count source.
        (count_program(), 64, "invalid s_bcnt1_i32_b64 source"),
        (count_program(), 32, "invalid s_bcnt1_i32_b64 source"),

count_program() defaults to src=106 and sets vcc_lo/vcc_hi with s_mov_b32 literals. With s0 == 106 accepted, the guard no longer refuses these two programs, and it is the only place that emits this diagnostic for s_bcnt1_i32_b64, so compile_case (lines 46-47) and native_scalar_mask64_controls fail. Your ctest regex ^(native_salu_bitscan64_vcc_|native_wave64_exec_salu|native_salu_bitscan64) does not select that test. CI does not either: the pull_request Windows job runs ctest --preset pr (.github/workflows/windows.yml:493), and its filter (CMakePresets.json:51) matches none of native_salu_bitscan64*, native_wave64_exec_salu* or native_scalar_mask64*.

Fix: remove lines 90-92 (or switch the two entries to count_program(src=124), M0, which stays refused) and keep count_program(src=107) on line 89.

Smaller points:

  • No test in this PR refuses vcc_hi (107) as S0. A guard of s0 == 106 || s0 == 107 is caught only by the count_program(src=107) case above, in the file this PR leaves failing. A sop1(op, 24, VCC + 1) refusal in the new controls would cover it.
  • The wave32 cmp_lt16/cmp_eq0 cases expect vcc_hi == 0. In wave32 write_ballot writes only vcc_lo, so the expected value relies on the initial vcc_hi, which those cases do not set.
  • The "5 reference mutants" only mutate the Python reference, not the translator.

Basis: diff read in full against main 212d4b5; nothing built or run. git merge-tree of 414874b with main 212d4b5 is clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants