From patchwork Sun May 26 09:28:20 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: 49269 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:542:0:b0:460:55fa:d5ed with SMTP id 63csp2662426vqf; Sun, 26 May 2024 02:28:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUMZHUk35LURZHjOViwznnOlqMkCiLQEoW8U1e4GRn22nUzEvvwkxbRhXb8V95ILlF6zHRfFoAev+2RvFLwhFmdK9H6RUdn0J3fOw== X-Google-Smtp-Source: AGHT+IGfstBRr+yPqhY9ZgieNThg+pjUQRnVtSTIVpZytS+COlPcPo+4MsKR2wNvV/8r9RdnmMQo X-Received: by 2002:a50:cc08:0:b0:579:c5df:af84 with SMTP id 4fb4d7f45d1cf-579c5dfb2e5mr1459102a12.15.1716715714038; Sun, 26 May 2024 02:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716715714; cv=none; d=google.com; s=arc-20160816; b=eumMuDep6VNWl11iG1plH6kFYsvgp2GEijmz/N+qQtCvi49O1UAw+KIgXKL22nB0QP qn2ARBV6uLnbb8BbVVBCDnG4I1uEY8Rhwlr+oP2FkEC4KZglFrWAd05zgNkj869w6dHA Dt4wqqBVWeg3qAMabpPe3apgkPjnp71RQmIWPSrooFHlDmv/LdfzlXAEi6mqYcKQoI1w 6e4kCiocxvYKmQVeCg7ytE6ZimnQDBDUlWqRW9yGRj5VY20nPy3qfSAXAD3Rysj3sfqf eaCPMClLOpIVItoFpQZRiAOGUU65uNmsEn/t8SVZ16ugX/lQaxC/c+C9pTa+VJP66Xyv /Ciw== 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=40SbzB8jHhU1Q832ReoEsWkeLEp6aBCkTT6SQtEn6Bk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=pGLqCQR2TmTUhjK8hQioLTn0Ssu3KFZBsA+NnzxOc+2hcEj6422Uvab++RhpCQsbTU sYn+NwscVDFIdOVcTcrtqEBKVOHRQWNBCzoh4zHf8ZJB+7PUCENuogOanVwWBqcfJ+Zc W3TFZGEf0vvaokHBYNehgNztMbV82F6Y7u+XJ3QGtwWxb7Bnrk3oXcgErm43KIpbH/oQ adQyTyHEdnYOJeSaElTnlVvKmRkXQT8d2J1XGO4bEurQWZtO1s6Hg/0JFHAWmWMqOInI C8I5sGZLAhwU5TK119ZaFCHfgXvO1Bvz2NDhdu5pakLzEH3ViQg3VuWGDVpZ0v5AogHg AdTw==; 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-57863fc680dsi1959775a12.8.2024.05.26.02.28.33; Sun, 26 May 2024 02:28:34 -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 7664968D4BE; Sun, 26 May 2024 12:28:30 +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 CCD1768D12C for ; Sun, 26 May 2024 12:28:23 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 48420C006F for ; Sun, 26 May 2024 12:28:23 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 May 2024 12:28:20 +0300 Message-ID: <20240526092823.16116-1-remi@remlab.net> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/vp7dsp: add R-V V vp7_luma_dc_wht 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: 2HfyU3Cow+hs This works out a bit more favourably than VP8's due to: - additional multiplications that can be vectored, - hardware-supported fixed-point rounding mode. vp7_luma_dc_wht_c: 3.2 vp7_luma_dc_wht_rvv_i64: 2.0 --- libavcodec/riscv/Makefile | 2 + libavcodec/riscv/vp7dsp_init.c | 41 +++++++++++++++ libavcodec/riscv/vp7dsp_rvv.S | 96 ++++++++++++++++++++++++++++++++++ libavcodec/vp8dsp.c | 4 ++ libavcodec/vp8dsp.h | 2 + 5 files changed, 145 insertions(+) create mode 100644 libavcodec/riscv/vp7dsp_init.c create mode 100644 libavcodec/riscv/vp7dsp_rvv.S diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile index e608436aa4..590655f829 100644 --- a/libavcodec/riscv/Makefile +++ b/libavcodec/riscv/Makefile @@ -65,6 +65,8 @@ RVV-OBJS-$(CONFIG_UTVIDEO_DECODER) += riscv/utvideodsp_rvv.o OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_init.o RV-OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_rvi.o RVV-OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_rvv.o +OBJS-$(CONFIG_VP7_DECODER) += riscv/vp7dsp_init.o +RVV-OBJS-$(CONFIG_VP7_DECODER) += riscv/vp7dsp_rvv.o OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_init.o RV-OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_rvi.o RVV-OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_rvv.o diff --git a/libavcodec/riscv/vp7dsp_init.c b/libavcodec/riscv/vp7dsp_init.c new file mode 100644 index 0000000000..6d9aba43d9 --- /dev/null +++ b/libavcodec/riscv/vp7dsp_init.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Rémi Denis-Courmont. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/riscv/cpu.h" +#include "libavcodec/vp8dsp.h" + +void ff_vp7_luma_dc_wht_rvv(int16_t block[4][4][16], int16_t dc[16]); + +av_cold void ff_vp7dsp_init_riscv(VP8DSPContext *c) +{ +#if HAVE_RVV + int flags = av_get_cpu_flags(); + + if (flags & AV_CPU_FLAG_RVV_I32 && ff_rv_vlen_least(128)) { +#if __riscv_xlen >= 64 + c->vp8_luma_dc_wht = ff_vp7_luma_dc_wht_rvv; +#endif + } +#endif +} diff --git a/libavcodec/riscv/vp7dsp_rvv.S b/libavcodec/riscv/vp7dsp_rvv.S new file mode 100644 index 0000000000..fb21e9a595 --- /dev/null +++ b/libavcodec/riscv/vp7dsp_rvv.S @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Rémi Denis-Courmont. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/riscv/asm.S" + +#if __riscv_xlen >= 64 +func ff_vp7_luma_dc_wht_rvv, zve32x + csrwi vxrm, 0 + li t4, 12540 + vsetivli zero, 4, e16, mf2, ta, ma + vlseg4e16.v v0, (a1) + li t6, 30274 + vwmul.vx v8, v1, t4 + li t5, 23170 + vwmul.vx v9, v3, t6 + addi t1, sp, -12 * 2 + vwmul.vx v10, v1, t6 + addi t2, sp, -8 * 2 + vwmul.vx v11, v3, t4 + addi t3, sp, -4 * 2 + vwadd.vv v4, v0, v2 + addi sp, sp, -16 * 2 + vwsub.vv v5, v0, v2 + vsetvli zero, zero, e32, m1, ta, ma + vadd.vv v7, v10, v11 + vmul.vx v4, v4, t5 + vsub.vv v6, v8, v9 + vmul.vx v5, v5, t5 + vadd.vv v0, v4, v7 + vsub.vv v3, v4, v7 + vadd.vv v1, v5, v6 + vsub.vv v2, v5, v6 + vsetvli zero, zero, e16, mf2, ta, ma + vnsra.wi v4, v0, 14 + vnsra.wi v7, v3, 14 + vnsra.wi v5, v1, 14 + vnsra.wi v6, v2, 14 + vsseg4e16.v v4, (sp) + vle16.v v0, (sp) + vle16.v v1, (t1) + vle16.v v2, (t2) + vle16.v v3, (t3) + vwmul.vx v8, v1, t4 + li t0, 16 * 2 + vwmul.vx v9, v3, t6 + addi t1, a0, 1 * 4 * 16 * 2 + vwmul.vx v10, v1, t6 + addi t2, a0, 2 * 4 * 16 * 2 + vwmul.vx v11, v3, t4 + addi t3, a0, 3 * 4 * 16 * 2 + vwadd.vv v4, v0, v2 + vwsub.vv v5, v0, v2 + vsetvli zero, zero, e32, m1, ta, ma + vmul.vx v4, v4, t5 + sd zero, (a1) + vadd.vv v7, v10, v11 + sd zero, 8(a1) + vmul.vx v5, v5, t5 + sd zero, 16(a1) + vsub.vv v6, v8, v9 + sd zero, 24(a1) + vadd.vv v0, v4, v7 + addi sp, sp, 16 * 2 + vsub.vv v3, v4, v7 + vadd.vv v1, v5, v6 + vsub.vv v2, v5, v6 + vsetvli zero, zero, e16, mf2, ta, ma + vnclip.wi v4, v0, 18 + vnclip.wi v5, v1, 18 + vnclip.wi v6, v2, 18 + vnclip.wi v7, v3, 18 + vsse16.v v4, (a0), t0 + vsse16.v v5, (t1), t0 + vsse16.v v6, (t2), t0 + vsse16.v v7, (t3), t0 + + ret +endfunc +#endif diff --git a/libavcodec/vp8dsp.c b/libavcodec/vp8dsp.c index 8624c3ae15..88bb67f78d 100644 --- a/libavcodec/vp8dsp.c +++ b/libavcodec/vp8dsp.c @@ -712,6 +712,10 @@ av_cold void ff_vp7dsp_init(VP8DSPContext *dsp) dsp->vp8_v_loop_filter_simple = vp7_v_loop_filter_simple_c; dsp->vp8_h_loop_filter_simple = vp7_h_loop_filter_simple_c; + +#if ARCH_RISCV + ff_vp7dsp_init_riscv(dsp); +#endif } #endif /* CONFIG_VP7_DECODER */ diff --git a/libavcodec/vp8dsp.h b/libavcodec/vp8dsp.h index 3bf12b6b45..e3de2e0494 100644 --- a/libavcodec/vp8dsp.h +++ b/libavcodec/vp8dsp.h @@ -90,6 +90,8 @@ void ff_vp78dsp_init_ppc(VP8DSPContext *c); void ff_vp78dsp_init_riscv(VP8DSPContext *c); void ff_vp78dsp_init_x86(VP8DSPContext *c); +void ff_vp7dsp_init_riscv(VP8DSPContext *c); + void ff_vp8dsp_init(VP8DSPContext *c); void ff_vp8dsp_init_aarch64(VP8DSPContext *c); void ff_vp8dsp_init_arm(VP8DSPContext *c);