diff --git a/libcperciva/cpusupport/Build/cpusupport-X86-SSE2.c b/libcperciva/cpusupport/Build/cpusupport-X86-SSE2.c new file mode 100644 index 00000000..0a5ad6ca --- /dev/null +++ b/libcperciva/cpusupport/Build/cpusupport-X86-SSE2.c @@ -0,0 +1,12 @@ +#include + +static char a[16]; + +int main(void) +{ + __m128i x; + + x = _mm_loadu_si128((__m128i *)a); + _mm_storeu_si128((__m128i *)a, x); + return (a[0]); +} diff --git a/libcperciva/cpusupport/Build/cpusupport.sh b/libcperciva/cpusupport/Build/cpusupport.sh index ca0e0152..663a7cfc 100644 --- a/libcperciva/cpusupport/Build/cpusupport.sh +++ b/libcperciva/cpusupport/Build/cpusupport.sh @@ -34,4 +34,5 @@ feature() { } feature X86 CPUID "" +feature X86 SSE2 "" "-msse2" "-msse2 -Wno-cast-align" feature X86 AESNI "" "-maes" "-maes -Wno-cast-align" "-maes -Wno-missing-prototypes -Wno-cast-qual" diff --git a/libcperciva/cpusupport/cpusupport.h b/libcperciva/cpusupport/cpusupport.h index b2a6eb41..36d3a07c 100644 --- a/libcperciva/cpusupport/cpusupport.h +++ b/libcperciva/cpusupport/cpusupport.h @@ -59,5 +59,6 @@ * from this list so that the associated C files can be omitted. */ CPUSUPPORT_FEATURE(x86, aesni); +CPUSUPPORT_FEATURE(x86, sse2); #endif /* !_CPUSUPPORT_H_ */ diff --git a/libcperciva/cpusupport/cpusupport_x86_sse2.c b/libcperciva/cpusupport/cpusupport_x86_sse2.c new file mode 100644 index 00000000..848bcf97 --- /dev/null +++ b/libcperciva/cpusupport/cpusupport_x86_sse2.c @@ -0,0 +1,30 @@ +#include "cpusupport.h" + +#ifdef CPUSUPPORT_X86_CPUID +#include +#endif + +#define CPUID_SSE2_BIT (1 << 26) + +CPUSUPPORT_FEATURE_DECL(x86, sse2) +{ +#ifdef CPUSUPPORT_X86_CPUID + unsigned int eax, ebx, ecx, edx; + + /* Check if CPUID supports the level we need. */ + if (!__get_cpuid(0, &eax, &ebx, &ecx, &edx)) + goto unsupported; + if (eax < 1) + goto unsupported; + + /* Ask about CPU features. */ + if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx)) + goto unsupported; + + /* Return the relevant feature bit. */ + return (edx & CPUID_SSE2_BIT); + +unsupported: +#endif + return (0); +}