XAudio2: vectorize acphal i16-to-f32 PCM conversion with runtime AVX2 #1240
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!1240
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1240"
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?
@AlpPesen on GitHub · 2026-11-24 13:36 UTC · original
AlpPesen:perf/acphal-avx2-i16-to-f32→main· +108 −5 · 1 files · 1 commits · openVectorizes the Opus
i16 -> f32sample conversion and non-zero sample counter inacphal::decode_intousing runtime-detected AVX2 (#459item 3a), keeping the scalar implementation as fallback for non-AVX2 CPUs and tail elements.Part of #459. (Disjoint from open
acphal.rsPRs #463, #468, #471, and #939.)What is in it
crates/xcl/src/hle/acphal.rs:convert_i16_to_f32_scalar,convert_i16_to_f32_avx2(#[target_feature(enable = "avx2")]), and runtime-dispatchedconvert_i16_to_f32(OnceLock<bool>viais_x86_feature_detected!("avx2")).i16samples per iteration (_mm256_cvtepi16_epi32->_mm256_cvtepi32_ps->_mm256_mul_ps(1.0 / 32768.0)) and count zero lanes directly in a 256-bit SIMD accumulator (_mm256_sub_epi32on_mm256_cmpeq_epi32), avoiding per-iterationmovemask/popcntdependencies. Because32768.0 = 2^15is an exact power of two, multiplying by1.0 / 32768.0is bit-identical to dividing by32768.0across all 65,536i16values.convert_i16_to_f32_avx2_matches_scalar_bit_for_bitunit test verifying exhaustive bit-exactf32and non-zero count parity acrossi16::MIN..=i16::MAX, tail lengths0..=17, and shorter destination slices.Measured on Intel Core i9-9900K (
--release, 200,000 iterations per buffer length):N)Regression run
Baseline (
main):This PR (
perf/acphal-avx2-i16-to-f32):Tested
Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K (AVX2), 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, Driver
32.0.21045.29003),rustc 1.100.0 (0ef1bc386 2026-11-09).cargo test -p xcl --lib hle::acphal:::8 passed; 0 failed; 0 ignored; 0 skipped.XCL_REQUIRE_GPU=wave64,mesh cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:739 passed; 3 failed; 41 ignored; 0 skipped. All 3 failures are the pre-existing RDNA2placed_title_textures_share_vram_and_preserve_pixels+ 2VRAM_TEST_LOCKPoisonErrorcascades on unmodifiedmain(tracked in #470)..\scripts\smoke.ps1 -Game '<game folder>\YouKnowWho'onae27c9e101166065a2e72279123a4c240608d00b(see Regression run above).Not tested
convert_i16_to_f32_avx2_matches_scalar_bit_for_bit).acphalaudio decode traffic (microbenchmarked in--releaseon i9-9900K;YouKnowWhosmoke verified no regression).AI use
Antigravity (Gemini 4 Neon) implemented the runtime-detected AVX2 conversion and bit-exact unit test in
crates/xcl/src/hle/acphal.rs, ran the release benchmark, full test suite, and smoke run.@thehollowedone on GitHub · 2026-11-24 13:47 UTC · original
Independent Ryzen 7 9800X3D check on
ae27c9e(Windows 11 build 26300, Rust 1.99.1 MSVC, release). The stock exhaustive parity test passed with AVX2 available. For 1,920 interleaved samples, the converter took a median 101 ns with runtime dispatch versus 425 ns for scalar, about 4.2× faster.I also timed XCL’s
decode_intowith the in-tree synthetic 20 ms stereo CELT packets. In the scalar comparison build I changed only which converterdecode_intocalled. Five alternating pairs of 2,048 packets per run gave medians of 25.8 µs per packet (AVX2, 24.9–26.7) and 26.6 µs (scalar, 24.1–27.1). Every packet produced 960 stereo frames and each run’s final PCM block had the same digest. The decode ranges overlap, so I could only establish a clear speedup for the conversion step.Synthetic audio only. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch benchmark and drafted this report.
@DavidM1911 on GitHub · 2026-11-24 14:02 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
@DavidM1911 on GitHub · 2026-11-26 04:32 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.