Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support
@ 2022-09-06 16:49 Rémi Denis-Courmont
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 1/5] doc: reference the RISC-V specification remi
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Rémi Denis-Courmont @ 2022-09-06 16:49 UTC (permalink / raw)
  To: ffmpeg-devel

The following changes since commit d9e3cb7e73c77ccddc4d29ed5c1be3920f72c226:

  avfilter/vf_scale: overwrite the width and height expressions with the original values (2022-09-06 10:10:42 -0300)

are available in the Git repository at:

  https://git.remlab.net/git/ffmpeg.git 

for you to fetch changes up to 0b31c3c3b1b9edef4107c5f7ddd4f3e0598dd21c:

  lavu/riscv: add <intmath.h> optimisations (2022-09-06 19:35:41 +0300)

This collects the previous three patchsets (Zbb-CLZ, Zbb-REV and RDCYCLE) and
adds bit weight, clipping and the barest amount of documentation.

----------------------------------------------------------------
Rémi Denis-Courmont (5):
      doc: reference the RISC-V specification
      lavu/riscv: AV_READ_TIME cycle counter
      configure/riscv: detect fast CLZ
      lavu/riscv: byte-swap operations
      lavu/riscv: add <intmath.h> optimisations

 configure                 |  6 +++
 doc/optimization.txt      |  5 +++
 libavutil/bswap.h         |  2 +
 libavutil/intmath.h       |  5 ++-
 libavutil/riscv/bswap.h   | 74 +++++++++++++++++++++++++++++++++++
 libavutil/riscv/intmath.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++
 libavutil/riscv/timer.h   | 53 +++++++++++++++++++++++++
 libavutil/timer.h         |  2 +
 8 files changed, 244 insertions(+), 2 deletions(-)
 create mode 100644 libavutil/riscv/bswap.h
 create mode 100644 libavutil/riscv/intmath.h
 create mode 100644 libavutil/riscv/timer.h

-- 
Rémi Denis-Courmont
http://www.remlab.net/



_______________________________________________
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] 8+ messages in thread

* [FFmpeg-devel] [PATCH 1/5] doc: reference the RISC-V specification
  2022-09-06 16:49 [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support Rémi Denis-Courmont
@ 2022-09-06 16:50 ` remi
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 2/5] lavu/riscv: AV_READ_TIME cycle counter remi
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: remi @ 2022-09-06 16:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Rémi Denis-Courmont <remi@remlab.net>

---
 doc/optimization.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/doc/optimization.txt b/doc/optimization.txt
index 974e2f9af2..3ed29fe38c 100644
--- a/doc/optimization.txt
+++ b/doc/optimization.txt
@@ -267,6 +267,11 @@ CELL/SPU:
 http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/30B3520C93F437AB87257060006FFE5E/$file/Language_Extensions_for_CBEA_2.4.pdf
 http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/9F820A5FFA3ECE8C8725716A0062585F/$file/CBE_Handbook_v1.1_24APR2007_pub.pdf
 
+RISC-V-specific:
+----------------
+The RISC-V Instruction Set Manual, Volume 1, Unprivileged ISA:
+https://riscv.org/technical/specifications/
+
 GCC asm links:
 --------------
 official doc but quite ugly
-- 
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] 8+ messages in thread

* [FFmpeg-devel] [PATCH 2/5] lavu/riscv: AV_READ_TIME cycle counter
  2022-09-06 16:49 [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support Rémi Denis-Courmont
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 1/5] doc: reference the RISC-V specification remi
@ 2022-09-06 16:50 ` remi
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 3/5] configure/riscv: detect fast CLZ remi
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: remi @ 2022-09-06 16:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Rémi Denis-Courmont <remi@remlab.net>

This uses the architected RISC-V 64-bit cycle counter from the
RISC-V unprivileged instruction set.

In 64-bit and 128-bit, this is a straightforward CSR read.
In 32-bit mode, the 64-bit value is exposed as two CSRs, which
cannot be read atomically, so a loop is necessary to detect and fix up
the race condition where the bottom half wraps exactly between the two
reads.
---
 libavutil/riscv/timer.h | 53 +++++++++++++++++++++++++++++++++++++++++
 libavutil/timer.h       |  2 ++
 2 files changed, 55 insertions(+)
 create mode 100644 libavutil/riscv/timer.h

