Skip to content

compute: accept EXEC as the destination of s_bitreplicate_b64_b32 - #3179

Merged
pigalot merged 1 commit into
R0Y00:mainfrom
Leyukaka:bitrep-exec
Nov 27, 2026
Merged

pigalot merged 1 commit into
R0Y00:mainfrom
Leyukaka:bitrep-exec

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Fixes #3170. Part of #2935. Target branch main. This is the direct C++ path; #3030 (merged) covered gfx2hlsl.py.

Change (src/gfx1013_direct_compute.inl): s_bitreplicate_b64_b32 now accepts EXEC (s126/s127) as its destination pair in compute.

  • D[63:0] doubles each bit of S0[31:0]. The low word comes from S0[15:0] and the high word from S0[31:16].
  • They are written to s126 and s127, like any other EXEC pair write in the direct path.
  • In wave32, active() reads s126 only. In split wave64, the upper half uses s127.
  • Odd pairs, other special registers and graphics stay refused.

Tests. The setup was Windows 11 build 26300.9974 with an NVIDIA GeForce RTX 5080 (driver 32.0.16.2101) and DXC from the Windows SDK 10.0.26100, on main 454fc0ed plus this commit.

  • native_bitreplicate_exec_hardware (new) sets EXEC from four sources: the literals 0xff00ff00, 0x0000ffff and 0xf0f0f0f0, and the inline constant 5. It also checks that SCC is unchanged. It stores lane values under that EXEC, restores EXEC and stores the saved EXEC words, all against a CPU reference.
  • native_bitreplicate_exec_controls keeps an odd destination refused.
  • native_direct_container and the native_salu* tests pass.
  • Mutation check, run by hand: writing the high word from S0[15:0] fails native_bitreplicate_exec_hardware.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests on main 6057071b. Since then only #3147 (3a550d0a, f16 frexp inline sources) touches gfx1013_direct_compute.inl, outside this path.

Requests Compiled before Compiled after
Capture, 2,689 403 407
One start-up run, 2,718 416 420

AI-assisted.

Captured compute programs set EXEC from a lane pattern with
s_bitreplicate_b64_b32 exec, <constant>. The direct path accepted only an
aligned general SGPR pair or VCC as the destination. EXEC (s126/s127) is
now accepted in compute; the two halves are written like any other EXEC
pair write. Odd pairs, other special registers and graphics stay refused.

native_bitreplicate_exec_hardware sets EXEC from four patterns, stores
lane values under it, restores EXEC and stores the saved EXEC words,
against a CPU reference; the controls keep an odd destination refused.

AI-assisted.
@KelboLive

Copy link
Copy Markdown
Contributor

Review of src/gfx1013_direct_compute.inl and src/gfx1013_compute_native.cpp changes:

s_cmp_lg_u64 is implemented as inequality, not signed less-than (BUG)

Lines 2258-2264:

const bool eq = n == "s_cmp_eq_u64";
const auto op = eq ? "eq" : "ne";
const auto combine = eq ? "and" : "or";
cond = ir.value(string(combine) + " i1 " + cmp(op, a_lo, b_lo) + ", " + cmp(op, a_hi, b_hi));

For s_cmp_eq_u64 this produces (a_lo==b_lo) AND (a_hi==b_hi) — correct for 64-bit equality.

For s_cmp_lg_u64 this produces (a_lo!=b_lo) OR (a_hi!=b_hi) — which is inequality, not signed less-than. In the RDNA2 ISA, s_cmp_lg_u64 sets SCC if S0 <signed S1. The current code treats it as a simple "not equal" check on 64 bits.

Fix: implement proper signed 64-bit comparison:

auto hi_neq = cmp("ne", a_hi, b_hi);
auto lo_signed_lt = cmp("slt", a_lo, b_lo);
cond = ir.value(string("select i1 ") + hi_neq + ", " + 
    ir.value(string("select i1 ") + cmp("slt", a_hi, b_hi) + ", true, false") + 
    ", " + lo_signed_lt);

s_bitcmp0_b64 / s_bitcmp1_b64 — looks correct ✓
The word selection via bit 5 of the index and single-bit extraction is right.

