perf: v_perm_b32 moves bytes in groups; a run-time selector reads a 16-byte table (1.9x / up to 2.2x on a 4060 Laptop) #586
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/586"
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?
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-28T16:36:57Z.
Stacked on #585 (rndne), itself on #581 and #570. It uses #581's bench and #585's bulk test harness (
exact_tests.rs). Only the last commit is new. Fullvictory-shadersuite and pytest results: see #585.What
Constant selector. The old form wrote 4 shifts, 4 masks, 3 shifts into place and 3 ors, whatever the bytes did. Now the work is grouped:
Instruction counts, from
cost:A selector moved into a register from a literal also takes the constant form. The old run-time form happened to fold down to it; the new one's unsigned minimum is a host operation that does not fold, so it is caught explicitly.
Selector known only at run time. The old form compared each selector byte with 8, 9, 10, 11, 12 and above, each with its own select: 103 instructions. Now the selector bytes 0-15 index the 16 bytes of four dwords:
0xFFFFFF00(12 → 0x00, 13-15 → 0xFF).A byte above 15 counts as 15. Per result byte that is an unsigned minimum, a pick among the four dwords, a shift and a mask: 73 instructions. No 64-bit integers, so it still runs on hosts without INT64.
TRANSLATOR_VERSION23.Bench (RTX 4060 Laptop, 8 dependent chains x 256 rounds, median of 3 alternating rounds)
v_perm_b32 v8, v8, v5, v6)0x050401000x0A0A05040x040506070x0C0C0C06Where the before numbers come from:
op_loop_ideal_bench.Tests
perm_tests::perm_costs_one_shift_and_mask_per_byte_group(shape) fails on #585 ("a byte swap writes 13 instructions"). It asserts ≤ 9 for a swap, for the same swap moved into s9 or v9, and 5 / 2 / 5 / 73 for the other forms.perm_tests::perm_with_a_run_time_selector_matches_rdna2runs 139,264 lanes:They are checked against RDNA 2's rule and the reference interpreter on all of them, on the RTX 4060 Laptop, Intel UHD (
VICTORY_D3D12_ADAPTER=Intel) and WARP.perm_tests::perm_with_a_constant_selector_matches_rdna2takes 30 constant selectors (swaps, rotations, extracts with zero or sign bytes, packs, every code in every byte, 0x10/0x80/0xFF codes). Each runs as a literal and moved into s9, on 4,096 random pairs. They are checked against RDNA 2's rule and the interpreter on the three adapters.AI use: written with Claude Code (Claude Opus 5.5): lowering, tests, measurements on my machine. The benches ran on my RTX 4060 Laptop, the parity runs also on Intel UHD and WARP.
🤖 Generated with Claude Code
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.