PR #21421 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21421
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21421.patch

For example, check the flag and set a function for test:

    if (ff_is_cpu_flags_test)
        c->bswap_buf = bswap_buf_2;

Run the test:
./tests/checkasm/checkasm --test=bswapdsp --bench=bswap_buf

bswap_buf_c:                          0.5 ( 1.00x)
bswap_buf_test:                       0.3 ( 2.04x)

Signed-off-by: Zhao Zhili <[email protected]>


>From 91e1ac15a456f3a2b2a28984c57ad366df28d611 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <[email protected]>
Date: Sat, 10 Jan 2026 01:03:37 +0800
Subject: [PATCH] tests/checkasm: add a fake cpu flag for benchmarking two C
 functions

For example, check the flag and set a function for test:

    if (ff_is_cpu_flags_test)
        c->bswap_buf = bswap_buf_2;

Run the test:
./tests/checkasm/checkasm --test=bswapdsp --bench=bswap_buf

bswap_buf_c:                          0.5 ( 1.00x)
bswap_buf_test:                       0.3 ( 2.04x)

Signed-off-by: Zhao Zhili <[email protected]>
---
 libavutil/cpu_internal.h  |  4 ++++
 tests/checkasm/checkasm.c | 15 +++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/libavutil/cpu_internal.h b/libavutil/cpu_internal.h
index 8dca62334a..7f36fecd49 100644
--- a/libavutil/cpu_internal.h
+++ b/libavutil/cpu_internal.h
@@ -44,6 +44,10 @@
 #define CPUEXT_FAST(flags, cpuext) CPUEXT_SUFFIX_FAST(flags, , cpuext)
 #define CPUEXT_SLOW(flags, cpuext) CPUEXT_SUFFIX_SLOW(flags, , cpuext)
 
+/* Fake CPU flag for testing only */
+#define AV_CPU_FLAG_TEST        0x80000000
+#define ff_is_cpu_flags_test    (av_get_cpu_flags() & AV_CPU_FLAG_TEST)
+
 int ff_get_cpu_flags_mips(void);
 int ff_get_cpu_flags_aarch64(void);
 int ff_get_cpu_flags_arm(void);
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 7dcdaeb2a4..8eb7e366bd 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -60,7 +60,7 @@
 #include "checkasm.h"
 #include "libavutil/avassert.h"
 #include "libavutil/common.h"
-#include "libavutil/cpu.h"
+#include "libavutil/cpu_internal.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/random_seed.h"
 
@@ -420,6 +420,9 @@ static const struct {
 #elif ARCH_WASM
     { "SIMD128",    "simd128",  AV_CPU_FLAG_SIMD128 },
 #endif
+
+    /* Don't put any flag after this one */
+    { "TEST", "test", AV_CPU_FLAG_TEST },
     { NULL }
 };
 
@@ -861,9 +864,13 @@ static void check_cpu_flag(const char *name, int flag)
 {
     int old_cpu_flag = state.cpu_flag;
 
-    flag |= old_cpu_flag;
-    av_force_cpu_flags(-1);
-    state.cpu_flag = flag & av_get_cpu_flags();
+    if (flag == AV_CPU_FLAG_TEST) {
+        state.cpu_flag = flag;
+    } else {
+        flag |= old_cpu_flag;
+        av_force_cpu_flags(-1);
+        state.cpu_flag = flag & av_get_cpu_flags();
+    }
     av_force_cpu_flags(state.cpu_flag);
 
     if (!flag || state.cpu_flag != old_cpu_flag) {
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to