Back to home page

EIC code displayed by LXR

 
 

    


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

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) 2014, 2020 Andrey Semashev
0007  */
0008 /*!
0009  * \file   atomic/detail/caps_gcc_atomic.hpp
0010  *
0011  * This header defines feature capabilities macros
0012  */
0013 
0014 #ifndef BOOST_ATOMIC_DETAIL_CAPS_GCC_ATOMIC_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_CAPS_GCC_ATOMIC_HPP_INCLUDED_
0016 
0017 #include <boost/atomic/detail/config.hpp>
0018 #include <boost/atomic/detail/int_sizes.hpp>
0019 
0020 #if defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND_HEADER)
0021 #include BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND_HEADER(boost/atomic/detail/caps_arch_)
0022 #endif
0023 
0024 #ifdef BOOST_HAS_PRAGMA_ONCE
0025 #pragma once
0026 #endif
0027 
0028 // Translate type-based lock-free macros to size-based ones
0029 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT8_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
0030 
0031 #if BOOST_ATOMIC_DETAIL_SIZEOF_SHORT == 2
0032 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
0033 #elif BOOST_ATOMIC_DETAIL_SIZEOF_INT == 2
0034 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
0035 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LONG == 2
0036 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
0037 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LLONG == 2
0038 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
0039 #else
0040 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE 0
0041 #endif
0042 
0043 #if BOOST_ATOMIC_DETAIL_SIZEOF_SHORT == 4
0044 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
0045 #elif BOOST_ATOMIC_DETAIL_SIZEOF_INT == 4
0046 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
0047 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LONG == 4
0048 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
0049 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LLONG == 4
0050 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
0051 #else
0052 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE 0
0053 #endif
0054 
0055 #if BOOST_ATOMIC_DETAIL_SIZEOF_SHORT == 8
0056 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
0057 #elif BOOST_ATOMIC_DETAIL_SIZEOF_INT == 8
0058 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
0059 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LONG == 8
0060 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
0061 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LLONG == 8
0062 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
0063 #else
0064 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE 0
0065 #endif
0066 
0067 #if BOOST_ATOMIC_DETAIL_SIZEOF_SHORT == 16
0068 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
0069 #elif BOOST_ATOMIC_DETAIL_SIZEOF_INT == 16
0070 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
0071 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LONG == 16
0072 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
0073 #elif BOOST_ATOMIC_DETAIL_SIZEOF_LLONG == 16
0074 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
0075 #else
0076 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE 0
0077 #endif
0078 
0079 // On x86-64, clang 3.4 does not implement 128-bit __atomic* intrinsics even though it defines __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16:
0080 // https://bugs.llvm.org/show_bug.cgi?id=19149
0081 // Another problem exists with gcc 7 and later, as it requires to link with libatomic to use 16-byte intrinsics:
0082 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80878
0083 // Both clang and gcc do generate cmpxchg16b for __sync_val_compare_and_swap though.
0084 #if defined(BOOST_ATOMIC_DETAIL_X86_HAS_CMPXCHG16B) &&\
0085     (\
0086         (defined(BOOST_CLANG) && (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 5))) ||\
0087         (defined(BOOST_GCC) && BOOST_GCC >= 70000)\
0088     )
0089 #undef BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE
0090 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE 0
0091 #endif
0092 
0093 // On 32-bit x86, there is a clang bug for 64-bit atomics: https://bugs.llvm.org/show_bug.cgi?id=19355. The compiler defines
0094 // __GCC_ATOMIC_LLONG_LOCK_FREE to 1 when the target architecture supports 64-bit atomic instructions (i.e. the value should be 2).
0095 // Additionally, any clang version requires to link with libatomic for 64-bit __atomic* intrinsics on x86. It does generate
0096 // cmpxchg8b for __sync_val_compare_and_swap though.
0097 #if defined(BOOST_ATOMIC_DETAIL_X86_HAS_CMPXCHG8B) && defined(BOOST_CLANG)
0098 #undef BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE
0099 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE 0
0100 #endif
0101 
0102 // Override arch-specific macros if atomic intrinsics provide better guarantees
0103 #if !defined(BOOST_ATOMIC_INT128_LOCK_FREE) || (BOOST_ATOMIC_INT128_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE)
0104 #undef BOOST_ATOMIC_INT128_LOCK_FREE
0105 #define BOOST_ATOMIC_INT128_LOCK_FREE BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT128_LOCK_FREE
0106 #endif
0107 
0108 #if !defined(BOOST_ATOMIC_INT64_LOCK_FREE) || (BOOST_ATOMIC_INT64_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE) || (BOOST_ATOMIC_INT64_LOCK_FREE < BOOST_ATOMIC_INT128_LOCK_FREE)
0109 #undef BOOST_ATOMIC_INT64_LOCK_FREE
0110 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE >= BOOST_ATOMIC_INT128_LOCK_FREE
0111 #define BOOST_ATOMIC_INT64_LOCK_FREE BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT64_LOCK_FREE
0112 #else
0113 #define BOOST_ATOMIC_INT64_LOCK_FREE BOOST_ATOMIC_INT128_LOCK_FREE
0114 #endif
0115 #endif
0116 
0117 #if !defined(BOOST_ATOMIC_INT32_LOCK_FREE) || (BOOST_ATOMIC_INT32_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE) || (BOOST_ATOMIC_INT32_LOCK_FREE < BOOST_ATOMIC_INT64_LOCK_FREE)
0118 #undef BOOST_ATOMIC_INT32_LOCK_FREE
0119 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE >= BOOST_ATOMIC_INT64_LOCK_FREE
0120 #define BOOST_ATOMIC_INT32_LOCK_FREE BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT32_LOCK_FREE
0121 #else
0122 #define BOOST_ATOMIC_INT32_LOCK_FREE BOOST_ATOMIC_INT64_LOCK_FREE
0123 #endif
0124 #endif
0125 
0126 #if !defined(BOOST_ATOMIC_INT16_LOCK_FREE) || (BOOST_ATOMIC_INT16_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE) || (BOOST_ATOMIC_INT16_LOCK_FREE < BOOST_ATOMIC_INT32_LOCK_FREE)
0127 #undef BOOST_ATOMIC_INT16_LOCK_FREE
0128 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE >= BOOST_ATOMIC_INT32_LOCK_FREE
0129 #define BOOST_ATOMIC_INT16_LOCK_FREE BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT16_LOCK_FREE
0130 #else
0131 #define BOOST_ATOMIC_INT16_LOCK_FREE BOOST_ATOMIC_INT32_LOCK_FREE
0132 #endif
0133 #endif
0134 
0135 #if !defined(BOOST_ATOMIC_INT8_LOCK_FREE) || (BOOST_ATOMIC_INT8_LOCK_FREE < BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT8_LOCK_FREE) || (BOOST_ATOMIC_INT8_LOCK_FREE < BOOST_ATOMIC_INT16_LOCK_FREE)
0136 #undef BOOST_ATOMIC_INT8_LOCK_FREE
0137 #if BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT8_LOCK_FREE >= BOOST_ATOMIC_INT16_LOCK_FREE
0138 #define BOOST_ATOMIC_INT8_LOCK_FREE BOOST_ATOMIC_DETAIL_GCC_ATOMIC_INT8_LOCK_FREE
0139 #else
0140 #define BOOST_ATOMIC_INT8_LOCK_FREE BOOST_ATOMIC_INT16_LOCK_FREE
0141 #endif
0142 #endif
0143 
0144 #if !defined(BOOST_ATOMIC_POINTER_LOCK_FREE) || (BOOST_ATOMIC_POINTER_LOCK_FREE < __GCC_ATOMIC_POINTER_LOCK_FREE)
0145 #undef BOOST_ATOMIC_POINTER_LOCK_FREE
0146 #define BOOST_ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
0147 #endif
0148 
0149 #if !defined(BOOST_ATOMIC_THREAD_FENCE) || (BOOST_ATOMIC_THREAD_FENCE < 2)
0150 #undef BOOST_ATOMIC_THREAD_FENCE
0151 #define BOOST_ATOMIC_THREAD_FENCE 2
0152 #endif
0153 #if !defined(BOOST_ATOMIC_SIGNAL_FENCE) || (BOOST_ATOMIC_SIGNAL_FENCE < 2)
0154 #undef BOOST_ATOMIC_SIGNAL_FENCE
0155 #define BOOST_ATOMIC_SIGNAL_FENCE 2
0156 #endif
0157 
0158 #endif // BOOST_ATOMIC_DETAIL_CAPS_GCC_ATOMIC_HPP_INCLUDED_