[FFmpeg-devel] [PATCH] lavc/llvidencdsp: add R-V V diff_bytes

Rémi Denis-Courmont remi at remlab.net
Sun Nov 19 22:23:55 EET 2023


diff_bytes_c:      163.0
diff_bytes_rvv_i32: 52.7
---
 libavcodec/lossless_videoencdsp.c   |  4 ++-
 libavcodec/lossless_videoencdsp.h   |  1 +
 libavcodec/riscv/Makefile           |  2 ++
 libavcodec/riscv/llvidencdsp_init.c | 39 +++++++++++++++++++++++++++++
 libavcodec/riscv/llvidencdsp_rvv.S  | 37 +++++++++++++++++++++++++++
 5 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/riscv/llvidencdsp_init.c
 create mode 100644 libavcodec/riscv/llvidencdsp_rvv.S

diff --git a/libavcodec/lossless_videoencdsp.c b/libavcodec/lossless_videoencdsp.c
index b4130ebc7b..e2dc99e201 100644
--- a/libavcodec/lossless_videoencdsp.c
+++ b/libavcodec/lossless_videoencdsp.c
@@ -94,7 +94,9 @@ av_cold void ff_llvidencdsp_init(LLVidEncDSPContext *c)
     c->sub_median_pred = sub_median_pred_c;
     c->sub_left_predict = sub_left_predict_c;
 
-#if ARCH_X86
+#if ARCH_RISCV
+    ff_llvidencdsp_init_riscv(c);
+#elif ARCH_X86
     ff_llvidencdsp_init_x86(c);
 #endif
 }
diff --git a/libavcodec/lossless_videoencdsp.h b/libavcodec/lossless_videoencdsp.h
index f2c2878485..07fff584af 100644
--- a/libavcodec/lossless_videoencdsp.h
+++ b/libavcodec/lossless_videoencdsp.h
@@ -40,6 +40,7 @@ typedef struct LLVidEncDSPContext {
 } LLVidEncDSPContext;
 
 void ff_llvidencdsp_init(LLVidEncDSPContext *c);
+void ff_llvidencdsp_init_riscv(LLVidEncDSPContext *c);
 void ff_llvidencdsp_init_x86(LLVidEncDSPContext *c);
 
 #endif /* AVCODEC_LOSSLESS_VIDEOENCDSP_H */
diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index 8f2a519827..2d0e6c19c8 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -30,6 +30,8 @@ OBJS-$(CONFIG_LLAUDDSP) += riscv/llauddsp_init.o
 RVV-OBJS-$(CONFIG_LLAUDDSP) += riscv/llauddsp_rvv.o
 OBJS-$(CONFIG_LLVIDDSP) += riscv/llviddsp_init.o
 RVV-OBJS-$(CONFIG_LLVIDDSP) += riscv/llviddsp_rvv.o
+OBJS-$(CONFIG_LLVIDENCDSP) += riscv/llvidencdsp_init.o
+RVV-OBJS-$(CONFIG_LLVIDENCDSP) += riscv/llvidencdsp_rvv.o
 OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_init.o
 RVV-OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_rvv.o
 OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o \
diff --git a/libavcodec/riscv/llvidencdsp_init.c b/libavcodec/riscv/llvidencdsp_init.c
new file mode 100644
index 0000000000..e35406dc41
--- /dev/null
+++ b/libavcodec/riscv/llvidencdsp_init.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2023 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 "config.h"
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavcodec/lossless_videoencdsp.h"
+
+void ff_llvidenc_diff_bytes_rvv(uint8_t *dst, const uint8_t *src1,
+                                const uint8_t *src2, intptr_t w);
+
+av_cold void ff_llvidencdsp_init_riscv(LLVidEncDSPContext *c)
+{
+#if HAVE_RVV
+    int flags = av_get_cpu_flags();
+
+    if (flags & AV_CPU_FLAG_RVV_I32) {
+        c->diff_bytes = ff_llvidenc_diff_bytes_rvv;
+    }
+#endif
+}
diff --git a/libavcodec/riscv/llvidencdsp_rvv.S b/libavcodec/riscv/llvidencdsp_rvv.S
new file mode 100644
index 0000000000..0342165127
--- /dev/null
+++ b/libavcodec/riscv/llvidencdsp_rvv.S
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2023 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_llvidenc_diff_bytes_rvv, zve32x
+1:
+        vsetvli t0, a3, e8, m8, ta, ma
+        vle8.v  v0, (a1)
+        sub     a3, a3, t0
+        vle8.v  v8, (a2)
+        add     a1, t0, a1
+        vsub.vv v8, v0, v8
+        add     a2, t0, a2
+        vse8.v  v8, (a0)
+        add     a0, t0, a0
+        bnez    a3, 1b
+
+        ret
+endfunc
-- 
2.42.0



More information about the ffmpeg-devel mailing list