]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Add ARM64 CRC32 instruction support detection on OpenBSD
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 7 Jun 2024 12:06:59 +0000 (15:06 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 7 Jun 2024 12:06:59 +0000 (15:06 +0300)
The C code is from Christian Weisgerber, I merely reordered the OSes.
Then I added the build system checks without testing them.

Also thanks to Brad Smith who submitted a similar patch on GitHub
a few hours after Christian had sent his via email.

Co-authored-by: Christian Weisgerber <naddy@mips.inka.de>
Closes: https://github.com/tukaani-project/xz/pull/125
CMakeLists.txt
configure.ac
src/liblzma/check/crc32_arm64.h
src/liblzma/check/crc_common.h

index ac3e45bf6eb1ec66747dbbffb1943e136b8e6acc..ab5bba723ce086175efa3e6fef23e86690cac4f3 100644 (file)
@@ -1220,6 +1220,12 @@ if(ALLOW_ARM64_CRC32)
         check_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
         tuklib_add_definition_if(liblzma HAVE_ELF_AUX_INFO)
 
+        # OpenBSD has a sysctl() based method. The macro CPU_ID_AA64ISAR0
+        # is used to detect when it's available.
+        check_symbol_exists(CPU_ID_AA64ISAR0 machine/cpu.h
+                            HAVE_CPU_ID_AA64ISAR0)
+        tuklib_add_definition_if(liblzma HAVE_CPU_ID_AA64ISAR0)
+
         # 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
index 57831048536057bc9125591d80fc9a49d037204b..74e7c53806c3ee0bc2c7aee2293f7c922e9b27fd 100644 (file)
@@ -1088,14 +1088,23 @@ uint32_t my_crc(uint32_t a, uint64_t b)
 ])
 
 # 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", ...).
+#
+# sysctl() with CPU_ID_AA64ISAR0 is used on OpenBSD.
 AS_IF([test "x$enable_arm64_crc32" = xyes], [
        AC_CHECK_FUNCS([getauxval elf_aux_info sysctlbyname], [break])
+       AC_CHECK_DECL([CPU_ID_AA64ISAR0],
+               [AC_DEFINE([HAVE_CPU_ID_AA64ISAR0], [1],
+                       [Define to 1 if CPU_ID_AA64ISAR0 is defined
+                       in <machine/cpu.h>.])],
+               [],
+               [#include <machine/cpu.h>])
 ])
 
 
index 39c1c63ec0eced25ad5042e1611ecd8064831d8d..5bad0e005d20fe680a4e4388e3c96a4ae2658c53 100644 (file)
 #if defined(CRC32_GENERIC) && defined(CRC32_ARCH_OPTIMIZED)
 #      if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
 #              include <sys/auxv.h>
+#      elif defined(HAVE_CPU_ID_AA64ISAR0)
+#              include <sys/types.h>
+#              include <sys/sysctl.h>
+#              include <machine/cpu.h>
+#              include <machine/armreg.h>
 #      elif defined(_WIN32)
 #              include <processthreadsapi.h>
 #      elif defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME)
@@ -89,6 +94,16 @@ is_arch_extension_supported(void)
 
        return (feature_flags & HWCAP_CRC32) != 0;
 
+#elif defined(HAVE_CPU_ID_AA64ISAR0)
+       const int isar0_mib[] = { CTL_MACHDEP, CPU_ID_AA64ISAR0 };
+       uint64_t isar0;
+       size_t len = sizeof(isar0);
+
+       if (sysctl(isar0_mib, 2, &isar0, &len, NULL, 0) == -1)
+               return false;
+
+       return ID_AA64ISAR0_CRC32(isar0) >= ID_AA64ISAR0_CRC32_BASE;
+
 #elif defined(_WIN32)
        return IsProcessorFeaturePresent(
                        PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
index 63a7b5cefebffc506dc54a6378134008ead3c806..1adf1474ef4c69932243504c048029c5ef0eed48 100644 (file)
@@ -50,6 +50,7 @@
 // Keep this in sync with changes to crc32_arm64.h
 #if defined(_WIN32) || defined(HAVE_GETAUXVAL) \
                || defined(HAVE_ELF_AUX_INFO) \
+               || defined(HAVE_CPU_ID_AA64ISAR0) \
                || (defined(__APPLE__) && defined(HAVE_SYSCTLBYNAME))
 #      define ARM64_RUNTIME_DETECTION 1
 #endif