Skip to content

Commit 41e7992

Browse files
authored
gh-99108: Disable HACL SIMD code on older versions of Android (#124304)
Disable HACL SIMD code on older versions of Android
1 parent 7ee9921 commit 41e7992

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
@@ -7817,47 +7817,57 @@ case "$ac_sys_system" in
78177817
esac
78187818
AC_SUBST([LIBHACL_CFLAGS])
78197819

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

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

0 commit comments

Comments
 (0)