RDNA2 decoder: opcodes from a table per encoding, fields a word at a time #479
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!479
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-479"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@TG0000 on GitHub · 2026-11-24 00:53 UTC · original
TG0000:perf/cpu-hotpath→main· +215 −43 · 1 files · 1 commits · openThe RDNA2 decoder is the first stage of every shader translation. The recompiler reads every operand through the same
field_value, so a faster decoder speeds up all of them. Per instruction,decode()used to:HashMap<(encoding, opcode), _>once for every primary encoding whose fixed bits matched,Vec<u32>: the head, the base words and the final words.What is in it
crates/xcl/src/gpu/rdna2.rsonly. Each primary encoding now keeps a dense1 << width(OP)table of its instructions (at most 1024 entries; the EXP encoding, which has no OP field, uses slot 0). When two instructions claim an opcode, the first one keeps it (spec before console extensions), as the oldor_insertdid, and the tables are still tried in spec priority order.bits()takes whole runs of a word at once. Bits past the last word still read as 0.[u32; 5]on the stack (the widest encoding is 160 bits). OnlyDecoded::wordsis allocated: 1 allocation per decode instead of 3.decode,field_value,Decoded) or to its results.Release microbenchmark (
#[ignore]d testgpu::rdna2::tests::bench_decode): it decodes the 23 812 instructions of the LLVM gfx10 disassembler corpus already intests/data/llvm-amdgpuand reads every operand field, as the recompiler does. Each figure is the best of 15 runs of 8 rounds. Before and after alternated, with a rebuild each time:origin/mainThat is ≈1.8× faster. The checksum over decoded lengths and field values is identical (
sink 1484757240) in every run.Tested
stable-x86_64-pc-windows-msvc; debug and release.bits_matches_one_at_a_time: every offset (also past the end) and every count 0..=64, on 0–6 random words, against the old bit-at-a-time loop.field_value_matches_one_at_a_time_for_every_field: every field of every encoding.opcode_tables_match_first_claim_lookup: every slot of every table against a first-claimHashMapbuilt like the old one.decoded_words_are_the_instruction_dwords: across the whole LLVM corpus, plus a trailing partial dword.llvm_gfx10_corpustest (name and length of 23 812 instructions) and the other decoder tests pass:cargo test --release -p xcl --lib rdna2: 13 passed, 2 ignored (one is the benchmark).cargo test --workspace --no-fail-fast -- --test-threads=4: lib 637 passed, 3 failed, 22 ignored; all integration tests pass (e2e 3/3). The three failures are GPU tests inhle::d3d12x(title_textures::placed_title_textures_share_vram_and_preserve_pixels,title_textures::transitions_apply_when_their_list_is_submitted,vram::d32s8_targets_take_their_own_size_of_video_memory). They fail the same way onorigin/mainon this machine, in two runs with main'srdna2.rs.cargo clippy -p xcl --all-targets: same warning counts asorigin/main(lib 422, lib test 632), so no new warnings.Regression run
main:
PR:
Not tested
AI use
🤖 Generated with Claude Code
@brothernog on GitHub · 2026-11-24 01:22 UTC · original
Independent check of
cbb03e1on NVIDIA. I read the decoder change against the old lookup, and I didn't find a behaviour difference:if let Some(s @ None)keeps the oldor_insertorder. Instructions of non-primary encodings are skipped, as before, since the oldby_opentries for them were never looked up. EXP (no OP field) uses slot 0, which is the oldno_opmap.1 << field_width("OP")slots, so a decoded OP always indexes inside it.field_widthsums the field's ranges.HEAD_WORDS = 5covers the widest encoding inrdna2_spec.rs: 160 bits, one encoding.base_wordsis sliced from it, and bytes past the input still read as 0, asread_wordsdid.Tested
cargo test -p xcl --lib rdna2: 13 passed, 0 failed, 2 ignored.cargo test --workspace --no-fail-fast -- --test-threads=4: 680 passed, 0 failed, 42 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware. Unlike your RX 6800 run, the threehle::d3d12xGPU tests pass here.Not tested
This review was AI-assisted.
@eizispark on GitHub · 2026-11-24 02:42 UTC · original
Hardware check of
cbb03e1b250e32801f1a5d6be6c5077e1961fc20(verified clean merge withmain3db536e): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace -- --test-threads=4:680 passed, 0 failed, 42 ignored(GPU tests skipped on this adapter:none; the threehle::d3d12xGPU tests that failed on RX 6800 also pass here)cargo test --release -p xcl --lib rdna2::tests::bench_decode -- --ignored --nocapture:23812 instructions x 8, best of 15: 12.94 ms, 68.0 ns/instruction (sink 1484757240)Regression run
main(9ce2070):PR (
cbb03e1):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.@raylitebull on GitHub · 2026-11-25 01:12 UTC · original
Both AMD (RX 9070 XT) and NVIDIA verification look great on
cbb03e1. Please rebase ontomainto resolve the currentrdna2.rsmerge conflict soBuild and test (Windows, no GPU)can run cleanly.@TG0000 on GitHub · 2026-11-25 12:28 UTC · original
Rebased onto main
1a0bbe3: head0f112d4. The conflict was in the tests only (main's SDWA text test and this PR's tests now stand side by side); the decoder change is as reviewed.Run on this head (Ryzen 9 5900X, Windows 11, MSVC):
cargo test -p xcl --lib rdna2: 24 passed, 0 failed, 2 ignored.bench_decode, release, one run: 111.4 ns per instruction, the checksum (1484757240) as before; main was not measured again beside it. Clippy stops on threeTAUconstants in files this PR does not touch, with this toolchain.Not run on this head: the whole suite, and the
xcl-smokepair. The blocks in the description are ofcbb03e1, so the description check is expected to ask for a fresh one until it is run.AI-assisted (Claude Code).
@DavidM1911 on GitHub · 2026-11-25 14:05 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.@TG0000 on GitHub · 2026-11-25 15:04 UTC · original
@DavidM1911 Rebased onto latest
main(head0ee075f) — thanks for testing!@DavidM1911 on GitHub · 2026-11-26 02:45 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.