Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PR] tests/checkasm: add a fake cpu flag for benchmarking two C functions (PR #21421)
@ 2026-01-09 18:09 Zhao Zhili via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: Zhao Zhili via ffmpeg-devel @ 2026-01-09 18:09 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Zhao Zhili

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 <zhilizhao@tencent.com>


>From 91e1ac15a456f3a2b2a28984c57ad366df28d611 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <zhilizhao@tencent.com>
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 <zhilizhao@tencent.com>
---
 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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-01-09 18:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-09 18:09 [FFmpeg-devel] [PR] tests/checkasm: add a fake cpu flag for benchmarking two C functions (PR #21421) Zhao Zhili via ffmpeg-devel

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