From patchwork Mon Dec 25 04:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: flow gg X-Patchwork-Id: 45314 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp2383868pzh; Sun, 24 Dec 2023 20:01:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXFLUZwclyjqImDquGzh8C7H18lcZ37b2iudyAE0Yl6zOh1nw55u/RceFZJ409xqFOcVR6 X-Received: by 2002:a17:906:6d99:b0:a23:5c9d:4233 with SMTP id h25-20020a1709066d9900b00a235c9d4233mr5831552ejt.7.1703476894251; Sun, 24 Dec 2023 20:01:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703476894; cv=none; d=google.com; s=arc-20160816; b=UDy4oAFaEaK3Rro/WvGGet+iTl+B/Z1a3hjFXLEJGg2HrnHKdenxxI3FlaT07ri/br 4MKYgpK+gYJw+Yx2k8ehEeG9NgZJY7QmU0zlN81UI/zUd/ANx77JvWZt1UYYuy+eWuwS LfSJFXEwNhPF6ZufbLKtXow+jDtQndRZz90Jy1T0PdMcR0QV62l4NQ0IdY4oR4wGMgr8 ozobUPjrBHIx0domYnEgNouYiJr08xB3IbjSqWtwM0YyF1t3TOFpzHmmgF7BNcuqdEP4 nziYtFBlrCBZZZfgZWmu6mCqCaA9nRLWHwDTSJNSKUgB1xjcPsTduDb7fp4MMql3JoEG Rc9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=p+8VaJMZh6Pc28PxwzSojt2cjsiiwDEFUDuZd1Owscg=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=PcBJqUjMoMtaC0/PqTUtS3cBJoeTRtwZakfNcP3lOG07PqzRMFD+/q287/HUK63SLi /kEweEhwX5eSutg74XZfnXBG/jHWwMalktPFtp7IcG8hty9uZo5jsj0xF994Ocoh27cW sQWgf9rEdCCRrBkip2TgVUsOdQi+fBz2B+2xUz/2mOX1qDbTkVPLejHbn+0VpubnVIJE gUSZO7WJLgesoz8M2AL0ybMmZ6GbDpuQ7P+9L/QHTf8ywyONnLDGRsZ461pNnYXgl1sh /06EeYhHG5B/N32IDR2OW5Sd45856ZUqbo97GtvM9x0Onf6QUsGSTfp1PipgvlORRNXL oycQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=TtNbh5dA; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u25-20020a1709064ad900b00a2341af65d7si4137085ejt.674.2023.12.24.20.01.33; Sun, 24 Dec 2023 20:01:34 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=TtNbh5dA; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D5B6668D191; Mon, 25 Dec 2023 06:01:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3218568D097 for ; Mon, 25 Dec 2023 06:01:25 +0200 (EET) Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-67f9fac086bso20967626d6.3 for ; Sun, 24 Dec 2023 20:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703476883; x=1704081683; darn=ffmpeg.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=5Ne+DgNHS0vrGQxuVsRItfT8FTUFwi7p4t1PrGWWVJE=; b=TtNbh5dAsXN94u5KPhvvLVY3OJsvHcJTTBKs81QutGoZ4h0/f6rgCCGTlT0EXQvUAO 4huGb7e7rZnI73A++19iaq5IXrRwJSvSWOI4TUuJ20ySHAqXfMQU7CDSLFWiuhanTCqZ NuOFbaOpview1waC74jAMNZ1IjAnRAe30z9jGJZ7VCiL+NHJe9rWG8rLRSNc6pPrgFDl 47acik0WdHKNicb3sIr5Q1CBBdSdGraEbjEAd98C4DGTUSuNDVLNZWyT8JzJXZWyqCVo /pzHYwxylIofT/I/4X4L0FFjKdNwqdVc+Y+Dz43V8NpV/TcZSF4te98YfvkSm8UbkE1X Iu2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703476883; x=1704081683; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5Ne+DgNHS0vrGQxuVsRItfT8FTUFwi7p4t1PrGWWVJE=; b=SQN/M19yP/qeudwSt954P49OaMt63ftVCkXkWuiTU7SbHlkgGueu/wKakUeWh2RX2n c1uK9+n8omfgrI51Yj+GoLwlB+Zuqc5BCOi4S6daOQxc4VFFt+vAy8xyZBe6RdlXDAih S38Q9z0YADWk92yGnYH+KRrqBD6wtRxN44zJ9HCxLSNgbzn9h7DB2V/x9cQufnU6svA+ gPY73z7veoDs/2XBg6mVjd9/bk7/BpDKpLc/abp+xoVV1pdVU5f0n9GlBa2s4OOr0scd hw2km4GsqMKzyGVMOlMkPSYCIMpWtQUXsRFpH+4Gd9wO5Zftcgc8tYFyV2Vh9SFTYglB psvw== X-Gm-Message-State: AOJu0Yxd4Qk4523QGQ8PL34wlFryxRh8nDonvjdp0jAqcXVZkBBIMRIg kkuwAu59hx1MUgDNDWYCUWyNzSg3Chg0iLwRWxPM54RilbH580k+n40= X-Received: by 2002:ad4:46d4:0:b0:680:a4c:275d with SMTP id pm20-20020ad446d4000000b006800a4c275dmr971586qvb.87.1703476883343; Sun, 24 Dec 2023 20:01:23 -0800 (PST) MIME-Version: 1.0 From: flow gg Date: Mon, 25 Dec 2023 12:01:12 +0800 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH 2/3] lavc/h264dsp: R-V V h264_add_pixels4_clear 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: jNvNQCMP0Kdz C908 h264_add_pixels4_clear_c: 96.0 h264_add_pixels4_clear_rvv_i64: 30.2 From 8b2838516915c27aa2831e797c2c41ad1d1bae1b Mon Sep 17 00:00:00 2001 From: sunyuechi Date: Mon, 25 Dec 2023 00:06:28 +0800 Subject: [PATCH 2/3] lavc/h264dsp: R-V V h264_add_pixels4_clear C908 h264_add_pixels4_clear_c: 96.0 h264_add_pixels4_clear_rvv_i64: 30.2 The number of vsets can be reduced, but that would lead to a change in the order of instructions, thus making it slower. --- libavcodec/h264dsp.c | 2 ++ libavcodec/h264dsp.h | 2 ++ libavcodec/riscv/Makefile | 2 ++ libavcodec/riscv/h264dsp_init.c | 41 ++++++++++++++++++++++++++++++++ libavcodec/riscv/h264dsp_rvv.S | 42 +++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 libavcodec/riscv/h264dsp_init.c create mode 100644 libavcodec/riscv/h264dsp_rvv.S diff --git a/libavcodec/h264dsp.c b/libavcodec/h264dsp.c index 4d2ee10bab..1ba936be1c 100644 --- a/libavcodec/h264dsp.c +++ b/libavcodec/h264dsp.c @@ -158,6 +158,8 @@ av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, ff_h264dsp_init_arm(c, bit_depth, chroma_format_idc); #elif ARCH_PPC ff_h264dsp_init_ppc(c, bit_depth, chroma_format_idc); +#elif ARCH_RISCV + ff_h264dsp_init_riscv(c, bit_depth, chroma_format_idc); #elif ARCH_X86 ff_h264dsp_init_x86(c, bit_depth, chroma_format_idc); #elif ARCH_MIPS diff --git a/libavcodec/h264dsp.h b/libavcodec/h264dsp.h index e0880c4d88..d940343b4a 100644 --- a/libavcodec/h264dsp.h +++ b/libavcodec/h264dsp.h @@ -125,6 +125,8 @@ void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, const int chroma_format_idc); void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, const int chroma_format_idc); +void ff_h264dsp_init_riscv(H264DSPContext *c, const int bit_depth, + const int chroma_format_idc); void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth, const int chroma_format_idc); void ff_h264dsp_init_mips(H264DSPContext *c, const int bit_depth, diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile index 35ad149326..7f253bba12 100644 --- a/libavcodec/riscv/Makefile +++ b/libavcodec/riscv/Makefile @@ -23,6 +23,8 @@ OBJS-$(CONFIG_FMTCONVERT) += riscv/fmtconvert_init.o RVV-OBJS-$(CONFIG_FMTCONVERT) += riscv/fmtconvert_rvv.o OBJS-$(CONFIG_G722DSP) += riscv/g722dsp_init.o RVV-OBJS-$(CONFIG_G722DSP) += riscv/g722dsp_rvv.o +OBJS-$(CONFIG_H264DSP) += riscv/h264dsp_init.o +RVV-OBJS-$(CONFIG_H264DSP) += riscv/h264dsp_rvv.o OBJS-$(CONFIG_JPEG2000_DECODER) += riscv/jpeg2000dsp_init.o RVV-OBJS-$(CONFIG_JPEG2000_DECODER) += riscv/jpeg2000dsp_rvv.o OBJS-$(CONFIG_H264CHROMA) += riscv/h264_chroma_init_riscv.o diff --git a/libavcodec/riscv/h264dsp_init.c b/libavcodec/riscv/h264dsp_init.c new file mode 100644 index 0000000000..2538bc01a5 --- /dev/null +++ b/libavcodec/riscv/h264dsp_init.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS). + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/riscv/cpu.h" +#include "libavcodec/h264dsp.h" + +void ff_h264_add_pixels4_clear_rvv(uint8_t *dst, int16_t *block, int stride); + +av_cold void ff_h264dsp_init_riscv(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) +{ +#if HAVE_RVV + int flags = av_get_cpu_flags(); + + if (flags & AV_CPU_FLAG_RVV_I64) { + if (bit_depth == 8) { + c->h264_add_pixels4_clear = ff_h264_add_pixels4_clear_rvv; + } + } +#endif +} diff --git a/libavcodec/riscv/h264dsp_rvv.S b/libavcodec/riscv/h264dsp_rvv.S new file mode 100644 index 0000000000..e6b943f57e --- /dev/null +++ b/libavcodec/riscv/h264dsp_rvv.S @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS). + * + * 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_h264_add_pixels4_clear_rvv, zve64x + vsetivli zero, 4, e8, mf4, ta, ma + vle64.v v24, (a1) + vsetivli zero, 4*4, e16, m2, ta, ma + li t0, 0xff + vand.vx v24, v24, t0 + addi a1, a1, 4*4*2 + vsetivli zero, 4, e8, mf4, ta, ma + vse64.v v0, (a1) + vsetivli zero, 4*4, e8, m1, ta, ma + vnclipu.wi v24, v24, 0 + vsetivli zero, 2, e8, mf8, ta, ma + vle64.v v8, (a0) + vsetivli zero, 4*4, e8, m1, ta, ma + vadd.vv v24, v24, v8 + vsetivli zero, 2, e8, mf8, ta, ma + vse64.v v24, (a0) + + ret +endfunc -- 2.43.0