Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Rémi Denis-Courmont" <remi@remlab.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] lavc/h264dsp: use saturing add/sub for R-V V 8-bit DC add
Date: Thu, 25 Jul 2024 21:15:23 +0300
Message-ID: <20240725181523.93924-1-remi@remlab.net> (raw)

T-Head C908 (cycles):
h264_idct4_dc_add_8bpp_c:      109.2
h264_idct4_dc_add_8bpp_rvv_i32: 34.5 (before)
h264_idct4_dc_add_8bpp_rvv_i32: 25.5 (after)
h264_idct8_dc_add_8bpp_c:      418.7
h264_idct8_dc_add_8bpp_rvv_i64: 69.5 (before)
h264_idct8_dc_add_8bpp_rvv_i64: 33.5 (after)
---
 libavcodec/riscv/h264dsp_init.c |  5 +++--
 libavcodec/riscv/h264idct_rvv.S | 28 ++++++++++++++++++----------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/libavcodec/riscv/h264dsp_init.c b/libavcodec/riscv/h264dsp_init.c
index 836c073559..671330d664 100644
--- a/libavcodec/riscv/h264dsp_init.c
+++ b/libavcodec/riscv/h264dsp_init.c
@@ -98,8 +98,8 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth,
 
             dsp->h264_idct_add  = ff_h264_idct_add_8_rvv;
             dsp->h264_idct8_add = ff_h264_idct8_add_8_rvv;
-            dsp->h264_idct_dc_add = ff_h264_idct4_dc_add_8_rvv;
             if (flags & AV_CPU_FLAG_RVB) {
+                dsp->h264_idct_dc_add     = ff_h264_idct4_dc_add_8_rvv;
                 dsp->h264_idct_add16      = ff_h264_idct_add16_8_rvv;
                 dsp->h264_idct_add16intra = ff_h264_idct_add16intra_8_rvv;
 #  if __riscv_xlen == 64
@@ -108,7 +108,8 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth,
             }
             if (flags & AV_CPU_FLAG_RVV_I64) {
                 dsp->h264_add_pixels8_clear = ff_h264_add_pixels8_8_rvv;
-                dsp->h264_idct8_dc_add      = ff_h264_idct8_dc_add_8_rvv;
+                if (flags & AV_CPU_FLAG_RVB)
+                    dsp->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_rvv;
             }
             dsp->h264_add_pixels4_clear = ff_h264_add_pixels4_8_rvv;
         }
diff --git a/libavcodec/riscv/h264idct_rvv.S b/libavcodec/riscv/h264idct_rvv.S
index a49a32c47e..3c547f1eb0 100644
--- a/libavcodec/riscv/h264idct_rvv.S
+++ b/libavcodec/riscv/h264idct_rvv.S
@@ -416,33 +416,41 @@ endfunc
 .endr
 
 .macro idct_dc_add8 width
-func ff_h264_idct\width\()_dc_add_8_rvv, zve64x
+func ff_h264_idct\width\()_dc_add_8_rvv, zve64x, b
 .if \width == 8
         vsetivli        zero, \width, e8, mf2, ta, ma
 .else
         vsetivli        zero, \width, e8, mf4, ta, ma
 .endif
         lh              t0, 0(a1)
+        li              t1, 255
         addi            t0, t0, 32
         srai            t0, t0, 6
         sh              zero, 0(a1)
 .if \width == 8
         li              a6, \width * \width
         vlse64.v        v24, (a0), a2
-        vsetvli         zero, a6, e16, m8, ta, ma
+        vsetvli         zero, a6, e8, m4, ta, ma
 .else
         vlse32.v        v24, (a0), a2
-        vsetivli        zero, \width * \width, e16, m2, ta, ma
+        vsetivli        zero, \width * \width, e8, m1, ta, ma
 .endif
-        vzext.vf2       v0, v24
-        vadd.vx         v0, v0, t0
-        vmax.vx         v0, v0, zero
-.if \width == 8
-        vsetvli         zero, zero, e8, m4, ta, ma
+        bgez            t0, 1f
+
+        neg             t0, t0
+        minu            t0, t0, t1
+        vssubu.vx       v24, v24, t0
+ .if \width == 8
+        vsetivli        zero, \width, e8, mf2, ta, ma
+        vsse64.v        v24, (a0), a2
 .else
-        vsetvli         zero, zero, e8, m1, ta, ma
+        vsetivli        zero, \width, e8, mf4, ta, ma
+        vsse32.v        v24, (a0), a2
 .endif
-        vnclipu.wi      v24, v0, 0
+        ret
+1:
+        minu            t0, t0, t1
+        vsaddu.vx       v24, v24, t0
 .if \width == 8
         vsetivli        zero, \width, e8, mf2, ta, ma
         vsse64.v        v24, (a0), a2
-- 
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".

                 reply	other threads:[~2024-07-25 18:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240725181523.93924-1-remi@remlab.net \
    --to=remi@remlab.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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