XAudio2: vectorize acphal i16-to-f32 PCM conversion with runtime AVX2 #1230
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by real-alponzo on 2026-11-24T13:36:17Z.
Vectorizes 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.Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-24T13:47:00Z.
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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T14:02:01Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
upstream-sync referenced this pull request2026-11-25 04:08:41 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:32:25Z.
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
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:31:32Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:12:43Z.
Triage (#1607) – head
ae27c9eNo open or merged PR vectorizes this conversion; #884 (same issue #459) changes the XMA2 bit reservoir, unrelated code.
convert_i16_to_f32_avx2matches the scalar loop it replaces indecode_into(multiply by 1/32768 is exact, the length is the shorter slice, the zero count is per lane), and the test compares all 65 536 values and the tails bit for bit.The loop runs once per Opus frame (about 960 samples per channel) next to the Opus decode itself; the diff has no measurement showing the conversion costs anything noticeable.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.