From patchwork Tue Sep 6 16:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 37717 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp3385539pzh; Tue, 6 Sep 2022 09:51:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR53Ly2g17gC6g2G8ozI147hQ3W2ITPNlijznfP+mQ8/ET/7xesIRUapS5zX6WpCkcoZVq9O X-Received: by 2002:a17:907:7e8e:b0:741:362a:9678 with SMTP id qb14-20020a1709077e8e00b00741362a9678mr33997697ejc.499.1662483068469; Tue, 06 Sep 2022 09:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662483068; cv=none; d=google.com; s=arc-20160816; b=JsXABurrMPFoOs3jk79YsccrWzUVBUbwerWvo9xKFfz4m0urjbaBzin2kZdMLCmJiA iwT24BuoYwDTvkzqf06cSvOV0WXZIy8sVD01p8mcxSc4WT9WGUAkevZtKBpIzlLZ9cda way7syjvRwOSW+Od5tAHlqzvSf1FJYD460Vt/NqLrEC+dHfuPgmIkmkcC6BqguEArCa6 wSB3SLWE/6zwg3yMfSL8gIL0zsWLHs6uQPEfTEItAGVLNlivgsMb5zHhlkQxdalFzwdI +4/GcjZ9aDKwklYuyUvaFjHJbX5UN05pWba4bENzDKgMRJo5Mc303vNaEtPoaEgQ7cnY W0tQ== 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=EFhlj4tFhN9xI8ubiogDZbXei/Ryo7zQmFw8n+T80HM=; b=YAHAf2aPOSwY51zdWgNwk6uHdBix3Jv8NRacbP77MtlMI0VPJiigXiVlFXQBOTN9Xx CeZu00i3dA2eJjI6BCyI5teVdpFYTclJlT0Khgj39aiNXUorb4fi8X8xqYWCxm75nCOF kQ4XfgtYL2b+e8IfALuAo4XlN2i3ADbqKv1gjKbNKgCYpLN72fkg15E0nfK2UPyfUTKx nVvbVjXlHhj4aoltswWI0zVZU3XgCB+7qvM2Dnh92VlHPOmFzGhRdJLfgB8PrsfwzhPG nhv9lu5Ael8qkkkk1pCfAPjvyeESvFARctqgM7kgsP/rWQxnuoSnRXfEAUfhg+AR4pDZ +ntg== 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 m13-20020a50d7cd000000b0044eebb9818dsi879497edj.456.2022.09.06.09.51.05; Tue, 06 Sep 2022 09:51:08 -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 5F03468BB3D; Tue, 6 Sep 2022 19:50:34 +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 68C9568BB0C for ; Tue, 6 Sep 2022 19:50:28 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 2D9AEC00B0 for ; Tue, 6 Sep 2022 19:50:28 +0300 (EEST) From: remi@remlab.net To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Sep 2022 19:50:27 +0300 Message-Id: <20220906165027.91347-5-remi@remlab.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <12048155.O9o76ZdvQC@basile.remlab.net> References: <12048155.O9o76ZdvQC@basile.remlab.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add optimisations 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: GnoP64N2D0/X From: RĂ©mi Denis-Courmont This provides some micro-optimisations for signed integer clipping, and support for bit weight with the Zbb extension. --- libavutil/intmath.h | 5 +- libavutil/riscv/intmath.h | 99 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 libavutil/riscv/intmath.h diff --git a/libavutil/intmath.h b/libavutil/intmath.h index 9573109e9d..c54d23b7bf 100644 --- a/libavutil/intmath.h +++ b/libavutil/intmath.h @@ -28,8 +28,9 @@ #if ARCH_ARM # include "arm/intmath.h" -#endif -#if ARCH_X86 +#elif ARCH_RISCV +# include "riscv/intmath.h" +#elif ARCH_X86 # include "x86/intmath.h" #endif diff --git a/libavutil/riscv/intmath.h b/libavutil/riscv/intmath.h new file mode 100644 index 0000000000..5a0bcc5b6a --- /dev/null +++ b/libavutil/riscv/intmath.h @@ -0,0 +1,99 @@ +/* + * 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 AVUTIL_RISCV_INTMATH_H +#define AVUTIL_RISCV_INTMATH_H + +#include + +#include "config.h" +#include "libavutil/attributes.h" + +/* + * The compiler is forced to sign-extend the result anyhow, so it is faster to + * compute it explicitly and use it. + */ +#define av_clip_int8 av_clip_int8_rvi +static av_always_inline av_const int8_t av_clip_int8_rvi(int a) +{ + union { uint8_t u; int8_t s; } u = { .u = a }; + + if (a != u.s) + a = ((a >> 31) ^ 0x7F); + return a; +} + +#define av_clip_int16 av_clip_int16_rvi +static av_always_inline av_const int16_t av_clip_int16_rvi(int a) +{ + union { uint8_t u; int8_t s; } u = { .u = a }; + + if (a != u.s) + a = ((a >> 31) ^ 0x7F); + return a; +} + +#define av_clipl_int32 av_clipl_int32_rvi +static av_always_inline av_const int32_t av_clipl_int32_rvi(int64_t a) +{ + union { uint32_t u; int32_t s; } u = { .u = a }; + + if (a != u.s) + a = ((a >> 63) ^ 0x7FFFFFFF); + return a; +} + +#define av_clip_intp2 av_clip_intp2_rvi +static av_always_inline av_const int av_clip_intp2_rvi(int a, int p) +{ + const int shift = 32 - p; + int b = (a << shift) >> shift; + + if (a != b) + b = (a >> 31) ^ ((1 << p) - 1); + return b; +} + +#if defined (__riscv_zbb) && (__riscv_zbb > 0) && HAVE_INLINE_ASM + +#define av_popcount av_popcount_rvb +static av_always_inline av_const int av_popcount_rvb(uint32_t x) +{ + int ret; + +#if (__riscv_xlen >= 64) + __asm__ ("cpopw %0, %1\n" : "=r" (ret) : "r" (x)); +#else + __asm__ ("cpop %0, %1\n" : "=r" (ret) : "r" (x)); +#endif + return ret; +} + +#if (__riscv_xlen >= 64) +#define av_popcount64 av_popcount64_rvb +static av_always_inline av_const int av_popcount64_rvb(uint64_t x) +{ + int ret; + + __asm__ ("cpop %0, %1\n" : "=r" (ret) : "r" (x)); + return ret; +} +#endif /* __riscv_xlen >= 64 */ +#endif /* __riscv_zbb */ + +#endif /* AVUTIL_RISCV_INTMATH_H */