Skip to content

Commit 055a86b

Browse files
committed
Check availability of Intel SIMD types
blake2module.c includes headers that use SIMD typedefs if an SIMD implementation will be built, but must not itself be compiled with the -m options that enable SIMD instructions. However, the *mminintrin headers are not always usable to get those typedefs if the corresponding -m option is not used.
1 parent 7380186 commit 055a86b

File tree

2 files changed

+133
-61
lines changed

2 files changed

+133
-61
lines changed

configure

+81-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+52-34
Original file line numberDiff line numberDiff line change
@@ -7847,24 +7847,34 @@ AC_SUBST([LIBHACL_CFLAGS])
78477847
# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI.
78487848
if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then
78497849
dnl This can be extended here to detect e.g. Power8, which HACL* should also support.
7850-
AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[
7851-
[LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"]
7852-
7853-
AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
7854-
7855-
# macOS universal2 builds *support* the -msse etc flags because they're
7856-
# available on x86_64. However, performance of the HACL SIMD128 implementation
7857-
# isn't great, so it's disabled on ARM64.
7858-
AC_MSG_CHECKING([for HACL* SIMD128 implementation])
7859-
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7860-
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"]
7861-
AC_MSG_RESULT([universal2])
7862-
else
7863-
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"]
7864-
AC_MSG_RESULT([standard])
7865-
fi
7850+
# Older versions of the mmintrin headers shipped with clang may error if they are
7851+
# included without using the corresponding -msse* option. See GH issue #130213.
7852+
AC_MSG_CHECKING([if __m128i can be used without -msse*])
7853+
AC_COMPILE_IFELSE(
7854+
[AC_LANG_PROGRAM([#include <emmintrin.h>
7855+
#include <tmmintrin.h>
7856+
#include <smmintrin.h>],
7857+
[__m128i testvar;])],
7858+
[AC_MSG_RESULT([yes])
7859+
AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[
7860+
[LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"]
7861+
7862+
AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
7863+
7864+
# macOS universal2 builds *support* the -msse etc flags because they're
7865+
# available on x86_64. However, performance of the HACL SIMD128 implementation
7866+
# isn't great, so it's disabled on ARM64.
7867+
AC_MSG_CHECKING([for HACL* SIMD128 implementation])
7868+
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7869+
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"]
7870+
AC_MSG_RESULT([universal2])
7871+
else
7872+
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"]
7873+
AC_MSG_RESULT([standard])
7874+
fi
78667875
7867-
], [], [-Werror])
7876+
], [], [-Werror])
7877+
], [AC_MSG_RESULT([no])])
78687878
fi
78697879
AC_SUBST([LIBHACL_SIMD128_FLAGS])
78707880
AC_SUBST([LIBHACL_SIMD128_OBJS])
@@ -7877,23 +7887,31 @@ AC_SUBST([LIBHACL_SIMD128_OBJS])
78777887
# (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a
78787888
# runtime CPUID check.
78797889
if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then
7880-
AX_CHECK_COMPILE_FLAG([-mavx2],[
7881-
[LIBHACL_SIMD256_FLAGS="-mavx2"]
7882-
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
7883-
7884-
# macOS universal2 builds *support* the -mavx2 compiler flag because it's
7885-
# available on x86_64; but the HACL SIMD256 build then fails because the
7886-
# implementation requires symbols that aren't available on ARM64. Use a
7887-
# wrapped implementation if we're building for universal2.
7888-
AC_MSG_CHECKING([for HACL* SIMD256 implementation])
7889-
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7890-
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"]
7891-
AC_MSG_RESULT([universal2])
7892-
else
7893-
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"]
7894-
AC_MSG_RESULT([standard])
7895-
fi
7896-
], [], [-Werror])
7890+
# Some versions of immintrin.h may not provide the __m256i type if no -mavx*
7891+
# option is used. See GH issue #130213.
7892+
AC_MSG_CHECKING([if __m256i can be used without -mavx2])
7893+
AC_COMPILE_IFELSE(
7894+
[AC_LANG_PROGRAM([#include <immintrin.h>],
7895+
[__m256i testvar;])],
7896+
[AC_MSG_RESULT([yes])
7897+
AX_CHECK_COMPILE_FLAG([-mavx2],[
7898+
[LIBHACL_SIMD256_FLAGS="-mavx2"]
7899+
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
7900+
7901+
# macOS universal2 builds *support* the -mavx2 compiler flag because it's
7902+
# available on x86_64; but the HACL SIMD256 build then fails because the
7903+
# implementation requires symbols that aren't available on ARM64. Use a
7904+
# wrapped implementation if we're building for universal2.
7905+
AC_MSG_CHECKING([for HACL* SIMD256 implementation])
7906+
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7907+
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"]
7908+
AC_MSG_RESULT([universal2])
7909+
else
7910+
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"]
7911+
AC_MSG_RESULT([standard])
7912+
fi
7913+
], [], [-Werror])
7914+
], [AC_MSG_RESULT([no])])
78977915
fi
78987916
AC_SUBST([LIBHACL_SIMD256_FLAGS])
78997917
AC_SUBST([LIBHACL_SIMD256_OBJS])

0 commit comments

Comments
 (0)