Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/atomic/detail/bitwise_fp_cast.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * Copyright (c) 2018, 2021 Andrey Semashev
0007  */
0008 /*!
0009  * \file   atomic/detail/bitwise_fp_cast.hpp
0010  *
0011  * This header defines \c bitwise_fp_cast used to convert between storage and floating point value types
0012  */
0013 
0014 #ifndef BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_
0016 
0017 #include <cstddef>
0018 #include <boost/atomic/detail/config.hpp>
0019 #include <boost/atomic/detail/float_sizes.hpp>
0020 #include <boost/atomic/detail/bitwise_cast.hpp>
0021 #if defined(BOOST_ATOMIC_DETAIL_BIT_CAST)
0022 #include <boost/atomic/detail/type_traits/integral_constant.hpp>
0023 #endif
0024 #include <boost/atomic/detail/header.hpp>
0025 
0026 #ifdef BOOST_HAS_PRAGMA_ONCE
0027 #pragma once
0028 #endif
0029 
0030 namespace boost {
0031 namespace atomics {
0032 namespace detail {
0033 
0034 /*!
0035  * \brief The type trait returns the size of the value of the specified floating point type
0036  *
0037  * This size may be less than <tt>sizeof(T)</tt> if the implementation uses padding bytes for a particular FP type. This is
0038  * often the case with 80-bit extended double, which is stored in 12 or 16 initial bytes with tail padding filled with garbage.
0039  */
0040 template< typename T >
0041 struct value_size_of
0042 {
0043     static BOOST_CONSTEXPR_OR_CONST std::size_t value = sizeof(T);
0044 };
0045 
0046 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE)
0047 template< >
0048 struct value_size_of< float >
0049 {
0050     static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE;
0051 };
0052 #endif
0053 
0054 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE)
0055 template< >
0056 struct value_size_of< double >
0057 {
0058     static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE;
0059 };
0060 #endif
0061 
0062 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE)
0063 template< >
0064 struct value_size_of< long double >
0065 {
0066     static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE;
0067 };
0068 #endif
0069 
0070 template< typename T >
0071 struct value_size_of< const T > : value_size_of< T > {};
0072 
0073 template< typename T >
0074 struct value_size_of< volatile T > : value_size_of< T > {};
0075 
0076 template< typename T >
0077 struct value_size_of< const volatile T > : value_size_of< T > {};
0078 
0079 
0080 #if !defined(BOOST_ATOMIC_NO_CLEAR_PADDING)
0081 // BOOST_ATOMIC_DETAIL_CLEAR_PADDING, which is used in bitwise_cast, will clear the tail padding bits in the source object.
0082 // We don't need to specify the actual value size to avoid redundant zeroing of the tail padding.
0083 #define BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_VALUE_SIZE_OF(x) sizeof(x)
0084 #else
0085 #define BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_VALUE_SIZE_OF(x) atomics::detail::value_size_of< x >::value
0086 #endif
0087 
0088 #if defined(BOOST_ATOMIC_DETAIL_BIT_CAST)
0089 
0090 //! Similar to bitwise_cast, but either \c From or \c To is expected to be a floating point type. Attempts to detect the actual value size in the source object and considers the rest of the object as padding.
0091 template< typename To, typename From >
0092 BOOST_FORCEINLINE BOOST_ATOMIC_DETAIL_CONSTEXPR_BITWISE_CAST To bitwise_fp_cast(From const& from) BOOST_NOEXCEPT
0093 {
0094     // For floating point types, has_unique_object_representations is typically false even if the type contains no padding bits.
0095     // Here, we rely on our detection of the actual value size to select constexpr bit_cast implementation when possible. We assume
0096     // here that floating point value bits are contiguous.
0097     return atomics::detail::bitwise_cast_impl< To, BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_VALUE_SIZE_OF(From) >(from, atomics::detail::integral_constant< bool,
0098         atomics::detail::value_size_of< From >::value == sizeof(From) && atomics::detail::value_size_of< From >::value == sizeof(To) >());
0099 }
0100 
0101 #else // defined(BOOST_ATOMIC_DETAIL_BIT_CAST)
0102 
0103 //! Similar to bitwise_cast, but either \c From or \c To is expected to be a floating point type. Attempts to detect the actual value size in the source object and considers the rest of the object as padding.
0104 template< typename To, typename From >
0105 BOOST_FORCEINLINE BOOST_ATOMIC_DETAIL_CONSTEXPR_BITWISE_CAST To bitwise_fp_cast(From const& from) BOOST_NOEXCEPT
0106 {
0107     return atomics::detail::bitwise_cast< To, BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_VALUE_SIZE_OF(From) >(from);
0108 }
0109 
0110 #endif // defined(BOOST_ATOMIC_DETAIL_BIT_CAST)
0111 
0112 } // namespace detail
0113 } // namespace atomics
0114 } // namespace boost
0115 
0116 #include <boost/atomic/detail/footer.hpp>
0117 
0118 #endif // BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_