diff mbox series

[FFmpeg-devel,5/7] avutil/riscv/asm: add helper macro to count varargs

Message ID 20240813140338.143045-5-jdek@itanimul.li
State New
Headers show
Series [FFmpeg-devel,1/7] checkasm: add csv/tsv bench output | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

J. Dekker Aug. 13, 2024, 2:03 p.m. UTC
From: Niklas Haas <git@haasn.dev>

(Ab)using nested macros to get the number of arguments passed to a
variadic macro. Useful for stack manipulation.
---
 libavutil/riscv/asm.S | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/libavutil/riscv/asm.S b/libavutil/riscv/asm.S
index 175f2a8672..db190e99ca 100644
--- a/libavutil/riscv/asm.S
+++ b/libavutil/riscv/asm.S
@@ -271,3 +271,20 @@ 
 #error Unhandled value of XLEN
 #endif
         .endm
+
+        .macro  count_args_inner num, arg, args:vararg
+        .ifb \arg
+        .equ    num_args, \num
+        .else
+        count_args_inner \num + 1, \args
+        .endif
+        .endm
+
+        /**
+         * Helper macro to count the number of arguments to a macro. Assigns
+         * the count to the symbol `num_args`.
+         * @param args arguments to count
+         */
+        .macro  count_args args:vararg
+        count_args_inner 0, \args
+        .endm