From patchwork Thu Apr 18 09:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pengxu X-Patchwork-Id: 48150 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ce4e:b0:1a9:af23:56c1 with SMTP id id14csp1570884pzb; Thu, 18 Apr 2024 02:43:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUtRu8mp+xLNmxDApZ+Vnc/3bKdUHWvSCcT4ptXsqCEhIzgWod8AitfevK4YscajpAdkRV7O6wlhdmassqVdYNIgIZWcMkjCur+/g== X-Google-Smtp-Source: AGHT+IFAwUBWjWb2kTPhyypVmVbASyshByqs824yhQo7NWrqEy7xcIlyP46MT1yU4Ws99HJja4Em X-Received: by 2002:ac2:599d:0:b0:516:d6b5:7caf with SMTP id w29-20020ac2599d000000b00516d6b57cafmr1050665lfn.6.1713433379977; Thu, 18 Apr 2024 02:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713433379; cv=none; d=google.com; s=arc-20160816; b=jU+6J6i9fv5++Fb1XtBKMOyqypGAkIFwyIgHjb0tz4x9nldxAhxhnVDCHwYeerotxC BvbcSA6z1V5+gmOu+l7MOd8Hap/7vnbouZTM2bASI8WjCF6ado6R1mrVR+vUfO6l1nH8 n7vFIUQB1duT+nNUt+s+N2szCOiUXfJqOybKl/7aoJRe6594JMk5ZbfEp1PWaACu6LDu 9MTp8YAx2vbo8DOcSbvb84APFoHs8mr2HY1doDl7Z/B3LvYfPQ5Dd+FhyELzJXbNf3ci WYd9BsUJ1HPnky6x2MvlUtbC684xagoN2zCOaYXIEo/VnjM0tRyc31oNqOTc5RJSnzFk /OZQ== 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=V0qZtxBgVpG1bd5sin35yDDDgTRCRcKughlnVXEAPeQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=vnm25adesfkj5qcNsjEjYRT5nM1ahMKI5OEpy3iN8Xm0N/llpirjwdTzWsHn0I55Ag otg+88veK+8ND+XGDSa9lLPLZ0ib55RgVeFunO8/A0nrVx9NEPQWLbxY6xvtrqMe01AJ tcCKM7OPxUtq9M1LtHVOl9YtbVKc1eM3MVdVmtb9GJnSDByVxXY7tA6YEm2LNcsRn2hY ykEgBp1ym5DijD0DaeCeDdRcs9uRd+EyqBau6kWjAwsc2XjYQIfYS0uKoLEdhrpthnEO sRNtS/j1G6cjrzcgUYGlcLL0gKjctRGyvLgvmpMF1Tnl3TT5OsPPNZWcOUmxLzcyLUx+ rV9g==; 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 n24-20020a170906165800b00a522c1fd809si620088ejd.826.2024.04.18.02.42.59; Thu, 18 Apr 2024 02:42:59 -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 9DF1968D449; Thu, 18 Apr 2024 12:42:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A8BC768D406 for ; Thu, 18 Apr 2024 12:42:34 +0300 (EEST) Received: from loongson.cn (unknown [36.33.26.33]) by gateway (Coremail) with SMTP id _____8DxK+kI6yBmaDUpAA--.9559S3; Thu, 18 Apr 2024 17:42:32 +0800 (CST) Received: from localhost (unknown [36.33.26.33]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRREF6yBm8_h+AA--.33748S3; Thu, 18 Apr 2024 17:42:29 +0800 (CST) From: pengxu To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Apr 2024 17:42:23 +0800 Message-Id: <20240418094223.21492-3-pengxu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240418094223.21492-1-pengxu@loongson.cn> References: <20240418094223.21492-1-pengxu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRREF6yBm8_h+AA--.33748S3 X-CM-SenderInfo: pshqw53x6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoW3Ar1fGF4xKrWrCrWrGr1xZwc_yoWDJr47pF Zxuwn0kw18WrZrAw4kJa45Zr18WFyrGrnag3W7tr48Cr4fXF4UWrn7tasrZFykX3y5Aa4S 9a1fKa42yF9YywcCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1j6r15MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jb_-PUUUUU= Subject: [FFmpeg-devel] [PATCH v3 2/2] avcodec/loongarch: add LSX optimization for aac audio encode 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: DBMHzJg0rX6l Add functions: ff_abs_pow34_lsx ff_aac_quantize_bands_lsx ./ffmpeg -f s16le -ac 2 -i ../../1.pcm -c:a aac -f null - before:37.5x after:48.1x --- libavcodec/aacencdsp.h | 3 + libavcodec/loongarch/Makefile | 2 + .../loongarch/aacencdsp_init_loongarch.c | 44 +++ libavcodec/loongarch/aacencdsp_loongarch.S | 254 ++++++++++++++++++ 4 files changed, 303 insertions(+) create mode 100644 libavcodec/loongarch/aacencdsp_init_loongarch.c create mode 100644 libavcodec/loongarch/aacencdsp_loongarch.S diff --git a/libavcodec/aacencdsp.h b/libavcodec/aacencdsp.h index 67836d8cf7..5db27a95a9 100644 --- a/libavcodec/aacencdsp.h +++ b/libavcodec/aacencdsp.h @@ -34,6 +34,7 @@ typedef struct AACEncDSPContext { void ff_aacenc_dsp_init_riscv(AACEncDSPContext *s); void ff_aacenc_dsp_init_x86(AACEncDSPContext *s); +void ff_aacenc_dsp_init_loongarch(AACEncDSPContext *s); static inline void abs_pow34_v(float *out, const float *in, const int size) { @@ -66,6 +67,8 @@ static inline void ff_aacenc_dsp_init(AACEncDSPContext *s) ff_aacenc_dsp_init_riscv(s); #elif ARCH_X86 ff_aacenc_dsp_init_x86(s); +#elif ARCH_LOONGARCH64 + ff_aacenc_dsp_init_loongarch(s); #endif } diff --git a/libavcodec/loongarch/Makefile b/libavcodec/loongarch/Makefile index 07da2964e4..068fd61810 100644 --- a/libavcodec/loongarch/Makefile +++ b/libavcodec/loongarch/Makefile @@ -9,6 +9,7 @@ OBJS-$(CONFIG_HPELDSP) += loongarch/hpeldsp_init_loongarch.o OBJS-$(CONFIG_IDCTDSP) += loongarch/idctdsp_init_loongarch.o OBJS-$(CONFIG_VIDEODSP) += loongarch/videodsp_init.o OBJS-$(CONFIG_HEVC_DECODER) += loongarch/hevcdsp_init_loongarch.o +OBJS-$(CONFIG_AAC_ENCODER) += loongarch/aacencdsp_init_loongarch.o LASX-OBJS-$(CONFIG_H264QPEL) += loongarch/h264qpel_lasx.o LASX-OBJS-$(CONFIG_H264DSP) += loongarch/h264dsp_lasx.o \ loongarch/h264_deblock_lasx.o @@ -38,3 +39,4 @@ LSX-OBJS-$(CONFIG_H264QPEL) += loongarch/h264qpel.o \ loongarch/h264qpel_lsx.o LSX-OBJS-$(CONFIG_H264CHROMA) += loongarch/h264chroma.o LSX-OBJS-$(CONFIG_H264PRED) += loongarch/h264intrapred.o +LSX-OBJS-$(CONFIG_AAC_ENCODER) += loongarch/aacencdsp_loongarch.o diff --git a/libavcodec/loongarch/aacencdsp_init_loongarch.c b/libavcodec/loongarch/aacencdsp_init_loongarch.c new file mode 100644 index 0000000000..b5422d85b5 --- /dev/null +++ b/libavcodec/loongarch/aacencdsp_init_loongarch.c @@ -0,0 +1,44 @@ +/* + * AAC encoder assembly optimizations + * Copyright (c) 2024 Loongson Technology Corporation Limited + * Contributed by PengXu + * + * 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 + */ + +#ifndef AVCODEC_LOONGARCH_AACENC_H +#define AVCODEC_LOONGARCH_AACENC_H + +#include "libavutil/loongarch/cpu.h" +#include "libavcodec/aacenc.h" + +void ff_abs_pow34_lsx(float *out, const float *in, const int size); +void ff_aac_quantize_bands_lsx(int *out, const float *in, const float *scaled, + int size, int is_signed, int maxval, const float Q34, + const float rounding); + +av_cold void ff_aacenc_dsp_init_loongarch(AACEncDSPContext *s) +{ + int cpu_flags = av_get_cpu_flags(); + + if (have_lsx(cpu_flags)) { + s->abs_pow34 = ff_abs_pow34_lsx; + s->quant_bands = ff_aac_quantize_bands_lsx; + } +} + +#endif /* AVCODEC_LOONGARCH_AACENC_H */ \ No newline at end of file diff --git a/libavcodec/loongarch/aacencdsp_loongarch.S b/libavcodec/loongarch/aacencdsp_loongarch.S new file mode 100644 index 0000000000..b80bb98aa9 --- /dev/null +++ b/libavcodec/loongarch/aacencdsp_loongarch.S @@ -0,0 +1,254 @@ +/* + * Loongarch LASX/LSX optimizeds AAC encoder DSP functions + * + * Copyright (c) 2024 Loongson Technology Corporation Limited + * Contributed by PengXu + * + * 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 "loongson_asm.S" + + +/* void ff_abs_pow34_lsx(float *out, const float *in, const int size); */ +// Param, out:a0, in:a1, size:a2 +function ff_abs_pow34_lsx + move t0, zero //loop param + move t1, zero //data index + + srai.d t2, a2, 2 + beq zero, t2, .FAPL02 + +.FAPL01: + add.d t3, a1, t1 + fld.s f0, t3, 0x00 + fld.s f1, t3, 0x04 + fld.s f2, t3, 0x08 + fld.s f3, t3, 0x0c + + fabs.s f0, f0 + fabs.s f1, f1 + fabs.s f2, f2 + fabs.s f3, f3 + + vextrins.w vr0, vr1, 0x10 + vextrins.w vr0, vr2, 0x20 + vextrins.w vr0, vr3, 0x30 + + vfsqrt.s vr4, vr0 + vfmul.s vr5, vr0, vr4 + vfsqrt.s vr6, vr5 + + vstx vr6, a0, t1 + + addi.d t1, t1, 16 + addi.d t0, t0, 1 + blt t0, t2, .FAPL01 + +.FAPL02: /* &2 */ + andi t0, a2, 2 + beq zero, t0, .FAPL03 + + add.d t3, a1, t1 + add.d t4, a0, t1 + + fld.s f0, t3, 0x00 + fld.s f1, t3, 0x04 + + fabs.s f0, f0 + fabs.s f1, f1 + + fsqrt.s f2, f0 + fsqrt.s f3, f1 + + fmul.s f4, f0, f2 + fmul.s f5, f1, f3 + + fsqrt.s f6, f4 + fsqrt.s f7, f5 + + fld.s f6, t4, 0x00 + fld.s f7, t4, 0x04 + + addi.d t1, t1, 8 + +.FAPL03: /* &1 */ + andi t0, a2, 1 + beq zero, t0, .FAPL04 + + fldx.s f0, a1, t1 + + fabs.s f0, f0 + fsqrt.s f2, f0 + fmul.s f4, f0, f2 + fsqrt.s f6, f4 + + fldx.s f6, a0, t1 + + addi.d t1, t1, 4 + +.FAPL04: +endfunc + + + +/* void ff_aac_quantize_bands_lsx(int *out, const float *in, const float *scaled, + int size, int is_signed, int maxval, const float Q34, + const float rounding) */ +// param: +// out: a0 +// in: a1 +// scaled: a2 +// size: a3 +// is_signed: a4 +// maxval: a5 +// Q34: f0 +// rounding: f1 +function ff_aac_quantize_bands_lsx + move t0, zero //loop param + move t1, zero //data index + + vpermi.w vr0, vr0, 0x00 //Q34 + vpermi.w vr1, vr1, 0x00 //rounding + + srai.d t2, a3, 2 ////loop max + beq zero, t2, .FAQBL02 + +.FAQBL01: /* /4 */ + vldx vr2, a2, t1 + vfmul.s vr3, vr2, vr0 //qc + vfadd.s vr4, vr3, vr1 + + movgr2fr.w f5, a5 + ffint.s.w f5, f5 + vpermi.w vr5, vr5, 0x00 //maxval + vfmin.s vr6, vr4, vr5 + vfrintrz.s vr7, vr6 //(float .0)tmp + + beq a4, zero, .S4ISEND + + fsub.s f8, f0, f0 + vshuf4i.w vr8, vr8, 0x00 //0.0f + vldx vr9, a1, t1 //in + vextrins.w vr10, vr9, 0x01 + vextrins.w vr11, vr9, 0x02 + vextrins.w vr12, vr9, 0x03 +.S4IS00: + fcmp.clt.s $fcc0, f9, f8 + bceqz $fcc0, .S4IS01 + vextrins.w vr13, vr7, 0x00 + fneg.s f13, f13 + vextrins.w vr7, vr13, 0x00 +.S4IS01: + fcmp.clt.s $fcc1, f10, f8 + bceqz $fcc1, .S4IS02 + vextrins.w vr13, vr7, 0x01 + fneg.s f13, f13 + vextrins.w vr7, vr13, 0x10 +.S4IS02: + fcmp.clt.s $fcc2, f11, f8 + bceqz $fcc2, .S4IS03 + vextrins.w vr13, vr7, 0x02 + fneg.s f13, f13 + vextrins.w vr7, vr13, 0x20 +.S4IS03: + fcmp.clt.s $fcc3, f12, f8 + bceqz $fcc3, .S4ISEND + vextrins.w vr13, vr7, 0x03 + fneg.s f13, f13 + vextrins.w vr7, vr13, 0x30 +.S4ISEND: + vftintrz.w.s vr14, vr7 + vstx vr14, a0, t1 + addi.d t1, t1, 16 + addi.d t0, t0, 1 + blt t0, t2, .FAQBL01 + +.FAQBL02: /* /2 */ + andi t2, a3, 2 + beq $r0, t2, .FAQBL03 + + vldx vr2, a2, t1 + vfmul.s vr3, vr2, vr0 //qc + vfadd.s vr4, vr3, vr1 + + movgr2fr.w f5, a5 + ffint.s.w f5, f5 + vpermi.w vr5, vr5, 0x00 //maxval + vfmin.s vr6, vr4, vr5 + vfrintrz.s vr7, vr6 //(float .0)tmp + + beq a4, zero, .S2ISEND + + fsub.s f8, f0, f0 + vshuf4i.w vr8, vr8, 0x00 //0.0f + vldx vr9, a1, t1 //in + vextrins.w vr10, vr9, 0x01 +.S2IS00: + fcmp.clt.s $fcc0, f9, f8 + bceqz $fcc0, .S2IS01 + vextrins.w vr13, vr7, 0x00 + fneg.s f13, f13 + vextrins.w vr7, vr13, 0x00 +.S2IS01: + fcmp.clt.s $fcc1, f10, f8 + bceqz $fcc1, .S2ISEND + vextrins.w vr13, vr7, 0x01 + fneg.s f13, f13 + vextrins.w vr7, vr13, 0x10 +.S2ISEND: + vftintrz.w.s vr14, vr7 + vpickve2gr.w t3, vr14, 0 + vpickve2gr.w t4, vr14, 1 + add.d t7, a0, t1 + st.w t3, t7, 0x00 + st.w t4, t7, 0x04 + addi.d t1, t1, 8 + +.FAQBL03: /* /1 */ + andi t2, a3, 1 + beq $r0, t2, .FAQBL04 + + vldx vr2, a2, t1 + vfmul.s vr3, vr2, vr0 //qc + vfadd.s vr4, vr3, vr1 + + movgr2fr.w f5, a5 + ffint.s.w f5, f5 + vpermi.w vr5, vr5, 0x00 //maxval + vfmin.s vr6, vr4, vr5 + vfrintrz.s vr7, vr6 //(float .0)tmp + + beq a4, zero, .S1ISEND + + fsub.s f8, f0, f0 + vshuf4i.w vr8, vr8, 0x00 //0.0f + vldx vr9, a1, t1 //in +.S1IS00: + fcmp.clt.s $fcc0, f9, f8 + bceqz $fcc0, .S1ISEND + vextrins.w vr13, vr7, 0x00 + fneg.s f13, f13 + vextrins.w vr7, vr13, 0x00 +.S1ISEND: + vftintrz.w.s vr14, vr7 + vpickve2gr.w t3, vr14, 0 + stx.w t3, a0, t1 + addi.d t1, t1, 4 + +.FAQBL04: +endfunc \ No newline at end of file