[FFmpeg-devel] [PATCH 2/3] lavu/riscv: add ff_rv_vlen_least()

Rémi Denis-Courmont remi at remlab.net
Fri May 10 19:39:42 EEST 2024


This inline function checks that the vector length is at least a given
value. With this, most run-time VLEN checks can be optimised away.
---
 libavutil/riscv/cpu.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libavutil/riscv/cpu.h b/libavutil/riscv/cpu.h
index 56035f8556..af1440f626 100644
--- a/libavutil/riscv/cpu.h
+++ b/libavutil/riscv/cpu.h
@@ -22,6 +22,7 @@
 #define AVUTIL_RISCV_CPU_H
 
 #include "config.h"
+#include <stdbool.h>
 #include <stddef.h>
 #include "libavutil/cpu.h"
 
@@ -42,4 +43,24 @@ static inline size_t ff_get_rv_vlenb(void)
     return vlenb;
 }
 #endif
+
+/**
+ * Checks that the vector bit-size is at least the given value.
+ * This is potentially undefined behaviour if vectors are not implemented.
+ */
+static inline bool ff_rv_vlen_least(unsigned int bits)
+{
+#ifdef __riscv_v_min_vlen
+    if (bits <= __riscv_min_vlen)
+        return true;
+#else
+    /*
+     * Vector lengths smaller than 128 bits are only possible in embedded cases
+     * and cannot be run-time detected, so we can assume 128 bits at least.
+     */
+    if (bits <= 128)
+        return true;
+#endif
+    return bits <= (8 * ff_get_rv_vlenb());
+}
 #endif
-- 
2.43.0



More information about the ffmpeg-devel mailing list