Skip to content

Commit fa677f1

Browse files
James R. Barlowstweil
James R. Barlow
authored andcommitted
Implement SIMD detection on macOS-gcc; complain if no SIMD detection
Change SIMD detection to instead check for compilers with __get_cpuid. Verified that this compiles and runs on macOS El Capitan with homebrew gcc. Also added an #error if SIMD checking is missing. Compilers that have no SIMD should make that explicit. [sw: Merged original commits and slightly polished the commit message] [sw: Removed test for __MINGW32__ which is no longer needed] Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent c768b58 commit fa677f1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/simddetect.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#endif // x86 target
2727

2828
#if defined(X86_BUILD)
29-
# if defined(__linux__) || defined(__MINGW32__)
29+
# if defined(__GNUC__)
3030
# include <cpuid.h>
3131
# elif defined(_WIN32)
3232
# include <intrin.h>
@@ -43,9 +43,10 @@ bool SIMDDetect::sse_available_;
4343
// Constructor.
4444
// Tests the architecture in a system-dependent way to detect AVX, SSE and
4545
// any other available SIMD equipment.
46+
// __GNUC__ is also defined by compilers that include GNU extensions such as clang.
4647
SIMDDetect::SIMDDetect() {
4748
#if defined(X86_BUILD)
48-
# if defined(__linux__) || defined(__MINGW32__)
49+
# if defined(__GNUC__)
4950
unsigned int eax, ebx, ecx, edx;
5051
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) != 0) {
5152
sse_available_ = (ecx & 0x00080000) != 0;
@@ -59,6 +60,8 @@ SIMDDetect::SIMDDetect() {
5960
sse_available_ = (cpuInfo[2] & 0x00080000) != 0;
6061
avx_available_ = (cpuInfo[2] & 0x10000000) != 0;
6162
}
63+
# else
64+
# error "I don't know how to test for SIMD with this compiler"
6265
# endif
6366
#endif // X86_BUILD
6467
}

0 commit comments

Comments
 (0)