s_cmov_b32/b64/k_i32 — looks correct ✓
Properly reads SCC from register 128, validates destination/source ranges per ISA spec, handles pair registers for b64 variant.

v_cvt_f16_u16/i16/u16/i16 — looks correct ✓
Uses the existing legacyF16ToF32 intrinsic for f16→int conversions with proper clamping/bounds logic. The inline half constant handling (registers 240-248) is consistent with how v_add_f16 already handles them.

s_bitreplicate_b64_b32 — looks correct ✓
The EXEC destination change (removing the i.dst != 126 guard) is appropriate since EXEC is a valid scalar pair register in compute mode, equivalent to VCC for this instruction. The bit-replication algorithm (interleaving zeros then duplicating) is standard and matches the ISA description.

transfer() clobber list — looks correct ✓
Adding s_cmovk_i32 to the set of instructions that clobber their destination symbol is right since it always writes D regardless of SCC state.

Summary: Blocker on s_cmp_lg_u64. The signed less-than comparison for 64-bit values needs a proper fix as shown above before this can merge.

@Leyukaka

Copy link
Copy Markdown
Collaborator Author

Thanks for reading through it. s_cmp_lg_u64 is "less or greater", that is, not equal: SCC = (S0 != S1), as in tools/disasm_rdna2.py (SOPC 0x13, "not-equal unsigned 64-bit") and tools/startup/gfx2hlsl.py. So the OR of the per-half inequalities is the intended 64-bit test. That code also came from #3081, which is on main; this PR does not change it. This PR only accepts EXEC as the destination of s_bitreplicate_b64_b32.

AI-assisted.

@pigalot pigalot 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.

I reviewed f37a6dd3 merged over main d474a393. The merge is clean (tree 3b43fff4) and git diff --cached --check is clean.

What I traced.

  • Acceptance: the change only widens the destination check. EXEC (s126) is now accepted next to VCC in compute, and odd pairs, other special registers and graphics stay refused.
  • Writes: write(i.dst) and write(i.dst + 1) go through the same scalar storage as any other EXEC pair write. active() reads s126 on every vector write in wave32, and s127 for the upper half in split wave64, so the lane mask applies from the next instruction.
  • Analysis: transfer already clears both words for s_bitreplicate_b64_b32, which leaves EXEC unknown. SCC is not written.

What I ran. I built compile_dxil native_store_replay in dev and release (plus native_compute_ir_dump in release for the _ir tests), then ran

python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(native_bitreplicate_exec_(controls|hardware)|native_salu[a-z0-9_]*|native_direct_container)$'
  • Results: 17/17 pass in Debug and Release /O2, with no skips. native_bitreplicate_exec_hardware covers all four sources and checks the lane stores under the replicated EXEC, both saved EXEC words, the unchanged SCC and the guards.
  • Negative control: on main 6cc46a3c, the PR's native_bitreplicate_exec_check.py controls passes, because the odd-pair refusal predates this PR. hardware fails, because the replay compile refuses +0x24: bitreplicate requires an aligned general scalar pair or compute VCC.

Mutants in src/gfx1013_direct_compute.inl. For each, I rebuilt in dev and ran both new tests:

Mutant Result
high word replicated from S0[15:0] killed (0x0000ffff, word 136: 0xffffffff vs 0x00000000)
high word not written killed (0xff00ff00, word 136: 0x00000000 vs 0xffff0000)
odd-pair refusal removed killed (controls)

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking. SCC is checked only from 0, so a lowering that cleared SCC would pass. A case that sets SCC to 1 before the bitreplicate would pin that too. Wave64 isn't exercised, which matches the PR's scope.

Verdict: approve on f37a6dd3.

Environment: NVIDIA GeForce RTX 5090 driver 610.88, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32, debug layer off.
CI: Build and test on Windows passes on f37a6dd3.

This reply was AI-assisted.

@pigalot
pigalot merged commit 5612e92 into R0Y00:main Nov 27, 2026
5 checks passed
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.

direct compute: accept EXEC as the destination of s_bitreplicate_b64_b32

3 participants