* [FFmpeg-devel] [PATCH] lavc/vp7dsp: add R-V V vp7_luma_dc_wht
@ 2024-05-26 9:28 Rémi Denis-Courmont
2024-05-26 11:12 ` [FFmpeg-devel] [PATCH 2/3] lavc/vp7dsp: revector ff_vp7_dc_wht_rvv Rémi Denis-Courmont
0 siblings, 1 reply; 3+ messages in thread
From: Rémi Denis-Courmont @ 2024-05-26 9:28 UTC (permalink / raw)
To: ffmpeg-devel
This works out a bit more favourably than VP8's due to:
- additional multiplications that can be vectored,
- hardware-supported fixed-point rounding mode.
vp7_luma_dc_wht_c: 3.2
vp7_luma_dc_wht_rvv_i64: 2.0
---
libavcodec/riscv/Makefile | 2 +
libavcodec/riscv/vp7dsp_init.c | 41 +++++++++++++++
libavcodec/riscv/vp7dsp_rvv.S | 96 ++++++++++++++++++++++++++++++++++
libavcodec/vp8dsp.c | 4 ++
libavcodec/vp8dsp.h | 2 +
5 files changed, 145 insertions(+)
create mode 100644 libavcodec/riscv/vp7dsp_init.c
create mode 100644 libavcodec/riscv/vp7dsp_rvv.S
diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index e608436aa4..590655f829 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -65,6 +65,8 @@ RVV-OBJS-$(CONFIG_UTVIDEO_DECODER) += riscv/utvideodsp_rvv.o
OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_init.o
RV-OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_rvi.o
RVV-OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_rvv.o
+OBJS-$(CONFIG_VP7_DECODER) += riscv/vp7dsp_init.o
+RVV-OBJS-$(CONFIG_VP7_DECODER) += riscv/vp7dsp_rvv.o
OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_init.o
RV-OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_rvi.o
RVV-OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_rvv.o
diff --git a/libavcodec/riscv/vp7dsp_init.c b/libavcodec/riscv/vp7dsp_init.c
new file mode 100644
index 0000000000..6d9aba43d9
--- /dev/null
+++ b/libavcodec/riscv/vp7dsp_init.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2024 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 "libavutil/riscv/cpu.h"
+#include "libavcodec/vp8dsp.h"
+
+void ff_vp7_luma_dc_wht_rvv(int16_t block[4][4][16], int16_t dc[16]);
+
+av_cold void ff_vp7dsp_init_riscv(VP8DSPContext *c)
+{
+#if HAVE_RVV
+ int flags = av_get_cpu_flags();
+
+ if (flags & AV_CPU_FLAG_RVV_I32 && ff_rv_vlen_least(128)) {
+#if __riscv_xlen >= 64
+ c->vp8_luma_dc_wht = ff_vp7_luma_dc_wht_rvv;
+#endif
+ }
+#endif
+}
diff --git a/libavcodec/riscv/vp7dsp_rvv.S b/libavcodec/riscv/vp7dsp_rvv.S
new file mode 100644
index 0000000000..fb21e9a595
--- /dev/null
+++ b/libavcodec/riscv/vp7dsp_rvv.S
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2024 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"
+
+#if __riscv_xlen >= 64
+func ff_vp7_luma_dc_wht_rvv, zve32x
+ csrwi vxrm, 0
+ li t4, 12540
+ vsetivli zero, 4, e16, mf2, ta, ma
+ vlseg4e16.v v0, (a1)
+ li t6, 30274
+ vwmul.vx v8, v1, t4
+ li t5, 23170
+ vwmul.vx v9, v3, t6
+ addi t1, sp, -12 * 2
+ vwmul.vx v10, v1, t6
+ addi t2, sp, -8 * 2
+ vwmul.vx v11, v3, t4
+ addi t3, sp, -4 * 2
+ vwadd.vv v4, v0, v2
+ addi sp, sp, -16 * 2
+ vwsub.vv v5, v0, v2
+ vsetvli zero, zero, e32, m1, ta, ma
+ vadd.vv v7, v10, v11
+ vmul.vx v4, v4, t5
+ vsub.vv v6, v8, v9
+ vmul.vx v5, v5, t5
+ vadd.vv v0, v4, v7
+ vsub.vv v3, v4, v7
+ vadd.vv v1, v5, v6
+ vsub.vv v2, v5, v6
+ vsetvli zero, zero, e16, mf2, ta, ma
+ vnsra.wi v4, v0, 14
+ vnsra.wi v7, v3, 14
+ vnsra.wi v5, v1, 14
+ vnsra.wi v6, v2, 14
+ vsseg4e16.v v4, (sp)
+ vle16.v v0, (sp)
+ vle16.v v1, (t1)
+ vle16.v v2, (t2)
+ vle16.v v3, (t3)
+ vwmul.vx v8, v1, t4
+ li t0, 16 * 2
+ vwmul.vx v9, v3, t6
+ addi t1, a0, 1 * 4 * 16 * 2
+ vwmul.vx v10, v1, t6
+ addi t2, a0, 2 * 4 * 16 * 2
+ vwmul.vx v11, v3, t4
+ addi t3, a0, 3 * 4 * 16 * 2
+ vwadd.vv v4, v0, v2
+ vwsub.vv v5, v0, v2
+ vsetvli zero, zero, e32, m1, ta, ma
+ vmul.vx v4, v4, t5
+ sd zero, (a1)
+ vadd.vv v7, v10, v11
+ sd zero, 8(a1)
+ vmul.vx v5, v5, t5
+ sd zero, 16(a1)
+ vsub.vv v6, v8, v9
+ sd zero, 24(a1)
+ vadd.vv v0, v4, v7
+ addi sp, sp, 16 * 2
+ vsub.vv v3, v4, v7
+ vadd.vv v1, v5, v6
+ vsub.vv v2, v5, v6
+ vsetvli zero, zero, e16, mf2, ta, ma
+ vnclip.wi v4, v0, 18
+ vnclip.wi v5, v1, 18
+ vnclip.wi v6, v2, 18
+ vnclip.wi v7, v3, 18
+ vsse16.v v4, (a0), t0
+ vsse16.v v5, (t1), t0
+ vsse16.v v6, (t2), t0
+ vsse16.v v7, (t3), t0
+
+ ret
+endfunc
+#endif
diff --git a/libavcodec/vp8dsp.c b/libavcodec/vp8dsp.c
index 8624c3ae15..88bb67f78d 100644
--- a/libavcodec/vp8dsp.c
+++ b/libavcodec/vp8dsp.c
@@ -712,6 +712,10 @@ av_cold void ff_vp7dsp_init(VP8DSPContext *dsp)
dsp->vp8_v_loop_filter_simple = vp7_v_loop_filter_simple_c;
dsp->vp8_h_loop_filter_simple = vp7_h_loop_filter_simple_c;
+
+#if ARCH_RISCV
+ ff_vp7dsp_init_riscv(dsp);
+#endif
}
#endif /* CONFIG_VP7_DECODER */
diff --git a/libavcodec/vp8dsp.h b/libavcodec/vp8dsp.h
index 3bf12b6b45..e3de2e0494 100644
--- a/libavcodec/vp8dsp.h
+++ b/libavcodec/vp8dsp.h
@@ -90,6 +90,8 @@ void ff_vp78dsp_init_ppc(VP8DSPContext *c);
void ff_vp78dsp_init_riscv(VP8DSPContext *c);
void ff_vp78dsp_init_x86(VP8DSPContext *c);
+void ff_vp7dsp_init_riscv(VP8DSPContext *c);
+
void ff_vp8dsp_init(VP8DSPContext *c);
void ff_vp8dsp_init_aarch64(VP8DSPContext *c);
void ff_vp8dsp_init_arm(VP8DSPContext *c);
--
2.45.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [FFmpeg-devel] [PATCH 2/3] lavc/vp7dsp: revector ff_vp7_dc_wht_rvv
2024-05-26 9:28 [FFmpeg-devel] [PATCH] lavc/vp7dsp: add R-V V vp7_luma_dc_wht Rémi Denis-Courmont
@ 2024-05-26 11:12 ` Rémi Denis-Courmont
2024-05-26 11:12 ` [FFmpeg-devel] [PATCH 3/3] lavc/vp7dsp: R-V V vp7_idct_add Rémi Denis-Courmont
0 siblings, 1 reply; 3+ messages in thread
From: Rémi Denis-Courmont @ 2024-05-26 11:12 UTC (permalink / raw)
To: ffmpeg-devel
This prepares for some code reuse.
---
libavcodec/riscv/vp7dsp_init.c | 3 ++-
libavcodec/riscv/vp7dsp_rvv.S | 23 ++++++++++++++---------
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/libavcodec/riscv/vp7dsp_init.c b/libavcodec/riscv/vp7dsp_init.c
index 5a57a39d0b..1406eb1c6a 100644
--- a/libavcodec/riscv/vp7dsp_init.c
+++ b/libavcodec/riscv/vp7dsp_init.c
@@ -32,7 +32,8 @@ av_cold void ff_vp7dsp_init_riscv(VP8DSPContext *c)
#if HAVE_RVV
int flags = av_get_cpu_flags();
- if ((flags & AV_CPU_FLAG_RVV_I32) && ff_rv_vlen_least(128)) {
+ if ((flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB_ADDR) &&
+ ff_rv_vlen_least(128)) {
#if __riscv_xlen >= 64
c->vp8_luma_dc_wht = ff_vp7_luma_dc_wht_rvv;
#endif
diff --git a/libavcodec/riscv/vp7dsp_rvv.S b/libavcodec/riscv/vp7dsp_rvv.S
index 819d2056dc..06e251f5ce 100644
--- a/libavcodec/riscv/vp7dsp_rvv.S
+++ b/libavcodec/riscv/vp7dsp_rvv.S
@@ -22,6 +22,15 @@
#if __riscv_xlen >= 64
func ff_vp7_luma_dc_wht_rvv, zve32x
+ li a2, 4 * 16 * 2
+ li a7, 16 * 2
+ jal t0, 1f
+ vsse16.v v4, (a0), a7
+ vsse16.v v5, (t1), a7
+ vsse16.v v6, (t2), a7
+ vsse16.v v7, (t3), a7
+ ret
+1:
csrwi vxrm, 0
li t4, 12540
vsetivli zero, 4, e16, mf2, ta, ma
@@ -58,14 +67,14 @@ func ff_vp7_luma_dc_wht_rvv, zve32x
vle16.v v2, (t2)
vle16.v v3, (t3)
vwmul.vx v8, v1, t4
- li t0, 16 * 2
vwmul.vx v9, v3, t6
- addi t1, a0, 1 * 4 * 16 * 2
+ add t1, a2, a0
vwmul.vx v10, v1, t6
- addi t2, a0, 2 * 4 * 16 * 2
+ sh1add t2, a2, a0
vwmul.vx v11, v3, t4
- addi t3, a0, 3 * 4 * 16 * 2
+ sh1add a2, a2, a2 # a2 *= 3
vwadd.vv v4, v0, v2
+ add t3, a2, a0
vwsub.vv v5, v0, v2
vsetvli zero, zero, e32, m1, ta, ma
vmul.vx v4, v4, t5
@@ -86,10 +95,6 @@ func ff_vp7_luma_dc_wht_rvv, zve32x
vnclip.wi v5, v1, 18
vnclip.wi v6, v2, 18
vnclip.wi v7, v3, 18
- vsse16.v v4, (a0), t0
- vsse16.v v5, (t1), t0
- vsse16.v v6, (t2), t0
- vsse16.v v7, (t3), t0
- ret
+ jr t0
endfunc
#endif
--
2.45.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] lavc/vp7dsp: R-V V vp7_idct_add
2024-05-26 11:12 ` [FFmpeg-devel] [PATCH 2/3] lavc/vp7dsp: revector ff_vp7_dc_wht_rvv Rémi Denis-Courmont
@ 2024-05-26 11:12 ` Rémi Denis-Courmont
0 siblings, 0 replies; 3+ messages in thread
From: Rémi Denis-Courmont @ 2024-05-26 11:12 UTC (permalink / raw)
To: ffmpeg-devel
Most of the code is shared with DC, thanks to minor earlier changes.
vp7_idct_add_c: 5.2
vp7_idct_add_rvv_i32: 2.5
---
libavcodec/riscv/vp7dsp_init.c | 2 ++
libavcodec/riscv/vp7dsp_rvv.S | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/libavcodec/riscv/vp7dsp_init.c b/libavcodec/riscv/vp7dsp_init.c
index 1406eb1c6a..ae7f2d4277 100644
--- a/libavcodec/riscv/vp7dsp_init.c
+++ b/libavcodec/riscv/vp7dsp_init.c
@@ -26,6 +26,7 @@
#include "libavcodec/vp8dsp.h"
void ff_vp7_luma_dc_wht_rvv(int16_t block[4][4][16], int16_t dc[16]);
+void ff_vp7_idct_add_rvv(uint8_t *dst, int16_t block[16], ptrdiff_t stride);
av_cold void ff_vp7dsp_init_riscv(VP8DSPContext *c)
{
@@ -37,6 +38,7 @@ av_cold void ff_vp7dsp_init_riscv(VP8DSPContext *c)
#if __riscv_xlen >= 64
c->vp8_luma_dc_wht = ff_vp7_luma_dc_wht_rvv;
#endif
+ c->vp8_idct_add = ff_vp7_idct_add_rvv;
}
#endif
}
diff --git a/libavcodec/riscv/vp7dsp_rvv.S b/libavcodec/riscv/vp7dsp_rvv.S
index 06e251f5ce..2a4c404bbb 100644
--- a/libavcodec/riscv/vp7dsp_rvv.S
+++ b/libavcodec/riscv/vp7dsp_rvv.S
@@ -97,4 +97,33 @@ func ff_vp7_luma_dc_wht_rvv, zve32x
vnclip.wi v7, v3, 18
jr t0
endfunc
+
+func ff_vp7_idct_add_rvv, zve32x
+ jal t0, 1b
+ csrwi vxrm, 2
+ vsetvli zero, zero, e8, mf4, ta, ma
+ vle8.v v12, (a0)
+ vle8.v v13, (t1)
+ vwaddu.wv v4, v4, v12
+ vle8.v v14, (t2)
+ vwaddu.wv v5, v5, v13
+ vle8.v v15, (t3)
+ vwaddu.wv v6, v6, v14
+ vwaddu.wv v7, v7, v15
+ vsetvli zero, zero, e16, mf2, ta, ma
+ vmax.vx v4, v4, zero
+ vmax.vx v5, v5, zero
+ vmax.vx v6, v6, zero
+ vmax.vx v7, v7, zero
+ vsetvli zero, zero, e8, mf4, ta, ma
+ vnclipu.wi v0, v4, 0
+ vnclipu.wi v1, v5, 0
+ vse8.v v0, (a0)
+ vnclipu.wi v2, v6, 0
+ vse8.v v1, (t1)
+ vnclipu.wi v3, v7, 0
+ vse8.v v2, (t2)
+ vse8.v v3, (t3)
+ ret
+endfunc
#endif
--
2.45.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-26 11:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-26 9:28 [FFmpeg-devel] [PATCH] lavc/vp7dsp: add R-V V vp7_luma_dc_wht Rémi Denis-Courmont
2024-05-26 11:12 ` [FFmpeg-devel] [PATCH 2/3] lavc/vp7dsp: revector ff_vp7_dc_wht_rvv Rémi Denis-Courmont
2024-05-26 11:12 ` [FFmpeg-devel] [PATCH 3/3] lavc/vp7dsp: R-V V vp7_idct_add Rémi Denis-Courmont
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git