diff --git a/src/compat/byteswap.h b/src/compat/byteswap.h index fe47f4899..818bbda0c 100644 --- a/src/compat/byteswap.h +++ b/src/compat/byteswap.h @@ -30,26 +30,40 @@ #endif // !defined(bswap_16) #else + +#include + // Non-Mac OS X / non-Darwin #if HAVE_DECL_BSWAP_16 == 0 inline uint16_t bswap_16(uint16_t x) { +#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2 + return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x); +#else return (x >> 8) | (x << 8); +#endif } #endif // HAVE_DECL_BSWAP16 == 0 #if HAVE_DECL_BSWAP_32 == 0 inline uint32_t bswap_32(uint32_t x) { +#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4 + return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x); +#else return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) | ((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24)); +#endif } #endif // HAVE_DECL_BSWAP32 == 0 #if HAVE_DECL_BSWAP_64 == 0 inline uint64_t bswap_64(uint64_t x) { +#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8 + return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x); +#else return (((x & 0xff00000000000000ull) >> 56) | ((x & 0x00ff000000000000ull) >> 40) | ((x & 0x0000ff0000000000ull) >> 24) @@ -58,6 +72,7 @@ inline uint64_t bswap_64(uint64_t x) | ((x & 0x0000000000ff0000ull) << 24) | ((x & 0x000000000000ff00ull) << 40) | ((x & 0x00000000000000ffull) << 56)); +#endif } #endif // HAVE_DECL_BSWAP64 == 0