From patchwork Mon Aug 29 11:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6ZmI5piK?= X-Patchwork-Id: 37549 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp1876790pzh; Mon, 29 Aug 2022 04:27:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7jHrTCnJHnocYUzPtQNrS9GfCc7ErUalxHIHFUD1QcQyBkmUUpmYXs7XfL6iwL6kSz+JO+ X-Received: by 2002:a17:907:7b95:b0:731:113a:d7a2 with SMTP id ne21-20020a1709077b9500b00731113ad7a2mr12835874ejc.377.1661772439540; Mon, 29 Aug 2022 04:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661772439; cv=none; d=google.com; s=arc-20160816; b=cKlHilsBTrpjo5O+HFTaHVa2YLYDZa04UMXD3r0qs6HFy3w75xg5duGeeTwnNBImbj CTHP23WcemTH3xmSNL8hN/eytrO3S4hbZtSfSG5zVJXNBMdhxduOejRyDgsAy794FDNA DJlNe/uj9MBNLm6yy/H7fsv5tfHX5ENnstfPNOYI5UaOCyC3lYycS2Zz8i6jmW8u34OH 63oh4X0qShmtjerb0+c4/zBOoH+zkQuvwNw9YzNm+hNy7r90XgpjvhzrC8skSTgxap2b LlAxf34f+pWz7pQlhu/QV+TD6TdmZyhcArtMnOPtzgvWlTRLM5BeSD+LtdUaAFSG5x/4 rVjA== 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=GCSDaV52pI/G0S3dGwn2GnDC7OgTBF3b8Jrdd60T8F0=; b=ScTtMyHHDDnobellfCITrIFcNk8qZmwXN7J8F5BYYlUp7ntgBoA7ZIdzNz2QdROaEl EGEeYA3pKXxN8Dq5jSe4Yl9DdP8WpCOqv4Te05TyoSxQTy/Xon0HiDuBMjYv4+HQKoOm Z15n3eYAkkY4DZYsdAy27aopuV3J275fm/3Rf3V5pwAhwYooe8NI7yHGULoyQr8QZ1mT /y8NS/DTns19qffR5VTsoWa2AW6/QQOzwsR5JDcBos8q2dF4FWcmecG67TlS7XMHoEkW 37gxflE2I/K1oZVNfbt8sRfxoqLOJfScXtYaweP6oYmnQRjUs+CmsWP7kytN80qAwhXb 0QBg== 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 y90-20020a50bb63000000b0044718c3e05dsi6483412ede.78.2022.08.29.04.27.19; Mon, 29 Aug 2022 04:27:19 -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 2FD1768B9E9; Mon, 29 Aug 2022 14:27:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7028C68B94F for ; Mon, 29 Aug 2022 14:27:00 +0300 (EEST) Received: from localhost (unknown [36.33.26.144]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxbWuCogxjENkLAA--.5425S3; Mon, 29 Aug 2022 19:26:58 +0800 (CST) From: Hao Chen To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Aug 2022 19:26:54 +0800 Message-Id: <20220829112656.9229-2-chenhao@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220829112656.9229-1-chenhao@loongson.cn> References: <20220829112656.9229-1-chenhao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxbWuCogxjENkLAA--.5425S3 X-Coremail-Antispam: 1UD129KBjvAXoWDXFy7Gw4rZF4rZFWftry7Jrb_yoWrKr4fWo WkWws2yrn7Ww4Iyr45tr1kta1DJa15CF1UJFW7Jwsay3WfJFy5ArWvvw45Jw4ktr4kZr17 GF4UXasrZFn0qwn5n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYj7k0a2IF6w4kM7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0 x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj4 1l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0 I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8KwCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jr0_JrylIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU5EoGJUUUUU== X-CM-SenderInfo: hfkh0xtdr6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH v1 1/3] swscale/la: Optimize hscale functions with lasx. 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: P9BI7zUE8nlF ffmpeg -i ~/media/1_h264_1080p_30fps_3Mbps.mp4 -f rawvideo -s 640x480 -y /dev/null -an before: 101fps after: 138fps Signed-off-by: Hao Chen --- libswscale/loongarch/Makefile | 3 + libswscale/loongarch/input_lasx.c | 192 ++++ libswscale/loongarch/swscale_init_loongarch.c | 50 + libswscale/loongarch/swscale_lasx.c | 959 ++++++++++++++++++ libswscale/loongarch/swscale_loongarch.h | 50 + libswscale/swscale.c | 2 + libswscale/swscale_internal.h | 2 + libswscale/utils.c | 13 +- 8 files changed, 1270 insertions(+), 1 deletion(-) create mode 100644 libswscale/loongarch/Makefile create mode 100644 libswscale/loongarch/input_lasx.c create mode 100644 libswscale/loongarch/swscale_init_loongarch.c create mode 100644 libswscale/loongarch/swscale_lasx.c create mode 100644 libswscale/loongarch/swscale_loongarch.h diff --git a/libswscale/loongarch/Makefile b/libswscale/loongarch/Makefile new file mode 100644 index 0000000000..586a1717b6 --- /dev/null +++ b/libswscale/loongarch/Makefile @@ -0,0 +1,3 @@ +OBJS-$(CONFIG_SWSCALE) += loongarch/swscale_init_loongarch.o +LASX-OBJS-$(CONFIG_SWSCALE) += loongarch/swscale_lasx.o \ + loongarch/input_lasx.o \ diff --git a/libswscale/loongarch/input_lasx.c b/libswscale/loongarch/input_lasx.c new file mode 100644 index 0000000000..6fcb998bc0 --- /dev/null +++ b/libswscale/loongarch/input_lasx.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2022 Loongson Technology Corporation Limited + * Contributed by Hao Chen(chenhao@loongson.cn) + * + * 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 "swscale_loongarch.h" +#include "libavutil/loongarch/loongson_intrinsics.h" + +void planar_rgb_to_uv_lasx(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], + int width, int32_t *rgb2yuv) +{ + int i; + uint16_t *dstU = (uint16_t *)_dstU; + uint16_t *dstV = (uint16_t *)_dstV; + int set = 0x4001 << (RGB2YUV_SHIFT - 7); + int len = width - 15; + int32_t tem_ru = rgb2yuv[RU_IDX], tem_gu = rgb2yuv[GU_IDX]; + int32_t tem_bu = rgb2yuv[BU_IDX], tem_rv = rgb2yuv[RV_IDX]; + int32_t tem_gv = rgb2yuv[GV_IDX], tem_bv = rgb2yuv[BV_IDX]; + int shift = RGB2YUV_SHIFT - 6; + const uint8_t *src0 = src[0], *src1 = src[1], *src2 = src[2]; + __m256i ru, gu, bu, rv, gv, bv; + __m256i mask = {0x0D0C090805040100, 0x1D1C191815141110, + 0x0D0C090805040100, 0x1D1C191815141110}; + __m256i temp = __lasx_xvreplgr2vr_w(set); + __m256i sra = __lasx_xvreplgr2vr_w(shift); + + ru = __lasx_xvreplgr2vr_w(tem_ru); + gu = __lasx_xvreplgr2vr_w(tem_gu); + bu = __lasx_xvreplgr2vr_w(tem_bu); + rv = __lasx_xvreplgr2vr_w(tem_rv); + gv = __lasx_xvreplgr2vr_w(tem_gv); + bv = __lasx_xvreplgr2vr_w(tem_bv); + for (i = 0; i < len; i += 16) { + __m256i _g, _b, _r; + __m256i g_l, g_h, b_l, b_h, r_l, r_h; + __m256i v_l, v_h, u_l, u_h, u_lh, v_lh; + + DUP2_ARG2(__lasx_xvld, src0 + i, 0, src1 + i, 0, _g, _b); + _r = __lasx_xvld(src2 + i, 0); + g_l = __lasx_vext2xv_wu_bu(_g); + DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_l, r_l); + _g = __lasx_xvpermi_d(_g, 0x01); + _b = __lasx_xvpermi_d(_b, 0x01); + _r = __lasx_xvpermi_d(_r, 0x01); + g_h = __lasx_vext2xv_wu_bu(_g); + DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_h, r_h); + u_l = __lasx_xvmadd_w(temp, ru, r_l); + u_h = __lasx_xvmadd_w(temp, ru, r_h); + v_l = __lasx_xvmadd_w(temp, rv, r_l); + v_h = __lasx_xvmadd_w(temp, rv, r_h); + u_l = __lasx_xvmadd_w(u_l, gu, g_l); + u_l = __lasx_xvmadd_w(u_l, bu, b_l); + u_h = __lasx_xvmadd_w(u_h, gu, g_h); + u_h = __lasx_xvmadd_w(u_h, bu, b_h); + v_l = __lasx_xvmadd_w(v_l, gv, g_l); + v_l = __lasx_xvmadd_w(v_l, bv, b_l); + v_h = __lasx_xvmadd_w(v_h, gv, g_h); + v_h = __lasx_xvmadd_w(v_h, bv, b_h); + u_l = __lasx_xvsra_w(u_l, sra); + u_h = __lasx_xvsra_w(u_h, sra); + v_l = __lasx_xvsra_w(v_l, sra); + v_h = __lasx_xvsra_w(v_h, sra); + DUP2_ARG3(__lasx_xvshuf_b, u_h, u_l, mask, v_h, v_l, mask, u_lh, v_lh); + u_lh = __lasx_xvpermi_d(u_lh, 0xD8); + v_lh = __lasx_xvpermi_d(v_lh, 0xD8); + __lasx_xvst(u_lh, (dstU + i), 0); + __lasx_xvst(v_lh, (dstV + i), 0); + } + if (width - i >= 8) { + __m256i _g, _b, _r; + __m256i g_l, b_l, r_l; + __m256i v_l, u_l, u, v; + + _g = __lasx_xvldrepl_d((src0 + i), 0); + _b = __lasx_xvldrepl_d((src1 + i), 0); + _r = __lasx_xvldrepl_d((src2 + i), 0); + g_l = __lasx_vext2xv_wu_bu(_g); + DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_l, r_l); + u_l = __lasx_xvmadd_w(temp, ru, r_l); + v_l = __lasx_xvmadd_w(temp, rv, r_l); + u_l = __lasx_xvmadd_w(u_l, gu, g_l); + u_l = __lasx_xvmadd_w(u_l, bu, b_l); + v_l = __lasx_xvmadd_w(v_l, gv, g_l); + v_l = __lasx_xvmadd_w(v_l, bv, b_l); + u_l = __lasx_xvsra_w(u_l, sra); + v_l = __lasx_xvsra_w(v_l, sra); + DUP2_ARG3(__lasx_xvshuf_b, u_l, u_l, mask, v_l, v_l, mask, u, v); + __lasx_xvstelm_d(u, (dstU + i), 0, 0); + __lasx_xvstelm_d(u, (dstU + i), 8, 2); + __lasx_xvstelm_d(v, (dstV + i), 0, 0); + __lasx_xvstelm_d(v, (dstV + i), 8, 2); + i += 8; + } + for (; i < width; i++) { + int g = src[0][i]; + int b = src[1][i]; + int r = src[2][i]; + + dstU[i] = (tem_ru * r + tem_gu * g + tem_bu * b + set) >> shift; + dstV[i] = (tem_rv * r + tem_gv * g + tem_bv * b + set) >> shift; + } +} + +void planar_rgb_to_y_lasx(uint8_t *_dst, const uint8_t *src[4], int width, + int32_t *rgb2yuv) +{ + int i; + int shift = (RGB2YUV_SHIFT - 6); + int set = 0x801 << (RGB2YUV_SHIFT - 7); + int len = width - 15; + uint16_t *dst = (uint16_t *)_dst; + int32_t tem_ry = rgb2yuv[RY_IDX], tem_gy = rgb2yuv[GY_IDX]; + int32_t tem_by = rgb2yuv[BY_IDX]; + const uint8_t *src0 = src[0], *src1 = src[1], *src2 = src[2]; + __m256i mask = {0x0D0C090805040100, 0x1D1C191815141110, + 0x0D0C090805040100, 0x1D1C191815141110}; + __m256i temp = __lasx_xvreplgr2vr_w(set); + __m256i sra = __lasx_xvreplgr2vr_w(shift); + __m256i ry = __lasx_xvreplgr2vr_w(tem_ry); + __m256i gy = __lasx_xvreplgr2vr_w(tem_gy); + __m256i by = __lasx_xvreplgr2vr_w(tem_by); + + for (i = 0; i < len; i += 16) { + __m256i _g, _b, _r; + __m256i g_l, g_h, b_l, b_h, r_l, r_h; + __m256i y_l, y_h, y_lh; + + DUP2_ARG2(__lasx_xvld, src0 + i, 0, src1 + i, 0, _g, _b); + _r = __lasx_xvld(src2 + i, 0); + g_l = __lasx_vext2xv_wu_bu(_g); + DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_l, r_l); + _g = __lasx_xvpermi_d(_g, 0x01); + _b = __lasx_xvpermi_d(_b, 0x01); + _r = __lasx_xvpermi_d(_r, 0x01); + g_h = __lasx_vext2xv_wu_bu(_g); + DUP2_ARG1(__lasx_vext2xv_wu_bu,_b, _r, b_h, r_h); + y_l = __lasx_xvmadd_w(temp, ry, r_l); + y_h = __lasx_xvmadd_w(temp, ry, r_h); + y_l = __lasx_xvmadd_w(y_l, gy, g_l); + y_l = __lasx_xvmadd_w(y_l, by, b_l); + y_h = __lasx_xvmadd_w(y_h, gy, g_h); + y_h = __lasx_xvmadd_w(y_h, by, b_h); + y_l = __lasx_xvsra_w(y_l, sra); + y_h = __lasx_xvsra_w(y_h, sra); + y_lh = __lasx_xvshuf_b(y_h, y_l, mask); + y_lh = __lasx_xvpermi_d(y_lh, 0xD8); + __lasx_xvst(y_lh, (dst + i), 0); + } + if (width - i >= 8) { + __m256i _g, _b, _r; + __m256i g_l, b_l, r_l; + __m256i y_l, y; + + _g = __lasx_xvldrepl_d((src0 + i), 0); + _b = __lasx_xvldrepl_d((src1 + i), 0); + _r = __lasx_xvldrepl_d((src2 + i), 0); + g_l = __lasx_vext2xv_wu_bu(_g); + DUP2_ARG1(__lasx_vext2xv_wu_bu, _b, _r, b_l, r_l); + y_l = __lasx_xvmadd_w(temp, ry, r_l); + y_l = __lasx_xvmadd_w(y_l, gy, g_l); + y_l = __lasx_xvmadd_w(y_l, by, b_l); + y_l = __lasx_xvsra_w(y_l, sra); + y = __lasx_xvshuf_b(y_l, y_l, mask); + __lasx_xvstelm_d(y, (dst + i), 0, 0); + __lasx_xvstelm_d(y, (dst + i), 8, 2); + i += 8; + } + for (; i < width; i++) { + int g = src[0][i]; + int b = src[1][i]; + int r = src[2][i]; + + dst[i] = (tem_ry * r + tem_gy * g + tem_by * b + set) >> shift; + } +} diff --git a/libswscale/loongarch/swscale_init_loongarch.c b/libswscale/loongarch/swscale_init_loongarch.c new file mode 100644 index 0000000000..197dc6e1e7 --- /dev/null +++ b/libswscale/loongarch/swscale_init_loongarch.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 Loongson Technology Corporation Limited + * Contributed by Hao Chen(chenhao@loongson.cn) + * + * 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 "swscale_loongarch.h" +#include "libswscale/swscale_internal.h" +#include "libavutil/loongarch/cpu.h" + +av_cold void ff_sws_init_swscale_loongarch(SwsContext *c) +{ + int cpu_flags = av_get_cpu_flags(); + if (have_lasx(cpu_flags)) { + if (c->srcBpc == 8) { + if (c->dstBpc <= 14) { + c->hyScale = c->hcScale = ff_hscale_8_to_15_lasx; + } else { + c->hyScale = c->hcScale = ff_hscale_8_to_19_lasx; + } + } else { + c->hyScale = c->hcScale = c->dstBpc > 14 ? ff_hscale_16_to_19_lasx + : ff_hscale_16_to_15_lasx; + } + switch (c->srcFormat) { + case AV_PIX_FMT_GBRAP: + case AV_PIX_FMT_GBRP: + { + c->readChrPlanar = planar_rgb_to_uv_lasx; + c->readLumPlanar = planar_rgb_to_y_lasx; + } + break; + } + } +} diff --git a/libswscale/loongarch/swscale_lasx.c b/libswscale/loongarch/swscale_lasx.c new file mode 100644 index 0000000000..53bfdf7e5c --- /dev/null +++ b/libswscale/loongarch/swscale_lasx.c @@ -0,0 +1,959 @@ +/* + * Copyright (C) 2022 Loongson Technology Corporation Limited + * Contributed by Hao Chen(chenhao@loongson.cn) + * + * 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 "swscale_loongarch.h" +#include "libavutil/loongarch/loongson_intrinsics.h" +#include "libavutil/intreadwrite.h" + +#define SCALE_8_16(_sh) \ +{ \ + src0 = __lasx_xvldrepl_d(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_d(src + filterPos[1], 0); \ + src2 = __lasx_xvldrepl_d(src + filterPos[2], 0); \ + src3 = __lasx_xvldrepl_d(src + filterPos[3], 0); \ + src4 = __lasx_xvldrepl_d(src + filterPos[4], 0); \ + src5 = __lasx_xvldrepl_d(src + filterPos[5], 0); \ + src6 = __lasx_xvldrepl_d(src + filterPos[6], 0); \ + src7 = __lasx_xvldrepl_d(src + filterPos[7], 0); \ + src8 = __lasx_xvldrepl_d(src + filterPos[8], 0); \ + src9 = __lasx_xvldrepl_d(src + filterPos[9], 0); \ + src10 = __lasx_xvldrepl_d(src + filterPos[10], 0); \ + src11 = __lasx_xvldrepl_d(src + filterPos[11], 0); \ + src12 = __lasx_xvldrepl_d(src + filterPos[12], 0); \ + src13 = __lasx_xvldrepl_d(src + filterPos[13], 0); \ + src14 = __lasx_xvldrepl_d(src + filterPos[14], 0); \ + src15 = __lasx_xvldrepl_d(src + filterPos[15], 0); \ + DUP4_ARG2(__lasx_xvld, filter, 0, filter, 32, filter, 64, \ + filter, 96, filter0, filter1, filter2, filter3); \ + DUP4_ARG2(__lasx_xvld, filter, 128, filter, 160, \ + filter, 192, filter, 224, filter4, \ + filter5, filter6, filter7); \ + DUP4_ARG2(__lasx_xvilvl_d, src1, src0, src3, src2, \ + src5, src4, src7, src6, src0, src2, src4, src6); \ + DUP4_ARG2(__lasx_xvilvl_d, src9, src8, src11, src10, \ + src13, src12, src15, src14, src8, src10, src12, src14); \ + DUP4_ARG1(__lasx_vext2xv_hu_bu, src0, src2, src4, src6, \ + src0, src2, src4, src6); \ + DUP4_ARG1(__lasx_vext2xv_hu_bu, src8, src10, src12, \ + src14, src8, src10, src12, src14); \ + DUP4_ARG2(__lasx_xvdp2_w_h, filter0, src0, filter1, src2, \ + filter2, src4, filter3, src6, src0, src1, src2, src3); \ + DUP4_ARG2(__lasx_xvdp2_w_h, filter4, src8, filter5, src10, \ + filter6, src12, filter7, src14, src4, src5, src6, src7);\ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src1 = __lasx_xvhaddw_d_w(src1, src1); \ + src2 = __lasx_xvhaddw_d_w(src2, src2); \ + src3 = __lasx_xvhaddw_d_w(src3, src3); \ + src4 = __lasx_xvhaddw_d_w(src4, src4); \ + src5 = __lasx_xvhaddw_d_w(src5, src5); \ + src6 = __lasx_xvhaddw_d_w(src6, src6); \ + src7 = __lasx_xvhaddw_d_w(src7, src7); \ + DUP4_ARG2(__lasx_xvpickev_w, src1, src0, src3, src2, \ + src5, src4, src7, src6, src0, src1, src2, src3); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src1 = __lasx_xvhaddw_d_w(src1, src1); \ + src2 = __lasx_xvhaddw_d_w(src2, src2); \ + src3 = __lasx_xvhaddw_d_w(src3, src3); \ + DUP2_ARG2(__lasx_xvpickev_w, src1, src0, src3, src2, src0, src1); \ + DUP2_ARG2(__lasx_xvsrai_w, src0, _sh, src1, _sh, src0, src1); \ + src0 = __lasx_xvmin_w(src0, vmax); \ + src1 = __lasx_xvmin_w(src1, vmax); \ + src0 = __lasx_xvperm_w(src0, shuf); \ + src1 = __lasx_xvperm_w(src1, shuf); \ + src0 = __lasx_xvpickev_h(src1, src0); \ + src0 = __lasx_xvpermi_d(src0, 0xd8); \ + __lasx_xvst(src0, dst, 0); \ + filterPos += 16; \ + filter += 128; \ + dst += 16; \ +} + +#define SCALE_8_8(_sh) \ +{ \ + src0 = __lasx_xvldrepl_d(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_d(src + filterPos[1], 0); \ + src2 = __lasx_xvldrepl_d(src + filterPos[2], 0); \ + src3 = __lasx_xvldrepl_d(src + filterPos[3], 0); \ + src4 = __lasx_xvldrepl_d(src + filterPos[4], 0); \ + src5 = __lasx_xvldrepl_d(src + filterPos[5], 0); \ + src6 = __lasx_xvldrepl_d(src + filterPos[6], 0); \ + src7 = __lasx_xvldrepl_d(src + filterPos[7], 0); \ + DUP4_ARG2(__lasx_xvld, filter, 0, filter, 32, filter, 64, \ + filter, 96, filter0, filter1, filter2, filter3); \ + DUP4_ARG2(__lasx_xvilvl_d, src1, src0, src3, src2, \ + src5, src4, src7, src6, src0, src2, src4, src6); \ + DUP4_ARG1(__lasx_vext2xv_hu_bu, src0, src2, src4, src6, \ + src0, src2, src4, src6); \ + DUP4_ARG2(__lasx_xvdp2_w_h, filter0, src0, filter1, src2, \ + filter2, src4, filter3, src6, src0, src1, src2,src3); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src1 = __lasx_xvhaddw_d_w(src1, src1); \ + src2 = __lasx_xvhaddw_d_w(src2, src2); \ + src3 = __lasx_xvhaddw_d_w(src3, src3); \ + DUP2_ARG2(__lasx_xvpickev_w, src1, src0, src3, src2, src0, src1); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src1 = __lasx_xvhaddw_d_w(src1, src1); \ + src0 = __lasx_xvpickev_w(src1, src0); \ + src0 = __lasx_xvsrai_w(src0, _sh); \ + src0 = __lasx_xvmin_w(src0, vmax); \ + src0 = __lasx_xvperm_w(src0, shuf); \ +} + +#define SCALE_8_4(_sh) \ +{ \ + src0 = __lasx_xvldrepl_d(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_d(src + filterPos[1], 0); \ + src2 = __lasx_xvldrepl_d(src + filterPos[2], 0); \ + src3 = __lasx_xvldrepl_d(src + filterPos[3], 0); \ + DUP2_ARG2(__lasx_xvld, filter, 0, filter, 32, filter0, filter1); \ + DUP2_ARG2(__lasx_xvilvl_d, src1, src0, src3, src2, src0, src2); \ + DUP2_ARG1(__lasx_vext2xv_hu_bu, src0, src2, src0, src2); \ + DUP2_ARG2(__lasx_xvdp2_w_h, filter0, src0, filter1, src2, src0, src1);\ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src1 = __lasx_xvhaddw_d_w(src1, src1); \ + src0 = __lasx_xvpickev_w(src1, src0); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src0 = __lasx_xvpickev_w(src0, src0); \ + src0 = __lasx_xvsrai_w(src0, _sh); \ + src0 = __lasx_xvmin_w(src0, vmax); \ + src0 = __lasx_xvperm_w(src0, shuf); \ +} + +#define SCALE_8_2(_sh) \ +{ \ + src0 = __lasx_xvldrepl_d(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_d(src + filterPos[1], 0); \ + filter0 = __lasx_xvld(filter, 0); \ + src0 = __lasx_xvilvl_d(src1, src0); \ + src0 = __lasx_vext2xv_hu_bu(src0); \ + src0 = __lasx_xvdp2_w_h(filter0, src0); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src0 = __lasx_xvhaddw_q_d(src0, src0); \ + src0 = __lasx_xvsrai_w(src0, _sh); \ + src0 = __lasx_xvmin_w(src0, vmax); \ + dst[0] = __lasx_xvpickve2gr_w(src0, 0); \ + dst[1] = __lasx_xvpickve2gr_w(src0, 4); \ + filterPos += 2; \ + filter += 16; \ + dst += 2; \ +} + +#define SCALE_4_16(_sh) \ +{ \ + src0 = __lasx_xvldrepl_w(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_w(src + filterPos[1], 0); \ + src2 = __lasx_xvldrepl_w(src + filterPos[2], 0); \ + src3 = __lasx_xvldrepl_w(src + filterPos[3], 0); \ + src4 = __lasx_xvldrepl_w(src + filterPos[4], 0); \ + src5 = __lasx_xvldrepl_w(src + filterPos[5], 0); \ + src6 = __lasx_xvldrepl_w(src + filterPos[6], 0); \ + src7 = __lasx_xvldrepl_w(src + filterPos[7], 0); \ + src8 = __lasx_xvldrepl_w(src + filterPos[8], 0); \ + src9 = __lasx_xvldrepl_w(src + filterPos[9], 0); \ + src10 = __lasx_xvldrepl_w(src + filterPos[10], 0); \ + src11 = __lasx_xvldrepl_w(src + filterPos[11], 0); \ + src12 = __lasx_xvldrepl_w(src + filterPos[12], 0); \ + src13 = __lasx_xvldrepl_w(src + filterPos[13], 0); \ + src14 = __lasx_xvldrepl_w(src + filterPos[14], 0); \ + src15 = __lasx_xvldrepl_w(src + filterPos[15], 0); \ + DUP4_ARG2(__lasx_xvld, filter, 0, filter, 32, filter, 64, \ + filter, 96, filter0, filter1, filter2, filter3); \ + DUP4_ARG2(__lasx_xvilvl_w, src1, src0, src3, src2, src5, \ + src4, src7, src6, src0, src2, src4, src6); \ + DUP4_ARG2(__lasx_xvilvl_w, src9, src8, src11, src10, src13, \ + src12, src15, src14, src8, src10, src12, src14); \ + DUP4_ARG2(__lasx_xvilvl_d, src2, src0, src6, src4, src10, \ + src8, src14, src12, src0, src1, src2, src3); \ + DUP4_ARG1(__lasx_vext2xv_hu_bu, src0, src1, src2, src3, \ + src0, src1, src2, src3); \ + DUP4_ARG2(__lasx_xvdp2_w_h, filter0, src0, filter1, src1, \ + filter2, src2, filter3, src3, src0, src1, src2, src3); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src1 = __lasx_xvhaddw_d_w(src1, src1); \ + src2 = __lasx_xvhaddw_d_w(src2, src2); \ + src3 = __lasx_xvhaddw_d_w(src3, src3); \ + DUP2_ARG2(__lasx_xvpickev_w, src1, src0, src3, src2, src0, src1); \ + DUP2_ARG2(__lasx_xvsrai_w, src0, _sh, src1, _sh, src0, src1); \ + src0 = __lasx_xvmin_w(src0, vmax); \ + src1 = __lasx_xvmin_w(src1, vmax); \ + src0 = __lasx_xvpickev_h(src1, src0); \ + src0 = __lasx_xvperm_w(src0, shuf); \ + __lasx_xvst(src0, dst, 0); \ + filterPos += 16; \ + filter += 64; \ + dst += 16; \ +} + +#define SCALE_4_8(_sh) \ +{ \ + src0 = __lasx_xvldrepl_w(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_w(src + filterPos[1], 0); \ + src2 = __lasx_xvldrepl_w(src + filterPos[2], 0); \ + src3 = __lasx_xvldrepl_w(src + filterPos[3], 0); \ + src4 = __lasx_xvldrepl_w(src + filterPos[4], 0); \ + src5 = __lasx_xvldrepl_w(src + filterPos[5], 0); \ + src6 = __lasx_xvldrepl_w(src + filterPos[6], 0); \ + src7 = __lasx_xvldrepl_w(src + filterPos[7], 0); \ + DUP2_ARG2(__lasx_xvld, filter, 0, filter, 32, filter0, filter1); \ + DUP4_ARG2(__lasx_xvilvl_w, src1, src0, src3, src2, src5, \ + src4, src7, src6, src0, src2, src4, src6); \ + DUP2_ARG2(__lasx_xvilvl_d, src2, src0, src6, src4, src0, src1); \ + \ + DUP2_ARG1(__lasx_vext2xv_hu_bu, src0, src1, src0, src1); \ + DUP2_ARG2(__lasx_xvdp2_w_h, filter0, src0, filter1, src1, src0, src1);\ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src1 = __lasx_xvhaddw_d_w(src1, src1); \ + src0 = __lasx_xvpickev_w(src1, src0); \ + src0 = __lasx_xvsrai_w(src0, _sh); \ + src0 = __lasx_xvmin_w(src0, vmax); \ +} + +#define SCALE_4_4(_sh) \ +{ \ + src0 = __lasx_xvldrepl_w(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_w(src + filterPos[1], 0); \ + src2 = __lasx_xvldrepl_w(src + filterPos[2], 0); \ + src3 = __lasx_xvldrepl_w(src + filterPos[3], 0); \ + filter0 = __lasx_xvld(filter, 0); \ + DUP2_ARG2(__lasx_xvilvl_w, src1, src0, src3, src2, src0, src1); \ + \ + src0 = __lasx_xvilvl_d(src1, src0); \ + src0 = __lasx_vext2xv_hu_bu(src0); \ + src0 = __lasx_xvdp2_w_h(filter0, src0); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src0 = __lasx_xvsrai_w(src0, _sh); \ + src0 = __lasx_xvmin_w(src0, vmax); \ + src0 = __lasx_xvpickev_w(src0, src0); \ + src0 = __lasx_xvpermi_d(src0, 0xd8); \ +} + +#define SCALE_4_2(_sh) \ +{ \ + src0 = __lasx_xvldrepl_w(src + filterPos[0], 0); \ + src1 = __lasx_xvldrepl_w(src + filterPos[1], 0); \ + filter0 = __lasx_xvld(filter, 0); \ + src0 = __lasx_xvilvl_w(src1, src0); \ + src0 = __lasx_vext2xv_hu_bu(src0); \ + src0 = __lasx_xvdp2_w_h(filter0, src0); \ + src0 = __lasx_xvhaddw_d_w(src0, src0); \ + src0 = __lasx_xvsrai_w(src0, _sh); \ + src0 = __lasx_xvmin_w(src0, vmax); \ + dst[0] = __lasx_xvpickve2gr_w(src0, 0); \ + dst[1] = __lasx_xvpickve2gr_w(src0, 2); \ + filterPos += 2; \ + filter += 8; \ + dst += 2; \ +} + +#define SCALE_16 \ +{ \ + int dex = j << 1; \ + src0 = __lasx_xvldrepl_d((srcPos1 + j), 0); \ + src1 = __lasx_xvldrepl_d((srcPos2 + j), 0); \ + src2 = __lasx_xvldrepl_d((srcPos3 + j), 0); \ + src3 = __lasx_xvldrepl_d((srcPos4 + j), 0); \ + DUP4_ARG2(__lasx_xvldx, filterStart1, dex, filterStart2, dex, \ + filterStart3, dex, filterStart4, dex, filter0, \ + filter1, filter2, filter3); \ + src0 = __lasx_xvpermi_q(src0, src1, 0x02); \ + src1 = __lasx_xvpermi_q(src2, src3, 0x02); \ + filter0 = __lasx_xvpermi_q(filter0, filter1, 0x02); \ + filter1 = __lasx_xvpermi_q(filter2, filter3, 0x02); \ + DUP2_ARG2(__lasx_xvilvl_b, zero, src0, zero, src1, src0, src1); \ + DUP2_ARG2(__lasx_xvdp2_w_h, filter0, src0, filter1, src1, \ + out0, out1); \ + src0 = __lasx_xvhaddw_d_w(out0, out0); \ + src1 = __lasx_xvhaddw_d_w(out1, out1); \ + out0 = __lasx_xvpackev_d(src1, src0); \ + out1 = __lasx_xvpackod_d(src1, src0); \ + out0 = __lasx_xvadd_w(out0, out1); \ + out = __lasx_xvadd_w(out, out0); \ +} + +void ff_hscale_8_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, + const uint8_t *src, const int16_t *filter, + const int32_t *filterPos, int filterSize) +{ + int i; + int max = (1 << 15) - 1; + + if (filterSize == 8) { + __m256i src0, src1, src2, src3, src4, src5, src6, src7; + __m256i src8, src9, src10, src11, src12, src13, src14, src15; + __m256i filter0, filter1, filter2, filter3; + __m256i filter4, filter5, filter6, filter7; + __m256i vmax = __lasx_xvreplgr2vr_w(max); + __m256i shuf = {0x0000000400000000, 0x0000000500000001, + 0x0000000600000002, 0x0000000700000003}; + int len = dstW >> 4; + int res = dstW & 15; + while (len--) { + SCALE_8_16(7); + } + if (res & 8) { + SCALE_8_8(7); + src0 = __lasx_xvpickev_h(src0, src0); + __lasx_xvstelm_d(src0, dst, 0, 0); + __lasx_xvstelm_d(src0, dst, 8, 2); + filterPos += 8; + filter += 64; + dst += 8; + } + if (res & 4) { + SCALE_8_4(7); + src0 = __lasx_xvpickev_h(src0, src0); + __lasx_xvstelm_d(src0, dst, 0, 0); + filterPos += 4; + filter += 32; + dst += 4; + } + if (res & 2) { + SCALE_8_2(7); + } + if (res & 1) { + int val = 0; + src0 = __lasx_xvldrepl_d(src + filterPos[0], 0); + filter0 = __lasx_xvld(filter, 0); + src0 = __lasx_vext2xv_hu_bu(src0); + src0 = __lasx_xvdp2_w_h(filter0, src0); + src0 = __lasx_xvhaddw_d_w(src0, src0); + src0 = __lasx_xvhaddw_q_d(src0, src0); + val = __lasx_xvpickve2gr_w(src0, 0); + dst[0] = FFMIN(val >> 7, max); + } + } else if (filterSize == 4) { + __m256i src0, src1, src2, src3, src4, src5, src6, src7; + __m256i src8, src9, src10, src11, src12, src13, src14, src15; + __m256i filter0, filter1, filter2, filter3; + __m256i vmax = __lasx_xvreplgr2vr_w(max); + __m256i shuf = {0x0000000400000000, 0x0000000500000001, + 0x0000000600000002, 0x0000000700000003}; + int len = dstW >> 4; + int res = dstW & 15; + while (len--) { + SCALE_4_16(7); + } + if (res & 8) { + SCALE_4_8(7); + src0 = __lasx_xvpickev_h(src1, src0); + src0 = __lasx_xvperm_w(src0, shuf); + __lasx_xvstelm_d(src0, dst, 0, 0); + __lasx_xvstelm_d(src0, dst, 8, 1); + filterPos += 8; + filter += 32; + dst += 8; + } + if (res & 4) { + SCALE_4_4(7); + src0 = __lasx_xvpickev_h(src0, src0); + __lasx_xvstelm_d(src0, dst, 0, 0); + filterPos += 4; + filter += 16; + dst += 4; + } + if (res & 2) { + SCALE_4_2(7); + } + if (res & 1) { + int val = 0; + const uint8_t *srcPos = src + filterPos[0]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[0] = FFMIN(val >> 7, max); + } + } else if (filterSize > 8) { + int filterlen = filterSize - 7; + int len = dstW >> 2; + int res = dstW & 3; + __m256i zero = __lasx_xvldi(0); + + while (len--) { + __m256i src0, src1, src2, src3; + __m256i filter0, filter1, filter2, filter3, out0, out1; + __m256i out = zero; + const uint8_t *srcPos1 = src + filterPos[0]; + const uint8_t *srcPos2 = src + filterPos[1]; + const uint8_t *srcPos3 = src + filterPos[2]; + const uint8_t *srcPos4 = src + filterPos[3]; + const int16_t *filterStart1 = filter; + const int16_t *filterStart2 = filterStart1 + filterSize; + const int16_t *filterStart3 = filterStart2 + filterSize; + const int16_t *filterStart4 = filterStart3 + filterSize; + int j, val1 = 0, val2 = 0, val3 = 0, val4 = 0; + + for (j = 0; j < filterlen; j += 8) { + SCALE_16 + } + val1 = __lasx_xvpickve2gr_w(out, 0); + val2 = __lasx_xvpickve2gr_w(out, 4); + val3 = __lasx_xvpickve2gr_w(out, 2); + val4 = __lasx_xvpickve2gr_w(out, 6); + for (; j < filterSize; j++) { + val1 += ((int)srcPos1[j]) * filterStart1[j]; + val2 += ((int)srcPos2[j]) * filterStart2[j]; + val3 += ((int)srcPos3[j]) * filterStart3[j]; + val4 += ((int)srcPos4[j]) * filterStart4[j]; + } + dst[0] = FFMIN(val1 >> 7, max); + dst[1] = FFMIN(val2 >> 7, max); + dst[2] = FFMIN(val3 >> 7, max); + dst[3] = FFMIN(val4 >> 7, max); + dst += 4; + filterPos += 4; + filter = filterStart4 + filterSize; + } + for(i = 0; i < res; i++) { + int j, val = 0; + const uint8_t *srcPos = src + filterPos[i]; + __m256i src1, filter0, out0; + + for (j = 0; j < filterlen; j += 8) { + src1 = __lasx_xvldrepl_d((srcPos + j), 0); + filter0 = __lasx_xvld(filter + j, 0); + src1 = __lasx_xvilvl_b(zero, src1); + out0 = __lasx_xvdp2_w_h(filter0, src1); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvhaddw_q_d(out0, out0); + val += __lasx_xvpickve2gr_w(out0, 0); + } + for (; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> 7, max); + filter += filterSize; + } + } else { + for (i = 0; i < dstW; i++) { + int val = 0; + const uint8_t *srcPos = src + filterPos[i]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> 7, max); + filter += filterSize; + } + } +} + +void ff_hscale_8_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, + const uint8_t *src, const int16_t *filter, + const int32_t *filterPos, int filterSize) +{ + int i; + int max = (1 << 19) - 1; + int32_t *dst = (int32_t *) _dst; + + if (filterSize == 8) { + __m256i src0, src1, src2, src3, src4, src5, src6, src7; + __m256i filter0, filter1, filter2, filter3; + __m256i vmax = __lasx_xvreplgr2vr_w(max); + __m256i shuf = {0x0000000400000000, 0x0000000500000001, + 0x0000000600000002, 0x0000000700000003}; + int len = dstW >> 3; + int res = dstW & 7; + while (len--) { + SCALE_8_8(3); + __lasx_xvst(src0, dst, 0); + filterPos += 8; + filter += 64; + dst += 8; + } + if (res & 4) { + SCALE_8_4(3); + __lasx_xvstelm_d(src0, dst, 0, 0); + __lasx_xvstelm_d(src0, dst, 8, 1); + filterPos += 4; + filter += 32; + dst += 4; + } + if (res & 2) { + SCALE_8_2(3); + } + if (res & 1) { + int val = 0; + __m256i src0, filter0, out0; + + src0 = __lasx_xvldrepl_d(src + filterPos[0], 0); + filter0 = __lasx_xvld(filter, 0); + src0 = __lasx_vext2xv_hu_bu(src0); + out0 = __lasx_xvdp2_w_h(filter0, src0); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvhaddw_q_d(out0, out0); + val = __lasx_xvpickve2gr_w(out0, 0); + dst[0] = FFMIN(val >> 3, max); + } + } else if (filterSize == 4) { + __m256i src0, src1, src2, src3, src4, src5, src6, src7; + __m256i filter0, filter1; + __m256i vmax = __lasx_xvreplgr2vr_w(max); + __m256i shuf = {0x0000000100000000, 0x0000000500000004, + 0x0000000300000002, 0x0000000700000006}; + int len = dstW >> 3; + int res = dstW & 7; + while (len--) { + SCALE_4_8(3); + src0 = __lasx_xvperm_w(src0, shuf); + __lasx_xvst(src0, dst, 0); + filterPos += 8; + filter += 32; + dst += 8; + } + if (res & 4) { + SCALE_4_4(3); + __lasx_xvstelm_d(src0, dst, 0, 0); + __lasx_xvstelm_d(src0, dst, 8, 1); + filterPos += 4; + filter += 16; + dst += 4; + } + if (res & 2) { + SCALE_4_2(3); + } + if (res & 1) { + int val = 0; + const uint8_t *srcPos = src + filterPos[0]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[0] = FFMIN(val >> 3, max); + } + } else if (filterSize > 8) { + int len = dstW >> 2; + int res = dstW & 3; + int filterlen = filterSize - 7; + __m256i zero = __lasx_xvldi(0); + + while (len--) { + __m256i src0, src1, src2, src3; + __m256i filter0, filter1, filter2, filter3, out0, out1; + __m256i out = zero; + const uint8_t *srcPos1 = src + filterPos[0]; + const uint8_t *srcPos2 = src + filterPos[1]; + const uint8_t *srcPos3 = src + filterPos[2]; + const uint8_t *srcPos4 = src + filterPos[3]; + const int16_t *filterStart1 = filter; + const int16_t *filterStart2 = filterStart1 + filterSize; + const int16_t *filterStart3 = filterStart2 + filterSize; + const int16_t *filterStart4 = filterStart3 + filterSize; + int j, val1 = 0, val2 = 0, val3 = 0, val4 = 0; + + for (j = 0; j < filterlen; j += 8) { + SCALE_16 + } + val1 = __lasx_xvpickve2gr_w(out, 0); + val2 = __lasx_xvpickve2gr_w(out, 4); + val3 = __lasx_xvpickve2gr_w(out, 2); + val4 = __lasx_xvpickve2gr_w(out, 6); + for (; j < filterSize; j++) { + val1 += ((int)srcPos1[j]) * filterStart1[j]; + val2 += ((int)srcPos2[j]) * filterStart2[j]; + val3 += ((int)srcPos3[j]) * filterStart3[j]; + val4 += ((int)srcPos4[j]) * filterStart4[j]; + } + dst[0] = FFMIN(val1 >> 3, max); + dst[1] = FFMIN(val2 >> 3, max); + dst[2] = FFMIN(val3 >> 3, max); + dst[3] = FFMIN(val4 >> 3, max); + dst += 4; + filterPos += 4; + filter = filterStart4 + filterSize; + } + for (i = 0; i < res; i++) { + int j, val = 0; + const uint8_t *srcPos = src + filterPos[i]; + __m256i src1, filter0, out0; + + for (j = 0; j < filterlen; j += 8) { + src1 = __lasx_xvldrepl_d((srcPos + j), 0); + filter0 = __lasx_xvld(filter + j, 0); + src1 = __lasx_xvilvl_b(zero, src1); + out0 = __lasx_xvdp2_w_h(filter0, src1); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvhaddw_q_d(out0, out0); + val += __lasx_xvpickve2gr_w(out0, 0); + } + for (; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> 3, max); + filter += filterSize; + } + } else { + for (i = 0; i < dstW; i++) { + int val = 0; + const uint8_t *srcPos = src + filterPos[i]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> 3, max); + filter += filterSize; + } + } +} + +#undef SCALE_16 + +#define SCALE_8 \ +{ \ + int val1, val2, val3, val4; \ + __m256i src0, src1, src2, src3, filter0, filter1, out0, out1; \ + DUP4_ARG2(__lasx_xvld, src + filterPos[0], 0, src + filterPos[1], 0, \ + src + filterPos[2], 0, src + filterPos[3], 0, src0, src1, src2,\ + src3); \ + DUP2_ARG2(__lasx_xvld, filter, 0, filter, 32, filter0, filter1); \ + src0 = __lasx_xvpermi_q(src0, src1, 0x02); \ + src2 = __lasx_xvpermi_q(src2, src3, 0x02); \ + DUP2_ARG2(__lasx_xvdp2_w_hu_h, src0, filter0, src2, filter1, out0, out1);\ + src0 = __lasx_xvhaddw_d_w(out0, out0); \ + src1 = __lasx_xvhaddw_d_w(out1, out1); \ + out0 = __lasx_xvpackev_d(src1, src0); \ + out1 = __lasx_xvpackod_d(src1, src0); \ + out0 = __lasx_xvadd_w(out0, out1); \ + out0 = __lasx_xvsra_w(out0, shift); \ + val1 = __lasx_xvpickve2gr_w(out0, 0); \ + val2 = __lasx_xvpickve2gr_w(out0, 4); \ + val3 = __lasx_xvpickve2gr_w(out0, 2); \ + val4 = __lasx_xvpickve2gr_w(out0, 6); \ + dst[0] = FFMIN(val1, max); \ + dst[1] = FFMIN(val2, max); \ + dst[2] = FFMIN(val3, max); \ + dst[3] = FFMIN(val4, max); \ + filterPos += 4; \ + filter += 32; \ + dst += 4; \ +} + +#define SCALE_16 \ +{ \ + int dex = j << 1; \ + DUP4_ARG2(__lasx_xvldx, srcPos1, dex, srcPos2, dex, srcPos3, dex, \ + srcPos4, dex, src0, src1, src2, src3); \ + DUP4_ARG2(__lasx_xvldx, filterStart1, dex, filterStart2, dex, \ + filterStart3, dex, filterStart4, dex, filter0, \ + filter1, filter2, filter3); \ + src0 = __lasx_xvpermi_q(src0, src1, 0x02); \ + src1 = __lasx_xvpermi_q(src2, src3, 0x02); \ + filter0 = __lasx_xvpermi_q(filter0, filter1, 0x02); \ + filter1 = __lasx_xvpermi_q(filter2, filter3, 0x02); \ + DUP2_ARG2(__lasx_xvdp2_w_hu_h, src0, filter0, src1, filter1, out0, out1);\ + src0 = __lasx_xvhaddw_d_w(out0, out0); \ + src1 = __lasx_xvhaddw_d_w(out1, out1); \ + out0 = __lasx_xvpackev_d(src1, src0); \ + out1 = __lasx_xvpackod_d(src1, src0); \ + out0 = __lasx_xvadd_w(out0, out1); \ + out = __lasx_xvadd_w(out, out0); \ +} + +void ff_hscale_16_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + int i; + const uint16_t *src = (const uint16_t *) _src; + int sh = desc->comp[0].depth - 1; + int max = (1 << 15) - 1; + int len = dstW >> 2; + int res = dstW & 3; + __m256i shift; + __m256i zero = __lasx_xvldi(0); + + if (sh < 15) { + sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : + (desc->comp[0].depth - 1); + } else if (desc->flags && AV_PIX_FMT_FLAG_FLOAT) { + sh = 15; + } + shift = __lasx_xvreplgr2vr_w(sh); + + if (filterSize == 8) { + for (i = 0; i < len; i++) { + SCALE_8 + } + for (i = 0; i < res; i++) { + int val = 0; + __m256i src0, filter0, out0; + + src0 = __lasx_xvld(src + filterPos[i], 0); + filter0 = __lasx_xvld(filter, 0); + out0 = __lasx_xvdp2_w_hu_h(src0, filter0); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvhaddw_q_d(out0, out0); + val = __lasx_xvpickve2gr_w(out0, 0); + dst[i] = FFMIN(val >> sh, max); + filter += 8; + } + } else if (filterSize == 4) { + for (i = 0; i < len; i++) { + __m256i src1, src2, src3, src4, src0, filter0, out0; + + src1 = __lasx_xvldrepl_d(src + filterPos[0], 0); + src2 = __lasx_xvldrepl_d(src + filterPos[1], 0); + src3 = __lasx_xvldrepl_d(src + filterPos[2], 0); + src4 = __lasx_xvldrepl_d(src + filterPos[3], 0); + filter0 = __lasx_xvld(filter, 0); + src1 = __lasx_xvextrins_d(src1, src2, 0x10); + src3 = __lasx_xvextrins_d(src3, src4, 0x10); + src0 = __lasx_xvpermi_q(src1, src3, 0x02); + out0 = __lasx_xvdp2_w_hu_h(src0, filter0); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvsra_w(out0, shift); + dst[0] = FFMIN((__lasx_xvpickve2gr_w(out0, 0)), max); + dst[1] = FFMIN((__lasx_xvpickve2gr_w(out0, 2)), max); + dst[2] = FFMIN((__lasx_xvpickve2gr_w(out0, 4)), max); + dst[3] = FFMIN((__lasx_xvpickve2gr_w(out0, 6)), max); + dst += 4; + filterPos += 4; + filter += 16; + } + for (i = 0; i < res; i++) { + int val = 0; + const uint16_t *srcPos = src + filterPos[i]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> sh, max); + filter += 4; + } + } else if (filterSize > 8) { + int filterlen = filterSize - 7; + + for (i = 0; i < len; i++) { + __m256i src0, src1, src2, src3; + __m256i filter0, filter1, filter2, filter3, out0, out1; + __m256i out = zero; + const uint16_t *srcPos1 = src + filterPos[0]; + const uint16_t *srcPos2 = src + filterPos[1]; + const uint16_t *srcPos3 = src + filterPos[2]; + const uint16_t *srcPos4 = src + filterPos[3]; + const int16_t *filterStart1 = filter; + const int16_t *filterStart2 = filterStart1 + filterSize; + const int16_t *filterStart3 = filterStart2 + filterSize; + const int16_t *filterStart4 = filterStart3 + filterSize; + int j, val1 = 0, val2 = 0, val3 = 0, val4 = 0; + + for (j = 0; j < filterlen; j += 8) { + SCALE_16 + } + val1 = __lasx_xvpickve2gr_w(out, 0); + val2 = __lasx_xvpickve2gr_w(out, 4); + val3 = __lasx_xvpickve2gr_w(out, 2); + val4 = __lasx_xvpickve2gr_w(out, 6); + for (; j < filterSize; j++) { + val1 += ((int)srcPos1[j]) * filterStart1[j]; + val2 += ((int)srcPos2[j]) * filterStart2[j]; + val3 += ((int)srcPos3[j]) * filterStart3[j]; + val4 += ((int)srcPos4[j]) * filterStart4[j]; + } + dst[0] = FFMIN(val1 >> sh, max); + dst[1] = FFMIN(val2 >> sh, max); + dst[2] = FFMIN(val3 >> sh, max); + dst[3] = FFMIN(val4 >> sh, max); + dst += 4; + filterPos += 4; + filter = filterStart4 + filterSize; + } + for (i = 0; i < res; i++) { + int j, val = 0; + const uint16_t *srcPos = src + filterPos[i]; + __m256i src0, filter0, out0; + + for (j = 0; j < filterlen; j += 8) { + int dex = j << 1; + DUP2_ARG2(__lasx_xvldx, srcPos, dex, filter, dex, src0, filter0); + out0 = __lasx_xvdp2_w_hu_h(src0, filter0); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvhaddw_q_d(out0, out0); + val += __lasx_xvpickve2gr_w(out0, 0); + } + for (; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> sh, max); + filter += filterSize; + } + } else { + for (i = 0; i < dstW; i++) { + int val = 0; + const uint16_t *srcPos = src + filterPos[i]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> sh, max); + filter += filterSize; + } + } +} + +void ff_hscale_16_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + int i; + int32_t *dst = (int32_t *) _dst; + const uint16_t *src = (const uint16_t *) _src; + int sh = desc->comp[0].depth - 5; + int max = (1 << 19) - 1; + int len = dstW >> 2; + int res = dstW & 3; + __m256i shift; + __m256i zero = __lasx_xvldi(0); + + if ((isAnyRGB(c->srcFormat) || c->srcFormat == AV_PIX_FMT_PAL8) + && desc->comp[0].depth<16) { + sh = 9; + } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { + sh = 11; + } + shift = __lasx_xvreplgr2vr_w(sh); + + if (filterSize == 8) { + for (i = 0; i < len; i++) { + SCALE_8 + } + for (i = 0; i < res; i++) { + int val = 0; + __m256i src0, filter0, out0; + + DUP2_ARG2(__lasx_xvld, src + filterPos[i], 0, filter, 0, + src0, filter0); + out0 = __lasx_xvdp2_w_hu_h(src0, filter0); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvhaddw_q_d(out0, out0); + val = __lasx_xvpickve2gr_w(out0, 0); + dst[i] = FFMIN(val >> sh, max); + filter += 8; + } + } else if (filterSize == 4) { + for (i = 0; i < len; i++) { + __m256i src1, src2, src3, src4, src0, filter0, out0; + + src1 = __lasx_xvldrepl_d(src + filterPos[0], 0); + src2 = __lasx_xvldrepl_d(src + filterPos[1], 0); + src3 = __lasx_xvldrepl_d(src + filterPos[2], 0); + src4 = __lasx_xvldrepl_d(src + filterPos[3], 0); + filter0 = __lasx_xvld(filter, 0); + src1 = __lasx_xvextrins_d(src1, src2, 0x10); + src3 = __lasx_xvextrins_d(src3, src4, 0x10); + src0 = __lasx_xvpermi_q(src1, src3, 0x02); + out0 = __lasx_xvdp2_w_hu_h(src0, filter0); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvsra_w(out0, shift); + dst[0] = FFMIN((__lasx_xvpickve2gr_w(out0, 0)), max); + dst[1] = FFMIN((__lasx_xvpickve2gr_w(out0, 2)), max); + dst[2] = FFMIN((__lasx_xvpickve2gr_w(out0, 4)), max); + dst[3] = FFMIN((__lasx_xvpickve2gr_w(out0, 6)), max); + dst += 4; + filterPos += 4; + filter += 16; + } + for (i = 0; i < res; i++) { + int val = 0; + const uint16_t *srcPos = src + filterPos[i]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> sh, max); + filter += 4; + } + } else if (filterSize > 8) { + int filterlen = filterSize - 7; + + for (i = 0; i < len; i ++) { + __m256i src0, src1, src2, src3; + __m256i filter0, filter1, filter2, filter3, out0, out1; + __m256i out = zero; + const uint16_t *srcPos1 = src + filterPos[0]; + const uint16_t *srcPos2 = src + filterPos[1]; + const uint16_t *srcPos3 = src + filterPos[2]; + const uint16_t *srcPos4 = src + filterPos[3]; + const int16_t *filterStart1 = filter; + const int16_t *filterStart2 = filterStart1 + filterSize; + const int16_t *filterStart3 = filterStart2 + filterSize; + const int16_t *filterStart4 = filterStart3 + filterSize; + int j, val1 = 0, val2 = 0, val3 = 0, val4 = 0; + + for (j = 0; j < filterlen; j += 8) { + SCALE_16 + } + val1 = __lasx_xvpickve2gr_w(out, 0); + val2 = __lasx_xvpickve2gr_w(out, 4); + val3 = __lasx_xvpickve2gr_w(out, 2); + val4 = __lasx_xvpickve2gr_w(out, 6); + for (; j < filterSize; j++) { + val1 += ((int)srcPos1[j]) * filterStart1[j]; + val2 += ((int)srcPos2[j]) * filterStart2[j]; + val3 += ((int)srcPos3[j]) * filterStart3[j]; + val4 += ((int)srcPos4[j]) * filterStart4[j]; + } + dst[0] = FFMIN(val1 >> sh, max); + dst[1] = FFMIN(val2 >> sh, max); + dst[2] = FFMIN(val3 >> sh, max); + dst[3] = FFMIN(val4 >> sh, max); + dst += 4; + filterPos += 4; + filter = filterStart4 + filterSize; + } + for (i = 0; i < res; i++) { + int j, val = 0; + const uint16_t *srcPos = src + filterPos[i]; + __m256i src0, filter0, out0; + + for (j = 0; j < filterlen; j += 8) { + int dex = j << 1; + DUP2_ARG2(__lasx_xvldx, srcPos, dex, filter, dex, + src0, filter0); + out0 = __lasx_xvdp2_w_hu_h(src0, filter0); + out0 = __lasx_xvhaddw_d_w(out0, out0); + out0 = __lasx_xvhaddw_q_d(out0, out0); + val += __lasx_xvpickve2gr_w(out0, 0); + } + for (; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> sh, max); + filter += filterSize; + } + } else { + for (i = 0; i < dstW; i++) { + int val = 0; + const uint16_t *srcPos = src + filterPos[i]; + + for (int j = 0; j < filterSize; j++) { + val += ((int)srcPos[j]) * filter[j]; + } + dst[i] = FFMIN(val >> sh, max); + filter += filterSize; + } + } +} + +#undef SCALE_8 +#undef SCALE_16 diff --git a/libswscale/loongarch/swscale_loongarch.h b/libswscale/loongarch/swscale_loongarch.h new file mode 100644 index 0000000000..67e24d544c --- /dev/null +++ b/libswscale/loongarch/swscale_loongarch.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 Loongson Technology Corporation Limited + * Contributed by Hao Chen(chenhao@loongson.cn) + * + * 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 SWSCALE_LOONGARCH_SWSCALE_LOONGARCH_H +#define SWSCALE_LOONGARCH_SWSCALE_LOONGARCH_H + +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" + +void ff_hscale_8_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, + const uint8_t *src, const int16_t *filter, + const int32_t *filterPos, int filterSize); + +void ff_hscale_8_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, + const uint8_t *src, const int16_t *filter, + const int32_t *filterPos, int filterSize); + +void ff_hscale_16_to_19_lasx(SwsContext *c, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize); + +void ff_hscale_16_to_15_lasx(SwsContext *c, int16_t *dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize); + +void planar_rgb_to_uv_lasx(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4], + int width, int32_t *rgb2yuv); + +void planar_rgb_to_y_lasx(uint8_t *_dst, const uint8_t *src[4], int width, + int32_t *rgb2yuv); + +#endif /* SWSCALE_LOONGARCH_SWSCALE_LOONGARCH_H */ diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 7b40f49da4..367d045a02 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -598,6 +598,8 @@ void ff_sws_init_scale(SwsContext *c) ff_sws_init_swscale_aarch64(c); #elif ARCH_ARM ff_sws_init_swscale_arm(c); +#elif ARCH_LOONGARCH64 + ff_sws_init_swscale_loongarch(c); #endif } diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 6c14ce8536..abeebbb002 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -698,6 +698,7 @@ av_cold void ff_sws_init_range_convert(SwsContext *c); SwsFunc ff_yuv2rgb_init_x86(SwsContext *c); SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c); +SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c); static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt) { @@ -983,6 +984,7 @@ void ff_sws_init_swscale_vsx(SwsContext *c); void ff_sws_init_swscale_x86(SwsContext *c); void ff_sws_init_swscale_aarch64(SwsContext *c); void ff_sws_init_swscale_arm(SwsContext *c); +void ff_sws_init_swscale_loongarch(SwsContext *c); void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc); diff --git a/libswscale/utils.c b/libswscale/utils.c index a621a35862..f762fba1df 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -53,6 +53,7 @@ #include "libavutil/ppc/cpu.h" #include "libavutil/x86/asm.h" #include "libavutil/x86/cpu.h" +#include "libavutil/loongarch/cpu.h" #include "rgb2rgb.h" #include "swscale.h" @@ -654,6 +655,15 @@ static av_cold int initFilter(int16_t **outFilter, int32_t **filterPos, filterAlign = 1; } + if (have_lasx(cpu_flags)) { + int reNum = minFilterSize & (0x07); + + if (minFilterSize < 5) + filterAlign = 4; + if (reNum < 3) + filterAlign = 1; + } + av_assert0(minFilterSize > 0); filterSize = (minFilterSize + (filterAlign - 1)) & (~(filterAlign - 1)); av_assert0(filterSize > 0); @@ -1839,7 +1849,8 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, { const int filterAlign = X86_MMX(cpu_flags) ? 4 : PPC_ALTIVEC(cpu_flags) ? 8 : - have_neon(cpu_flags) ? 4 : 1; + have_neon(cpu_flags) ? 4 : + have_lasx(cpu_flags) ? 8 : 1; if ((ret = initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, From patchwork Mon Aug 29 11:18:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6ZmI5piK?= X-Patchwork-Id: 37548 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp1872728pzh; Mon, 29 Aug 2022 04:18:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR4hkWUNEEteWJfpeyL5y6aHIRd0CGi0w+qQfESgEcHCXZj6CbBEFUW8k6WOM2B+cSX5fBaR X-Received: by 2002:a17:907:1c89:b0:734:d05c:582e with SMTP id nb9-20020a1709071c8900b00734d05c582emr13424858ejc.282.1661771926443; Mon, 29 Aug 2022 04:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661771926; cv=none; d=google.com; s=arc-20160816; b=u62una653iIhp/OQrpvHrMxp10wafntFYNz8QtaJFZkGZS2FxnLByFhXIjydG2KdWK 2zmgzaKYfqP8OLagkeiw5bIq/I0vA8fhMNaq4TdQ25nViqff49Cp8UTaDhLhUprUQ2Ej NVBOc+Qy9HSl9PGPrqQxe52wddxFZo9mLtLqPSjtT8InFYpQ0G396mHNfCErbOaoxpJ9 SaRD8yMSBt9q0R1d9qqIUerFNlcbZ9FsDNRGRtznLCqLSYamGzqUkXMpX00Fbtw0wxpT 3D55Ioh3sHhMEVFhjLh5X/SxprNNPHdN9QO6dkhmqZ3tcEmIr0b2qImM38f91HrdMF/o JJUw== 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=t7TEqUMWfUXAe9cPz5+a5rIkzVixmMuAI2X+xFgYzoY=; b=DwBZeUET54oAMqrC1wRLB9/I4jX06J2TqoIFrJhZDSi0Kh8SaBsBt94QJN6vWfXaYe TrlrRduHKBoUX2rsMjqgNm+eAm2tx2VDWe8qixxS65i+Y0wsrAe/An25EGGLLnIaMtvq C3Z9yC69SbfAg11hxvty+1LvjOH1vlb4n3Uhw2k1smQmOUy/fVfxe85GTIMJ9yvf/qY5 2DtBIKbPG1HOtGe6BzhdDEDBUCOOh4j5LLWJkkfQiOhFSN0Ewb/pgw0EYTZfjFQkQBy/ nDvbsHvpLiqzEBdkcaL2hUG+o9zHq5HQE/yS2dnxgRij3n4W24sJOwXzPl1dWZWs1elI R2tA== 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 ss2-20020a170907c00200b0073d710fec77si4643686ejc.251.2022.08.29.04.18.45; Mon, 29 Aug 2022 04:18:46 -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 6041B68B9DF; Mon, 29 Aug 2022 14:18:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2600268B9CE for ; Mon, 29 Aug 2022 14:18:35 +0300 (EEST) Received: from localhost (unknown [36.33.26.144]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxrmuIoAxjV9gLAA--.38969S3; Mon, 29 Aug 2022 19:18:32 +0800 (CST) From: Hao Chen To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Aug 2022 19:18:24 +0800 Message-Id: <20220829111825.8867-2-chenhao@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxrmuIoAxjV9gLAA--.38969S3 X-Coremail-Antispam: 1UD129KBjvAXoWfGF4UWry8tF1UGFyDWw48Zwb_yoW8AF17Wo WrKF40vry7Ww1IkryFkr95XFyjka4xCr45A3y2yw47Aa43ZFy5uryYyw4FvFWSyrWDJFZa qayUXFZ8ZFy3Gw1kn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYj7k0a2IF6w4kM7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0 x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj4 1l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0 I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8KwCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jr0_JrylIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU5_b15UUUUU== X-CM-SenderInfo: hfkh0xtdr6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH v1 2/3] swscale/la: Add yuv2rgb_lasx.c and rgb2rgb_lasx.c files 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: nKN2+tfFxzBc ffmpeg -i ~/media/1_h264_1080p_30fps_3Mbps.mp4 -f rawvideo -pix_fmt rgb24 -y /dev/null -an before: 178fps after: 210fps Signed-off-by: Hao Chen --- libswscale/loongarch/Makefile | 2 + libswscale/loongarch/rgb2rgb_lasx.c | 52 +++ libswscale/loongarch/swscale_init_loongarch.c | 42 +++ libswscale/loongarch/swscale_loongarch.h | 22 ++ libswscale/loongarch/yuv2rgb_lasx.c | 329 ++++++++++++++++++ libswscale/rgb2rgb.c | 2 + libswscale/rgb2rgb.h | 1 + libswscale/yuv2rgb.c | 2 + 8 files changed, 452 insertions(+) create mode 100644 libswscale/loongarch/rgb2rgb_lasx.c create mode 100644 libswscale/loongarch/yuv2rgb_lasx.c diff --git a/libswscale/loongarch/Makefile b/libswscale/loongarch/Makefile index 586a1717b6..4345971514 100644 --- a/libswscale/loongarch/Makefile +++ b/libswscale/loongarch/Makefile @@ -1,3 +1,5 @@ OBJS-$(CONFIG_SWSCALE) += loongarch/swscale_init_loongarch.o LASX-OBJS-$(CONFIG_SWSCALE) += loongarch/swscale_lasx.o \ loongarch/input_lasx.o \ + loongarch/yuv2rgb_lasx.o \ + loongarch/rgb2rgb_lasx.o diff --git a/libswscale/loongarch/rgb2rgb_lasx.c b/libswscale/loongarch/rgb2rgb_lasx.c new file mode 100644 index 0000000000..68684ca595 --- /dev/null +++ b/libswscale/loongarch/rgb2rgb_lasx.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Loongson Technology Corporation Limited + * Contributed by Hao Chen(chenhao@loongson.cn) + * + * 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 "swscale_loongarch.h" +#include "libavutil/loongarch/loongson_intrinsics.h" + +void ff_interleave_bytes_lasx(const uint8_t *src1, const uint8_t *src2, + uint8_t *dest, int width, int height, + int src1Stride, int src2Stride, int dstStride) +{ + int h; + int len = width & (0xFFFFFFF0); + + for (h = 0; h < height; h++) { + int w, index = 0; + __m256i src_1, src_2, dst; + + for (w = 0; w < len; w += 16) { + DUP2_ARG2(__lasx_xvld, src1 + w, 0, src2 + w, 0, src_1, src_2); + src_1 = __lasx_xvpermi_d(src_1, 0xD8); + src_2 = __lasx_xvpermi_d(src_2, 0xD8); + dst = __lasx_xvilvl_b(src_2, src_1); + __lasx_xvst(dst, dest + index, 0); + index += 32; + } + for (w = 0; w < width; w++) { + dest[(w << 1) + 0] = src1[w]; + dest[(w << 1) + 1] = src2[w]; + } + dest += dstStride; + src1 += src1Stride; + src2 += src2Stride; + } +} diff --git a/libswscale/loongarch/swscale_init_loongarch.c b/libswscale/loongarch/swscale_init_loongarch.c index 197dc6e1e7..1e0bb1b116 100644 --- a/libswscale/loongarch/swscale_init_loongarch.c +++ b/libswscale/loongarch/swscale_init_loongarch.c @@ -21,6 +21,7 @@ #include "swscale_loongarch.h" #include "libswscale/swscale_internal.h" +#include "libswscale/rgb2rgb.h" #include "libavutil/loongarch/cpu.h" av_cold void ff_sws_init_swscale_loongarch(SwsContext *c) @@ -48,3 +49,44 @@ av_cold void ff_sws_init_swscale_loongarch(SwsContext *c) } } } + +av_cold void rgb2rgb_init_loongarch(void) +{ + int cpu_flags = av_get_cpu_flags(); + if (have_lasx(cpu_flags)) + interleaveBytes = ff_interleave_bytes_lasx; +} + +av_cold SwsFunc ff_yuv2rgb_init_loongarch(SwsContext *c) +{ + int cpu_flags = av_get_cpu_flags(); + if (have_lasx(cpu_flags)) { + switch (c->dstFormat) { + case AV_PIX_FMT_RGB24: + return yuv420_rgb24_lasx; + case AV_PIX_FMT_BGR24: + return yuv420_bgr24_lasx; + case AV_PIX_FMT_RGBA: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_rgba32_lasx; + case AV_PIX_FMT_ARGB: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_argb32_lasx; + case AV_PIX_FMT_BGRA: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_bgra32_lasx; + case AV_PIX_FMT_ABGR: + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat)) { + break; + } else + return yuv420_abgr32_lasx; + } + } + return NULL; +} diff --git a/libswscale/loongarch/swscale_loongarch.h b/libswscale/loongarch/swscale_loongarch.h index 67e24d544c..07a8145da2 100644 --- a/libswscale/loongarch/swscale_loongarch.h +++ b/libswscale/loongarch/swscale_loongarch.h @@ -47,4 +47,26 @@ void planar_rgb_to_uv_lasx(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *src[4] void planar_rgb_to_y_lasx(uint8_t *_dst, const uint8_t *src[4], int width, int32_t *rgb2yuv); +int yuv420_rgb24_lasx(SwsContext *c, const uint8_t *src[], int srcStride[], + int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); + +int yuv420_bgr24_lasx(SwsContext *c, const uint8_t *src[], int srcStride[], + int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); + +int yuv420_rgba32_lasx(SwsContext *c, const uint8_t *src[], int srcStride[], + int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); + +int yuv420_bgra32_lasx(SwsContext *c, const uint8_t *src[], int srcStride[], + int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); + +int yuv420_argb32_lasx(SwsContext *c, const uint8_t *src[], int srcStride[], + int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); + +int yuv420_abgr32_lasx(SwsContext *c, const uint8_t *src[], int srcStride[], + int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]); + +void ff_interleave_bytes_lasx(const uint8_t *src1, const uint8_t *src2, + uint8_t *dest, int width, int height, + int src1Stride, int src2Stride, int dstStride); + #endif /* SWSCALE_LOONGARCH_SWSCALE_LOONGARCH_H */ diff --git a/libswscale/loongarch/yuv2rgb_lasx.c b/libswscale/loongarch/yuv2rgb_lasx.c new file mode 100644 index 0000000000..6f160fe880 --- /dev/null +++ b/libswscale/loongarch/yuv2rgb_lasx.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2022 Loongson Technology Corporation Limited + * Contributed by Hao Chen(chenhao@loongson.cn) + * + * 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 "swscale_loongarch.h" +#include "libavutil/loongarch/loongson_intrinsics.h" + +#define YUV2RGB_LOAD_COE \ + /* Load x_offset */ \ + __m256i y_offset = __lasx_xvreplgr2vr_d(c->yOffset); \ + __m256i u_offset = __lasx_xvreplgr2vr_d(c->uOffset); \ + __m256i v_offset = __lasx_xvreplgr2vr_d(c->vOffset); \ + /* Load x_coeff */ \ + __m256i ug_coeff = __lasx_xvreplgr2vr_d(c->ugCoeff); \ + __m256i vg_coeff = __lasx_xvreplgr2vr_d(c->vgCoeff); \ + __m256i y_coeff = __lasx_xvreplgr2vr_d(c->yCoeff); \ + __m256i ub_coeff = __lasx_xvreplgr2vr_d(c->ubCoeff); \ + __m256i vr_coeff = __lasx_xvreplgr2vr_d(c->vrCoeff); \ + +#define LOAD_YUV_16 \ + m_y1 = __lasx_xvld(py_1, 0); \ + m_y2 = __lasx_xvld(py_2, 0); \ + m_u = __lasx_xvldrepl_d(pu, 0); \ + m_v = __lasx_xvldrepl_d(pv, 0); \ + DUP2_ARG2(__lasx_xvilvl_b, m_u, m_u, m_v, m_v, m_u, m_v);\ + DUP4_ARG1(__lasx_vext2xv_hu_bu, m_y1, m_y2, m_u, m_v, \ + m_y1, m_y2, m_u, m_v); \ + +/* YUV2RGB method + * The conversion method is as follows: + * R = Y' * y_coeff + V' * vr_coeff + * G = Y' * y_coeff + V' * vg_coeff + U' * ug_coeff + * B = Y' * y_coeff + U' * ub_coeff + * + * where X' = X * 8 - x_offset + * + */ + +#define YUV2RGB \ + m_y1 = __lasx_xvslli_h(m_y1, 3); \ + m_y2 = __lasx_xvslli_h(m_y2, 3); \ + m_u = __lasx_xvslli_h(m_u, 3); \ + m_v = __lasx_xvslli_h(m_v, 3); \ + m_y1 = __lasx_xvsub_h(m_y1, y_offset); \ + m_y2 = __lasx_xvsub_h(m_y2, y_offset); \ + m_u = __lasx_xvsub_h(m_u, u_offset); \ + m_v = __lasx_xvsub_h(m_v, v_offset); \ + y_1 = __lasx_xvmuh_h(m_y1, y_coeff); \ + y_2 = __lasx_xvmuh_h(m_y2, y_coeff); \ + u2g = __lasx_xvmuh_h(m_u, ug_coeff); \ + u2b = __lasx_xvmuh_h(m_u, ub_coeff); \ + v2r = __lasx_xvmuh_h(m_v, vr_coeff); \ + v2g = __lasx_xvmuh_h(m_v, vg_coeff); \ + r1 = __lasx_xvsadd_h(y_1, v2r); \ + v2g = __lasx_xvsadd_h(v2g, u2g); \ + g1 = __lasx_xvsadd_h(y_1, v2g); \ + b1 = __lasx_xvsadd_h(y_1, u2b); \ + r2 = __lasx_xvsadd_h(y_2, v2r); \ + g2 = __lasx_xvsadd_h(y_2, v2g); \ + b2 = __lasx_xvsadd_h(y_2, u2b); \ + DUP4_ARG1(__lasx_xvclip255_h, r1, g1, b1, r2, r1, g1, b1, r2); \ + DUP2_ARG1(__lasx_xvclip255_h, g2, b2, g2, b2); \ + +#define RGB_PACK(r, g, b, rgb_l, rgb_h) \ +{ \ + __m256i rg; \ + rg = __lasx_xvpackev_b(g, r); \ + DUP2_ARG3(__lasx_xvshuf_b, b, rg, shuf2, b, rg, shuf3, rgb_l, rgb_h); \ +} + +#define RGB32_PACK(a, r, g, b, rgb_l, rgb_h) \ +{ \ + __m256i ra, bg, tmp0, tmp1; \ + ra = __lasx_xvpackev_b(r, a); \ + bg = __lasx_xvpackev_b(b, g); \ + tmp0 = __lasx_xvilvl_h(bg, ra); \ + tmp1 = __lasx_xvilvh_h(bg, ra); \ + rgb_l = __lasx_xvpermi_q(tmp1, tmp0, 0x20); \ + rgb_h = __lasx_xvpermi_q(tmp1, tmp0, 0x31); \ +} + +#define RGB_STORE(rgb_l, rgb_h, image) \ +{ \ + __lasx_xvstelm_d(rgb_l, image, 0, 0); \ + __lasx_xvstelm_d(rgb_l, image, 8, 1); \ + __lasx_xvstelm_d(rgb_h, image, 16, 0); \ + __lasx_xvstelm_d(rgb_l, image, 24, 2); \ + __lasx_xvstelm_d(rgb_l, image, 32, 3); \ + __lasx_xvstelm_d(rgb_h, image, 40, 2); \ +} + +#define RGB32_STORE(rgb_l, rgb_h, image) \ +{ \ + __lasx_xvst(rgb_l, image, 0); \ + __lasx_xvst(rgb_h, image, 32); \ +} + +#define YUV2RGBFUNC(func_name, dst_type, alpha) \ + int func_name(SwsContext *c, const uint8_t *src[], \ + int srcStride[], int srcSliceY, int srcSliceH, \ + uint8_t *dst[], int dstStride[]) \ +{ \ + int x, y, h_size, vshift, res; \ + __m256i m_y1, m_y2, m_u, m_v; \ + __m256i y_1, y_2, u2g, v2g, u2b, v2r, rgb1_l, rgb1_h; \ + __m256i rgb2_l, rgb2_h, r1, g1, b1, r2, g2, b2; \ + __m256i shuf2 = {0x0504120302100100, 0x0A18090816070614, \ + 0x0504120302100100, 0x0A18090816070614}; \ + __m256i shuf3 = {0x1E0F0E1C0D0C1A0B, 0x0101010101010101, \ + 0x1E0F0E1C0D0C1A0B, 0x0101010101010101}; \ + YUV2RGB_LOAD_COE \ + \ + h_size = c->dstW >> 4; \ + res = (c->dstW & 15) >> 1; \ + vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + for (y = 0; y < srcSliceH; y += 2) { \ + dst_type av_unused *r, *g, *b; \ + dst_type *image1 = (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]);\ + dst_type *image2 = (dst_type *)(image1 + dstStride[0]);\ + const uint8_t *py_1 = src[0] + y * srcStride[0]; \ + const uint8_t *py_2 = py_1 + srcStride[0]; \ + const uint8_t *pu = src[1] + (y >> vshift) * srcStride[1]; \ + const uint8_t *pv = src[2] + (y >> vshift) * srcStride[2]; \ + for(x = 0; x < h_size; x++) { \ + +#define YUV2RGBFUNC32(func_name, dst_type, alpha) \ + int func_name(SwsContext *c, const uint8_t *src[], \ + int srcStride[], int srcSliceY, int srcSliceH, \ + uint8_t *dst[], int dstStride[]) \ +{ \ + int x, y, h_size, vshift, res; \ + __m256i m_y1, m_y2, m_u, m_v; \ + __m256i y_1, y_2, u2g, v2g, u2b, v2r, rgb1_l, rgb1_h; \ + __m256i rgb2_l, rgb2_h, r1, g1, b1, r2, g2, b2; \ + __m256i a = __lasx_xvldi(0xFF); \ + \ + YUV2RGB_LOAD_COE \ + \ + h_size = c->dstW >> 4; \ + res = (c->dstW & 15) >> 1; \ + vshift = c->srcFormat != AV_PIX_FMT_YUV422P; \ + for (y = 0; y < srcSliceH; y += 2) { \ + int yd = y + srcSliceY; \ + dst_type av_unused *r, *g, *b; \ + dst_type *image1 = (dst_type *)(dst[0] + (yd) * dstStride[0]); \ + dst_type *image2 = (dst_type *)(dst[0] + (yd + 1) * dstStride[0]); \ + const uint8_t *py_1 = src[0] + y * srcStride[0]; \ + const uint8_t *py_2 = py_1 + srcStride[0]; \ + const uint8_t *pu = src[1] + (y >> vshift) * srcStride[1]; \ + const uint8_t *pv = src[2] + (y >> vshift) * srcStride[2]; \ + for(x = 0; x < h_size; x++) { \ + +#define DEALYUV2RGBREMAIN \ + py_1 += 16; \ + py_2 += 16; \ + pu += 8; \ + pv += 8; \ + image1 += 48; \ + image2 += 48; \ + } \ + for (x = 0; x < res; x++) { \ + int av_unused U, V, Y; \ + U = pu[0]; \ + V = pv[0]; \ + r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \ + g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] \ + + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \ + b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM]; \ + +#define DEALYUV2RGBREMAIN32 \ + py_1 += 16; \ + py_2 += 16; \ + pu += 8; \ + pv += 8; \ + image1 += 16; \ + image2 += 16; \ + } \ + for (x = 0; x < res; x++) { \ + int av_unused U, V, Y; \ + U = pu[0]; \ + V = pv[0]; \ + r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \ + g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] \ + + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \ + b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM]; \ + + +#define PUTRGB24(dst, src) \ + Y = src[0]; \ + dst[0] = r[Y]; \ + dst[1] = g[Y]; \ + dst[2] = b[Y]; \ + Y = src[1]; \ + dst[3] = r[Y]; \ + dst[4] = g[Y]; \ + dst[5] = b[Y]; + +#define PUTBGR24(dst, src) \ + Y = src[0]; \ + dst[0] = b[Y]; \ + dst[1] = g[Y]; \ + dst[2] = r[Y]; \ + Y = src[1]; \ + dst[3] = b[Y]; \ + dst[4] = g[Y]; \ + dst[5] = r[Y]; + +#define PUTRGB(dst, src) \ + Y = src[0]; \ + dst[0] = r[Y] + g[Y] + b[Y]; \ + Y = src[1]; \ + dst[1] = r[Y] + g[Y] + b[Y]; \ + +#define ENDRES \ + pu += 1; \ + pv += 1; \ + py_1 += 2; \ + py_2 += 2; \ + image1 += 6; \ + image2 += 6; \ + +#define ENDRES32 \ + pu += 1; \ + pv += 1; \ + py_1 += 2; \ + py_2 += 2; \ + image1 += 2; \ + image2 += 2; \ + +#define END_FUNC() \ + } \ + } \ + return srcSliceH; \ +} + +YUV2RGBFUNC(yuv420_rgb24_lasx, uint8_t, 0) + LOAD_YUV_16 + YUV2RGB + RGB_PACK(r1, g1, b1, rgb1_l, rgb1_h); + RGB_PACK(r2, g2, b2, rgb2_l, rgb2_h); + RGB_STORE(rgb1_l, rgb1_h, image1); + RGB_STORE(rgb2_l, rgb2_h, image2); + DEALYUV2RGBREMAIN + PUTRGB24(image1, py_1); + PUTRGB24(image2, py_2); + ENDRES + END_FUNC() + +YUV2RGBFUNC(yuv420_bgr24_lasx, uint8_t, 0) + LOAD_YUV_16 + YUV2RGB + RGB_PACK(b1, g1, r1, rgb1_l, rgb1_h); + RGB_PACK(b2, g2, r2, rgb2_l, rgb2_h); + RGB_STORE(rgb1_l, rgb1_h, image1); + RGB_STORE(rgb2_l, rgb2_h, image2); + DEALYUV2RGBREMAIN + PUTBGR24(image1, py_1); + PUTBGR24(image2, py_2); + ENDRES + END_FUNC() + +YUV2RGBFUNC32(yuv420_rgba32_lasx, uint32_t, 0) + LOAD_YUV_16 + YUV2RGB + RGB32_PACK(r1, g1, b1, a, rgb1_l, rgb1_h); + RGB32_PACK(r2, g2, b2, a, rgb2_l, rgb2_h); + RGB32_STORE(rgb1_l, rgb1_h, image1); + RGB32_STORE(rgb2_l, rgb2_h, image2); + DEALYUV2RGBREMAIN32 + PUTRGB(image1, py_1); + PUTRGB(image2, py_2); + ENDRES32 + END_FUNC() + +YUV2RGBFUNC32(yuv420_bgra32_lasx, uint32_t, 0) + LOAD_YUV_16 + YUV2RGB + RGB32_PACK(b1, g1, r1, a, rgb1_l, rgb1_h); + RGB32_PACK(b2, g2, r2, a, rgb2_l, rgb2_h); + RGB32_STORE(rgb1_l, rgb1_h, image1); + RGB32_STORE(rgb2_l, rgb2_h, image2); + DEALYUV2RGBREMAIN32 + PUTRGB(image1, py_1); + PUTRGB(image2, py_2); + ENDRES32 + END_FUNC() + +YUV2RGBFUNC32(yuv420_argb32_lasx, uint32_t, 0) + LOAD_YUV_16 + YUV2RGB + RGB32_PACK(a, r1, g1, b1, rgb1_l, rgb1_h); + RGB32_PACK(a, r2, g2, b2, rgb2_l, rgb2_h); + RGB32_STORE(rgb1_l, rgb1_h, image1); + RGB32_STORE(rgb2_l, rgb2_h, image2); + DEALYUV2RGBREMAIN32 + PUTRGB(image1, py_1); + PUTRGB(image2, py_2); + ENDRES32 + END_FUNC() + +YUV2RGBFUNC32(yuv420_abgr32_lasx, uint32_t, 0) + LOAD_YUV_16 + YUV2RGB + RGB32_PACK(a, b1, g1, r1, rgb1_l, rgb1_h); + RGB32_PACK(a, b2, g2, r2, rgb2_l, rgb2_h); + RGB32_STORE(rgb1_l, rgb1_h, image1); + RGB32_STORE(rgb2_l, rgb2_h, image2); + DEALYUV2RGBREMAIN32 + PUTRGB(image1, py_1); + PUTRGB(image2, py_2); + ENDRES32 + END_FUNC() diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c index 4f1ac9c465..3af775b389 100644 --- a/libswscale/rgb2rgb.c +++ b/libswscale/rgb2rgb.c @@ -141,6 +141,8 @@ av_cold void ff_sws_rgb2rgb_init(void) rgb2rgb_init_aarch64(); #elif ARCH_X86 rgb2rgb_init_x86(); +#elif ARCH_LOONGARCH64 + rgb2rgb_init_loongarch(); #endif } diff --git a/libswscale/rgb2rgb.h b/libswscale/rgb2rgb.h index 7272e98c57..db85bfc42f 100644 --- a/libswscale/rgb2rgb.h +++ b/libswscale/rgb2rgb.h @@ -168,5 +168,6 @@ void ff_sws_rgb2rgb_init(void); void rgb2rgb_init_aarch64(void); void rgb2rgb_init_x86(void); +void rgb2rgb_init_loongarch(void); #endif /* SWSCALE_RGB2RGB_H */ diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c index 6ee483d12a..9c3f5e23c6 100644 --- a/libswscale/yuv2rgb.c +++ b/libswscale/yuv2rgb.c @@ -683,6 +683,8 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) t = ff_yuv2rgb_init_ppc(c); #elif ARCH_X86 t = ff_yuv2rgb_init_x86(c); +#elif ARCH_LOONGARCH64 + t = ff_yuv2rgb_init_loongarch(c); #endif if (t)