On Sun, May 26, 2024 at 02:01:47AM -0400, Brad Smith wrote:
> Here is a diff to add arm64 CPU feature detection support to
> aom and libvpx.
 
Here is an updated diff with the newly addded I8MM support.

I'm guessing this is only on something really new like an M3
CPU system.


Index: aom/Makefile
===================================================================
RCS file: /home/cvs/ports/multimedia/aom/Makefile,v
diff -u -p -u -p -r1.23 Makefile
--- aom/Makefile        7 May 2024 15:01:42 -0000       1.23
+++ aom/Makefile        27 May 2024 06:22:52 -0000
@@ -3,6 +3,7 @@ COMMENT=        Alliance for Open Media AV1 vid
 V=             3.9.0
 DISTNAME=      libaom-$V
 PKGNAME=       aom-$V
+REVISION=      0
 CATEGORIES=    multimedia
 
 SHARED_LIBS=   aom     4.2
Index: aom/patches/patch-aom_ports_aarch64_cpudetect_c
===================================================================
RCS file: 
/home/cvs/ports/multimedia/aom/patches/patch-aom_ports_aarch64_cpudetect_c,v
diff -u -p -u -p -r1.2 patch-aom_ports_aarch64_cpudetect_c
--- aom/patches/patch-aom_ports_aarch64_cpudetect_c     7 May 2024 15:01:42 
-0000       1.2
+++ aom/patches/patch-aom_ports_aarch64_cpudetect_c     27 May 2024 06:22:52 
-0000
@@ -1,23 +1,53 @@
-Allow ARM CPU runtime detection code to build on OpenBSD.
+Add AArch64 CPU feature detection support for OpenBSD.
 
 Index: aom_ports/aarch64_cpudetect.c
 --- aom_ports/aarch64_cpudetect.c.orig
 +++ aom_ports/aarch64_cpudetect.c
