[FFmpeg-cvslog] aarch64: Add Apple runtime detection of dotprod and i8mm using sysctl

Martin Storsjö git at videolan.org
Tue Jun 6 13:25:44 EEST 2023


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri May 26 10:20:21 2023 +0300| [9b0052200aa959d5ac939620bc14f0403621ab05] | committer: Martin Storsjö

aarch64: Add Apple runtime detection of dotprod and i8mm using sysctl

For now, there's not much value in this since Clang don't support
enabling the dotprod or i8mm features with either .arch_extension
or .arch (it has to be enabled by the base arch flags passed to
the compiler). But it may be supported in the future.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9b0052200aa959d5ac939620bc14f0403621ab05
---

 configure               |  2 ++
 libavutil/aarch64/cpu.c | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/configure b/configure
index 5127fa0d8c..2992dae283 100755
--- a/configure
+++ b/configure
@@ -2348,6 +2348,7 @@ SYSTEM_FUNCS="
     strerror_r
     sysconf
     sysctl
+    sysctlbyname
     usleep
     UTGetOSTypeFromString
     VirtualAlloc
@@ -6394,6 +6395,7 @@ check_func_headers mach/mach_time.h mach_absolute_time
 check_func_headers stdlib.h getenv
 check_func_headers sys/stat.h lstat
 check_func_headers sys/auxv.h getauxval
+check_func_headers sys/sysctl.h sysctlbyname
 
 check_func_headers windows.h GetModuleHandle
 check_func_headers windows.h GetProcessAffinityMask
diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c
index 025bf30828..b808a7650e 100644
--- a/libavutil/aarch64/cpu.c
+++ b/libavutil/aarch64/cpu.c
@@ -61,6 +61,28 @@ static int detect_flags(void)
     return flags;
 }
 
+#elif defined(__APPLE__) && HAVE_SYSCTLBYNAME
+#include <sys/sysctl.h>
+
+static int detect_flags(void)
+{
+    uint32_t value = 0;
+    size_t size;
+    int flags = 0;
+
+    size = sizeof(value);
+    if (!sysctlbyname("hw.optional.arm.FEAT_DotProd", &value, &size, NULL, 0)) {
+        if (value)
+            flags |= AV_CPU_FLAG_DOTPROD;
+    }
+    size = sizeof(value);
+    if (!sysctlbyname("hw.optional.arm.FEAT_I8MM", &value, &size, NULL, 0)) {
+        if (value)
+            flags |= AV_CPU_FLAG_I8MM;
+    }
+    return flags;
+}
+
 #else
 
 static int detect_flags(void)



More information about the ffmpeg-cvslog mailing list