aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Denis-Courmont <remi@remlab.net>2024-07-25 22:17:48 +0300
committerRémi Denis-Courmont <remi@remlab.net>2024-07-28 21:24:58 +0300
commit39ced529b0588b4516cd94bd9b498fb06a387101 (patch)
tree08183d2c993a7183c6ac8057b1d55b4e2224d7dd
parentb0b3bea10bab54f22f976245da343fb42c9c1f28 (diff)
downloadffmpeg-39ced529b0588b4516cd94bd9b498fb06a387101.tar.gz
lavu/riscv: implement floating point clips
Unlike x86, fmin/fmax are single instructions, not function calls. They are much much faster than doing a comparison, then branching based on its results. With this, audiodsp.vector_clipf gets almost twice as fast, and a properly unrollled version of it gets 4-5x faster, on SiFive-U74. This is only the low-hanging fruit: FFMIN and FFMAX are presumably affected as well. This likely applies to other instruction sets with native IEEE floats, especially those lacking a conditional select instruction.
-rw-r--r--libavutil/riscv/intmath.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/libavutil/riscv/intmath.h b/libavutil/riscv/intmath.h
index 3e7ab864c5..24f165eef1 100644
--- a/libavutil/riscv/intmath.h
+++ b/libavutil/riscv/intmath.h
@@ -22,6 +22,7 @@
#define AVUTIL_RISCV_INTMATH_H
#include <stdint.h>
+#include <math.h>
#include "config.h"
#include "libavutil/attributes.h"
@@ -72,6 +73,24 @@ static av_always_inline av_const int av_clip_intp2_rvi(int a, int p)
return b;
}
+#if defined (__riscv_f) || defined (__riscv_zfinx)
+#define av_clipf av_clipf_rvf
+static av_always_inline av_const float av_clipf_rvf(float a, float min,
+ float max)
+{
+ return fminf(fmaxf(a, min), max);
+}
+#endif
+
+#if defined (__riscv_d) || defined (__riscv_zdinx)
+#define av_clipd av_clipd_rvd
+static av_always_inline av_const float av_clipd_rvd(double a, double min,
+ double max)
+{
+ return fmin(fmax(a, min), max);
+}
+#endif
+
#if defined (__GNUC__) || defined (__clang__)
static inline av_const int ff_ctz_rv(int x)
{