diff mbox series

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

Message ID 20240812171613.16049-1-remi@remlab.net
State New
Headers show
Series [FFmpeg-devel] lavc/mpegvideoencdsp: R-V V pix_norm1 | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Rémi Denis-Courmont Aug. 12, 2024, 5:16 p.m. UTC
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 mbox series

Patch

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