aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Denis-Courmont <remi@remlab.net>2024-05-10 19:37:01 +0300
committerRémi Denis-Courmont <remi@remlab.net>2024-05-13 18:36:07 +0300
commit247c5b2b97b1de6645d1cb9f69a21ca0e76341d8 (patch)
treefefd5c8f1adb454d1895e86ee95e6320815322d7
parent38e7b0ecf8bc876072dc1a6caf7cadc2360910f3 (diff)
downloadffmpeg-247c5b2b97b1de6645d1cb9f69a21ca0e76341d8.tar.gz
lavu/riscv: add ff_rv_vlen_least()
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.
-rw-r--r--libavutil/riscv/cpu.h21
1 files changed, 21 insertions, 0 deletions
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