From 4ea26f0b8cdf9dfbf8b1fb832f56e92833fc2e8f Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 9 May 2014 20:26:43 -0700 Subject: [PATCH] Stricter autoconf checks for MMX/SSE2/SSE3 --- configure.ac | 32 +++++++++++++++++-- .../sse/pwhash_scryptxsalsa208sha256_sse.c | 8 ++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index d56a3717..9794f169 100644 --- a/configure.ac +++ b/configure.ac @@ -243,9 +243,35 @@ AC_CHECK_TOOL([AR], [ar], [ar]) dnl Checks for headers AS_IF([test "x$EMSCRIPTEN" = "x"],[ - AC_CHECK_HEADERS([mmintrin.h], [], [], [#pragma GCC target("mmx")]) - AC_CHECK_HEADERS([emmintrin.h], [], [], [#pragma GCC target("sse2")]) - AC_CHECK_HEADERS([pmmintrin.h], [], [], [#pragma GCC target("sse3")]) + + AC_MSG_CHECKING(for MMX instructions set) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#pragma GCC target("mmx") +#include +]], [[ __m64 x = _mm_setzero_si64(); ]])], + [AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_MMINTRIN_H], [1], [mmx is available])], + [AC_MSG_RESULT(no)]) + + AC_MSG_CHECKING(for SSE2 instructions set) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#pragma GCC target("sse2") +#include +]], [[ __m128d x = _mm_setzero_pd(); ]])], + [AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_EMMINTRIN_H], [1], [sse2 is available])], + [AC_MSG_RESULT(no)]) + + AC_MSG_CHECKING(for SSE3 instructions set) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#pragma GCC target("sse3") +#include +]], [[ __m128 x = _mm_addsub_ps(_mm_cvtpd_ps(_mm_setzero_pd()), + _mm_cvtpd_ps(_mm_setzero_pd())); ]])], + [AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_PMMINTRIN_H], [1], [sse3 is available])], + [AC_MSG_RESULT(no)]) + ]) AC_CHECK_HEADERS([sys/mman.h]) diff --git a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256_sse.c b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256_sse.c index a471e6c4..d340dd05 100644 --- a/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256_sse.c +++ b/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256_sse.c @@ -29,12 +29,12 @@ */ #if defined(HAVE_EMMINTRIN_H) || defined(_MSC_VER) -# if __GNUC__ -# pragma GCC target("sse2") -# endif +#if __GNUC__ +# pragma GCC target("sse2") +#endif #include #if defined(__XOP__) && defined(DISABLED) -#include +# include #endif #include