[FFmpeg-devel] [NOT FOR MERGE] [PATCH] lavc/bswapdsp: do not assume aligned input on RISC-V
Rémi Denis-Courmont
remi at remlab.net
Fri Jan 13 22:18:44 EET 2023
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
More information about the ffmpeg-devel
mailing list