aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/aarch64/cpu.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2024-03-12 10:23:15 +0200
committerMartin Storsjö <martin@martin.st>2024-04-10 10:39:08 +0300
commit8339a45400458ab91f973ef671cbf99e38284e7e (patch)
tree4af3def48629639f351268a171da90bd8b67cc76 /libavutil/aarch64/cpu.c
parent41b73ae883ec2a70c814e394de0e5ae5f1f13e87 (diff)
downloadffmpeg-8339a45400458ab91f973ef671cbf99e38284e7e.tar.gz
aarch64: Factorize code for CPU feature detection on Apple platforms
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavutil/aarch64/cpu.c')
-rw-r--r--libavutil/aarch64/cpu.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/libavutil/aarch64/cpu.c b/libavutil/aarch64/cpu.c
index 7a05391343..196bdaf6b0 100644
--- a/libavutil/aarch64/cpu.c
+++ b/libavutil/aarch64/cpu.c
@@ -45,22 +45,23 @@ static int detect_flags(void)
#elif defined(__APPLE__) && HAVE_SYSCTLBYNAME
#include <sys/sysctl.h>
+static int have_feature(const char *feature) {
+ uint32_t value = 0;
+ size_t size = sizeof(value);
+ if (!sysctlbyname(feature, &value, &size, NULL, 0))
+ return value;
+ return 0;
+}
+
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;
- }
+ if (have_feature("hw.optional.arm.FEAT_DotProd"))
+ flags |= AV_CPU_FLAG_DOTPROD;
+ if (have_feature("hw.optional.arm.FEAT_I8MM"))
+ flags |= AV_CPU_FLAG_I8MM;
+
return flags;
}