From patchwork Sat Jul 27 20:31:21 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: 50764 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:16f:b0:489:2eb3:e4c4 with SMTP id h47csp386008vqi; Sat, 27 Jul 2024 13:31:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUUE8IlZtTQd/zPZzuouJ2NyQvkmrFRYkh7QGx9MVXFa0hpq8+bZhHGr0PqyZwd6wBLUz4psqSL8eWmU9FX4rn2sio1NC8pQY9YFA== X-Google-Smtp-Source: AGHT+IHAExezE68FvyTqvizWsnx7+bvffe9JLjGDUbCWvDv/RdL9j19AzCNoeFzV0srZGV3oJxAS X-Received: by 2002:a2e:7405:0:b0:2ef:265e:bb8b with SMTP id 38308e7fff4ca-2f12ecd411emr19434251fa.18.1722112304315; Sat, 27 Jul 2024 13:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722112304; cv=none; d=google.com; s=arc-20160816; b=RP1B1D7fVvcYuvuDCKZwA6ysxsimszkPpq4JwwItbhgSSenNH/hAN/KSiMXfIicYr6 oo/i6+HYcHIcKISFkIS1oO0x/ri99k4fZvD6Dyq6s7fO2gh88kXBhaBGxUg8dfAsvoQl pvddD4RimP/Bw0PNYRAB9GuPwyrAlB0vJdrqofGd92E7EeCxjyhqRL5fT2Q2LDcSRpDz mSaEfzXNE4EEoIwkT+zmi9vtq8v0Drd0aY3tRy1cr01fpxBS08eDTvX6XcHOkhyY6py2 mv/5oP2iV0L/w0RvOfr9VGVFbLtZ1FqeDUKtklHNL9XRSrydjOso1Dc9unZkZ2sUWFe1 mYSw== 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:references:in-reply-to:message-id :date:to:from:delivered-to; bh=hbIuXYhHqt5/xA19ZqBCrQecSLREjpBDiQl57Cw9trE=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=XY57mY8sR5pKK8d9Pm8O7ZcMKw07UcFVwbztvzPYo8tXbPEZDfbjXcZvbctIkcrSLG Kd+P7YHVL83gwHzw8avaKWAtRrxjGPNRByXxRHcp+8Nba1suoD8s5ksejJakuxQgfqwo 5R9sSFPJefyYe7Jc4M5Ngw9PTyqEzQqf65XftPtrB9InlTx0EOyWmz9DGnHFFGUPV51q Jg17zT0BZp0flNnA4BYAN2p48ni4YEiYut7eSG9aoT+vPTDjl0kqRJPY8gUYK1s/lQi7 OgHjy7klQx2DWAHDt6GSfr2EtgS+BmmQ2LnSvBr0ZD5fGsa8weEx7Cs3z+xXpdNlhPPF AF1Q==; 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 38308e7fff4ca-2f03d08d427si16094541fa.103.2024.07.27.13.31.43; Sat, 27 Jul 2024 13:31:44 -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 758D368D6AD; Sat, 27 Jul 2024 23:31:31 +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 6CD9668BB61 for ; Sat, 27 Jul 2024 23:31:23 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id D3E54C01A0 for ; Sat, 27 Jul 2024 23:31:22 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 27 Jul 2024 23:31:21 +0300 Message-ID: <20240727203122.104260-2-remi@remlab.net> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240727203122.104260-1-remi@remlab.net> References: <20240727203122.104260-1-remi@remlab.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] lavc/videodsp: RISC-V zicbop prefetch 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: wsqF+M/f6tms There are currently no ways to run-time detect the CPU capability, so we take it for granted (in the worst case, it will execute NOPs). --- libavcodec/riscv/Makefile | 2 ++ libavcodec/riscv/videodsp.S | 34 ++++++++++++++++++++++++++++++ libavcodec/riscv/videodsp_init.c | 36 ++++++++++++++++++++++++++++++++ libavcodec/videodsp.c | 2 ++ libavcodec/videodsp.h | 1 + 5 files changed, 75 insertions(+) create mode 100644 libavcodec/riscv/videodsp.S create mode 100644 libavcodec/riscv/videodsp_init.c diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile index 0bbdd38116..05d0646256 100644 --- a/libavcodec/riscv/Makefile +++ b/libavcodec/riscv/Makefile @@ -67,6 +67,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_VIDEODSP) += riscv/videodsp_init.o +RV-OBJS-$(CONFIG_VIDEODSP) += riscv/videodsp.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 diff --git a/libavcodec/riscv/videodsp.S b/libavcodec/riscv/videodsp.S new file mode 100644 index 0000000000..72bf70ec52 --- /dev/null +++ b/libavcodec/riscv/videodsp.S @@ -0,0 +1,34 @@ +/* + * Copyright © 2022 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/riscv/asm.S" + +#if HAVE_RV_ZICBOP +func ff_prefetch_rv_zicbop, zicbop +1: + addi a2, a2, -1 + prefetch.r (a0) + add a0, a0, a1 + bnez a2, 1b + + ret +endfunc +#endif diff --git a/libavcodec/riscv/videodsp_init.c b/libavcodec/riscv/videodsp_init.c new file mode 100644 index 0000000000..f2c9aae3ca --- /dev/null +++ b/libavcodec/riscv/videodsp_init.c @@ -0,0 +1,36 @@ +/* + * 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 "libavcodec/videodsp.h" + +void ff_prefetch_rv_zicbop(const uint8_t *mem, ptrdiff_t stride, int h); + +av_cold void ff_videodsp_init_riscv(VideoDSPContext *ctx, int bpc) +{ +#if HAVE_RV_ZICBOP + /* TODO: Since we pay for the indirect function call anyway, we should + * only set this if Cache-Block Operation Prefetch (Zicbop) is actually + * supported and otherwise save a few cycles of NOPs. + * But so far there are no means to detect Zicbop (in user mode). + */ + ctx->prefetch = ff_prefetch_rv_zicbop; +#endif +} diff --git a/libavcodec/videodsp.c b/libavcodec/videodsp.c index bdff2e76f5..a19e87a819 100644 --- a/libavcodec/videodsp.c +++ b/libavcodec/videodsp.c @@ -51,6 +51,8 @@ av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc) ff_videodsp_init_arm(ctx, bpc); #elif ARCH_PPC ff_videodsp_init_ppc(ctx, bpc); +#elif ARCH_RISCV + ff_videodsp_init_riscv(ctx, bpc); #elif ARCH_X86 ff_videodsp_init_x86(ctx, bpc); #elif ARCH_MIPS diff --git a/libavcodec/videodsp.h b/libavcodec/videodsp.h index e8960b609d..1be3188d09 100644 --- a/libavcodec/videodsp.h +++ b/libavcodec/videodsp.h @@ -81,6 +81,7 @@ void ff_videodsp_init(VideoDSPContext *ctx, int bpc); void ff_videodsp_init_aarch64(VideoDSPContext *ctx, int bpc); void ff_videodsp_init_arm(VideoDSPContext *ctx, int bpc); void ff_videodsp_init_ppc(VideoDSPContext *ctx, int bpc); +void ff_videodsp_init_riscv(VideoDSPContext *ctx, int bpc); void ff_videodsp_init_x86(VideoDSPContext *ctx, int bpc); void ff_videodsp_init_mips(VideoDSPContext *ctx, int bpc); void ff_videodsp_init_loongarch(VideoDSPContext *ctx, int bpc);