Skip to content

Support for dynamic AVX2 dispatch to avoid SIGILL on non-AVX2 CPUs #3875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Laky-64 opened this issue May 3, 2025 · 0 comments
Open

Support for dynamic AVX2 dispatch to avoid SIGILL on non-AVX2 CPUs #3875

Laky-64 opened this issue May 3, 2025 · 0 comments

Comments

@Laky-64
Copy link

Laky-64 commented May 3, 2025

Hi,

I'd like to ask whether there is any plan or known way to support dynamic dispatch of AVX2 code paths in OpenH264.

Currently, when OpenH264 is built with "HAVE_AVX2", it seems that AVX2 instructions are embedded directly into the binary. As a result, attempting to load or use the library on CPUs that do not support AVX2 results in an illegal instruction crash (SIGILL), even if the code that uses AVX2 is not explicitly executed.

I’ve noticed that OpenH264 already includes runtime CPU feature detection via WelsCPUFeatureDetect, which correctly detects AVX2 availability. However, this doesn’t prevent issues when AVX2 instructions are present in the binary and accidentally executed (e.g., via function pointer assignment, or even indirectly).

Would it be possible to refactor the AVX2-accelerated paths into separate functions and use a runtime dispatch mechanism, similar to how some libraries (e.g., x264, libjpeg-turbo, or libvpx) manage this?

This would allow:

Building one universal .so (or .dll) with all SIMD variants included.

Avoiding SIGILL crashes on older CPUs.

Keeping high performance where supported.

Logs

0x00007fffe4b0b3b9 in WelsLog(TagLogContext*, int, char const*, ...) () from /home/laky64/CLionProjects/ntgcalls/tests/venv/lib64/python3.13/site-packages/ntgcalls.cpython-313-x86_64-linux-gnu.so
(gdb) bt
#0  0x00007fffe4b0b3b9 in WelsLog(TagLogContext*, int, char const*, ...) () from /home/laky64/CLionProjects/ntgcalls/tests/venv/lib64/python3.13/site-packages/ntgcalls.cpython-313-x86_64-linux-gnu.so
#1  0x00007fffe4b08d54 in WelsEnc::CWelsH264SVCEncoder::InitializeExt(TagEncParamExt const*) () from /home/laky64/CLionProjects/ntgcalls/tests/venv/lib64/python3.13/site-packages/ntgcalls.cpython-313-x86_64-linux-gnu.so
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

No branches or pull requests

1 participant