Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:57

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-2023 Andrey Semashev
0007  */
0008 /*!
0009  * \file   atomic/detail/float_sizes.hpp
0010  *
0011  * This header defines macros for testing buitin floating point type sizes
0012  */
0013 
0014 #ifndef BOOST_ATOMIC_DETAIL_FLOAT_SIZES_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_FLOAT_SIZES_HPP_INCLUDED_
0016 
0017 #include <boost/atomic/detail/config.hpp>
0018 
0019 #ifdef BOOST_HAS_PRAGMA_ONCE
0020 #pragma once
0021 #endif
0022 
0023 // Detect value sizes of the different floating point types. The value sizes may be less than the corresponding type sizes
0024 // if the type contains padding bits. This is typical e.g. with x87 80-bit extended double types, which are often represented as 96 or 128-bit types.
0025 // See: https://en.wikipedia.org/wiki/IEEE_754
0026 // For Intel x87 extended double see: https://en.wikipedia.org/wiki/Extended_precision#x86_Architecture_Extended_Precision_Format
0027 // For IBM extended double (a.k.a. double-double) see: https://en.wikipedia.org/wiki/Long_double#Implementations, https://gcc.gnu.org/wiki/Ieee128PowerPC
0028 
0029 #if defined(__FLT_RADIX__) && defined(__FLT_MANT_DIG__) && defined(__FLT_MAX_EXP__) && \
0030     defined(__DBL_MANT_DIG__) && defined(__DBL_MAX_EXP__) && defined(__LDBL_MANT_DIG__) && defined(__LDBL_MAX_EXP__)
0031 
0032 #if (__FLT_RADIX__ == 2)
0033 
0034 #if (__FLT_MANT_DIG__ == 11) && (__FLT_MAX_EXP__ == 16) // IEEE 754 binary16
0035 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 2
0036 #elif (__FLT_MANT_DIG__ == 24) && (__FLT_MAX_EXP__ == 128) // IEEE 754 binary32
0037 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 4
0038 #elif (__FLT_MANT_DIG__ == 53) && (__FLT_MAX_EXP__ == 1024) // IEEE 754 binary64
0039 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 8
0040 #elif (__FLT_MANT_DIG__ == 64 || __FLT_MANT_DIG__ == 53 || __FLT_MANT_DIG__ == 24) && (__FLT_MAX_EXP__ == 16384) // x87 extended double, with full 64-bit significand or reduced to 53 or 24 bits
0041 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 10
0042 #elif (__FLT_MANT_DIG__ == 106) && (__FLT_MAX_EXP__ == 1024) // IBM extended double
0043 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 16
0044 #elif (__FLT_MANT_DIG__ == 113) && (__FLT_MAX_EXP__ == 16384) // IEEE 754 binary128
0045 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 16
0046 #elif (__FLT_MANT_DIG__ == 237) && (__FLT_MAX_EXP__ == 262144) // IEEE 754 binary256
0047 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 32
0048 #endif
0049 
0050 #if (__DBL_MANT_DIG__ == 11) && (__DBL_MAX_EXP__ == 16) // IEEE 754 binary16
0051 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 2
0052 #elif (__DBL_MANT_DIG__ == 24) && (__DBL_MAX_EXP__ == 128) // IEEE 754 binary32
0053 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 4
0054 #elif (__DBL_MANT_DIG__ == 53) && (__DBL_MAX_EXP__ == 1024) // IEEE 754 binary64
0055 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 8
0056 #elif (__DBL_MANT_DIG__ == 64 || __DBL_MANT_DIG__ == 53 || __DBL_MANT_DIG__ == 24) && (__DBL_MAX_EXP__ == 16384) // x87 extended double, with full 64-bit significand or reduced to 53 or 24 bits
0057 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 10
0058 #elif (__DBL_MANT_DIG__ == 106) && (__DBL_MAX_EXP__ == 1024) // IBM extended double
0059 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 16
0060 #elif (__DBL_MANT_DIG__ == 113) && (__DBL_MAX_EXP__ == 16384) // IEEE 754 binary128
0061 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 16
0062 #elif (__DBL_MANT_DIG__ == 237) && (__DBL_MAX_EXP__ == 262144) // IEEE 754 binary256
0063 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 32
0064 #endif
0065 
0066 #if (__LDBL_MANT_DIG__ == 11) && (__LDBL_MAX_EXP__ == 16) // IEEE 754 binary16
0067 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 2
0068 #elif (__LDBL_MANT_DIG__ == 24) && (__LDBL_MAX_EXP__ == 128) // IEEE 754 binary32
0069 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 4
0070 #elif (__LDBL_MANT_DIG__ == 53) && (__LDBL_MAX_EXP__ == 1024) // IEEE 754 binary64
0071 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 8
0072 #elif (__LDBL_MANT_DIG__ == 64 || __LDBL_MANT_DIG__ == 53 || __LDBL_MANT_DIG__ == 24) && (__LDBL_MAX_EXP__ == 16384) // x87 extended double, with full 64-bit significand or reduced to 53 or 24 bits
0073 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 10
0074 #elif (__LDBL_MANT_DIG__ == 106) && (__LDBL_MAX_EXP__ == 1024) // IBM extended double
0075 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 16
0076 #elif (__LDBL_MANT_DIG__ == 113) && (__LDBL_MAX_EXP__ == 16384) // IEEE 754 binary128
0077 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 16
0078 #elif (__LDBL_MANT_DIG__ == 237) && (__LDBL_MAX_EXP__ == 262144) // IEEE 754 binary256
0079 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 32
0080 #endif
0081 
0082 #elif (__FLT_RADIX__ == 10)
0083 
0084 #if (__FLT_MANT_DIG__ == 7) && (__FLT_MAX_EXP__ == 97) // IEEE 754 decimal32
0085 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 4
0086 #elif (__FLT_MANT_DIG__ == 16) && (__FLT_MAX_EXP__ == 385) // IEEE 754 decimal64
0087 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 8
0088 #elif (__FLT_MANT_DIG__ == 34) && (__FLT_MAX_EXP__ == 6145) // IEEE 754 decimal128
0089 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 16
0090 #endif
0091 
0092 #if (__DBL_MANT_DIG__ == 7) && (__DBL_MAX_EXP__ == 97) // IEEE 754 decimal32
0093 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 4
0094 #elif (__DBL_MANT_DIG__ == 16) && (__DBL_MAX_EXP__ == 385) // IEEE 754 decimal64
0095 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 8
0096 #elif (__DBL_MANT_DIG__ == 34) && (__DBL_MAX_EXP__ == 6145) // IEEE 754 decimal128
0097 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 16
0098 #endif
0099 
0100 #if (__LDBL_MANT_DIG__ == 7) && (__LDBL_MAX_EXP__ == 97) // IEEE 754 decimal32
0101 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 4
0102 #elif (__LDBL_MANT_DIG__ == 16) && (__LDBL_MAX_EXP__ == 385) // IEEE 754 decimal64
0103 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 8
0104 #elif (__LDBL_MANT_DIG__ == 34) && (__LDBL_MAX_EXP__ == 6145) // IEEE 754 decimal128
0105 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 16
0106 #endif
0107 
0108 #endif
0109 
0110 #else // defined(__FLT_RADIX__) ...
0111 
0112 #include <cfloat>
0113 
0114 #if (FLT_RADIX == 2)
0115 
0116 #if (FLT_MANT_DIG == 11) && (FLT_MAX_EXP == 16) // IEEE 754 binary16
0117 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 2
0118 #elif (FLT_MANT_DIG == 24) && (FLT_MAX_EXP == 128) // IEEE 754 binary32
0119 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 4
0120 #elif (FLT_MANT_DIG == 53) && (FLT_MAX_EXP == 1024) // IEEE 754 binary64
0121 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 8
0122 #elif (FLT_MANT_DIG == 64 || FLT_MANT_DIG == 53 || FLT_MANT_DIG == 24) && (FLT_MAX_EXP == 16384) // x87 extended double, with full 64-bit significand or reduced to 53 or 24 bits
0123 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 10
0124 #elif (FLT_MANT_DIG == 106) && (FLT_MAX_EXP == 1024) // IBM extended double
0125 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 16
0126 #elif (FLT_MANT_DIG == 113) && (FLT_MAX_EXP == 16384) // IEEE 754 binary128
0127 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 16
0128 #elif (FLT_MANT_DIG == 237) && (FLT_MAX_EXP == 262144) // IEEE 754 binary256
0129 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 32
0130 #endif
0131 
0132 #if (DBL_MANT_DIG == 11) && (DBL_MAX_EXP == 16) // IEEE 754 binary16
0133 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 2
0134 #elif (DBL_MANT_DIG == 24) && (DBL_MAX_EXP == 128) // IEEE 754 binary32
0135 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 4
0136 #elif (DBL_MANT_DIG == 53) && (DBL_MAX_EXP == 1024) // IEEE 754 binary64
0137 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 8
0138 #elif (DBL_MANT_DIG == 64 || DBL_MANT_DIG == 53 || DBL_MANT_DIG == 24) && (DBL_MAX_EXP == 16384) // x87 extended double, with full 64-bit significand or reduced to 53 or 24 bits
0139 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 10
0140 #elif (DBL_MANT_DIG == 106) && (DBL_MAX_EXP == 1024) // IBM extended double
0141 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 16
0142 #elif (DBL_MANT_DIG == 113) && (DBL_MAX_EXP == 16384) // IEEE 754 binary128
0143 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 16
0144 #elif (DBL_MANT_DIG == 237) && (DBL_MAX_EXP == 262144) // IEEE 754 binary256
0145 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 32
0146 #endif
0147 
0148 #if (LDBL_MANT_DIG == 11) && (LDBL_MAX_EXP == 16) // IEEE 754 binary16
0149 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 2
0150 #elif (LDBL_MANT_DIG == 24) && (LDBL_MAX_EXP == 128) // IEEE 754 binary32
0151 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 4
0152 #elif (LDBL_MANT_DIG == 53) && (LDBL_MAX_EXP == 1024) // IEEE 754 binary64
0153 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 8
0154 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 53 || LDBL_MANT_DIG == 24) && (LDBL_MAX_EXP == 16384) // x87 extended double, with full 64-bit significand or reduced to 53 or 24 bits
0155 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 10
0156 #elif (LDBL_MANT_DIG == 106) && (LDBL_MAX_EXP == 1024) // IBM extended double
0157 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 16
0158 #elif (LDBL_MANT_DIG == 113) && (LDBL_MAX_EXP == 16384) // IEEE 754 binary128
0159 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 16
0160 #elif (LDBL_MANT_DIG == 237) && (LDBL_MAX_EXP == 262144) // IEEE 754 binary256
0161 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 32
0162 #endif
0163 
0164 #elif (FLT_RADIX == 10)
0165 
0166 #if (FLT_MANT_DIG == 7) && (FLT_MAX_EXP == 97) // IEEE 754 decimal32
0167 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 4
0168 #elif (FLT_MANT_DIG == 16) && (FLT_MAX_EXP == 385) // IEEE 754 decimal64
0169 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 8
0170 #elif (FLT_MANT_DIG == 34) && (FLT_MAX_EXP == 6145) // IEEE 754 decimal128
0171 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE 16
0172 #endif
0173 
0174 #if (DBL_MANT_DIG == 7) && (DBL_MAX_EXP == 97) // IEEE 754 decimal32
0175 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 4
0176 #elif (DBL_MANT_DIG == 16) && (DBL_MAX_EXP == 385) // IEEE 754 decimal64
0177 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 8
0178 #elif (DBL_MANT_DIG == 34) && (DBL_MAX_EXP == 6145) // IEEE 754 decimal128
0179 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE 16
0180 #endif
0181 
0182 #if (LDBL_MANT_DIG == 7) && (LDBL_MAX_EXP == 97) // IEEE 754 decimal32
0183 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 4
0184 #elif (LDBL_MANT_DIG == 16) && (LDBL_MAX_EXP == 385) // IEEE 754 decimal64
0185 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 8
0186 #elif (LDBL_MANT_DIG == 34) && (LDBL_MAX_EXP == 6145) // IEEE 754 decimal128
0187 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE 16
0188 #endif
0189 
0190 #endif
0191 
0192 #endif // defined(__FLT_RADIX__) ...
0193 
0194 // GCC and compatible compilers define internal macros with builtin type traits
0195 #if defined(__SIZEOF_FLOAT__)
0196 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT __SIZEOF_FLOAT__
0197 #endif
0198 #if defined(__SIZEOF_DOUBLE__)
0199 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE __SIZEOF_DOUBLE__
0200 #endif
0201 #if defined(__SIZEOF_LONG_DOUBLE__)
0202 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE __SIZEOF_LONG_DOUBLE__
0203 #endif
0204 
0205 #if !defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT) || !defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE) || !defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE)
0206 
0207 #define BOOST_ATOMIC_DETAIL_ALIGN_SIZE_TO_POWER_OF_2(x)\
0208     ((x) == 1u ? 1u : ((x) == 2u ? 2u : ((x) <= 4u ? 4u : ((x) <= 8u ? 8u : ((x) <= 16u ? 16u : ((x) <= 32u ? 32u : (x)))))))
0209 
0210 // Make our best guess. These sizes may not be accurate, but they are good enough to estimate the size of the storage required to hold these types.
0211 #if !defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT) && defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE)
0212 #define BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT BOOST_ATOMIC_DETAIL_ALIGN_SIZE_TO_POWER_OF_2(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE)
0213 #endif
0214 #if !defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE) && defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE)
0215 #define BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE BOOST_ATOMIC_DETAIL_ALIGN_SIZE_TO_POWER_OF_2(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE)
0216 #endif
0217 #if !defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE) && defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE)
0218 #define BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE BOOST_ATOMIC_DETAIL_ALIGN_SIZE_TO_POWER_OF_2(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE)
0219 #endif
0220 
0221 #endif // !defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT) || !defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE) || !defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE)
0222 
0223 #if !defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE) || !defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT) ||\
0224     !defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE) || !defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE) ||\
0225     !defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE) || !defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE)
0226 #error Boost.Atomic: Failed to determine builtin floating point type sizes, the target platform is not supported. Please, report to the developers (patches are welcome).
0227 #endif
0228 
0229 #endif // BOOST_ATOMIC_DETAIL_FLOAT_SIZES_HPP_INCLUDED_