-
Notifications
You must be signed in to change notification settings - Fork 75
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
x86: improve SIMD detection #257
base: master
Are you sure you want to change the base?
Conversation
Since 56dbde0 (Add xgetbv feature detection support on x86, 2024-03-23), AVX support can be "rescinded" if it has been partially disabled, but the check added didn't include the possibility that OSXSAVE could be also disabled (ex: using the `noxsave` kernel parameter in Linux). Correct that and while at it, add a similar check for SSE2 (only relevant in 32bit) and for the possibility that if not enabled (ex: the OS never set CR4.OSFXSR), then SSE41 support should also be rescinded.
if ((feature_list & CPU_FEATURE_OSXSAVE) && (execute_get_xcr0_low() & 0x4) == 0) | ||
#if defined(SLJIT_CONFIG_X86_32) && SLJIT_CONFIG_X86_32 | ||
if (!(feature_list & CPU_FEATURE_SSE2)) | ||
feature_list &= ~(sljit_u32)CPU_FEATURE_SSE41; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who sets this? Does the compiler runs on that old hardware?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like AVX2; SSE2 also needs OS support, which could be missing (ex: Debian 3).
When gcc
targets a CPU with SSE2 it defines __SSE2__
just like MSVC does with _M_IX86_FP
Note that in this case, if saving of the XMM registers is not supported, any operation that uses them will SIGILL, hence why this code disables SSE41 (hence SIMD) in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question was how is it possible to set SSE4.1 without setting SSE2. I always worry that we accidentally disables features for newer systems.
if (info[3] & 0x8000) | ||
feature_list |= CPU_FEATURE_CMOV; | ||
#if (defined(SLJIT_DETECT_SSE2) && SLJIT_DETECT_SSE2) \ | ||
&& (defined(__SSE2__) || (defined(_WIN64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will disable SSE2 with SUNPRO, TINYC or other compilers than won't provide the defines.
Avoid SIGILL when AVX has been disabled by removing OSXSAVE, as well as when SSE2 is not enabled (most likely by running a really old OS in modern hardware)