- aarch64: Simplify the linux runtime cpu detection code
  f05948ada435d95fed3cc9279cec0ccef8a10a2c
- aarch64: Use regular hwcaps flags instead of HWCAP_CPUID for CPU feature detection on Linux
  e30369bc1c683aeab6ea74bc37b4ae77b03f79b5
- avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul()
  fe4b9ef69f10df2424e22cc8a1a63848c0857460
- aarch64: Implement support for elf_aux_info(3) on FreeBSD and OpenBSD
  a3f79fd22a367207097c78e0a5d2bc213efe9f80

Index: libavutil/aarch64/cpu.c
--- libavutil/aarch64/cpu.c.orig
+++ libavutil/aarch64/cpu.c
@@ -20,42 +20,24 @@
 #include "libavutil/cpu_internal.h"
 #include "config.h"
 
-#if (defined(__linux__) || defined(__ANDROID__)) && HAVE_GETAUXVAL
+#if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
 #include <stdint.h>
 #include <sys/auxv.h>
 
-#define get_cpu_feature_reg(reg, val) \
-        __asm__("mrs %0, " #reg : "=r" (val))
+#define HWCAP_AARCH64_ASIMDDP (1 << 20)
+#define HWCAP2_AARCH64_I8MM   (1 << 13)
 
 static int detect_flags(void)
 {
     int flags = 0;
-    unsigned long hwcap;
 
-    hwcap = getauxval(AT_HWCAP);
+    unsigned long hwcap = ff_getauxval(AT_HWCAP);
+    unsigned long hwcap2 = ff_getauxval(AT_HWCAP2);
 
-#if defined(HWCAP_CPUID)
-    // We can check for DOTPROD and I8MM using HWCAP_ASIMDDP and
-    // HWCAP2_I8MM too, avoiding to read the CPUID registers (which triggers
-    // a trap, handled by the kernel). However the HWCAP_* defines for these
-    // extensions are added much later than HWCAP_CPUID, so the userland
-    // headers might lack support for them even if the binary later is run
-    // on hardware that does support it (and where the kernel might support
-    // HWCAP_CPUID).
-    // See https://www.kernel.org/doc/html/latest/arm64/cpu-feature-registers.html
-    if (hwcap & HWCAP_CPUID) {
-        uint64_t tmp;
-
-        get_cpu_feature_reg(ID_AA64ISAR0_EL1, tmp);
-        if (((tmp >> 44) & 0xf) == 0x1)
-            flags |= AV_CPU_FLAG_DOTPROD;
-        get_cpu_feature_reg(ID_AA64ISAR1_EL1, tmp);
-        if (((tmp >> 52) & 0xf) == 0x1)
-            flags |= AV_CPU_FLAG_I8MM;
-    }
-#else
-    (void)hwcap;
-#endif
+    if (hwcap & HWCAP_AARCH64_ASIMDDP)
+        flags |= AV_CPU_FLAG_DOTPROD;
+    if (hwcap2 & HWCAP2_AARCH64_I8MM)
+        flags |= AV_CPU_FLAG_I8MM;
 
     return flags;
 }
