diff options
Diffstat (limited to 'src/libffmpeg/libavcodec/bswap.h')
-rw-r--r-- | src/libffmpeg/libavcodec/bswap.h | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/src/libffmpeg/libavcodec/bswap.h b/src/libffmpeg/libavcodec/bswap.h index eb1d87a55..50fd57178 100644 --- a/src/libffmpeg/libavcodec/bswap.h +++ b/src/libffmpeg/libavcodec/bswap.h @@ -17,16 +17,15 @@ #endif #if defined(ARCH_X86) || defined(ARCH_X86_64) -static inline uint16_t ByteSwap16(uint16_t x) +static always_inline uint16_t bswap_16(uint16_t x) { - __asm("xchgb %b0,%h0" : + __asm("rorw $8, %0" : LEGACY_REGS (x) : "0" (x)); return x; } -#define bswap_16(x) ByteSwap16(x) -static inline uint32_t ByteSwap32(uint32_t x) +static always_inline uint32_t bswap_32(uint32_t x) { #if __CPU__ > 386 __asm("bswap %0": @@ -40,9 +39,8 @@ static inline uint32_t ByteSwap32(uint32_t x) "0" (x)); return x; } -#define bswap_32(x) ByteSwap32(x) -static inline uint64_t ByteSwap64(uint64_t x) +static inline uint64_t bswap_64(uint64_t x) { #ifdef ARCH_X86_64 __asm("bswap %0": @@ -50,24 +48,26 @@ static inline uint64_t ByteSwap64(uint64_t x) "0" (x)); return x; #else - register union { __extension__ uint64_t __ll; - uint32_t __l[2]; } __x; - asm("xchgl %0,%1": - "=r"(__x.__l[0]),"=r"(__x.__l[1]): - "0"(bswap_32((uint32_t)x)),"1"(bswap_32((uint32_t)(x>>32)))); - return __x.__ll; + union { + uint64_t ll; + struct { + uint32_t l,h; + } l; + } r; + r.l.l = bswap_32 (x); + r.l.h = bswap_32 (x>>32); + return r.ll; #endif } -#define bswap_64(x) ByteSwap64(x) #elif defined(ARCH_SH4) -static inline uint16_t ByteSwap16(uint16_t x) { +static always_inline uint16_t bswap_16(uint16_t x) { __asm__("swap.b %0,%0":"=r"(x):"0"(x)); return x; } -static inline uint32_t ByteSwap32(uint32_t x) { +static always_inline uint32_t bswap_32(uint32_t x) { __asm__( "swap.b %0,%0\n" "swap.w %0,%0\n" @@ -76,10 +76,7 @@ static inline uint32_t ByteSwap32(uint32_t x) { return x; } -#define bswap_16(x) ByteSwap16(x) -#define bswap_32(x) ByteSwap32(x) - -static inline uint64_t ByteSwap64(uint64_t x) +static inline uint64_t bswap_64(uint64_t x) { union { uint64_t ll; @@ -91,20 +88,37 @@ static inline uint64_t ByteSwap64(uint64_t x) r.l.h = bswap_32 (x>>32); return r.ll; } -#define bswap_64(x) ByteSwap64(x) - #else -#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) - +static always_inline uint16_t bswap_16(uint16_t x){ + return (x>>8) | (x<<8); +} -// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. -#define bswap_32(x) \ - ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) +#ifdef ARCH_ARM +static always_inline uint32_t bswap_32(uint32_t x){ + uint32_t t; + __asm__ ( + "eor %1, %0, %0, ror #16 \n\t" + "bic %1, %1, #0xFF0000 \n\t" + "mov %0, %0, ror #8 \n\t" + "eor %0, %0, %1, lsr #8 \n\t" + : "+r"(x), "+r"(t)); + return x; +} +#else +static always_inline uint32_t bswap_32(uint32_t x){ + x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); + return (x>>16) | (x<<16); +} +#endif -static inline uint64_t ByteSwap64(uint64_t x) +static inline uint64_t bswap_64(uint64_t x) { +#if 0 + x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); + x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); + return (x>>32) | (x<<32); +#else union { uint64_t ll; uint32_t l[2]; @@ -113,9 +127,8 @@ static inline uint64_t ByteSwap64(uint64_t x) r.l[0] = bswap_32 (w.l[1]); r.l[1] = bswap_32 (w.l[0]); return r.ll; +#endif } -#define bswap_64(x) ByteSwap64(x) - #endif /* !ARCH_X86 */ #endif /* !HAVE_BYTESWAP_H */ |