Skip to content

Optimize swizzle_dyn AVX2 implementation#542

Merged
programmerjake merged 1 commit into
rust-lang:masterfrom
Shnatsel:optimize-avx2-swizzle-dyn
Jul 22, 2026
Merged

Optimize swizzle_dyn AVX2 implementation#542
programmerjake merged 1 commit into
rust-lang:masterfrom
Shnatsel:optimize-avx2-swizzle-dyn

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Jul 22, 2026

Copy link
Copy Markdown
Member

llvm-mca shows:

End-to-end benchmarks on a toy base64 implementation using 512-bit shuffles improve by 7% to 13% on my Zen4 workstation, depending on how you count.

Benchmark details

$ RUSTFLAGS='--cfg disable_dispatch_avx512' cargo bench  --bench codec -- 1048576
    Finished `bench` profile [optimized] target(s) in 0.02s
     Running benches/codec.rs (target/release/deps/codec-0676c1840143d734)
encode/1048576          time:   [103.20 µs 103.31 µs 103.45 µs]
                        thrpt:  [9.4398 GiB/s 9.4524 GiB/s 9.4631 GiB/s]
                 change:
                        time:   [−11.900% −11.804% −11.685%] (p = 0.00 < 0.05)
                        thrpt:  [+13.231% +13.384% +13.507%]
                        Performance has improved.
Found 13 outliers among 100 measurements (13.00%)
  12 (12.00%) high mild
  1 (1.00%) high severe

decode/1048576          time:   [163.61 µs 163.63 µs 163.65 µs]
                        thrpt:  [5.9674 GiB/s 5.9682 GiB/s 5.9689 GiB/s]
                 change:
                        time:   [−7.6401% −7.5954% −7.5538%] (p = 0.00 < 0.05)
                        thrpt:  [+8.1710% +8.2197% +8.2721%]
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe

This is a port/upstreaming of my work on fearless_simd: linebender/fearless_simd#276

Disassembly and llvm-mca measurements are from fearless_simd because this repo does not include instructions on how to disassemble and benchmark it (as opposed to the std::simd re-export of its older version).

Correctness of this formulation was verified using random testing against the scalar reference on 100k inputs: linebender/fearless_simd@4e8a56a
On top of the usual unit tests.

 llvm-mca shows no change on Haswell and Broadwell, but Zen 1, Zen 2 and Tiger Lake show a 23% improvement, and a 7-20% improvement on Zen 3.
@programmerjake
programmerjake merged commit 7a0e3d2 into rust-lang:master Jul 22, 2026
53 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.

2 participants