Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] aarch64: Factorize code for CPU feature detection on Apple platforms
@ 2024-03-12  8:27 Martin Storsjö
  2024-04-10  7:38 ` Martin Storsjö
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Storsjö @ 2024-03-12  8:27 UTC (permalink / raw)
  To: ffmpeg-devel

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] aarch64: Factorize code for CPU feature detection on Apple platforms
  2024-03-12  8:27 [FFmpeg-devel] [PATCH] aarch64: Factorize code for CPU feature detection on Apple platforms Martin Storsjö
@ 2024-04-10  7:38 ` Martin Storsjö
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Storsjö @ 2024-04-10  7:38 UTC (permalink / raw)
  To: ffmpeg-devel

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
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-10  7:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-12  8:27 [FFmpeg-devel] [PATCH] aarch64: Factorize code for CPU feature detection on Apple platforms Martin Storsjö
2024-04-10  7:38 ` Martin Storsjö

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git