Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] riscv/bswap: use compiler builtins
@ 2023-04-20 17:53 Rémi Denis-Courmont
  2023-05-02 15:54 ` Rémi Denis-Courmont
  0 siblings, 1 reply; 2+ messages in thread
From: Rémi Denis-Courmont @ 2023-04-20 17:53 UTC (permalink / raw)
  To: ffmpeg-devel

av_bswapXX() are used in context that expect exact size types, notably
variable arguments to av_log(). On Linux RV64, uint_fast32_t is an
unsigned long, so the current inline assembler does not work properly.

Since GCC and Clang gained their byte-swap built-ins before they
supported RISC-V, we can simply defer to them. As an added bonus, the
compiler can do instruction scheduling, which it couldn't with the Zbb
inline assembler.
---
 libavutil/riscv/bswap.h | 52 ++++-------------------------------------
 1 file changed, 5 insertions(+), 47 deletions(-)

diff --git a/libavutil/riscv/bswap.h b/libavutil/riscv/bswap.h
index de1429c0f7..ce75de974e 100644
--- a/libavutil/riscv/bswap.h
+++ b/libavutil/riscv/bswap.h
@@ -23,52 +23,10 @@
 #include "config.h"
 #include "libavutil/attributes.h"
 
-#if defined (__riscv_zbb) && (__riscv_zbb > 0) && HAVE_INLINE_ASM
+#if defined (__GNUC__) || defined (__clang__)
+#define av_bswap16 __builtin_bswap16
+#define av_bswap32 __builtin_bswap32
+#define av_bswap64 __builtin_bswap64
+#endif
 
-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.40.0

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

* Re: [FFmpeg-devel] [PATCH 1/2] riscv/bswap: use compiler builtins
  2023-04-20 17:53 [FFmpeg-devel] [PATCH 1/2] riscv/bswap: use compiler builtins Rémi Denis-Courmont
@ 2023-05-02 15:54 ` Rémi Denis-Courmont
  0 siblings, 0 replies; 2+ messages in thread
From: Rémi Denis-Courmont @ 2023-05-02 15:54 UTC (permalink / raw)
  To: ffmpeg-devel

Ping.

-- 
雷米‧德尼-库尔蒙
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] 2+ messages in thread

end of thread, other threads:[~2023-05-02 15:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20 17:53 [FFmpeg-devel] [PATCH 1/2] riscv/bswap: use compiler builtins Rémi Denis-Courmont
2023-05-02 15:54 ` 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