diff mbox series

[FFmpeg-devel] aarch64: Factorize code for CPU feature detection on Apple platforms

Message ID 20240312082719.1884075-1-martin@martin.st
State Accepted
Commit 8339a45400458ab91f973ef671cbf99e38284e7e
Headers show
Series [FFmpeg-devel] aarch64: Factorize code for CPU feature detection on Apple platforms | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Martin Storsjö March 12, 2024, 8:27 a.m. UTC
---
 libavutil/aarch64/cpu.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

Comments

Martin Storsjö April 10, 2024, 7:38 a.m. UTC | #1
On Tue, 12 Mar 2024, Martin Storsjö wrote:

> ---
> libavutil/aarch64/cpu.c | 25 +++++++++++++------------
> 1 file 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;
> }

Will apply.

// Martin
diff mbox series

Patch

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;
 }