Skip to content

Commit 198a0b9

Browse files
committed
Disable HACL SIMD code on older versions of Android
1 parent 342e654 commit 198a0b9

File tree

2 files changed

+86
-66
lines changed

2 files changed

+86
-66
lines changed

configure

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

configure.ac

+47-37
Original file line numberDiff line numberDiff line change
@@ -7810,47 +7810,57 @@ case "$ac_sys_system" in
78107810
esac
78117811
AC_SUBST([LIBHACL_CFLAGS])
78127812

7813-
dnl This can be extended here to detect e.g. Power8, which HACL* should also support.
7814-
AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[
7815-
[LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"]
7816-
7817-
AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
7818-
7819-
# macOS universal2 builds *support* the -msse etc flags because they're
7820-
# available on x86_64. However, performance of the HACL SIMD128 implementation
7821-
# isn't great, so it's disabled on ARM64.
7822-
AC_MSG_CHECKING([for HACL* SIMD128 implementation])
7823-
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7824-
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"]
7825-
AC_MSG_RESULT([universal2])
7826-
else
7827-
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"]
7828-
AC_MSG_RESULT([standard])
7829-
fi
7830-
7831-
], [], [-Werror])
7813+
# The SIMD files use aligned_alloc, which is not available on older versions of
7814+
# Android.
7815+
if test "$ac_sys_system" != "Linux-android" || test "$ANDROID_API_LEVEL" -ge 28; then
7816+
dnl This can be extended here to detect e.g. Power8, which HACL* should also support.
7817+
AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[
7818+
[LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"]
7819+
7820+
AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
7821+
7822+
# macOS universal2 builds *support* the -msse etc flags because they're
7823+
# available on x86_64. However, performance of the HACL SIMD128 implementation
7824+
# isn't great, so it's disabled on ARM64.
7825+
AC_MSG_CHECKING([for HACL* SIMD128 implementation])
7826+
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7827+
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"]
7828+
AC_MSG_RESULT([universal2])
7829+
else
7830+
[LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"]
7831+
AC_MSG_RESULT([standard])
7832+
fi
78327833
7834+
], [], [-Werror])
7835+
fi
78337836
AC_SUBST([LIBHACL_SIMD128_FLAGS])
78347837
AC_SUBST([LIBHACL_SIMD128_OBJS])
78357838

7836-
AX_CHECK_COMPILE_FLAG([-mavx2],[
7837-
[LIBHACL_SIMD256_FLAGS="-mavx2"]
7838-
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
7839-
7840-
# macOS universal2 builds *support* the -mavx2 compiler flag because it's
7841-
# available on x86_64; but the HACL SIMD256 build then fails because the
7842-
# implementation requires symbols that aren't available on ARM64. Use a
7843-
# wrapped implementation if we're building for universal2.
7844-
AC_MSG_CHECKING([for HACL* SIMD256 implementation])
7845-
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7846-
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"]
7847-
AC_MSG_RESULT([universal2])
7848-
else
7849-
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"]
7850-
AC_MSG_RESULT([standard])
7851-
fi
7852-
], [], [-Werror])
7853-
7839+
# The SIMD files use aligned_alloc, which is not available on older versions of
7840+
# Android.
7841+
#
7842+
# Although AVX support is not guaranteed on Android
7843+
# (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a
7844+
# runtime CPUID check.
7845+
if test "$ac_sys_system" != "Linux-android" || test "$ANDROID_API_LEVEL" -ge 28; then
7846+
AX_CHECK_COMPILE_FLAG([-mavx2],[
7847+
[LIBHACL_SIMD256_FLAGS="-mavx2"]
7848+
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
7849+
7850+
# macOS universal2 builds *support* the -mavx2 compiler flag because it's
7851+
# available on x86_64; but the HACL SIMD256 build then fails because the
7852+
# implementation requires symbols that aren't available on ARM64. Use a
7853+
# wrapped implementation if we're building for universal2.
7854+
AC_MSG_CHECKING([for HACL* SIMD256 implementation])
7855+
if test "$UNIVERSAL_ARCHS" == "universal2"; then
7856+
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"]
7857+
AC_MSG_RESULT([universal2])
7858+
else
7859+
[LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"]
7860+
AC_MSG_RESULT([standard])
7861+
fi
7862+
], [], [-Werror])
7863+
fi
78547864
AC_SUBST([LIBHACL_SIMD256_FLAGS])
78557865
AC_SUBST([LIBHACL_SIMD256_OBJS])
78567866

0 commit comments

Comments
 (0)