From patchwork Tue Jun 4 20:05:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 49561 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d153:0:b0:460:55fa:d5ed with SMTP id bt19csp128764vqb; Tue, 4 Jun 2024 13:05:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUsYN0SGNrpDJyZrSYJMmkVb9uNsCUWK35wlvG6CecLO8LphYW0GP7OJBJbQ4TVw2KsFbVWw3ZOCs7ansjRtzjPd8RrLvtGlFv5ew== X-Google-Smtp-Source: AGHT+IFnz6Nkv6+r0IUX0Y+s0xSaZtXmfYlCvob79pyUwJwxBwex/9p8aI/MEYmvMiP2+/H+n37m X-Received: by 2002:a50:9e62:0:b0:57a:79c2:e9d2 with SMTP id 4fb4d7f45d1cf-57a8b6fb8a5mr402467a12.20.1717531530369; Tue, 04 Jun 2024 13:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717531530; cv=none; d=google.com; s=arc-20160816; b=j/tKdXqDrvK5myGHtEuDcJOCUIUmyD6Cc9LJmy6E3DLZPKS3HWginWTDk0FTabRkRM eymYi2BNXjynm6UYj18x/xVM0RWEKhiSX1hMTteHhdyJn2lhrpGqPobodd2EwDrbxDZB /2lzZ2jUyd7dgTt02M0nBM4S0hbcDGpVl3EjnWqzBM+8lm/0iUNMbUF7W/Pn7gZmVfvQ oe9DMjY6DOFx6foo0LtWJ1hwhOtmvONtu03MA3SsXZXG76+Gw8gL863bleUDPWS8lena GxA6FColNLAgl1uo8q6sxzwczJm3qvmGLodvLHn1tasa3ScZUZa7mKGQDTTn/1eHSxwv 9T6Q== 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=NrYoHQ9O6vuVc9aNArDdQQU22hWWOlSPQ4Hu9ngpFXE=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=eme+XJoBzjlvLw3kKilTooR56ObaLDmN4/BH8/A3hs9xn0Q7hkBob4JhPWqPk2phnK Xw4mRKtP6ljqyOvNxp4GEdbJK/69gvGjvzxjSUpuBShQV8SEf2yUkYpnj2rZfwaUdXCK eOfl0k/O8RNXmQojMW3nZ8o7eFqvNIojUPHraIqglV9TUsXsZ4pv0zOqx8X61w0DOvlC SNV8rKfFFoUThixAWYObsWdgEfKXggZb9w1Fx8IeqIqBTAMOoKKw+qoX+KiNCmpex0lB vSB0pmHUfGjF1jlWu4cZGnju2ohpwLycLFG1w0nakm82b/QiiXpLJgBMqYIVp0Qi7pfr nsDA==; 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 4fb4d7f45d1cf-57a31ca5cd9si5456217a12.542.2024.06.04.13.05.24; Tue, 04 Jun 2024 13:05:30 -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 0418668D6F0; Tue, 4 Jun 2024 23:05:21 +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 CD05768D5AF for ; Tue, 4 Jun 2024 23:05:14 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 661D1C0138 for ; Tue, 4 Jun 2024 23:05:14 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 4 Jun 2024 23:05:13 +0300 Message-ID: <20240604200514.37736-1-remi@remlab.net> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] sws/input: add R-V V rgb24ToY 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: OszpgRWkK9Zb T-Head C908: rgb24_to_y_8_c: 2.0 rgb24_to_y_8_rvv_i32: 3.0 rgb24_to_y_128_c: 26.2 rgb24_to_y_128_rvv_i32: 10.5 rgb24_to_y_1080_c: 235.7 rgb24_to_y_1080_rvv_i32: 102.0 rgb24_to_y_1280_c: 260.0 rgb24_to_y_1280_rvv_i32: 100.2 rgb24_to_y_1920_c: 405.7 rgb24_to_y_1920_rvv_i32: 166.7 SpacemiT X60: rgb24_to_y_8_c: 1.7 rgb24_to_y_8_rvv_i32: 2.5 rgb24_to_y_128_c: 23.2 rgb24_to_y_128_rvv_i32: 5.0 rgb24_to_y_1080_c: 195.0 rgb24_to_y_1080_rvv_i32: 38.0 rgb24_to_y_1280_c: 231.0 rgb24_to_y_1280_rvv_i32: 45.0 rgb24_to_y_1920_c: 346.2 rgb24_to_y_1920_rvv_i32: 67.2 --- libswscale/riscv/Makefile | 6 +++-- libswscale/riscv/input.S | 51 +++++++++++++++++++++++++++++++++++ libswscale/riscv/swscale.c | 40 +++++++++++++++++++++++++++ libswscale/swscale.c | 2 ++ libswscale/swscale_internal.h | 1 + 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 libswscale/riscv/input.S create mode 100644 libswscale/riscv/swscale.c diff --git a/libswscale/riscv/Makefile b/libswscale/riscv/Makefile index 48afaf62aa..d1b0eae367 100644 --- a/libswscale/riscv/Makefile +++ b/libswscale/riscv/Makefile @@ -1,3 +1,5 @@ -OBJS += riscv/rgb2rgb.o +OBJS += riscv/rgb2rgb.o \ + riscv/swscale.o RV-OBJS += riscv/rgb2rgb_rvb.o -RVV-OBJS += riscv/rgb2rgb_rvv.o +RVV-OBJS += riscv/input.o \ + riscv/rgb2rgb_rvv.o diff --git a/libswscale/riscv/input.S b/libswscale/riscv/input.S new file mode 100644 index 0000000000..c2dca8fe29 --- /dev/null +++ b/libswscale/riscv/input.S @@ -0,0 +1,51 @@ +/* + * Copyright © 2024 Rémi Denis-Courmont. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/riscv/asm.S" + +func ff_rgb24ToY_rvv, zve32x + csrwi vxrm, 0 + lw t1, 0(a5) # RY + lw t2, 4(a5) # GY + lw t3, 8(a5) # BY + li t4, 32 << (15 - 1) +1: + vsetvli t0, a4, e32, m8, ta, ma + vlseg3e8.v v0, (a1) + sub a4, a4, t0 + vzext.vf4 v8, v0 + sh1add t5, t0, t0 # t1 = 3 * t0 + vzext.vf4 v16, v2 + vzext.vf4 v24, v4 + add a1, t5, a1 + vmul.vx v8, v8, t1 + vmul.vx v16, v16, t2 + vmul.vx v24, v24, t3 + vadd.vv v8, v8, v16 + vadd.vx v24, v24, t4 + vadd.vv v8, v8, v24 + vsetvli zero, zero, e16, m4, ta, ma + vnclipu.wi v0, v8, 15 - 6 + vse16.v v0, (a0) + sh1add a0, t0, a0 + bnez a4, 1b + + ret +endfunc diff --git a/libswscale/riscv/swscale.c b/libswscale/riscv/swscale.c new file mode 100644 index 0000000000..71f01a8a5a --- /dev/null +++ b/libswscale/riscv/swscale.c @@ -0,0 +1,40 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "libavutil/attributes.h" +#include "libavutil/riscv/cpu.h" +#include "libswscale/swscale_internal.h" + +void ff_rgb24ToY_rvv(uint8_t *dst, const uint8_t *src, const uint8_t *, + const uint8_t *, int width, uint32_t *coeffs, void *); + +av_cold void ff_sws_init_swscale_riscv(SwsContext *c) +{ +#if HAVE_RVV + int flags = av_get_cpu_flags(); + + if ((flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB_ADDR)) { + switch (c->srcFormat) { + case AV_PIX_FMT_RGB24: + c->lumToYV12 = ff_rgb24ToY_rvv; + break; + } + } +#endif +} diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 2795429b6c..9736734881 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -602,6 +602,8 @@ void ff_sws_init_scale(SwsContext *c) ff_sws_init_swscale_arm(c); #elif ARCH_LOONGARCH64 ff_sws_init_swscale_loongarch(c); +#elif ARCH_RISCV + ff_sws_init_swscale_riscv(c); #endif } diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index d4b0c3cee2..5007dd422f 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -988,6 +988,7 @@ 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_sws_init_swscale_riscv(SwsContext *c); void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc);