diff mbox series

[FFmpeg-devel,1/2] aarch64: relax byte-swap assembler constraints

Message ID 20220903150518.169643-1-remi@remlab.net
State Accepted
Commit 164021423a25f02c6253bb8d73ae9a443a129381
Headers show
Series [FFmpeg-devel,1/2] aarch64: relax byte-swap assembler constraints | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Rémi Denis-Courmont Sept. 3, 2022, 3:05 p.m. UTC
From: Rémi Denis-Courmont <remi@remlab.net>

There are no particular reasons to force the compiler to use the same
register as output and input operand. This forces an extra MOV
instruction if the input value needs to be reused after the swap.

In most cases, this makes no differences, as the compiler will seleect
the same register for both operands either way.
---
 libavutil/aarch64/bswap.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/aarch64/bswap.h b/libavutil/aarch64/bswap.h
index 1e735c52cf..7abca657ba 100644
--- a/libavutil/aarch64/bswap.h
+++ b/libavutil/aarch64/bswap.h
@@ -28,22 +28,28 @@ 
 #define av_bswap16 av_bswap16
 static av_always_inline av_const unsigned av_bswap16(unsigned x)
 {
-    __asm__("rev16 %w0, %w0" : "+r"(x));
-    return x;
+    unsigned y;
+
+    __asm__("rev16 %w0, %w1" : "=r"(y) : "r"(x));
+    return y;
 }
 
 #define av_bswap32 av_bswap32
 static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
 {
-    __asm__("rev %w0, %w0" : "+r"(x));
-    return x;
+    uint32_t y;
+
+    __asm__("rev %w0, %w1" : "=r"(y) : "r"(x));
+    return y;
 }
 
 #define av_bswap64 av_bswap64
 static av_always_inline av_const uint64_t av_bswap64(uint64_t x)
 {
-    __asm__("rev %0, %0" : "+r"(x));
-    return x;
+    uint64_t y;
+
+    __asm__("rev %0, %1" : "=r"(y) : "r"(x));
+    return y;
 }
 
 #endif /* HAVE_INLINE_ASM */