From patchwork Fri Dec 8 17:46:51 2023 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: 44981 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp1457099pzf; Fri, 8 Dec 2023 09:47:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQgAmxOix1TvtyJPFTboMQXs88H+7boE9OxJ/9X8mFQM2wM/W7MHSIR/6rxtBzMXhYJUa3 X-Received: by 2002:a17:907:a092:b0:a1d:8a15:3bdf with SMTP id hu18-20020a170907a09200b00a1d8a153bdfmr309159ejc.7.1702057624297; Fri, 08 Dec 2023 09:47:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702057624; cv=none; d=google.com; s=arc-20160816; b=0v/4QLabNG8360CQshAIShHGzo0Q4MJTDIG4+LoRW7vp6NijwJfdajDDo7+RLz3ul4 C1mL4pGfHA7iXYHA1TJJ47DQwrT+eJ+cpTBEGxkgdvokwhS0dNvGUjaE6eloktxcH8Hj rkO6UOjnUebYZvNFnJ2eaghlsEsCDm+FUhRk5TNpKrYYJOFZBL5FZraBHO72wOJKt3Aw elsq9pX2eflgPzfBaEIzoqNOATtxSa9x/P9kGu0Db1VMYV9/QIs8sIbumTJJ+HQO66D7 0G89FB/Mu8BM6dm50l5LC/eGIPTp+Eb2IhCR3KRShnXTch+HFqlsbnbDSkzVj5EWujJS qsVA== 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=lihPcse4W9ksr5m3yRrWASDGfaG1gKP2dNGl2gyWHyc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=RW7Ah9QUI78NGHC5/JnlS113qjZtYMI++IZR6EUG9kwWNCt3Xy50vRY7mrpR3K8LZ0 n3osvnkhJ0fuBoDDJ4RzG7+GXsbXq29WrtQlcLiDyNWh6BLoJqI2JzSRbouUfXe1zFzj TB5MKHodJGMYQljLjqLCrxrv5dIoOfs3ktQY5+FkXS3nxwpHwpf7q6HECO7QcCudErT3 MfzKoSgjnFOOHx7fz/XCtchPq5qi3UKC9fEVMtn2H7BwXdIxyKQxyDpNuVRpgFdB7Juz nCf3IFGE0BftQbdQB39A7vI+uqv/c8pMdPlv1noMl0Zus9Hyje9ziDcejnoBVrymT/rw UKCA== 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 i15-20020a170906114f00b00a1d559e24d3si998088eja.33.2023.12.08.09.47.03; Fri, 08 Dec 2023 09:47:04 -0800 (PST) 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 E1A6368D04F; Fri, 8 Dec 2023 19:47:00 +0200 (EET) 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 750D968CFEC for ; Fri, 8 Dec 2023 19:46:53 +0200 (EET) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id D0194C018A for ; Fri, 8 Dec 2023 19:46:52 +0200 (EET) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Dec 2023 19:46:51 +0200 Message-ID: <20231208174652.21299-1-remi@remlab.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/lpc: R-V V apply_welch_window 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: tc+KY0iafjVd apply_welch_window_even_c: 617.5 apply_welch_window_even_rvv_f64: 235.0 apply_welch_window_odd_c: 709.0 apply_welch_window_odd_rvv_f64: 256.5 --- libavcodec/lpc.c | 4 +- libavcodec/lpc.h | 1 + libavcodec/riscv/Makefile | 2 + libavcodec/riscv/lpc_init.c | 37 ++++++++++++++++ libavcodec/riscv/lpc_rvv.S | 88 +++++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 libavcodec/riscv/lpc_init.c create mode 100644 libavcodec/riscv/lpc_rvv.S diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c index dc6a3060ce..9e2fd0f128 100644 --- a/libavcodec/lpc.c +++ b/libavcodec/lpc.c @@ -320,7 +320,9 @@ av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, s->lpc_apply_welch_window = lpc_apply_welch_window_c; s->lpc_compute_autocorr = lpc_compute_autocorr_c; -#if ARCH_X86 +#if ARCH_RISCV + ff_lpc_init_riscv(s); +#elif ARCH_X86 ff_lpc_init_x86(s); #endif diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h index 467d0b2830..0200baea5c 100644 --- a/libavcodec/lpc.h +++ b/libavcodec/lpc.h @@ -109,6 +109,7 @@ double ff_lpc_calc_ref_coefs_f(LPCContext *s, const float *samples, int len, */ int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type); +void ff_lpc_init_riscv(LPCContext *s); void ff_lpc_init_x86(LPCContext *s); /** diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile index e9825c0856..1d4572fbc5 100644 --- a/libavcodec/riscv/Makefile +++ b/libavcodec/riscv/Makefile @@ -33,6 +33,8 @@ OBJS-$(CONFIG_LLVIDDSP) += riscv/llviddsp_init.o RVV-OBJS-$(CONFIG_LLVIDDSP) += riscv/llviddsp_rvv.o OBJS-$(CONFIG_LLVIDENCDSP) += riscv/llvidencdsp_init.o RVV-OBJS-$(CONFIG_LLVIDENCDSP) += riscv/llvidencdsp_rvv.o +OBJS-$(CONFIG_LPC) += riscv/lpc_init.o +RVV-OBJS-$(CONFIG_LPC) += riscv/lpc_rvv.o OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_init.o RVV-OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_rvv.o OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o diff --git a/libavcodec/riscv/lpc_init.c b/libavcodec/riscv/lpc_init.c new file mode 100644 index 0000000000..c16e5745f0 --- /dev/null +++ b/libavcodec/riscv/lpc_init.c @@ -0,0 +1,37 @@ +/* + * 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/attributes.h" +#include "libavutil/cpu.h" +#include "libavcodec/lpc.h" + +void ff_lpc_apply_welch_window_rvv(const int32_t *, ptrdiff_t, double *); + +av_cold void ff_lpc_init_riscv(LPCContext *c) +{ +#if HAVE_RVV && (__riscv_xlen >= 64) + int flags = av_get_cpu_flags(); + + if ((flags & AV_CPU_FLAG_RVV_F64) && (flags & AV_CPU_FLAG_RVB_ADDR)) + c->lpc_apply_welch_window = ff_lpc_apply_welch_window_rvv; +#endif +} diff --git a/libavcodec/riscv/lpc_rvv.S b/libavcodec/riscv/lpc_rvv.S new file mode 100644 index 0000000000..2bc729d400 --- /dev/null +++ b/libavcodec/riscv/lpc_rvv.S @@ -0,0 +1,88 @@ +/* + * Copyright © 2023 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_lpc_apply_welch_window_rvv, zve64d + vsetvli t0, zero, e64, m8, ta, ma + vid.v v0 + addi t2, a1, -1 + vfcvt.f.xu.v v0, v0 + li t3, 2 + fcvt.d.l ft2, t2 + srai t1, a1, 1 + fcvt.d.l ft3, t3 + li t4, 1 + fdiv.d ft0, ft3, ft2 # ft0 = c = 2. / (len - 1) + fcvt.d.l fa1, t4 # fa1 = 1. + fsub.d ft1, ft0, fa1 + vfrsub.vf v0, v0, ft1 # v0[i] = c - i - 1. +1: + vsetvli t0, t1, e64, m8, ta, ma + vfmul.vv v16, v0, v0 # no fused multipy-add as v0 is reused + sub t1, t1, t0 + vle32.v v8, (a0) + fcvt.d.l ft2, t0 + vfrsub.vf v16, v16, fa1 # v16 = 1. - w * w + sh2add a0, t0, a0 + vsetvli zero, zero, e32, m4, ta, ma + vfwcvt.f.x.v v24, v8 + vsetvli zero, zero, e64, m8, ta, ma + vfsub.vf v0, v0, ft2 # v0 -= vl + vfmul.vv v8, v24, v16 + vse64.v v8, (a2) + sh3add a2, t0, a2 + bnez t1, 1b + + andi t1, a1, 1 + beqz t1, 2f + + sd zero, (a2) + addi a0, a0, 4 + addi a2, a2, 8 +2: + vsetvli t0, zero, e64, m8, ta, ma + vid.v v0 + srai t1, a1, 1 + vfcvt.f.xu.v v0, v0 + fcvt.d.l ft1, t1 + fsub.d ft1, ft0, ft1 # ft1 = c - (len / 2) + vfadd.vf v0, v0, ft1 # v0[i] = c - (len / 2) + i +3: + vsetvli t0, t1, e64, m8, ta, ma + vfmul.vv v16, v0, v0 + sub t1, t1, t0 + vle32.v v8, (a0) + fcvt.d.l ft2, t0 + vfrsub.vf v16, v16, fa1 # v16 = 1. - w * w + sh2add a0, t0, a0 + vsetvli zero, zero, e32, m4, ta, ma + vfwcvt.f.x.v v24, v8 + vsetvli zero, zero, e64, m8, ta, ma + vfadd.vf v0, v0, ft2 # v0 += vl + vfmul.vv v8, v24, v16 + vse64.v v8, (a2) + sh3add a2, t0, a2 + bnez t1, 3b + + ret +endfunc +#endif