From patchwork Tue Jul 2 17:13:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 50287 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp2595906vqv; Tue, 2 Jul 2024 10:24:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUMVYzESR7tgY04bYmlWgh7TRxLbOhiy0zEsfxgeFlRJy74jUYTSoeg2IqthdkpyJTyKZWxezp2gtnrmPfMOMcZRXCJzJ/ZLt9HHA== X-Google-Smtp-Source: AGHT+IF3/JY8tbbvSD/PnRuX0wu/FpxZuMSx9gAbJr+gT5KL8rBUat4sAHSteEmfdLKUEos06O4k X-Received: by 2002:a05:6402:354c:b0:57c:a77d:a61e with SMTP id 4fb4d7f45d1cf-5879ede2779mr6694030a12.7.1719941046314; Tue, 02 Jul 2024 10:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719941046; cv=none; d=google.com; s=arc-20160816; b=bkjQZgyO5iuGtyIdy5XOm6G3BLdlLwIbo7Qc/+AfnfYp4HqOpoeJ7f7t1fv0JrCuGY ieyOCZjmM1aPOAszIU+TLBhTzkuaiwSzokajGSEZQVUhKhnRqgdi2nb8boZ6n/q8eLdm O818jBBUyqgPzLIxf6/UgfnHfYsDR9Ne0coXjvkR2SdavUTy1GZu1rfbxps+3CaqeAlt fxtEMbXS7xAaN5aOG7BkQuEjKYkXoaw+kIvQ9Fn7aj8q91vsLsDmlaAZ++ujyRzTtsoW dz153Ws8C41x2sjxPh95sQIDyGtvMb73gyiDnWYcr8g/iPXngGY9c+mKjq7eoOO7/cIc tdHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=sW4QRh+7W2aHK/g1FPie8ckT9hQfgJ9gsz9yWNC+y1c=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=TXSJ4S9amrwzbKc0UBXX7op7qVNIF5lCe5AStxBRgoZFoel+UH11JgcvEnD9O4u2ro d2JHsln7VPKRKtMCHZio0DGIliU+ADK14IXO2KUBRXSWwOfAvkoZSh7uFDzHFfKvPh/u BZ/tG7o5ya85YTdEVfsqAJBRwTo44GCk3wELS7LNvIfsCeTnE26yK2iGUk7MzWE5eZum cpzWzVZpwqWJJSb2K9MFiBBMXvyssPAWDbvl+n6VGpSQOitUZwIgLdrgL4DOliVhY3h4 iiVs+Ye3LUVlrxHKn4EEGRH4/8ERwo19cdXNY7Be1hpOqTZlVg8WIPJxnJ5rb/rra1Dt 5bkg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-58615b3d107si4854976a12.664.2024.07.02.10.24.05; Tue, 02 Jul 2024 10:24:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B49968D92F; Tue, 2 Jul 2024 20:13:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ursule.remlab.net (vps-a2bccee9.vps.ovh.net [51.75.19.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A1FA568D903 for ; Tue, 2 Jul 2024 20:13:37 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id D980BC013A for ; Tue, 2 Jul 2024 20:13:36 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Jul 2024 20:13:33 +0300 Message-ID: <20240702171336.26390-1-remi@remlab.net> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavc/h264dsp: R-V V 8-bit h264_idct_add16 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: buPVW6a1tMSM 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