From patchwork Tue Oct 4 17:17:16 2022 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: 38557 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4d9:b0:9c:f4b:4e41 with SMTP id 25csp231155pzd; Tue, 4 Oct 2022 10:17:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6DcqU7YCtrMjw5GdanAi1DCt0QXSsUp2SMOU4ZLQOXqKwekyX+HKz7Og4KEyvsxtMnd1Vn X-Received: by 2002:a17:906:fd84:b0:730:acee:d067 with SMTP id xa4-20020a170906fd8400b00730aceed067mr20601413ejb.206.1664903868773; Tue, 04 Oct 2022 10:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664903868; cv=none; d=google.com; s=arc-20160816; b=QUpEvlLMFO5hlhAN2iRjCE+OAfKnhiCH8qE0pgL46GsPOD31qKKjjfXOLlefRGnaZf Yg5iXAq5gsVIud9wXsIfsnqPPugJIcpKYJoPdz6hOM248bdr11fyHV1i9GEzKolqsIpM vWYK3WUnu95SwQLH7Svxgzo0MjKpS4GfACWmWGgEisewlDCn1uZLXVYlm007rSBZP3U7 SFHZ/2fpnTHz3nUAkL6wA/azEX3S0W8qTcuFD8SDJno/d8rlyTwLF6MQ8kcAfhY9J4pD bbx+7bAPmCNToZwryPUBftaCm4GjRgDILuSYxQV2YP2ipQN9Bhckt52lXcNVrO21Pq/C spHQ== 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=p7cWIWxg3clKVx930M6A1YIg32HytP6bxj0EAc7DGeA=; b=JTZKfF+vR6HfpQNyTDi+o5EG1A0vC8jkAmzBwKQnz2eoegbpYZta79r0QOm+9v802J neg2zn5QnQSj/3ZF6RQJwiSRbRM4sITPbqAAjEd+3ftkdSiaSWMq0yyiY1tp/8OL93Zc rmg6eW73oxxqYWR9q+Zm7H6jo/7O3msw49ETTvZvX0oNH06HYsG2mApy8mM84cZVpUFd Sm2PC6Eo3vra7m+jdoky5GUsBs+ie/9qHjOJEDSX3G8HevEDQzvGwkUvTPUji4AOavsp Eeiy3cuZ2YHy1JWi78uCaKqiat1bqFrs96qWPDSBl4Ai0CUpK0FfyqzerMSHhJsg7rCT +A2w== 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 y88-20020a50bb61000000b004543b0bf7casi10488399ede.492.2022.10.04.10.17.48; Tue, 04 Oct 2022 10:17:48 -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 0353D68BC91; Tue, 4 Oct 2022 20:17:28 +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 EE5AE68BC6C for ; Tue, 4 Oct 2022 20:17:19 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 441D9C00AA for ; Tue, 4 Oct 2022 20:17:18 +0300 (EEST) From: remi@remlab.net To: ffmpeg-devel@ffmpeg.org Date: Tue, 4 Oct 2022 20:17:16 +0300 Message-Id: <20221004171718.47203-1-remi@remlab.net> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavc/alacdsp: RISC-V V decorrelate_stereo 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: 1J6FZzf3kdYH From: Rémi Denis-Courmont To avoid data dependencies, this does the following unroll, which requires one extra but probably free addition: coeff = (b * left_weight) >> decorr_shift; b += a; a -= coeff; b -= coeff; swap(a, b); --- libavcodec/alacdsp.c | 4 ++- libavcodec/alacdsp.h | 1 + libavcodec/riscv/Makefile | 2 ++ libavcodec/riscv/alacdsp_init.c | 39 ++++++++++++++++++++++++++++ libavcodec/riscv/alacdsp_rvv.S | 46 +++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 libavcodec/riscv/alacdsp_init.c create mode 100644 libavcodec/riscv/alacdsp_rvv.S diff --git a/libavcodec/alacdsp.c b/libavcodec/alacdsp.c index b033a27970..a604566afb 100644 --- a/libavcodec/alacdsp.c +++ b/libavcodec/alacdsp.c @@ -58,7 +58,9 @@ av_cold void ff_alacdsp_init(ALACDSPContext *c) c->append_extra_bits[0] = c->append_extra_bits[1] = append_extra_bits; -#if ARCH_X86 +#if ARCH_RISCV + ff_alacdsp_init_riscv(c); +#elif ARCH_X86 ff_alacdsp_init_x86(c); #endif } diff --git a/libavcodec/alacdsp.h b/libavcodec/alacdsp.h index f8b56dd5dc..489ebc6704 100644 --- a/libavcodec/alacdsp.h +++ b/libavcodec/alacdsp.h @@ -29,6 +29,7 @@ typedef struct ALACDSPContext { } ALACDSPContext; void ff_alacdsp_init(ALACDSPContext *c); +void ff_alacdsp_init_riscv(ALACDSPContext *c); void ff_alacdsp_init_x86(ALACDSPContext *c); #endif /* AVCODEC_ALACDSP_H */ diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile index 0fb2c81c75..81f4b985ac 100644 --- a/libavcodec/riscv/Makefile +++ b/libavcodec/riscv/Makefile @@ -1,5 +1,7 @@ OBJS-$(CONFIG_AAC_DECODER) += riscv/aacpsdsp_init.o RVV-OBJS-$(CONFIG_AAC_DECODER) += riscv/aacpsdsp_rvv.o +OBJS-$(CONFIG_ALAC_DECODER) += riscv/alacdsp_init.o +RVV-OBJS-$(CONFIG_ALAC_DECODER) += riscv/alacdsp_rvv.o OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_init.o \ riscv/audiodsp_rvf.o RVV-OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_rvv.o diff --git a/libavcodec/riscv/alacdsp_init.c b/libavcodec/riscv/alacdsp_init.c new file mode 100644 index 0000000000..9ddebaa60b --- /dev/null +++ b/libavcodec/riscv/alacdsp_init.c @@ -0,0 +1,39 @@ +/* + * 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 + +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavcodec/avcodec.h" +#include "libavcodec/alacdsp.h" + +void ff_alac_decorrelate_stereo_rvv(int32_t *buffer[2], int nb_samples, + int decorr_shift, int decorr_left_weight); + +av_cold void ff_alacdsp_init_riscv(ALACDSPContext *c) +{ +#if HAVE_RVV && (__riscv_xlen == 64) + int flags = av_get_cpu_flags(); + + if (flags & AV_CPU_FLAG_RVV_I32) + c->decorrelate_stereo = ff_alac_decorrelate_stereo_rvv; +#endif +} diff --git a/libavcodec/riscv/alacdsp_rvv.S b/libavcodec/riscv/alacdsp_rvv.S new file mode 100644 index 0000000000..5d75d6f2f9 --- /dev/null +++ b/libavcodec/riscv/alacdsp_rvv.S @@ -0,0 +1,46 @@ +/* + * 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 (__riscv_xlen == 64) +func ff_alac_decorrelate_stereo_rvv, zve32x + ld a4, 8(a0) + ld a0, 0(a0) +1: + vsetvli t0, a1, e32, m1, ta, ma + vle32.v v24, (a4) + sub a1, a1, t0 + vle32.v v16, (a0) + vmul.vx v8, v24, a3 + vadd.vv v24, v24, v16 + vsra.vx v8, v8, a2 + vsub.vv v16, v16, v8 + vsub.vv v24, v24, v8 + vse32.v v16, (a4) + sh2add a4, t0, a4 + vse32.v v24, (a0) + sh2add a0, t0, a0 + bnez a1, 1b + + ret +endfunc +#endif