diff mbox series

[FFmpeg-devel,19/29] lavc/audiodsp: RISC-V V vector_clip_int32

Message ID 20220922183726.38624-19-remi@remlab.net
State New
Headers show
Series [FFmpeg-devel,01/29] lavu/cpu: detect RISC-V base extensions | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Rémi Denis-Courmont Sept. 22, 2022, 6:37 p.m. UTC
From: Rémi Denis-Courmont <remi@remlab.net>

---
 libavcodec/riscv/Makefile        |  1 +
 libavcodec/riscv/audiodsp_init.c |  9 ++++++++
 libavcodec/riscv/audiodsp_rvv.S  | 37 ++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 libavcodec/riscv/audiodsp_rvv.S
diff mbox series

Patch

diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index da07f1fe96..99541b075e 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -1,4 +1,5 @@ 
 OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_init.o \
                            riscv/audiodsp_rvf.o
+RVV-OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_rvv.o
 OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o \
                               riscv/pixblockdsp_rvi.o
diff --git a/libavcodec/riscv/audiodsp_init.c b/libavcodec/riscv/audiodsp_init.c
index c5842815d6..ce8b60ee52 100644
--- a/libavcodec/riscv/audiodsp_init.c
+++ b/libavcodec/riscv/audiodsp_init.c
@@ -18,16 +18,25 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
+
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavcodec/audiodsp.h"
 
 void ff_vector_clipf_rvf(float *dst, const float *src, int len, float min, float max);
 
+void ff_vector_clip_int32_rvv(int32_t *dst, const int32_t *src, int32_t min,
+                              int32_t max, unsigned int len);
+
 av_cold void ff_audiodsp_init_riscv(AudioDSPContext *c)
 {
     int flags = av_get_cpu_flags();
 
     if (flags & AV_CPU_FLAG_RVF)
         c->vector_clipf = ff_vector_clipf_rvf;
+#if HAVE_RVV
+    if (flags & AV_CPU_FLAG_RV_ZVE32X)
+        c->vector_clip_int32 = ff_vector_clip_int32_rvv;
+#endif
 }
diff --git a/libavcodec/riscv/audiodsp_rvv.S b/libavcodec/riscv/audiodsp_rvv.S
new file mode 100644
index 0000000000..26b3cdffcf
--- /dev/null
+++ b/libavcodec/riscv/audiodsp_rvv.S
@@ -0,0 +1,37 @@ 
+/*
+ * Copyright © 2022 Rémi Denis-Courmont.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/riscv/asm.S"
+
+func ff_vector_clip_int32_rvv, zve32x
+1:
+        vsetvli t0, a4, e32, m1, ta, ma
+        vle32.v v8, (a1)
+        slli    t1, t0, 2
+        vmax.vx v8, v8, a2
+        add     a1, a1, t1
+        vmin.vx v8, v8, a3
+        sub     a4, a4, t0
+        vse32.v v8, (a0)
+        add     a0, a0, t1
+        bnez    a4, 1b
+
+        ret
+endfunc