diff --git a/libavutil/riscv/timer.h b/libavutil/riscv/timer.h
new file mode 100644
index 0000000000..a34157a566
--- /dev/null
+++ b/libavutil/riscv/timer.h
@@ -0,0 +1,53 @@
+/*
+ * 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_TIMER_H
+#define AVUTIL_RISCV_TIMER_H
+
+#include "config.h"
+
+#if HAVE_INLINE_ASM
+#include <stdint.h>
+
+static inline uint64_t rdcycle64(void)
+{
+#if (__riscv_xlen >= 64)
+    uintptr_t cycles;
+
+    __asm__ volatile ("rdcycle %0" : "=r"(cycles));
+
+#else
+    uint64_t cycles;
+    uint32_t hi, lo, check;
+
+    __asm__ volatile (
+        "1: rdcycleh %0\n"
+        "   rdcycle  %1\n"
+        "   rdcycleh %2\n"
+        "   bne %0, %2, 1b\n" : "=r" (hi), "=r" (lo), "=r" (check));
+
+    cycles = (((uint64_t)hi) << 32) | lo;
+
+#endif
+    return cycles;
+}
+
+#define AV_READ_TIME rdcycle64
+
+#endif
+#endif /* AVUTIL_RISCV_TIMER_H */
diff --git a/libavutil/timer.h b/libavutil/timer.h
index 48e576739f..d3db5a27ef 100644
--- a/libavutil/timer.h
+++ b/libavutil/timer.h
@@ -57,6 +57,8 @@
 #   include "arm/timer.h"
 #elif ARCH_PPC
 #   include "ppc/timer.h"
+#elif ARCH_RISCV
+#   include "riscv/timer.h"
 #elif ARCH_X86
 #   include "x86/timer.h"
 #endif
-- 
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] 8+ messages in thread

* [FFmpeg-devel] [PATCH 3/5] configure/riscv: detect fast CLZ
  2022-09-06 16:49 [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support Rémi Denis-Courmont
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 1/5] doc: reference the RISC-V specification remi
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 2/5] lavu/riscv: AV_READ_TIME cycle counter remi
@ 2022-09-06 16:50 ` remi
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 4/5] lavu/riscv: byte-swap operations remi
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: remi @ 2022-09-06 16:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Rémi Denis-Courmont <remi@remlab.net>

RISC-V defines the CLZ instruction as part of the ratified Zbb subset
of the (not yet ratified) bit mapulation extension (B). We can detect
it from the __riscv_zbb predefined constant. At least GCC 12 already
supports this correctly.

Note that the macro will be non-zero if supported, zero if enabled
in the compiler flags (e.g. -march=rv64gzbb) but not known to the
compiler, and undefined otherwise.
---
 configure | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/configure b/configure
index 9e51abd0d3..b7dc1d8656 100755
--- a/configure
+++ b/configure
@@ -5334,6 +5334,12 @@ elif enabled ppc; then
         ;;
     esac
 
+elif enabled riscv; then
+
+    if test_cpp_condition stddef.h "__riscv_zbb"; then
+        enable fast_clz
+    fi
+
 elif enabled sparc; then
 
     case $cpu in
-- 
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] 8+ messages in thread

* [FFmpeg-devel] [PATCH 4/5] lavu/riscv: byte-swap operations
  2022-09-06 16:49 [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support Rémi Denis-Courmont
                   ` (2 preceding siblings ...)
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 3/5] configure/riscv: detect fast CLZ remi
@ 2022-09-06 16:50 ` remi
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add <intmath.h> optimisations remi
  2022-09-06 16:53 ` remi
  5 siblings, 0 replies; 8+ messages in thread
From: remi @ 2022-09-06 16:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Rémi Denis-Courmont <remi@remlab.net>

If the target supports the Basic bit-manipulation (Zbb) extension, then
the REV8 instruction is available to reverse byte order.

Note that this instruction only exists at the "XLEN" register size,
so we need to right shift the result down to the data width.

If Zbb is not supported, then this patchset does nothing. Support for
run-time detection is left for the future. Currently, there are no
bits in auxv/ELF HWCAP for Z-extensions, so there are no clean ways to
do this.
---
 libavutil/bswap.h       |  2 ++
 libavutil/riscv/bswap.h | 74 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 libavutil/riscv/bswap.h

diff --git a/libavutil/bswap.h b/libavutil/bswap.h
index 91cb79538d..4840ab433f 100644
--- a/libavutil/bswap.h
+++ b/libavutil/bswap.h
@@ -40,6 +40,8 @@
 #   include "arm/bswap.h"
 #elif ARCH_AVR32
 #   include "avr32/bswap.h"
+#elif ARCH_RISCV
+#   include "riscv/bswap.h"
 #elif ARCH_SH4
 #   include "sh4/bswap.h"
 #elif ARCH_X86
