aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2024-01-22 00:42:28 +0800
committerJia Tan <jiat0218@gmail.com>2024-02-01 20:09:11 +0800
commit61908e816049af7a9f43ea804a57ee8570e2e644 (patch)
treebec4861cf6e1686939cbedf05bca63525f5cc1dd
parentBuild: Add support for ARM64 CRC32 instruction detection. (diff)
downloadxz-61908e816049af7a9f43ea804a57ee8570e2e644.tar.xz
CMake: Add support for ARM64 CRC32 instruction detection.
-rw-r--r--CMakeLists.txt50
1 files changed, 50 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0cb08fc7..b21090f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1007,6 +1007,56 @@ calculation if supported by the system" ON)
endif()
endif()
+# 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.
+option(ALLOW_ARM64_CRC32 "Allow ARM64 CRC32 instruction if supported by \
+the system" ON)
+
+if(ALLOW_ARM64_CRC32)
+ check_c_source_compiles("
+ #include <stdint.h>
+
+ #ifndef _MSC_VER
+ #include <arm_acle.h>
+ #endif
+
+ #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);
+ }
+ int main(void) { return 0; }
+ "
+ HAVE_ARM64_CRC32)
+
+ if(HAVE_ARM64_CRC32)
+ target_compile_definitions(liblzma PRIVATE HAVE_ARM64_CRC32)
+
+ # Check for ARM64 CRC32 instruction runtime detection.
+ # getauxval() is supported on Linux.
+ check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL)
+ tuklib_add_definition_if(liblzma HAVE_GETAUXVAL)
+
+ # elf_aux_info() is supported on FreeBSD.
+ check_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
+ tuklib_add_definition_if(liblzma HAVE_ELF_AUX_INFO)
+
+ # 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", ...).
+ check_symbol_exists(sysctlbyname sys/sysctl.h HAVE_SYSCTLBYNAME)
+ tuklib_add_definition_if(liblzma HAVE_SYSCTLBYNAME)
+ endif()
+endif()
+
+
# Support -fvisiblity=hidden when building shared liblzma.
# These lines do nothing on Windows (even under Cygwin).
# HAVE_VISIBILITY should always be defined to 0 or 1.