#include <cstddef>
#include <boost/cstdint.hpp>
#include <boost/atomic/detail/config.hpp>
-#if !defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_MEMCMP) || !defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_MEMCPY)
-#include <cstring>
-#endif
+#include <boost/atomic/detail/string_ops.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
#pragma once
BOOST_ATOMIC_DETAIL_MEMCPY(to.data, const_cast< unsigned char const* >(from.data), Size);
}
-template< std::size_t Size, bool Signed >
+template< std::size_t Size >
struct make_storage_type
{
typedef buffer_storage< Size > type;
};
template< >
-struct make_storage_type< 1u, false >
+struct make_storage_type< 1u >
{
typedef boost::uint8_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
};
template< >
-struct make_storage_type< 1u, true >
-{
- typedef boost::int8_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
-
- struct BOOST_ATOMIC_DETAIL_MAY_ALIAS aligned
- {
- type value;
-
- BOOST_DEFAULTED_FUNCTION(aligned(), {})
- BOOST_FORCEINLINE BOOST_CONSTEXPR explicit aligned(type v) BOOST_NOEXCEPT : value(v) {}
- };
-};
-
-template< >
-struct make_storage_type< 2u, false >
+struct make_storage_type< 2u >
{
typedef boost::uint16_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
};
template< >
-struct make_storage_type< 2u, true >
-{
- typedef boost::int16_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
-
- struct BOOST_ATOMIC_DETAIL_MAY_ALIAS aligned
- {
- BOOST_ALIGNMENT(2) type value;
-
- BOOST_DEFAULTED_FUNCTION(aligned(), {})
- BOOST_FORCEINLINE BOOST_CONSTEXPR explicit aligned(type v) BOOST_NOEXCEPT : value(v) {}
- };
-};
-
-template< >
-struct make_storage_type< 4u, false >
+struct make_storage_type< 4u >
{
typedef boost::uint32_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
};
template< >
-struct make_storage_type< 4u, true >
-{
- typedef boost::int32_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
-
- struct BOOST_ATOMIC_DETAIL_MAY_ALIAS aligned
- {
- BOOST_ALIGNMENT(4) type value;
-
- BOOST_DEFAULTED_FUNCTION(aligned(), {})
- BOOST_FORCEINLINE BOOST_CONSTEXPR explicit aligned(type v) BOOST_NOEXCEPT : value(v) {}
- };
-};
-
-template< >
-struct make_storage_type< 8u, false >
+struct make_storage_type< 8u >
{
typedef boost::uint64_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
};
};
-template< >
-struct make_storage_type< 8u, true >
-{
- typedef boost::int64_t BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
-
- struct BOOST_ATOMIC_DETAIL_MAY_ALIAS aligned
- {
- BOOST_ALIGNMENT(8) type value;
-
- BOOST_DEFAULTED_FUNCTION(aligned(), {})
- BOOST_FORCEINLINE BOOST_CONSTEXPR explicit aligned(type v) BOOST_NOEXCEPT : value(v) {}
- };
-};
-
#if defined(BOOST_HAS_INT128)
template< >
-struct make_storage_type< 16u, false >
+struct make_storage_type< 16u >
{
typedef boost::uint128_type BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
};
};
-template< >
-struct make_storage_type< 16u, true >
-{
- typedef boost::int128_type BOOST_ATOMIC_DETAIL_MAY_ALIAS type;
-
- struct BOOST_ATOMIC_DETAIL_MAY_ALIAS aligned
- {
- BOOST_ALIGNMENT(16) type value;
-
- BOOST_DEFAULTED_FUNCTION(aligned(), {})
- BOOST_FORCEINLINE BOOST_CONSTEXPR explicit aligned(type v) BOOST_NOEXCEPT : value(v) {}
- };
-};
-
#elif !defined(BOOST_NO_ALIGNMENT)
struct BOOST_ATOMIC_DETAIL_MAY_ALIAS storage128_t
BOOST_FORCEINLINE bool operator! () const BOOST_NOEXCEPT
{
- return data[0] == 0 && data[1] == 0;
+ return (data[0] | data[1]) == 0u;
}
};
BOOST_FORCEINLINE bool operator== (storage128_t const& left, storage128_t const& right) BOOST_NOEXCEPT
{
- return left.data[0] == right.data[0] && left.data[1] == right.data[1];
+ return ((left.data[0] ^ right.data[0]) | (left.data[1] ^ right.data[1])) == 0u;
}
BOOST_FORCEINLINE bool operator!= (storage128_t const& left, storage128_t const& right) BOOST_NOEXCEPT
{
to.data[1] = from.data[1];
}
-template< bool Signed >
-struct make_storage_type< 16u, Signed >
+template< >
+struct make_storage_type< 16u >
{
typedef storage128_t type;
template< typename T >
struct storage_size_of
{
- enum _
- {
- size = sizeof(T),
- value = (size == 3 ? 4 : (size >= 5 && size <= 7 ? 8 : (size >= 9 && size <= 15 ? 16 : size)))
- };
+ static BOOST_CONSTEXPR_OR_CONST std::size_t size = sizeof(T);
+ static BOOST_CONSTEXPR_OR_CONST std::size_t value = (size == 3u ? 4u : (size >= 5u && size <= 7u ? 8u : (size >= 9u && size <= 15u ? 16u : size)));
};
} // namespace detail