]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add AArch64 feature detection support for OpenBSD
authorBrad Smith <brad@comstyle.com>
Wed, 22 May 2024 23:11:05 +0000 (19:11 -0400)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 25 May 2024 20:05:38 +0000 (22:05 +0200)
arch/arm/arm_features.c

index 247ed027dd8786c8517ea72681612da3de3d0748..d0d49764f4e5d7cba41fe5e492a9d5e10aaeaa02 100644 (file)
 #  ifndef ID_AA64ISAR0_CRC32_VAL
 #    define ID_AA64ISAR0_CRC32_VAL ID_AA64ISAR0_CRC32
 #  endif
+#elif defined(__OpenBSD__) && defined(__aarch64__)
+#  include <machine/armreg.h>
+#  include <machine/cpu.h>
+#  include <sys/sysctl.h>
+#  include <sys/types.h>
 #elif defined(__APPLE__)
 #  if !defined(_DARWIN_C_SOURCE)
 #    define _DARWIN_C_SOURCE /* enable types aliases (eg u_int) */
@@ -30,6 +35,16 @@ static int arm_has_crc32() {
 #elif defined(__FreeBSD__) && defined(__aarch64__)
     return getenv("QEMU_EMULATING") == NULL
       && ID_AA64ISAR0_CRC32_VAL(READ_SPECIALREG(id_aa64isar0_el1)) >= ID_AA64ISAR0_CRC32_BASE;
+#elif defined(__OpenBSD__) && defined(__aarch64__)
+    int hascrc32 = 0;
+    int isar0_mib[] = { CTL_MACHDEP, CPU_ID_AA64ISAR0 };
+    uint64_t isar0 = 0;
+    size_t len = sizeof(isar0);
+    if (sysctl(isar0_mib, 2, &isar0, &len, NULL, 0) != -1) {
+      if (ID_AA64ISAR0_CRC32(isar0) >= ID_AA64ISAR0_CRC32_BASE)
+          hascrc32 = 1;
+    }
+    return hascrc32;
 #elif defined(__APPLE__)
     int hascrc32;
     size_t size = sizeof(hascrc32);