Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

carenas
Copy link
Contributor

@carenas carenas commented Jul 3, 2024

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)

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;
Copy link
Owner

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?

Copy link
Contributor Author

@carenas carenas Jul 5, 2024

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.

Copy link
Owner

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)))
Copy link
Contributor Author

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.

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.

2 participants