* [FFmpeg-devel] [PATCH 05/18] lavu/riscv: add <intmath.h> optimisations
@ 2022-09-09 15:48 remi
0 siblings, 0 replies; 3+ messages in thread
From: remi @ 2022-09-09 15:48 UTC (permalink / raw)
To: ffmpeg-devel
From: Rémi Denis-Courmont <remi@remlab.net>
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 | 103 ++++++++++++++++++++++++++++++++++++++
2 files changed, 106 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..78f7ba930a
--- /dev/null
+++ b/libavutil/riscv/intmath.h
@@ -0,0 +1,103 @@
+/*
+ * 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 <stdint.h>
+
+#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;
+
+#if (__riscv_xlen >= 128)
+ __asm__ ("cpopd %0, %1\n" : "=r" (ret) : "r" (x));
+#else
+ __asm__ ("cpop %0, %1\n" : "=r" (ret) : "r" (x));
+#endif
+ return ret;
+}
+#endif /* __riscv_xlen >= 64 */
+#endif /* __riscv_zbb */
+
+#endif /* AVUTIL_RISCV_INTMATH_H */
--
2.37.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".
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <2652141.mvXUDI8C0e@basile.remlab.net>]
* [FFmpeg-devel] [PATCH 05/18] lavu/riscv: add <intmath.h> optimisations
[not found] <2652141.mvXUDI8C0e@basile.remlab.net>
@ 2022-09-12 15:53 ` remi
2022-09-14 9:28 ` Rémi Denis-Courmont
0 siblings, 1 reply; 3+ messages in thread
From: remi @ 2022-09-12 15:53 UTC (permalink / raw)
To: ffmpeg-devel
From: Rémi Denis-Courmont <remi@remlab.net>
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 | 103 ++++++++++++++++++++++++++++++++++++++
2 files changed, 106 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..78f7ba930a
--- /dev/null
+++ b/libavutil/riscv/intmath.h
@@ -0,0 +1,103 @@
+/*
+ * 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 <stdint.h>
+
+#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;
+
+#if (__riscv_xlen >= 128)
+ __asm__ ("cpopd %0, %1\n" : "=r" (ret) : "r" (x));
+#else
+ __asm__ ("cpop %0, %1\n" : "=r" (ret) : "r" (x));
+#endif
+ return ret;
+}
+#endif /* __riscv_xlen >= 64 */
+#endif /* __riscv_zbb */
+
+#endif /* AVUTIL_RISCV_INTMATH_H */
--
2.37.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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-14 9:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 15:48 [FFmpeg-devel] [PATCH 05/18] lavu/riscv: add <intmath.h> optimisations remi
[not found] <2652141.mvXUDI8C0e@basile.remlab.net>
2022-09-12 15:53 ` remi
2022-09-14 9:28 ` Rémi Denis-Courmont
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git