[FFmpeg-devel] [PATCH 5/7] avutil/riscv/asm: add helper macro to count varargs
J. Dekker
jdek at itanimul.li
Tue Aug 13 17:03:34 EEST 2024
From: Niklas Haas <git at 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 --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
--
2.45.1
More information about the ffmpeg-devel
mailing list