endian_inl.h: add BSwap16

+ use it in VP8LoadNewBytes()

Change-Id: I701d3652dc0cbd553852978702ef68c2657bca1c
This commit is contained in:
James Zern 2014-07-04 00:41:14 -07:00
parent 6fbf5345e3
commit f2664d1aab
2 changed files with 10 additions and 2 deletions

View File

@ -89,8 +89,7 @@ static WEBP_INLINE void VP8LoadNewBytes(VP8BitReader* const br) {
bits = BSwap32(in_bits);
bits >>= (32 - BITS);
#elif (BITS == 16)
// gcc will recognize a 'rorw $8, ...' here:
bits = (bit_t)(in_bits >> 8) | ((in_bits & 0xff) << 8);
bits = BSwap16(in_bits);
#else // BITS == 8
bits = (bit_t)in_bits;
#endif // BITS > 32

View File

@ -61,6 +61,15 @@
#define HAVE_BUILTIN_BSWAP
#endif
static WEBP_INLINE uint16_t BSwap16(uint16_t x) {
#if defined(_MSC_VER)
return _byteswap_ushort(x);
#else
// gcc will recognize a 'rorw $8, ...' here:
return (x >> 8) | ((x & 0xff) << 8);
#endif // _MSC_VER
}
static WEBP_INLINE uint32_t BSwap32(uint32_t x) {
#if defined(HAVE_BUILTIN_BSWAP)
return __builtin_bswap32(x);