diff --git a/include/boost/core/bit.hpp b/include/boost/core/bit.hpp index a6147e4..67f7c98 100644 --- a/include/boost/core/bit.hpp +++ b/include/boost/core/bit.hpp @@ -47,12 +47,19 @@ # if __has_builtin(__builtin_bit_cast) # define BOOST_CORE_HAS_BUILTIN_BIT_CAST # endif +# if __has_builtin(__builtin_bswap16) +# define BOOST_CORE_HAS_BUILTIN_BSWAP16 +# endif #endif #if defined(BOOST_MSVC) && BOOST_MSVC >= 1926 # define BOOST_CORE_HAS_BUILTIN_BIT_CAST #endif +#if !defined(BOOST_CORE_HAS_BUILTIN_BSWAP16) && (defined(BOOST_GCC_VERSION) && BOOST_GCC_VERSION >= 40800) +# define BOOST_CORE_HAS_BUILTIN_BSWAP16 +#endif + namespace boost { namespace core @@ -825,11 +832,22 @@ BOOST_CONSTEXPR inline boost::uint8_t byteswap_impl( boost::uint8_t x ) BOOST_NO return x; } +#if defined(BOOST_CORE_HAS_BUILTIN_BSWAP16) + +BOOST_CONSTEXPR inline boost::uint16_t byteswap_impl( boost::uint16_t x ) BOOST_NOEXCEPT +{ + return __builtin_bswap16( x ); +} + +#else + BOOST_CONSTEXPR inline boost::uint16_t byteswap_impl( boost::uint16_t x ) BOOST_NOEXCEPT { return static_cast( x << 8 | x >> 8 ); } +#endif + #if defined(__GNUC__) || defined(__clang__) BOOST_CXX14_CONSTEXPR inline boost::uint32_t byteswap_impl( boost::uint32_t x ) BOOST_NOEXCEPT