Skip to content

Tests: check scalar ALU results and SCC on the GPU against the ISA - #620

Open
acaracargo wants to merge 1 commit into
xcl-dev:mainfrom
acaracargo:fork/salu-gpu-tests
Open

acaracargo wants to merge 1 commit into
xcl-dev:mainfrom
acaracargo:fork/salu-gpu-tests

Conversation

@acaracargo

Copy link
Copy Markdown

About 80 SALU instructions are translated in emit.rs but never run in a GPU test. This adds one test for 46 of them, each on edge values (sign, carry and overflow boundaries, shift counts past 31 / 63, all-ones and all-zero inputs). It compares the destination and SCC with a small model of the RDNA2 pseudo-code (salu_reference). For instructions that do not write SCC, it checks that SCC keeps both of its earlier values. Test only, no runtime change.

A search of open and closed PRs for "scalar", "SALU", "SCC" and the opcode names found no overlapping coverage. #445, #519, #545 and #590 cover VALU instructions only.

What is in it

  • crates/xcl/src/gpu/recomp/tests.rs: SaluCase, salu_reference and gpu_scalar_alu_results_and_scc, 68 cases in programs of 30. s[0:5] hold the operands and the destination, and s[8..97] hold each result and its SCC.
  • Opcodes: s_abs / s_absdiff, the SOPK s_addk / s_mulk / s_movk / s_cmovk, s_bcnt0, s_bfm, s_bitcmp0/1, s_bitset0, s_brev (32 and 64), s_cmov (32 and 64), s_ff0, s_lshl1..4_add, s_mul_hi (u32 and i32), s_pack_ll / lh / hh, s_sext (i8, i16), s_wqm (32 and 64), s_nand / nor / xnor / orn2 / andn2 / xor / or / not, s_ashr (i32 and i64), s_lshr_b64, s_min / s_max (i32, u32), s_sub_i32, s_cselect_b64 and s_cmp_lg_u64.
  • s_min / s_max get no equal operands. The RDNA2 ISA only says "set SCC iff the first value is selected", which does not say what a tie selects.

Tested

  • NVIDIA GeForce RTX 4060 (32-lane waves only), driver 610.88; Intel Core i5-13400F; Windows 11 Pro 26300; Rust 1.100.0 x86_64-pc-windows-msvc; DXC 1.9.2602.17 from the Windows SDK; debug.
  • cargo test --workspace -- --test-threads=4 on 0e158e4: 685 passed, 0 failed, 41 ignored. On main 9ce2070: 684 / 0 / 41.
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • Two local mutation checks caused the test to fail as expected (reverted): s_ff0_i32_b32 scanning the wrong bits, and s_pack_hh_b32_b16 writing SCC.

Regression run

  • Test-only change, no runtime regression run.

Not tested

  • AMD GPUs and native wave64. Here the programs ran in the split wave64 form.
  • Console hardware. The expected values come from the ISA's descriptions, not from a console.
  • s_min / s_max SCC on equal operands.

AI use

  • Claude Code (Claude Fable) wrote the test and the original description and ran the tests and the mutation checks.

68 cases over 46 SALU opcodes that no GPU test ran (s_abs/absdiff,
SOPK addk/mulk/movk/cmovk, s_bfm, s_bitcmp/bitset0, s_brev, s_cmov,
s_ff0, s_lshlN_add, s_mul_hi, s_pack, s_sext, s_wqm, the n-logic ops,
64-bit shifts, s_min/max, s_sub_i32, s_cselect_b64, s_cmp_lg_u64),
each on edge values, compared with a model of the RDNA2 pseudo-code:
the destination and SCC, including that an op which does not write
SCC keeps both values of it.

Min / max get no equal operands: the RDNA2 machine-readable ISA only
says "SCC iff the first value is selected", which leaves ties open.

Measured: RTX 4060 (wave32), Windows 11 Pro 26300, Rust 1.100, debug.
cargo test --workspace -- --test-threads=4: 678 passed, 0 failed,
41 ignored; SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask,
gpu_wave32_program_in_wave64_hardware. The min tie case was replaced
after that run; cargo test -p xcl --lib gpu_scalar: 3 passed.
Breaking s_ff0 or making s_pack_hh write SCC in emit.rs fails the test.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 0e158e4bedb6314e5f8ba5b9490d8171e2d8fe40 on AMD RDNA4; the PR was tested on NVIDIA only. I merged it onto current main 3db536e locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 687 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 647 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_scalar_alu_results_and_scc passes.

Review: I spot-checked salu_reference against the RDNA2 pseudo-code: SCC = result ≠ 0 for s_abs, s_absdiff, s_bcnt0, s_wqm and the nand/nor/xnor/orn2/andn2 cases; no SCC write for s_bfm, s_brev, s_sext, s_mul_hi, s_pack_*; s_bitcmp0/1 test bit S1[4:0]; s_ff0 gives −1 with no zero bit; s_pack_hh is {S1[31:16], S0[31:16]}. All match. I did not check every one of the 46 opcodes.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@caua-an

caua-an commented Nov 24, 2026

Copy link
Copy Markdown

