[FFmpeg-cvslog] bswap: make generic implementation more compiler-friendly

Mans Rullgard git at videolan.org
Tue Dec 13 00:59:43 CET 2011


ffmpeg | branch: master | Mans Rullgard <mans at mansr.com> | Mon Dec 12 00:50:08 2011 +0000| [f64c2e710fa1a7b59753224e717f57c48462076f] | committer: Mans Rullgard

bswap: make generic implementation more compiler-friendly

With these changes, gcc 4.5 and later recognise it as a bswap
and use the proper instructions on ARM and x86.  On x86, the
16-bit bswap is recognised from gcc 4.1.

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f64c2e710fa1a7b59753224e717f57c48462076f
---

 libavutil/arm/bswap.h |    2 ++
 libavutil/bswap.h     |   13 ++-----------
 libavutil/x86/bswap.h |    4 ++++
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/libavutil/arm/bswap.h b/libavutil/arm/bswap.h
index 478ae98..f94cbcf 100644
--- a/libavutil/arm/bswap.h
+++ b/libavutil/arm/bswap.h
@@ -51,6 +51,7 @@ static av_always_inline av_const unsigned av_bswap16(unsigned x)
 }
 #endif
 
+#if !AV_GCC_VERSION_AT_LEAST(4,5)
 #define av_bswap32 av_bswap32
 static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
 {
@@ -66,6 +67,7 @@ static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
 #endif /* HAVE_ARMV6 */
     return x;
 }
+#endif /* !AV_GCC_VERSION_AT_LEAST(4,5) */
 
 #endif /* __ARMCC_VERSION */
 
diff --git a/libavutil/bswap.h b/libavutil/bswap.h
index 3657ccd..8a350e1 100644
--- a/libavutil/bswap.h
+++ b/libavutil/bswap.h
@@ -65,23 +65,14 @@ static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
 #ifndef av_bswap32
 static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
 {
-    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
-    x= (x>>16) | (x<<16);
-    return x;
+    return AV_BSWAP32C(x);
 }
 #endif
 
 #ifndef av_bswap64
 static inline uint64_t av_const av_bswap64(uint64_t x)
 {
-    union {
-        uint64_t ll;
-        uint32_t l[2];
-    } w, r;
-    w.ll = x;
-    r.l[0] = av_bswap32 (w.l[1]);
-    r.l[1] = av_bswap32 (w.l[0]);
-    return r.ll;
+    return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
 }
 #endif
 
diff --git a/libavutil/x86/bswap.h b/libavutil/x86/bswap.h
index b60d9cc..6840b63 100644
--- a/libavutil/x86/bswap.h
+++ b/libavutil/x86/bswap.h
@@ -28,13 +28,16 @@
 #include "config.h"
 #include "libavutil/attributes.h"
 
+#if !AV_GCC_VERSION_AT_LEAST(4,1)
 #define av_bswap16 av_bswap16
 static av_always_inline av_const unsigned av_bswap16(unsigned x)
 {
     __asm__("rorw $8, %w0" : "+r"(x));
     return x;
 }
+#endif /* !AV_GCC_VERSION_AT_LEAST(4,1) */
 
+#if !AV_GCC_VERSION_AT_LEAST(4,5)
 #define av_bswap32 av_bswap32
 static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
 {
@@ -57,5 +60,6 @@ static inline uint64_t av_const av_bswap64(uint64_t x)
     return x;
 }
 #endif
+#endif /* !AV_GCC_VERSION_AT_LEAST(4,5) */
 
 #endif /* AVUTIL_X86_BSWAP_H */



More information about the ffmpeg-cvslog mailing list