Skip to content

Keep opus's runtime dispatch on x86_64 instead of presuming AVX2 - #7

Merged
andrewchen5678 merged 1 commit into
mainfrom
fix/x86-64-runtime-dispatch
Sep 2, 2026
Merged

andrewchen5678 merged 1 commit into
mainfrom
fix/x86-64-runtime-dispatch

Conversation

@andrewchen5678

Copy link
Copy Markdown
Contributor

The x86_64 archives presumed AVX2 (dispatch compiled out, -march=x86-64-v3), so a binary linking them SIGILLs on any CPU without AVX2. They now use opus's upstream default: SSE4.1 and AVX2 kernels compiled per file and selected by CPUID at run time. Measured cost on an i5-8500T: 0.73% of a core against 0.65% for 48 kHz stereo encode. build.sh verifies the dispatch build: MAY_HAVE on, PRESUME off, opus_select_arch present, and no AVX2/FMA instruction outside a *_avx2 kernel.

🤖 Generated with Claude Code

https://claude.ai/code/session_012Ly7cjta1J2gLEHdiyHX9S

The linux-x86_64 and windows-x86_64-msvc archives were built with
OPUS_X86_PRESUME_AVX2 and -march=x86-64-v3, which compiled the CPUID
dispatch out and spread AVX2 and FMA through 172 functions that are not
kernels. A binary linking them died on the first vfmadd on an Ivy Bridge
i5-3210M. Both targets now build with opus's own default: the SSE4.1 and
AVX2 kernels compiled per file and selected by opus_select_arch() at run
time, so a Coffee Lake keeps its AVX2 NSQ and pitch kernels and anything
without AVX2 runs the SSE4.1 ones.

Measured on an i5-8500T, 60 s of 48 kHz stereo at complexity 5: 0.65% of
a core with the floor, 0.73% without, identical output bytes. That is the
whole price, and the consuming project chose it over a second archive.

The floor verification gains a dispatch arm: MAY_HAVE on and PRESUME off in
the cmake cache, opus_select_arch present in the archive, and no AVX2 or
FMA instruction in any function not named *_avx2 — the property a global
-march would break. The symbol check counts rather than grep -q, because
under pipefail -q closing the pipe on its first match kills nm.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Ly7cjta1J2gLEHdiyHX9S
@andrewchen5678
andrewchen5678 merged commit 488bdb1 into main Sep 2, 2026
4 of 5 checks passed
@andrewchen5678
andrewchen5678 deleted the fix/x86-64-runtime-dispatch branch September 2, 2026 16:53
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.

1 participant