diff --git a/configure.ac b/configure.ac index bb2697f6..d2fa730c 100644 --- a/configure.ac +++ b/configure.ac @@ -380,6 +380,16 @@ AC_ARG_ENABLE([clmul-crc], AS_HELP_STRING([--disable-clmul-crc], [], [enable_clmul_crc=yes]) +############################ +# ARM64 CRC32 Instructions # +############################ + +AC_ARG_ENABLE([arm64-crc32], AS_HELP_STRING([--disable-arm64-crc32], + [Do not use ARM64 CRC32 instructions even if support for it + is detected.]), + [], [enable_arm64_crc32=yes]) + + ##################### # Size optimization # ##################### @@ -1087,6 +1097,48 @@ __m128i my_clmul(__m128i a) AC_MSG_RESULT([$enable_clmul_crc]) ]) +# ARM64 C Language Extensions define CRC32 functions in arm_acle.h. +# These are supported by at least GCC and Clang which both need +# __attribute__((__target__("+crc"))), unless the needed compiler flags +# are used to support the CRC instruction. +AC_MSG_CHECKING([if ARM64 CRC32 instruction is usable]) +AS_IF([test "x$enable_arm64_crc32" = xno], [ + AC_MSG_RESULT([no, --disable-arm64-crc32 was used]) +], [ + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +#include +#include + +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__) +__attribute__((__target__("+crc"))) +#endif +uint32_t my_crc(uint32_t a, uint64_t b) +{ + return __crc32d(a, b); +} + ]])], [ + AC_DEFINE([HAVE_ARM64_CRC32], [1], + [Define to 1 if ARM64 CRC32 instruction is supported. + See configure.ac for details.]) + enable_arm64_crc32=yes + ], [ + enable_arm64_crc32=no + ]) + AC_MSG_RESULT([$enable_arm64_crc32]) +]) + +# Check for ARM64 CRC32 instruction runtime detection. +# getauxval() is supported on Linux, elf_aux_info() on FreeBSD, and +# sysctlbyname("hw.optional.armv8_crc32", ...) is supported on Darwin +# (macOS, iOS, etc.). Note that sysctlbyname() is supported on FreeBSD, +# NetBSD, and possibly others too but the string is specific to Apple OSes. +# The C code is responsible for checking defined(__APPLE__) before using +# sysctlbyname("hw.optional.armv8_crc32", ...). +AS_IF([test "x$enable_arm64_crc32" = xyes], [ + AC_CHECK_FUNCS([getauxval elf_aux_info sysctlbyname]) +]) + + # Check for sandbox support. If one is found, set enable_sandbox=found. # # About -fsanitize: Of our three sandbox methods, only Landlock is