compute: accept EXEC as the destination of s_bitreplicate_b64_b32 #3179

Merged
Leyukaka merged 1 commit from upstream-pr/3179 into main 2026-11-27 22:02:11 +00:00
Leyukaka commented 2026-11-27 20:30:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-27T20:30:54Z.


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
  • 11 requests stopped first at this refusal, all s_bitreplicate_b64_b32 exec, <literal>.
  • 4 of them now compile. One is dispatched in the start-up run, 178 times.
  • Of the other 7, 4 stop at v_permlanex16_b32 (#3021, PR #3022) and 3 at "direct scalar move destination" (s_mov_b32 exec_hi).
  • No request that compiled before stops compiling.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5532721366 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3179). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-27T20:30:54Z. --- 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 | - 11 requests stopped first at this refusal, all `s_bitreplicate_b64_b32 exec, <literal>`. - 4 of them now compile. One is dispatched in the start-up run, 178 times. - Of the other 7, 4 stop at `v_permlanex16_b32` (#3021, PR #3022) and 3 at "direct scalar move destination" (`s_mov_b32 exec_hi`). - No request that compiled before stops compiling. AI-assisted.
KelboLive commented 2026-11-27 21:23:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T21:23:15Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228397679 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3179#issuecomment-7228397679). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T21:23:15Z. --- 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: ```cpp 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: ```cpp 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 commented 2026-11-27 21:57:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-27T21:57:19Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228900271 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3179#issuecomment-7228900271). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-27T21:57:19Z. --- 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 commented 2026-11-27 22:01:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T22:01:51Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093770847 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3179#pullrequestreview-6093770847). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T22:01:51Z. **Review:** APPROVED --- 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 ```powershell 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.
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!3179
No description provided.