forked from boostorg/endian
Make endian_reverse constexpr when possible
This commit is contained in:
@ -16,6 +16,20 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#if defined(BOOST_ENDIAN_NO_INTRINSICS)
|
||||||
|
# if defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||||
|
# define BOOST_ENDIAN_CONSTEXPR
|
||||||
|
# else
|
||||||
|
# define BOOST_ENDIAN_CONSTEXPR constexpr
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# if defined(BOOST_ENDIAN_CONSTEXPR_INTRINSICS)
|
||||||
|
# define BOOST_ENDIAN_CONSTEXPR BOOST_CONSTEXPR
|
||||||
|
# else
|
||||||
|
# define BOOST_ENDIAN_CONSTEXPR
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
namespace endian
|
namespace endian
|
||||||
@ -30,12 +44,12 @@ namespace detail
|
|||||||
// -- intrinsic approach suggested by reviewers, and by David Stone, who provided
|
// -- intrinsic approach suggested by reviewers, and by David Stone, who provided
|
||||||
// his Boost licensed macro implementation (detail/intrinsic.hpp)
|
// his Boost licensed macro implementation (detail/intrinsic.hpp)
|
||||||
|
|
||||||
inline uint8_t endian_reverse_impl( uint8_t x ) BOOST_NOEXCEPT
|
inline uint8_t BOOST_CONSTEXPR endian_reverse_impl( uint8_t x ) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT
|
inline uint16_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||||
|
|
||||||
@ -48,7 +62,7 @@ inline uint16_t endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT
|
inline uint32_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||||
|
|
||||||
@ -62,7 +76,7 @@ inline uint32_t endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t endian_reverse_impl(uint64_t x) BOOST_NOEXCEPT
|
inline uint64_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl(uint64_t x) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
#ifdef BOOST_ENDIAN_NO_INTRINSICS
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
|
#define __has_builtin(x) 0 // Compatibility with non-clang compilers
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER) && ( !defined(__clang__) || defined(__c2__) )
|
||||||
// Microsoft documents these as being compatible since Windows 95 and specifically
|
// Microsoft documents these as being compatible since Windows 95 and specifically
|
||||||
// lists runtime library support since Visual Studio 2003 (aka 7.1).
|
// lists runtime library support since Visual Studio 2003 (aka 7.1).
|
||||||
// Clang/c2 uses the Microsoft rather than GCC intrinsics, so we check for
|
// Clang/c2 uses the Microsoft rather than GCC intrinsics, so we check for
|
||||||
@ -46,6 +46,8 @@
|
|||||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) __builtin_bswap32(x)
|
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x) __builtin_bswap32(x)
|
||||||
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) __builtin_bswap64(x)
|
# define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x) __builtin_bswap64(x)
|
||||||
|
|
||||||
|
# define BOOST_ENDIAN_CONSTEXPR_INTRINSICS
|
||||||
|
|
||||||
// Linux systems provide the byteswap.h header, with
|
// Linux systems provide the byteswap.h header, with
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
// don't check for obsolete forms defined(linux) and defined(__linux) on the theory that
|
// don't check for obsolete forms defined(linux) and defined(__linux) on the theory that
|
||||||
|
Reference in New Issue
Block a user