diff --git a/libavutil/riscv/bswap.h b/libavutil/riscv/bswap.h
new file mode 100644
index 0000000000..de1429c0f7
--- /dev/null
+++ b/libavutil/riscv/bswap.h
@@ -0,0 +1,74 @@
+/*
+ * 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_BSWAP_H
+#define AVUTIL_RISCV_BSWAP_H
+
+#include <stdint.h>
+#include "config.h"
+#include "libavutil/attributes.h"
+
+#if defined (__riscv_zbb) && (__riscv_zbb > 0) && HAVE_INLINE_ASM
+
+static av_always_inline av_const uintptr_t av_bswap_xlen(uintptr_t x)
+{
+    uintptr_t y;
+
+    __asm__("rev8 %0, %1" : "=r" (y) : "r" (x));
+    return y;
+}
+
+#define av_bswap16 av_bswap16
+
+static av_always_inline av_const uint_fast16_t av_bswap16(uint_fast16_t x)
+{
+    return av_bswap_xlen(x) >> (__riscv_xlen - 16);
+}
+
+#if (__riscv_xlen == 32)
+#define av_bswap32 av_bswap_xlen
+#define av_bswap64 av_bswap64
+
+static av_always_inline av_const uint64_t av_bswap64(uint64_t x)
+{
+    return (((uint64_t)av_bswap32(x)) << 32) | av_bswap32(x >> 32);
+}
+
+#else
+#define av_bswap32 av_bswap32
+
+static av_always_inline av_const uint_fast32_t av_bswap32(uint_fast32_t x)
+{
+    return av_bswap_xlen(x) >> (__riscv_xlen - 32);
+}
+
+#if (__riscv_xlen == 64)
+#define av_bswap64 av_bswap_xlen
+
+#else
+#define av_bswap64 av_bswap64
+
+static av_always_inline av_const uint_fast64_t av_bswap64(uint_fast64_t x)
+{
+    return av_bswap_xlen(x) >> (__riscv_xlen - 64);
+}
+
+#endif /* __riscv_xlen > 64 */
+#endif /* __riscv_xlen > 32 */
+#endif /* __riscv_zbb */
+#endif /* AVUTIL_RISCV_BSWAP_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] 8+ messages in thread

* [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add <intmath.h> optimisations
  2022-09-06 16:49 [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support Rémi Denis-Courmont
                   ` (3 preceding siblings ...)
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 4/5] lavu/riscv: byte-swap operations remi
@ 2022-09-06 16:50 ` remi
  2022-09-06 17:00   ` Rémi Denis-Courmont
  2022-09-06 16:53 ` remi
  5 siblings, 1 reply; 8+ messages in thread
From: remi @ 2022-09-06 16:50 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 | 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 <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;
+
+    __asm__ ("cpop %0, %1\n" : "=r" (ret) : "r" (x));
+    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] 8+ messages in thread

* [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add <intmath.h> optimisations
  2022-09-06 16:49 [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support Rémi Denis-Courmont
                   ` (4 preceding siblings ...)
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add <intmath.h> optimisations remi
@ 2022-09-06 16:53 ` remi
  5 siblings, 0 replies; 8+ messages in thread
From: remi @ 2022-09-06 16: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] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add <intmath.h> optimisations
  2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add <intmath.h> optimisations remi
@ 2022-09-06 17:00   ` Rémi Denis-Courmont
  0 siblings, 0 replies; 8+ messages in thread
From: Rémi Denis-Courmont @ 2022-09-06 17:00 UTC (permalink / raw)
  To: ffmpeg-devel

Sorry, git-send-email boo boo. Scratch this one message.

-- 
レミ・デニ-クールモン
http://www.remlab.net/
_______________________________________________
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] 8+ messages in thread

end of thread, other threads:[~2022-09-06 17:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06 16:49 [FFmpeg-devel] [PATCHv2 0/5] RISC-V scalar and Zbb support Rémi Denis-Courmont
2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 1/5] doc: reference the RISC-V specification remi
2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 2/5] lavu/riscv: AV_READ_TIME cycle counter remi
2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 3/5] configure/riscv: detect fast CLZ remi
2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 4/5] lavu/riscv: byte-swap operations remi
2022-09-06 16:50 ` [FFmpeg-devel] [PATCH 5/5] lavu/riscv: add <intmath.h> optimisations remi
2022-09-06 17:00   ` Rémi Denis-Courmont
2022-09-06 16:53 ` remi

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