diff options
author | Jia Tan <jiat0218@gmail.com> | 2024-01-22 00:36:47 +0800 |
---|---|---|
committer | Jia Tan <jiat0218@gmail.com> | 2024-02-01 20:09:09 +0800 |
commit | c5f6d79cc9515a7f22d7ea4860c6cc394b295732 (patch) | |
tree | 71e9a092712aeaa3e172cabb56a13362abfbf075 /configure.ac | |
parent | Speed up CRC32 calculation on ARM64 (diff) | |
download | xz-c5f6d79cc9515a7f22d7ea4860c6cc394b295732.tar.xz |
Build: Add support for ARM64 CRC32 instruction detection.
This adds --enable-arm64-crc32/--disable-arm64-crc32 (enabled by
default) for using the ARM64 CRC32 instruction. This can be disabled if
one knows the binary will never need to run on an ARM64 machine
with this instruction extension.
Diffstat (limited to '')
-rw-r--r-- | configure.ac | 52 |
1 files changed, 52 insertions, 0 deletions
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 <arm_acle.h> +#include <stdint.h> + +#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 |