Tested: Clean head 0e158e4bedb6314e5f8ba5b9490d8171e2d8fe40; Windows 11 Home build 26200, Core Ultra 9 185H, Rust 1.100.0 MSVC x64, debug build, XCL_REQUIRE_GPU=1. Intel Arc integrated graphics driver 32.0.101.8860; RTX 4070 Laptop driver 616.92.

cargo test --offline --locked -p xcl --lib gpu_scalar_alu_results_and_scc -- --test-threads=1 --nocapture: 1 passed, 0 failed, 0 ignored, no skips with each of XCL_ADAPTER=intel and XCL_ADAPTER=nvidia. DXC 1.9.2602.17 was loaded.

Not tested: Full workspace suite, release builds, retail titles, or game-data samples (XCL_SAMPLE_* unset).

AI use: OpenCode with GPT-6.2 Sol ran the tests and drafted this report.

@4usphs

4usphs commented Nov 24, 2026

Copy link
Copy Markdown

Measured on RDNA2 hardware, for the two points under Not tested: console-generation hardware instead of the ISA text, and s_min / s_max SCC on equal operands.

Method. The Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, RDNA2), Windows 11 Pro 26200, display driver 32.0.21045.29003, AMD OpenCL 3652.0 (PAL,LC). Each case is one inline-assembly block in an OpenCL C kernel (the #518 / #772 method): s_cmp_eq_u32 0, 0|1 sets SCC, the instruction runs on SGPR operands with the destination preset to the case's d, and s_cselect_b32 1, 0 reads SCC back. All cases run 6 times, 3 in wave32 and 3 in wave64, with identical output. The reference is a line-by-line Python port of salu_reference from this PR.

Result.

  • All 68 cases in gpu_scalar_alu_results_and_scc match the hardware, results and SCC, including SCC kept by the instructions that do not write it.
  • s_min / s_max on equal operands: SCC = 0, whatever SCC was before. This holds for s_min_i32, s_max_i32, s_min_u32 and s_max_u32, each with 5 values (5, 0, -3, 0x80000000, 0xFFFFFFFF) and SCC 0 and 1 before (40 cases). That is the strict < / > that emit.rs uses (lines 1262–1265 on main 077ce40) and this test's reference. Non-ties in both orders (16 cases) give SCC = 1 exactly when S0 is the one selected. So the cases left out by the comment above S_MIN_U32 could be added with SCC = 0.

For comparison, the same probe on an RX 9070 XT (gfx1201, RDNA4, OpenCL 3686.0) gives the same results. The exception is s_ff0_i32_b32, which RDNA4's assembler refuses (removed there), so 66 of the 68 cases ran on it.

Not tested: the console itself (gfx1036 is a desktop RDNA2 APU of the same generation), RDNA1, this PR's D3D12 test on this GPU.

Kernel shape (one case)
{ uint d = 0x0u; uint sc; uint a = 0x5u; uint b = 0x5u;
  __asm__ volatile("s_cmp_eq_u32 0, 1\ns_min_i32 %0, %2, %3\ns_cselect_b32 %1, 1, 0"
                   : "+s"(d), "=&s"(sc) : "s"(a), "s"(b));
  o[4*i] = d; o[4*i+2] = sc; }

AI use: Claude Code (Claude Opus 5.5) wrote the OpenCL probes and the port of the reference, ran them on my PC and wrote this comment. I have not reviewed the code.

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (0e158e4)

Hardware / environment

  • PR Tests: check scalar ALU results and SCC on the GPU against the ISA #620 head: 0e158e4bedb6314e5f8ba5b9490d8171e2d8fe40, verified on a clean detached checkout.
  • Intel Arc A770 Graphics, driver 32.0.101.9175. AMD Ryzen 7 3800X 8-Core Processor. Windows x64, OS build 26200 (10.0.26200.0).
  • Rust 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc), unoptimized test profile with debug info and incremental compilation disabled. DXC and DXIL 1.9.2609.5, compiler revision 01b62ad4, confirmed in the focused run.

Commands and results

  • cargo test -p xcl --lib --no-run exited 0 in 1m 03s outside the Arc lock. Cargo built the library test executable and emitted one deprecation warning for AtomicU32::fetch_update. This command only compiled the tests.
  • Ran the following in PowerShell with execution policy Bypass. The variables identify the Arc lock script and the executable emitted by Cargo.
$env:XCL_ADAPTER = 'A770'
$env:RUST_TEST_NOCAPTURE = '1'
& $env:XCL_PR620_ARC_WRAPPER -Test {
    & $env:XCL_PR620_TEST_EXE gpu::recomp::tests::gpu_scalar_alu_results_and_scc --exact --nocapture --test-threads=1
}
  • The lock wrapper exited 0. Rust reported 1 passed, 0 failed, 0 ignored and 665 filtered out in 0.40 s. The UTF-8 log contained 0 skipped (case-sensitive ^SKIPPED count).

Observed behavior

The test compared the GPU destination register values and scalar condition code (SCC) against the test's RDNA2 ISA reference for 68 cases across 48 opcodes. All comparisons matched, including cases for arithmetic carry and overflow, masked shift counts, and SCC preservation. The wrapper acquired and released the Arc lock.

Not tested

Full GPU workspace suite and game smoke runs were omitted.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr620-focused.log and published.

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

Labels

off-goal Does not bear on the current goal (world loading); waits until it is reached

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants