Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [NOT FOR MERGE] [PATCH] lavc/bswapdsp: do not assume aligned input on RISC-V
@ 2023-01-13 20:18 Rémi Denis-Courmont
  0 siblings, 0 replies; only message in thread
From: Rémi Denis-Courmont @ 2023-01-13 20:18 UTC (permalink / raw)
  To: ffmpeg-devel

This fixes the RISC-V B code not to assume alignment. Unfortunately,
the whole idea behind the optimisation does not really work if the
input is unaligned, and the C code works just as well.

Notes:
- This does not fix the call prototypes, whose second parameter
  is expected to change to `const void *` separately.
- The RISC-V Vector code does not assume any alignment of either input
  or output buffers.
---
 libavcodec/bswapdsp.c           | 4 ++--
 libavcodec/bswapdsp.h           | 2 ++
 libavcodec/riscv/bswapdsp_rvb.S | 5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/bswapdsp.c b/libavcodec/bswapdsp.c
index f0ea2b55c5..901610c96d 100644
--- a/libavcodec/bswapdsp.c
+++ b/libavcodec/bswapdsp.c
@@ -22,7 +22,7 @@
 #include "libavutil/bswap.h"
 #include "bswapdsp.h"
 
-static void bswap_buf(uint32_t *dst, const uint32_t *src, int w)
+void ff_bswap32_buf(uint32_t *dst, const uint32_t *src, int w)
 {
     int i;
 
@@ -48,7 +48,7 @@ static void bswap16_buf(uint16_t *dst, const uint16_t *src, int len)
 
 av_cold void ff_bswapdsp_init(BswapDSPContext *c)
 {
-    c->bswap_buf   = bswap_buf;
+    c->bswap_buf   = ff_bswap32_buf;
     c->bswap16_buf = bswap16_buf;
 
 #if ARCH_RISCV
diff --git a/libavcodec/bswapdsp.h b/libavcodec/bswapdsp.h
index 6f4db66115..fa199b3be9 100644
--- a/libavcodec/bswapdsp.h
+++ b/libavcodec/bswapdsp.h
@@ -30,4 +30,6 @@ void ff_bswapdsp_init(BswapDSPContext *c);
 void ff_bswapdsp_init_riscv(BswapDSPContext *c);
 void ff_bswapdsp_init_x86(BswapDSPContext *c);
 
+void ff_bswap32_buf(uint32_t *dst, const uint32_t *src, int w);
+
 #endif /* AVCODEC_BSWAPDSP_H */
diff --git a/libavcodec/riscv/bswapdsp_rvb.S b/libavcodec/riscv/bswapdsp_rvb.S
index 91b47bf82d..795e44f478 100644
--- a/libavcodec/riscv/bswapdsp_rvb.S
+++ b/libavcodec/riscv/bswapdsp_rvb.S
@@ -23,7 +23,9 @@
 
 #if (__riscv_xlen >= 64)
 func ff_bswap32_buf_rvb, zbb
+        andi    t1, a1, 3
         andi    t0, a1, 4
+        bnez    t1, 6f
         beqz    t0, 1f
         /* Align a1 (input) to 64-bit */
         lwu     t0, (a1)
@@ -64,5 +66,8 @@ func ff_bswap32_buf_rvb, zbb
         sw      t0, -4(a0)
 5:
         ret
+
+6:      /* No worthy optimisation if unaligned */
+        tail    ff_bswap32_buf
 endfunc
 #endif
-- 
2.39.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] only message in thread

only message in thread, other threads:[~2023-01-13 20:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 20:18 [FFmpeg-devel] [NOT FOR MERGE] [PATCH] lavc/bswapdsp: do not assume aligned input on RISC-V 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