-@@ -19,7 +19,7 @@
- #include <sys/sysctl.h>
- #endif
- 
--#if !CONFIG_RUNTIME_CPU_DETECT
-+#if !CONFIG_RUNTIME_CPU_DETECT || defined(__OpenBSD__)
- 
- static int arm_get_cpu_caps(void) {
-   // This function should actually be a no-op. There is no way to adjust any 
of
-@@ -32,7 +32,7 @@ static int arm_get_cpu_caps(void) {
+@@ -178,7 +178,46 @@ static int arm_get_cpu_caps(void) {
    return flags;
  }
  
--#elif defined(__APPLE__)  // end !CONFIG_RUNTIME_CPU_DETECT
-+#elif defined(__APPLE__)  // end !CONFIG_RUNTIME_CPU_DETECT || __OpenBSD__
- 
- // sysctlbyname() parameter documentation for instruction set characteristics:
- // 
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
+-#else  // end __Fuchsia__
++#elif defined(__OpenBSD__)  // end __Fuchsia__
++
++#include <machine/armreg.h>
++#include <machine/cpu.h>
++#include <sys/types.h>
++#include <sys/sysctl.h>
++
++static int arm_get_cpu_caps(void) {
++  int flags = 0;
++  int mib[2];
++  uint64_t isar0;
++  uint64_t isar1;
++  size_t len;
++
++  flags |= HAS_NEON;  // Neon is mandatory in Armv8.0-A.
++
++  mib[0] = CTL_MACHDEP;
++  mib[1] = CPU_ID_AA64ISAR0;
++  len = sizeof(isar0);
++  if (sysctl(mib, 2, &isar0, &len, NULL, 0) != -1) {
++    if (ID_AA64ISAR0_CRC32(isar0) >= ID_AA64ISAR0_CRC32_BASE)
++      flags |= HAS_ARM_CRC32;
++    if (ID_AA64ISAR0_DP(isar0) >= ID_AA64ISAR0_DP_IMPL)
++      flags |= HAS_NEON_DOTPROD;
++  }
++
++  mib[0] = CTL_MACHDEP;
++  mib[1] = CPU_ID_AA64ISAR1;
++  len = sizeof(isar1);
++  if (sysctl(mib, 2, &isar1, &len, NULL, 0) != -1) {
++#ifdef ID_AA64ISAR1_I8MM_IMPL
++    if (ID_AA64ISAR1_I8MM(isar1) >= ID_AA64ISAR1_I8MM_IMPL)
++      flags |= HAS_NEON_I8MM;
++#endif
++  }
++
++  return flags;
++}
++
++#else  // end __OpenBSD__
+ #error \
+     "Runtime CPU detection selected, but no CPU detection method " \
+ "available for your platform. Rerun cmake with -DCONFIG_RUNTIME_CPU_DETECT=0."
Index: libvpx/Makefile
===================================================================
RCS file: /home/cvs/ports/multimedia/libvpx/Makefile,v
diff -u -p -u -p -r1.57 Makefile
--- libvpx/Makefile     29 Feb 2024 09:43:31 -0000      1.57
+++ libvpx/Makefile     27 May 2024 06:22:52 -0000
@@ -3,6 +3,7 @@ COMMENT=        Google VP8/VP9 video codec
 GH_ACCOUNT=    webmproject
 GH_PROJECT=    libvpx
 GH_TAGNAME=    v1.14.0
+REVISION=      0
 EPOCH=         0
 CATEGORIES=    multimedia
 
Index: libvpx/patches/patch-vpx_ports_aarch64_cpudetect_c
===================================================================
RCS file: 
/home/cvs/ports/multimedia/libvpx/patches/patch-vpx_ports_aarch64_cpudetect_c,v
diff -u -p -u -p -r1.1 patch-vpx_ports_aarch64_cpudetect_c
--- libvpx/patches/patch-vpx_ports_aarch64_cpudetect_c  29 Feb 2024 09:43:31 
-0000      1.1
+++ libvpx/patches/patch-vpx_ports_aarch64_cpudetect_c  27 May 2024 06:22:52 
-0000
@@ -1,23 +1,51 @@
-Allow ARM CPU runtime detection code to build on OpenBSD.
+Add AArch64 CPU feature detection support for OpenBSD.
 
 Index: vpx_ports/aarch64_cpudetect.c
 --- vpx_ports/aarch64_cpudetect.c.orig
 +++ vpx_ports/aarch64_cpudetect.c
-@@ -15,7 +15,7 @@
- #include <sys/sysctl.h>
- #endif
- 
--#if !CONFIG_RUNTIME_CPU_DETECT
-+#if !CONFIG_RUNTIME_CPU_DETECT || defined(__OpenBSD__)
- 
- static int arm_get_cpu_caps(void) {
-   // This function should actually be a no-op. There is no way to adjust any 
of
-@@ -28,7 +28,7 @@ static int arm_get_cpu_caps(void) {
+@@ -170,7 +170,44 @@ static int arm_get_cpu_caps(void) {
    return flags;
  }
  
--#elif defined(__APPLE__)  // end !CONFIG_RUNTIME_CPU_DETECT
-+#elif defined(__APPLE__)  // end !CONFIG_RUNTIME_CPU_DETECT || __OpenBSD__
- 
- // sysctlbyname() parameter documentation for instruction set characteristics:
- // 
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
+-#else  // end __Fuchsia__
++#elif defined(__OpenBSD__)  // end __Fuchsia__
++
++#include <machine/armreg.h>
++#include <machine/cpu.h>
++#include <sys/types.h>
++#include <sys/sysctl.h>
++
++static int arm_get_cpu_caps(void) {
++  int flags = 0;
++  int mib[2];
++  uint64_t isar0;
++  uint64_t isar1;
++  size_t len;
++
++  flags |= HAS_NEON;  // Neon is mandatory in Armv8.0-A.
++
++  mib[0] = CTL_MACHDEP;
++  mib[1] = CPU_ID_AA64ISAR0;
++  len = sizeof(isar0);
++  if (sysctl(mib, 2, &isar0, &len, NULL, 0) != -1) {
++    if (ID_AA64ISAR0_DP(isar0) >= ID_AA64ISAR0_DP_IMPL)
++      flags |= HAS_NEON_DOTPROD;
++  }
++
++  mib[0] = CTL_MACHDEP;
++  mib[1] = CPU_ID_AA64ISAR1;
++  len = sizeof(isar1);
++  if (sysctl(mib, 2, &isar1, &len, NULL, 0) != -1) {
++#ifdef ID_AA64ISAR1_I8MM_IMPL
++    if (ID_AA64ISAR1_I8MM(isar1) >= ID_AA64ISAR1_I8MM_IMPL)
++      flags |= HAS_NEON_I8MM;
++#endif
++  }
++
++  return flags;
++}
++
++#else  // end __OpenBSD__
+ #error \
+     "Runtime CPU detection selected, but no CPU detection method available" \
+ "for your platform. Rerun configure with --disable-runtime-cpu-detect."

Reply via email to