[x265] [PATCH v2 3/6] Add Apple Silicon run-time CPU feature detection
Hari Limaye
hari.limaye at arm.com
Wed Nov 6 15:35:45 UTC 2024
Add run-time CPU feature detection for ISA extensions on Apple Silicon
platforms.
---
source/CMakeLists.txt | 2 +-
source/common/aarch64/cpu.h | 40 ++++++++++++++++++++++++++++++++++---
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index f177c4522..52870452c 100755
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -88,7 +88,7 @@ elseif(ARM64MATCH GREATER "-1")
option(AARCH64_WARNINGS_AS_ERRORS "Build with -Werror for AArch64 Intrinsics files" OFF)
option(AARCH64_RUNTIME_CPU_DETECT "Enable AArch64 run-time CPU feature detection" ON)
- if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
+ if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
set(AARCH64_RUNTIME_CPU_DETECT OFF CACHE BOOL "" FORCE)
message(STATUS "Run-time CPU feature detection unsupported on this platform")
endif()
diff --git a/source/common/aarch64/cpu.h b/source/common/aarch64/cpu.h
index 88ce2e310..857ba980a 100644
--- a/source/common/aarch64/cpu.h
+++ b/source/common/aarch64/cpu.h
@@ -28,7 +28,41 @@
#if AARCH64_RUNTIME_CPU_DETECT
-#if defined(__linux__)
+#if defined(__APPLE__)
+
+#include <sys/sysctl.h>
+
+static inline bool have_feature(const char *feature)
+{
+ int64_t feature_present = 0;
+ size_t size = sizeof(feature_present);
+ if (sysctlbyname(feature, &feature_present, &size, NULL, 0) != 0)
+ {
+ return false;
+ }
+ return feature_present;
+}
+
+static inline int aarch64_get_cpu_flags()
+{
+ int flags = 0;
+
+#if HAVE_NEON
+ flags |= X265_CPU_NEON;
+#endif
+#if HAVE_NEON_DOTPROD
+ if (have_feature("hw.optional.arm.FEAT_DotProd"))
+ flags |= X265_CPU_NEON_DOTPROD;
+#endif
+#if HAVE_NEON_I8MM
+ if (have_feature("hw.optional.arm.FEAT_I8MM"))
+ flags |= X265_CPU_NEON_I8MM;
+#endif
+
+ return flags;
+}
+
+#elif defined(__linux__)
#include <sys/auxv.h>
@@ -67,12 +101,12 @@ static inline int aarch64_get_cpu_flags()
return flags;
}
-#else // defined(__linux__)
+#else // defined(__APPLE__)
#error \
"Run-time CPU feature detection selected, but no detection method" \
"available for your platform. Rerun cmake configure with" \
"-DAARCH64_RUNTIME_CPU_DETECT=OFF."
-#endif // defined(__linux__)
+#endif // defined(__APPLE__)
static inline int aarch64_cpu_detect()
{
--
2.42.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0003-Add-Apple-Silicon-run-time-CPU-feature-detection.patch
Type: text/x-patch
Size: 2820 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241106/46fbf51d/attachment.bin>
More information about the x265-devel
mailing list