mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
endian_inl.h: add BSwap64
Change-Id: I66672b770500294b8f4ee8fa4bf1dfff1119dbe6
This commit is contained in:
parent
47779d46c8
commit
ee70a90187
@ -72,21 +72,7 @@ static WEBP_INLINE void VP8LoadNewBytes(VP8BitReader* const br) {
|
||||
br->buf_ += BITS >> 3;
|
||||
#if !defined(__BIG_ENDIAN__)
|
||||
#if (BITS > 32)
|
||||
#if defined(HAVE_BUILTIN_BSWAP)
|
||||
bits = (bit_t)__builtin_bswap64(in_bits);
|
||||
#elif defined(_MSC_VER)
|
||||
bits = (bit_t)_byteswap_uint64(in_bits);
|
||||
#elif defined(__x86_64__)
|
||||
__asm__ volatile("bswapq %0" : "=r"(bits) : "0"(in_bits));
|
||||
#else // generic code for swapping 64-bit values (suggested by bdb@)
|
||||
bits = (bit_t)in_bits;
|
||||
bits = ((bits & 0xffffffff00000000ull) >> 32) |
|
||||
((bits & 0x00000000ffffffffull) << 32);
|
||||
bits = ((bits & 0xffff0000ffff0000ull) >> 16) |
|
||||
((bits & 0x0000ffff0000ffffull) << 16);
|
||||
bits = ((bits & 0xff00ff00ff00ff00ull) >> 8) |
|
||||
((bits & 0x00ff00ff00ff00ffull) << 8);
|
||||
#endif
|
||||
bits = BSwap64(in_bits);
|
||||
bits >>= 64 - BITS;
|
||||
#elif (BITS >= 24)
|
||||
bits = BSwap32(in_bits);
|
||||
|
@ -70,4 +70,21 @@ static WEBP_INLINE uint32_t BSwap32(uint32_t x) {
|
||||
#endif // HAVE_BUILTIN_BSWAP
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint64_t BSwap64(uint64_t x) {
|
||||
#if defined(HAVE_BUILTIN_BSWAP)
|
||||
return __builtin_bswap64(x);
|
||||
#elif defined(__x86_64__)
|
||||
uint64_t swapped_bytes;
|
||||
__asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x));
|
||||
return swapped_bytes;
|
||||
#elif defined(_MSC_VER)
|
||||
return (uint64_t)_byteswap_uint64(x);
|
||||
#else // generic code for swapping 64-bit values (suggested by bdb@)
|
||||
x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32);
|
||||
x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16);
|
||||
x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8);
|
||||
return x;
|
||||
#endif // HAVE_BUILTIN_BSWAP
|
||||
}
|
||||
|
||||
#endif // WEBP_UTILS_ENDIAN_INL_H_
|
||||
|
Loading…
Reference in New Issue
Block a user