[FFmpeg-devel] [PATCH] lavc/mpegvideoencdsp: R-V V pix_norm1

Rémi Denis-Courmont remi at remlab.net
Mon Aug 12 20:16:13 EEST 2024


T-Head C908:
pix_norm1_c:       480.2
pix_norm1_rvv_i64: 146.9

SpacemiT X60:
pix_norm1_c:       478.2
pix_norm1_rvv_i64:  92.7
---
 libavcodec/riscv/mpegvideoencdsp_init.c |  9 ++++++---
 libavcodec/riscv/mpegvideoencdsp_rvv.S  | 27 +++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/libavcodec/riscv/mpegvideoencdsp_init.c b/libavcodec/riscv/mpegvideoencdsp_init.c
index cae37ef7e1..eb5c8a5aed 100644
--- a/libavcodec/riscv/mpegvideoencdsp_init.c
+++ b/libavcodec/riscv/mpegvideoencdsp_init.c
@@ -24,6 +24,7 @@
 #include "libavcodec/mpegvideoencdsp.h"
 
 int ff_pix_sum_rvv(const uint8_t *pix, int line_size);
+int ff_pix_norm1_rvv(const uint8_t *pix, int line_size);
 
 av_cold void ff_mpegvideoencdsp_init_riscv(MpegvideoEncDSPContext *c,
                                            AVCodecContext *avctx)
@@ -31,8 +32,10 @@ av_cold void ff_mpegvideoencdsp_init_riscv(MpegvideoEncDSPContext *c,
 #if HAVE_RVV
     int flags = av_get_cpu_flags();
 
-    if ((flags & AV_CPU_FLAG_RVV_I64) && (flags & AV_CPU_FLAG_RVB) &&
-        ff_rv_vlen_least(128))
-        c->pix_sum = ff_pix_sum_rvv;
+    if (flags & AV_CPU_FLAG_RVV_I64) {
+        if ((flags & AV_CPU_FLAG_RVB) && ff_rv_vlen_least(128))
+            c->pix_sum = ff_pix_sum_rvv;
+        c->pix_norm1 = ff_pix_norm1_rvv;
+    }
 #endif
 }
diff --git a/libavcodec/riscv/mpegvideoencdsp_rvv.S b/libavcodec/riscv/mpegvideoencdsp_rvv.S
index 83cd919b7c..2f25b00eb2 100644
--- a/libavcodec/riscv/mpegvideoencdsp_rvv.S
+++ b/libavcodec/riscv/mpegvideoencdsp_rvv.S
@@ -44,3 +44,30 @@ func ff_pix_sum_rvv, zve64x, b
         zext.h      a0, a0
         ret
 endfunc
+
+func ff_pix_norm1_rvv, zve64x
+        lpad    0
+        li      t1, 16
+        vsetvli     t0, zero, e32, m8, ta, ma
+        vmv.v.x     v16, zero
+        vmv.s.x     v1, zero
+1:
+        vsetvli     t0, t1, e64, m2, ta, ma
+        vlsseg2e64.v    v8, (a0), a1
+        slli    t2, t0, 3
+        vsetvli     zero, t2, e8, m2, ta, ma
+        vwmulu.vv   v24, v8, v8
+        sub     t1, t1, t0
+        vwmulu.vv   v28, v10, v10
+        mul     t3, a1, t0
+        vsetvli     zero, zero, e16, m4, tu, ma
+        vwaddu.wv   v16, v16, v24
+        add     a0, t3, a0
+        vwaddu.wv   v16, v16, v28
+        bnez    t1, 1b
+
+        vsetvli     zero, zero, e32, m8, ta, ma
+        vredsum.vs  v1, v16, v1
+        vmv.x.s     a0, v1
+        ret
+endfunc
-- 
2.45.2



More information about the ffmpeg-devel mailing list