From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 5595A4AF48 for ; Thu, 25 Jul 2024 20:25:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9662468D79C; Thu, 25 Jul 2024 23:25:30 +0300 (EEST) Received: from ursule.remlab.net (vps-a2bccee9.vps.ovh.net [51.75.19.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8510568D682 for ; Thu, 25 Jul 2024 23:25:23 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id D797BC013B for ; Thu, 25 Jul 2024 23:25:22 +0300 (EEST) From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Jul 2024 23:25:15 +0300 Message-ID: <20240725202522.276182-1-remi@remlab.net> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] lavu/riscv: implement floating point clips 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Unlike x86, fmin/fmax are single instructions, not function calls. They are much much faster than doing a comparison, then branching based on its results. With this, audiodsp.vector_clipf gets almost twice as fast, and a properly unrollled version of it gets 4-5x faster, on SiFive-U74. This is only the low-hanging fruit: FFMIN and FFMAX are presumably affected as well. This likely applies to other instruction sets with native IEEE floats, especially those lacking a conditional select instruction. --- libavutil/riscv/intmath.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libavutil/riscv/intmath.h b/libavutil/riscv/intmath.h index 3e7ab864c5..24f165eef1 100644 --- a/libavutil/riscv/intmath.h +++ b/libavutil/riscv/intmath.h @@ -22,6 +22,7 @@ #define AVUTIL_RISCV_INTMATH_H #include +#include #include "config.h" #include "libavutil/attributes.h" @@ -72,6 +73,24 @@ static av_always_inline av_const int av_clip_intp2_rvi(int a, int p) return b; } +#if defined (__riscv_f) || defined (__riscv_zfinx) +#define av_clipf av_clipf_rvf +static av_always_inline av_const float av_clipf_rvf(float a, float min, + float max) +{ + return fminf(fmaxf(a, min), max); +} +#endif + +#if defined (__riscv_d) || defined (__riscv_zdinx) +#define av_clipd av_clipd_rvd +static av_always_inline av_const float av_clipd_rvd(double a, double min, + double max) +{ + return fmin(fmax(a, min), max); +} +#endif + #if defined (__GNUC__) || defined (__clang__) static inline av_const int ff_ctz_rv(int x) { -- 2.45.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".