Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16
@ 2024-07-02 17:13 Rémi Denis-Courmont
  2024-07-02 17:13 ` [FFmpeg-devel] [PATCH 2/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16intra Rémi Denis-Courmont
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2024-07-02 17:13 UTC (permalink / raw)
  To: ffmpeg-devel

While this *tends* to be faster than plain C, the performance numbers
are all over the place, presuambly due to the conditional character of
the main loop.

Some additional micro-optimisations should be feasible after the
underlying h264_idct_add and h264_idct_dc_add functions are also
implemented. Then it will no longer be necesseray to stricly abide by
the C ABI.
---
 libavcodec/riscv/Makefile       |   2 +-
 libavcodec/riscv/h264dsp_init.c |   6 ++
 libavcodec/riscv/h264idct_rvv.S | 106 ++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/riscv/h264idct_rvv.S

diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index a1510e8c6e..92e1544e76 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -31,7 +31,7 @@ RVV-OBJS-$(CONFIG_H263DSP) += riscv/h263dsp_rvv.o
 OBJS-$(CONFIG_H264CHROMA) += riscv/h264_chroma_init_riscv.o
 RVV-OBJS-$(CONFIG_H264CHROMA) += riscv/h264_mc_chroma.o
 OBJS-$(CONFIG_H264DSP) += riscv/h264dsp_init.o
-RVV-OBJS-$(CONFIG_H264DSP) += riscv/h264dsp_rvv.o
+RVV-OBJS-$(CONFIG_H264DSP) += riscv/h264dsp_rvv.o riscv/h264idct_rvv.o
 OBJS-$(CONFIG_HUFFYUV_DECODER) += riscv/huffyuvdsp_init.o
 RVV-OBJS-$(CONFIG_HUFFYUV_DECODER) += riscv/huffyuvdsp_rvv.o
 OBJS-$(CONFIG_IDCTDSP) += riscv/idctdsp_init.o
diff --git a/libavcodec/riscv/h264dsp_init.c b/libavcodec/riscv/h264dsp_init.c
index ab412a9924..5f318e3f2b 100644
--- a/libavcodec/riscv/h264dsp_init.c
+++ b/libavcodec/riscv/h264dsp_init.c
@@ -34,6 +34,10 @@ void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
 void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
                                             int alpha, int beta, int8_t *tc0);
 
+void ff_h264_idct_add16_8_rvv(uint8_t *dst, const int *blockoffset,
+                              int16_t *block, int stride,
+                              const uint8_t nnzc[5 * 8]);
+
 extern int ff_startcode_find_candidate_rvb(const uint8_t *, int);
 extern int ff_startcode_find_candidate_rvv(const uint8_t *, int);
 
@@ -52,6 +56,8 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth,
             dsp->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_8_rvv;
             dsp->h264_h_loop_filter_luma_mbaff =
                 ff_h264_h_loop_filter_luma_mbaff_8_rvv;
+
+            dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;
         }
         dsp->startcode_find_candidate = ff_startcode_find_candidate_rvv;
     }
diff --git a/libavcodec/riscv/h264idct_rvv.S b/libavcodec/riscv/h264idct_rvv.S
new file mode 100644
index 0000000000..74083f8221
--- /dev/null
+++ b/libavcodec/riscv/h264idct_rvv.S
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2024 Rémi Denis-Courmont.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "libavutil/riscv/asm.S"
+
+const ff_h264_scan8
+        .byte   014, 015, 024, 025, 016, 017, 026, 027
+        .byte   034, 035, 044, 045, 036, 037, 046, 047
+endconst
+
+#if (__riscv_xlen == 64)
+.irp    depth, 8
+func ff_h264_idct_add16_\depth\()_rvv, zve32x
+        addi    sp, sp, -80
+        lla     t0, ff_h264_scan8
+        sd      s0,   (sp)
+        li      t1, 32 << (\depth > 8)
+        mv      s0, sp
+        sd      ra,  8(sp)
+        sd      s1, 16(sp)
+        sd      s2, 24(sp)
+        sd      s3, 32(sp)
+        sd      s4, 40(sp)
+        sd      s5, 48(sp)
+        sd      s6, 56(sp)
+        sd      s7, 64(sp)
+        vsetivli  zero, 16, e8, m1, ta, ma
+        vle8.v    v8, (t0)
+        vlse16.v  v16, (a2), t1
+        vluxei8.v v12, (a4), v8
+.if \depth == 8
+        vsetvli   zero, zero, e16, m2, ta, ma
+.else
+        vsetvli   zero, zero, e32, m4, ta, ma
+.endif
+        vmsne.vi  v1, v16, 0
+        vsetvli   zero, zero, e8, m1, ta, ma
+        vmseq.vi  v2, v12, 1
+        vmsne.vi  v0, v12, 0
+        vmand.mm  v1, v1, v2
+        vsetvli   zero, zero, e16, m2, ta, ma
+        vmv.x.s   s2, v0
+        vmv.x.s   s3, v1
+        li      s1, 16
+        mv      s4, a0
+        mv      s5, a1
+        mv      s6, a2
+        mv      s7, a3
+1:
+        andi    t0, s2, 1
+        addi    s1, s1, -1
+        srli    s2, s2, 1
+        beqz    t0, 3f     # if (nnz)
+        lw      t2, (s5)   # block_offset[i]
+        andi    t1, s3, 1
+        mv      a1, s6
+        mv      a2, s7
+        add     a0, s4, t2
+        beqz    t1, 2f    # if (nnz == 1 && block[i * 16])
+        call    ff_h264_idct_dc_add_\depth\()_c
+        j       3f
+2:
+        call    ff_h264_idct_add_\depth\()_c
+3:
+        srli    s3, s3, 1
+        addi    s5, s5, 4
+        addi    s6, s6, 16 * 2 << (\depth > 8)
+        bnez    s1, 1b
+
+        ld      s7, 64(sp)
+        ld      s6, 56(sp)
+        ld      s5, 48(sp)
+        ld      s4, 40(sp)
+        ld      s3, 32(sp)
+        ld      s2, 24(sp)
+        ld      s1, 16(sp)
+        ld      ra,  8(sp)
+        ld      s0,  0(sp)
+        addi    sp, sp, 80
+        ret
+endfunc
+.endr
+#endif
-- 
2.45.2

_______________________________________________
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] 6+ messages in thread

* [FFmpeg-devel] [PATCH 2/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16intra
  2024-07-02 17:13 [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
@ 2024-07-02 17:13 ` Rémi Denis-Courmont
  2024-07-02 17:13 ` [FFmpeg-devel] [PATCH 3/3] lavc/h264dsp: R-V V 8-bit h264_idct8_add4 Rémi Denis-Courmont
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2024-07-02 17:13 UTC (permalink / raw)
  To: ffmpeg-devel

---
 libavcodec/riscv/h264dsp_init.c |  4 ++
 libavcodec/riscv/h264idct_rvv.S | 68 +++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/libavcodec/riscv/h264dsp_init.c b/libavcodec/riscv/h264dsp_init.c
index 5f318e3f2b..7badb86e87 100644
--- a/libavcodec/riscv/h264dsp_init.c
+++ b/libavcodec/riscv/h264dsp_init.c
@@ -37,6 +37,9 @@ void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
 void ff_h264_idct_add16_8_rvv(uint8_t *dst, const int *blockoffset,
                               int16_t *block, int stride,
                               const uint8_t nnzc[5 * 8]);
+void ff_h264_idct_add16intra_8_rvv(uint8_t *dst, const int *blockoffset,
+                                   int16_t *block, int stride,
+                                   const uint8_t nnzc[5 * 8]);
 
 extern int ff_startcode_find_candidate_rvb(const uint8_t *, int);
 extern int ff_startcode_find_candidate_rvv(const uint8_t *, int);
@@ -58,6 +61,7 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth,
                 ff_h264_h_loop_filter_luma_mbaff_8_rvv;
 
             dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;
+            dsp->h264_idct_add16intra = ff_h264_idct_add16intra_8_rvv;
         }
         dsp->startcode_find_candidate = ff_startcode_find_candidate_rvv;
     }
diff --git a/libavcodec/riscv/h264idct_rvv.S b/libavcodec/riscv/h264idct_rvv.S
index 74083f8221..42a29ba336 100644
--- a/libavcodec/riscv/h264idct_rvv.S
+++ b/libavcodec/riscv/h264idct_rvv.S
@@ -102,5 +102,73 @@ func ff_h264_idct_add16_\depth\()_rvv, zve32x
         addi    sp, sp, 80
         ret
 endfunc
+
+func ff_h264_idct_add16intra_\depth\()_rvv, zve32x
+        addi    sp, sp, -80
+        lla     t0, ff_h264_scan8
+        sd      s0,   (sp)
+        li      t1, 32 << (\depth > 8)
+        mv      s0, sp
+        sd      ra,  8(sp)
+        sd      s1, 16(sp)
+        sd      s2, 24(sp)
+        sd      s3, 32(sp)
+        sd      s4, 40(sp)
+        sd      s5, 48(sp)
+        sd      s6, 56(sp)
+        sd      s7, 64(sp)
+        vsetivli  zero, 16, e8, m1, ta, ma
+        vle8.v    v8, (t0)
+        vlse16.v  v16, (a2), t1
+        vluxei8.v v12, (a4), v8
+.if \depth == 8
+        vsetvli   zero, zero, e16, m2, ta, ma
+.else
+        vsetvli   zero, zero, e32, m4, ta, ma
+.endif
+        vmsne.vi  v1, v16, 0
+        vsetvli   zero, zero, e8, m1, ta, ma
+        vmsne.vi  v0, v12, 0
+        vsetvli   zero, zero, e16, m2, ta, ma
+        vmv.x.s   s2, v0
+        vmv.x.s   s3, v1
+        li      s1, 16
+        mv      s4, a0
+        mv      s5, a1
+        mv      s6, a2
+        mv      s7, a3
+1:
+        andi    t0, s2, 1
+        addi    s1, s1, -1
+        srli    s2, s2, 1
+        lw      t2, (s5)   # block_offset[i]
+        andi    t1, s3, 1
+        mv      a1, s6
+        mv      a2, s7
+        add     a0, s4, t2
+        beqz    t0, 2f     # if (nnzc[scan8[i]])
+        call    ff_h264_idct_add_\depth\()_c
+        j       3f
+2:
+        beqz    t1, 3f    # if (block[i * 16])
+        call    ff_h264_idct_dc_add_\depth\()_c
+3:
+        srli    s3, s3, 1
+        addi    s5, s5, 4
+        addi    s6, s6, 16 * 2 << (\depth > 8)
+        bnez    s1, 1b
+
+        ld      s7, 64(sp)
+        ld      s6, 56(sp)
+        ld      s5, 48(sp)
+        ld      s4, 40(sp)
+        ld      s3, 32(sp)
+        ld      s2, 24(sp)
+        ld      s1, 16(sp)
+        ld      ra,  8(sp)
+        ld      s0,  0(sp)
+        addi    sp, sp, 80
+        ret
+endfunc
 .endr
 #endif
-- 
2.45.2

_______________________________________________
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] 6+ messages in thread

* [FFmpeg-devel] [PATCH 3/3] lavc/h264dsp: R-V V 8-bit h264_idct8_add4
  2024-07-02 17:13 [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
  2024-07-02 17:13 ` [FFmpeg-devel] [PATCH 2/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16intra Rémi Denis-Courmont
@ 2024-07-02 17:13 ` Rémi Denis-Courmont
  2024-07-02 17:27 ` [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2024-07-02 17:13 UTC (permalink / raw)
  To: ffmpeg-devel

---
 libavcodec/riscv/h264dsp_init.c |  4 ++
 libavcodec/riscv/h264idct_rvv.S | 70 +++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/libavcodec/riscv/h264dsp_init.c b/libavcodec/riscv/h264dsp_init.c
index 7badb86e87..5cf75f280e 100644
--- a/libavcodec/riscv/h264dsp_init.c
+++ b/libavcodec/riscv/h264dsp_init.c
@@ -40,6 +40,9 @@ void ff_h264_idct_add16_8_rvv(uint8_t *dst, const int *blockoffset,
 void ff_h264_idct_add16intra_8_rvv(uint8_t *dst, const int *blockoffset,
                                    int16_t *block, int stride,
                                    const uint8_t nnzc[5 * 8]);
+void ff_h264_idct8_add4_8_rvv(uint8_t *dst, const int *blockoffset,
+                              int16_t *block, int stride,
+                              const uint8_t nnzc[5 * 8]);
 
 extern int ff_startcode_find_candidate_rvb(const uint8_t *, int);
 extern int ff_startcode_find_candidate_rvv(const uint8_t *, int);
@@ -62,6 +65,7 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth,
 
             dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;
             dsp->h264_idct_add16intra = ff_h264_idct_add16intra_8_rvv;
+            dsp->h264_idct8_add4 = ff_h264_idct8_add4_8_rvv;
         }
         dsp->startcode_find_candidate = ff_startcode_find_candidate_rvv;
     }
diff --git a/libavcodec/riscv/h264idct_rvv.S b/libavcodec/riscv/h264idct_rvv.S
index 42a29ba336..7422942717 100644
--- a/libavcodec/riscv/h264idct_rvv.S
+++ b/libavcodec/riscv/h264idct_rvv.S
@@ -170,5 +170,75 @@ func ff_h264_idct_add16intra_\depth\()_rvv, zve32x
         addi    sp, sp, 80
         ret
 endfunc
+
+func ff_h264_idct8_add4_\depth\()_rvv, zve32x
+        addi    sp, sp, -80
+        lla     t0, ff_h264_scan8
+        sd      s0,   (sp)
+        li      t1, 4 * 32 << (\depth > 8)
+        mv      s0, sp
+        li      t2, 4
+        sd      ra,  8(sp)
+        sd      s1, 16(sp)
+        sd      s2, 24(sp)
+        sd      s3, 32(sp)
+        sd      s4, 40(sp)
+        sd      s5, 48(sp)
+        sd      s6, 56(sp)
+        sd      s7, 64(sp)
+        vsetivli  zero, 4, e8, mf4, ta, ma
+        vlse8.v   v8, (t0), t2
+        vlse16.v  v16, (a2), t1
+        vluxei8.v v12, (a4), v8
+.if \depth == 8
+        vsetvli   zero, zero, e16, mf2, ta, ma
+.else
+        vsetvli   zero, zero, e32, m1, ta, ma
+.endif
+        vmsne.vi  v1, v16, 0
+        vsetvli   zero, zero, e8, mf4, ta, ma
+        vmseq.vi  v2, v12, 1
+        vmsne.vi  v0, v12, 0
+        vmand.mm  v1, v1, v2
+        vmv.x.s   s2, v0
+        vmv.x.s   s3, v1
+        li      s1, 4
+        mv      s4, a0
+        mv      s5, a1
+        mv      s6, a2
+        mv      s7, a3
+1:
+        andi    t0, s2, 1
+        addi    s1, s1, -1
+        srli    s2, s2, 1
+        beqz    t0, 3f     # if (nnz)
+        lw      t2, (s5)   # block_offset[i]
+        andi    t1, s3, 1
+        mv      a1, s6
+        mv      a2, s7
+        add     a0, s4, t2
+        beqz    t1, 2f    # if (nnz == 1 && block[i * 16])
+        call    ff_h264_idct8_dc_add_\depth\()_c
+        j       3f
+2:
+        call    ff_h264_idct8_add_\depth\()_c
+3:
+        srli    s3, s3, 1
+        addi    s5, s5, 4 * 4
+        addi    s6, s6, 4 * 16 * 2 << (\depth > 8)
+        bnez    s1, 1b
+
+        ld      s7, 64(sp)
+        ld      s6, 56(sp)
+        ld      s5, 48(sp)
+        ld      s4, 40(sp)
+        ld      s3, 32(sp)
+        ld      s2, 24(sp)
+        ld      s1, 16(sp)
+        ld      ra,  8(sp)
+        ld      s0,  0(sp)
+        addi    sp, sp, 80
+        ret
+endfunc
 .endr
 #endif
-- 
2.45.2

_______________________________________________
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] 6+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16
  2024-07-02 17:13 [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
  2024-07-02 17:13 ` [FFmpeg-devel] [PATCH 2/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16intra Rémi Denis-Courmont
  2024-07-02 17:13 ` [FFmpeg-devel] [PATCH 3/3] lavc/h264dsp: R-V V 8-bit h264_idct8_add4 Rémi Denis-Courmont
@ 2024-07-02 17:27 ` Rémi Denis-Courmont
  2024-07-02 19:22 ` [FFmpeg-devel] [PATCH 4/4] lavc/h264dsp: R-V V 8-bit h264_idct_add Rémi Denis-Courmont
  2024-07-03 17:09 ` [FFmpeg-devel] [PATCH 5/5] lavc/h264dsp: R-V V 8-bit h264_idct8_add Rémi Denis-Courmont
  4 siblings, 0 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2024-07-02 17:27 UTC (permalink / raw)
  To: ffmpeg-devel

Le tiistaina 2. heinäkuuta 2024, 20.13.33 EEST Rémi Denis-Courmont a écrit :
> @@ -52,6 +56,8 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp,
> const int bit_depth, dsp->h264_h_loop_filter_luma =
> ff_h264_h_loop_filter_luma_8_rvv; dsp->h264_h_loop_filter_luma_mbaff =
>                  ff_h264_h_loop_filter_luma_mbaff_8_rvv;
> +
> +            dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;

Will add missing __riscv_xlen guard.

>          }
>          dsp->startcode_find_candidate = ff_startcode_find_candidate_rvv;
>      }

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



_______________________________________________
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] 6+ messages in thread

* [FFmpeg-devel] [PATCH 4/4] lavc/h264dsp: R-V V 8-bit h264_idct_add
  2024-07-02 17:13 [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
                   ` (2 preceding siblings ...)
  2024-07-02 17:27 ` [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
@ 2024-07-02 19:22 ` Rémi Denis-Courmont
  2024-07-03 17:09 ` [FFmpeg-devel] [PATCH 5/5] lavc/h264dsp: R-V V 8-bit h264_idct8_add Rémi Denis-Courmont
  4 siblings, 0 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2024-07-02 19:22 UTC (permalink / raw)
  To: ffmpeg-devel

T-Head C908 (cycles):
h264_idct4_add_8bpp_c:      271.5
h264_idct4_add_8bpp_rvv_i32: 91.5
---
 libavcodec/riscv/h264dsp_init.c |  2 +
 libavcodec/riscv/h264idct_rvv.S | 83 ++++++++++++++++++++++++++++++++-
 2 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/libavcodec/riscv/h264dsp_init.c b/libavcodec/riscv/h264dsp_init.c
index 6b9ffe1c9f..f78ca3ea05 100644
--- a/libavcodec/riscv/h264dsp_init.c
+++ b/libavcodec/riscv/h264dsp_init.c
@@ -34,6 +34,7 @@ void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
 void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
                                             int alpha, int beta, int8_t *tc0);
 
+void ff_h264_idct_add_8_rvv(uint8_t *dst, int16_t *block, int stride);
 void ff_h264_idct_add16_8_rvv(uint8_t *dst, const int *blockoffset,
                               int16_t *block, int stride,
                               const uint8_t nnzc[5 * 8]);
@@ -63,6 +64,7 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth,
             dsp->h264_h_loop_filter_luma_mbaff =
                 ff_h264_h_loop_filter_luma_mbaff_8_rvv;
 
+            dsp->h264_idct_add = ff_h264_idct_add_8_rvv;
 #  if __riscv_xlen == 64
             dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;
             dsp->h264_idct_add16intra = ff_h264_idct_add16intra_8_rvv;
diff --git a/libavcodec/riscv/h264idct_rvv.S b/libavcodec/riscv/h264idct_rvv.S
index 7422942717..b36a7f7572 100644
--- a/libavcodec/riscv/h264idct_rvv.S
+++ b/libavcodec/riscv/h264idct_rvv.S
@@ -26,6 +26,83 @@
 
 #include "libavutil/riscv/asm.S"
 
+        .macro  sx rd, addr
+#if (__riscv_xlen == 32)
+        sw      \rd, \addr
+#elif (__riscv_xlen == 64)
+        sd      \rd, \addr
+#else
+        sq      \rd, \addr
+#endif
+        .endm
+
+        .variant_cc ff_h264_idct4_rvv
+func ff_h264_idct4_rvv, zve32x
+        vsra.vi v5, v1, 1
+        vsra.vi v7, v3, 1
+        vadd.vv v8, v0, v2   # z0
+        vsub.vv v9, v0, v2   # z1
+        vsub.vv v10, v5, v3  # z2
+        vadd.vv v11, v1, v7  # z3
+        vadd.vv v1, v9, v10
+        vsub.vv v2, v9, v10
+        vadd.vv v0, v8, v11
+        vsub.vv v3, v8, v11
+        jr      t0
+endfunc
+
+func ff_h264_idct_add_8_rvv, zve32x
+        csrwi       vxrm, 0
+.Lidct_add4_8_rvv:
+        vsetivli    zero, 4, e16, mf2, ta, ma
+        addi        t1, a1, 1 * 4 * 2
+        vle16.v     v0, (a1)
+        addi        t2, a1, 2 * 4 * 2
+        vle16.v     v1, (t1)
+        addi        t3, a1, 3 * 4 * 2
+        vle16.v     v2, (t2)
+        vle16.v     v3, (t3)
+        jal         t0, ff_h264_idct4_rvv
+        vse16.v     v0, (a1)
+        vse16.v     v1, (t1)
+        vse16.v     v2, (t2)
+        vse16.v     v3, (t3)
+        vlseg4e16.v v0, (a1)
+        .rept   256 / __riscv_xlen
+        sx      zero, ((__riscv_xlen / 8) * \+)(a1)
+        .endr
+        jal         t0, ff_h264_idct4_rvv
+        add         t1, a0, a2
+        vle8.v      v4, (a0)
+        add         t2, t1, a2
+        vle8.v      v5, (t1)
+        add         t3, t2, a2
+        vle8.v      v6, (t2)
+        vle8.v      v7, (t3)
+        .irp    n,0,1,2,3
+        vssra.vi    v\n, v\n, 6
+        .endr
+        vsetvli     zero, zero, e8, mf4, ta, ma
+        vwaddu.wv   v0, v0, v4
+        vwaddu.wv   v1, v1, v5
+        vwaddu.wv   v2, v2, v6
+        vwaddu.wv   v3, v3, v7
+        vsetvli     zero, zero, e16, mf2, ta, ma
+        .irp    n,0,1,2,3
+        vmax.vx     v\n, v\n, zero
+        .endr
+        vsetvli     zero, zero, e8, mf4, ta, ma
+        vnclipu.wi  v4, v0, 0
+        vnclipu.wi  v5, v1, 0
+        vnclipu.wi  v6, v2, 0
+        vnclipu.wi  v7, v3, 0
+        vse8.v      v4, (a0)
+        vse8.v      v5, (t1)
+        vse8.v      v6, (t2)
+        vse8.v      v7, (t3)
+        ret
+endfunc
+
 const ff_h264_scan8
         .byte   014, 015, 024, 025, 016, 017, 026, 027
         .byte   034, 035, 044, 045, 036, 037, 046, 047
@@ -34,6 +111,7 @@ endconst
 #if (__riscv_xlen == 64)
 .irp    depth, 8
 func ff_h264_idct_add16_\depth\()_rvv, zve32x
+        csrwi   vxrm, 0
         addi    sp, sp, -80
         lla     t0, ff_h264_scan8
         sd      s0,   (sp)
@@ -83,7 +161,7 @@ func ff_h264_idct_add16_\depth\()_rvv, zve32x
         call    ff_h264_idct_dc_add_\depth\()_c
         j       3f
 2:
-        call    ff_h264_idct_add_\depth\()_c
+        call    .Lidct_add4_\depth\()_rvv
 3:
         srli    s3, s3, 1
         addi    s5, s5, 4
@@ -104,6 +182,7 @@ func ff_h264_idct_add16_\depth\()_rvv, zve32x
 endfunc
 
 func ff_h264_idct_add16intra_\depth\()_rvv, zve32x
+        csrwi   vxrm, 0
         addi    sp, sp, -80
         lla     t0, ff_h264_scan8
         sd      s0,   (sp)
@@ -147,7 +226,7 @@ func ff_h264_idct_add16intra_\depth\()_rvv, zve32x
         mv      a2, s7
         add     a0, s4, t2
         beqz    t0, 2f     # if (nnzc[scan8[i]])
-        call    ff_h264_idct_add_\depth\()_c
+        call    .Lidct_add4_\depth\()_rvv
         j       3f
 2:
         beqz    t1, 3f    # if (block[i * 16])
-- 
2.45.2

_______________________________________________
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] 6+ messages in thread

* [FFmpeg-devel] [PATCH 5/5] lavc/h264dsp: R-V V 8-bit h264_idct8_add
  2024-07-02 17:13 [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
                   ` (3 preceding siblings ...)
  2024-07-02 19:22 ` [FFmpeg-devel] [PATCH 4/4] lavc/h264dsp: R-V V 8-bit h264_idct_add Rémi Denis-Courmont
@ 2024-07-03 17:09 ` Rémi Denis-Courmont
  4 siblings, 0 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2024-07-03 17:09 UTC (permalink / raw)
  To: ffmpeg-devel

T-Head C908 (cycles):
h264_idct8_add_8bpp_c:      1072.0
h264_idct8_add_8bpp_rvv_i32: 318.5
---
 libavcodec/riscv/h264dsp_init.c |   2 +
 libavcodec/riscv/h264idct_rvv.S | 137 +++++++++++++++++++++++++++++++-
 2 files changed, 138 insertions(+), 1 deletion(-)

diff --git a/libavcodec/riscv/h264dsp_init.c b/libavcodec/riscv/h264dsp_init.c
index f78ca3ea05..bf9743eb6b 100644
--- a/libavcodec/riscv/h264dsp_init.c
+++ b/libavcodec/riscv/h264dsp_init.c
@@ -35,6 +35,7 @@ void ff_h264_h_loop_filter_luma_mbaff_8_rvv(uint8_t *pix, ptrdiff_t stride,
                                             int alpha, int beta, int8_t *tc0);
 
 void ff_h264_idct_add_8_rvv(uint8_t *dst, int16_t *block, int stride);
+void ff_h264_idct8_add_8_rvv(uint8_t *dst, int16_t *block, int stride);
 void ff_h264_idct_add16_8_rvv(uint8_t *dst, const int *blockoffset,
                               int16_t *block, int stride,
                               const uint8_t nnzc[5 * 8]);
@@ -65,6 +66,7 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth,
                 ff_h264_h_loop_filter_luma_mbaff_8_rvv;
 
             dsp->h264_idct_add = ff_h264_idct_add_8_rvv;
+            dsp->h264_idct8_add = ff_h264_idct8_add_8_rvv;
 #  if __riscv_xlen == 64
             dsp->h264_idct_add16 = ff_h264_idct_add16_8_rvv;
             dsp->h264_idct_add16intra = ff_h264_idct_add16intra_8_rvv;
diff --git a/libavcodec/riscv/h264idct_rvv.S b/libavcodec/riscv/h264idct_rvv.S
index b36a7f7572..5dd55085bc 100644
--- a/libavcodec/riscv/h264idct_rvv.S
+++ b/libavcodec/riscv/h264idct_rvv.S
@@ -103,6 +103,140 @@ func ff_h264_idct_add_8_rvv, zve32x
         ret
 endfunc
 
+        .variant_cc ff_h264_idct8_rvv
+func ff_h264_idct8_rvv, zve32x
+        vsra.vi v9, v7, 1
+        vsra.vi v11, v3, 1
+        vsra.vi v12, v2, 1
+        vsra.vi v13, v5, 1
+        vsra.vi v14, v6, 1
+        vsra.vi v15, v1, 1
+        vadd.vv v9, v3, v9
+        vsub.vv v11, v1, v11
+        vsub.vv v13, v13, v1
+        vadd.vv v15, v3, v15
+        vsub.vv v9, v5, v9
+        vadd.vv v11, v11, v7
+        vadd.vv v13, v13, v7
+        vadd.vv v15, v15, v5
+        vadd.vv v8, v0, v4      # a0
+        vsub.vv v9, v9, v7      # a1
+        vsub.vv v10, v0, v4     # a2
+        vsub.vv v11, v11, v3    # a3
+        vsub.vv v12, v12, v6    # a4
+        vadd.vv v13, v13, v5    # a5
+        vadd.vv v14, v14, v2    # a6
+        vadd.vv v15, v15, v1    # a7
+# 8-15
+        vsra.vi v7, v9, 2
+        vsra.vi v5, v11, 2
+        vsra.vi v3, v13, 2
+        vsra.vi v1, v15, 2
+# 1,3,5,7,8-15  free: 0,2,4,6
+        vadd.vv v0, v8, v14     # b0
+        vadd.vv v6, v10, v12    # b2
+        vsub.vv v2, v10, v12    # b4
+        vsub.vv v4, v8, v14     # b6
+# 0-7,9,11,13,15 free: 8,10,12,14
+        vsub.vv v8, v15, v7    # b7
+        vsub.vv v14, v5, v13    # b5
+        vadd.vv v12, v1, v9     # b1
+        vadd.vv v10, v11, v3    # b3
+        vadd.vv v1, v6, v14
+        vsub.vv v6, v6, v14
+        vsub.vv v7, v0, v8
+        vadd.vv v0, v0, v8
+        vsub.vv v5, v2, v10
+        vadd.vv v2, v2, v10
+        vadd.vv v3, v4, v12
+        vsub.vv v4, v4, v12
+        jr      t0
+endfunc
+
+func ff_h264_idct8_add_8_rvv, zve32x
+        csrwi       vxrm, 0
+.Lidct8_add_8_rvv:
+        vsetivli    zero, 8, e16, m1, ta, ma
+        addi        t1, a1, 1 * 8 * 2
+        vle16.v     v0, (a1)
+        addi        t2, a1, 2 * 8 * 2
+        vle16.v     v1, (t1)
+        addi        t3, a1, 3 * 8 * 2
+        vle16.v     v2, (t2)
+        addi        t4, a1, 4 * 8 * 2
+        vle16.v     v3, (t3)
+        addi        t5, a1, 5 * 8 * 2
+        vle16.v     v4, (t4)
+        addi        t6, a1, 6 * 8 * 2
+        vle16.v     v5, (t5)
+        addi        a7, a1, 7 * 8 * 2
+        vle16.v     v6, (t6)
+        vle16.v     v7, (a7)
+        jal         t0, ff_h264_idct8_rvv
+        vse16.v     v0, (a1)
+        vse16.v     v1, (t1)
+        vse16.v     v2, (t2)
+        vse16.v     v3, (t3)
+        vse16.v     v4, (t4)
+        vse16.v     v5, (t5)
+        vse16.v     v6, (t6)
+        vse16.v     v7, (a7)
+        vlseg8e16.v v0, (a1)
+        .rept   1024 / __riscv_xlen
+        sx      zero, ((__riscv_xlen / 8) * \+)(a1)
+        .endr
+        jal         t0, ff_h264_idct8_rvv
+        add         t1, a0, a2
+        vle8.v      v16, (a0)
+        add         t2, t1, a2
+        vle8.v      v17, (t1)
+        add         t3, t2, a2
+        vle8.v      v18, (t2)
+        add         t4, t3, a2
+        vle8.v      v19, (t3)
+        add         t5, t4, a2
+        vle8.v      v20, (t4)
+        add         t6, t5, a2
+        vle8.v      v21, (t5)
+        add         a7, t6, a2
+        vle8.v      v22, (t6)
+        vle8.v      v23, (a7)
+        .irp    n,0,1,2,3,4,5,6,7
+        vssra.vi    v\n, v\n, 6
+        .endr
+        vsetvli     zero, zero, e8, mf2, ta, ma
+        vwaddu.wv   v0, v0, v16
+        vwaddu.wv   v1, v1, v17
+        vwaddu.wv   v2, v2, v18
+        vwaddu.wv   v3, v3, v19
+        vwaddu.wv   v4, v4, v20
+        vwaddu.wv   v5, v5, v21
+        vwaddu.wv   v6, v6, v22
+        vwaddu.wv   v7, v7, v23
+        vsetvli     zero, zero, e16, m1, ta, ma
+        .irp    n,0,1,2,3,4,5,6,7
+        vmax.vx     v\n, v\n, zero
+        .endr
+        vsetvli     zero, zero, e8, mf2, ta, ma
+        vnclipu.wi  v16, v0, 0
+        vnclipu.wi  v17, v1, 0
+        vnclipu.wi  v18, v2, 0
+        vnclipu.wi  v19, v3, 0
+        vnclipu.wi  v20, v4, 0
+        vnclipu.wi  v21, v5, 0
+        vnclipu.wi  v22, v6, 0
+        vnclipu.wi  v23, v7, 0
+        vse8.v      v16, (a0)
+        vse8.v      v17, (t1)
+        vse8.v      v18, (t2)
+        vse8.v      v19, (t3)
+        vse8.v      v20, (t4)
+        vse8.v      v21, (t5)
+        vse8.v      v22, (t6)
+        vse8.v      v23, (a7)
+        ret
+endfunc
+
 const ff_h264_scan8
         .byte   014, 015, 024, 025, 016, 017, 026, 027
         .byte   034, 035, 044, 045, 036, 037, 046, 047
@@ -251,6 +385,7 @@ func ff_h264_idct_add16intra_\depth\()_rvv, zve32x
 endfunc
 
 func ff_h264_idct8_add4_\depth\()_rvv, zve32x
+        csrwi       vxrm, 0
         addi    sp, sp, -80
         lla     t0, ff_h264_scan8
         sd      s0,   (sp)
@@ -300,7 +435,7 @@ func ff_h264_idct8_add4_\depth\()_rvv, zve32x
         call    ff_h264_idct8_dc_add_\depth\()_c
         j       3f
 2:
-        call    ff_h264_idct8_add_\depth\()_c
+        call    .Lidct8_add_\depth\()_rvv
 3:
         srli    s3, s3, 1
         addi    s5, s5, 4 * 4
-- 
2.45.2

_______________________________________________
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] 6+ messages in thread

end of thread, other threads:[~2024-07-03 17:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-02 17:13 [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
2024-07-02 17:13 ` [FFmpeg-devel] [PATCH 2/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16intra Rémi Denis-Courmont
2024-07-02 17:13 ` [FFmpeg-devel] [PATCH 3/3] lavc/h264dsp: R-V V 8-bit h264_idct8_add4 Rémi Denis-Courmont
2024-07-02 17:27 ` [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 Rémi Denis-Courmont
2024-07-02 19:22 ` [FFmpeg-devel] [PATCH 4/4] lavc/h264dsp: R-V V 8-bit h264_idct_add Rémi Denis-Courmont
2024-07-03 17:09 ` [FFmpeg-devel] [PATCH 5/5] lavc/h264dsp: R-V V 8-bit h264_idct8_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