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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions sljit_src/sljitNativeX86_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,13 @@ static void get_cpu_features(void)
feature_list |= CPU_FEATURE_OSXSAVE;
if (info[2] & 0x10000000)
feature_list |= CPU_FEATURE_AVX;
#if (defined SLJIT_DETECT_SSE2 && SLJIT_DETECT_SSE2)
if (info[3] & 0x4000000)
feature_list |= CPU_FEATURE_SSE2;
#endif
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.

if ((info[3] & 0x5000000) == 0x5000000)
feature_list |= CPU_FEATURE_SSE2;
#endif
}

info[0] = 0x80000000;
Expand All @@ -592,7 +593,11 @@ static void get_cpu_features(void)
feature_list |= CPU_FEATURE_LZCNT;
}

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.

#endif
if (!(feature_list & CPU_FEATURE_OSXSAVE) || (execute_get_xcr0_low() & 0x4) == 0)
feature_list &= ~(sljit_u32)(CPU_FEATURE_AVX | CPU_FEATURE_AVX2);

cpu_feature_list = feature_list;
Expand Down