summaryrefslogtreecommitdiff
path: root/libavutil/bswap.h
diff options
context:
space:
mode:
authorMans Rullgard <mans@mansr.com>2011-12-12 00:50:08 +0000
committerMans Rullgard <mans@mansr.com>2011-12-12 12:14:14 +0000
commitf64c2e710fa1a7b59753224e717f57c48462076f (patch)
tree760f8b52024f89e22778498c4f00ceac03f3f01e /libavutil/bswap.h
parent5695ae46f8771f5c63cb0f62faca6a3d27f7d921 (diff)
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@mansr.com>
Diffstat (limited to 'libavutil/bswap.h')
-rw-r--r--libavutil/bswap.h13
1 files changed, 2 insertions, 11 deletions
diff --git a/libavutil/bswap.h b/libavutil/bswap.h
index 3657ccd402..8a350e1cd5 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