1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 * 6 * Copyright (c) 2009 Helge Bahmann 7 * Copyright (c) 2014-2018, 2020 Andrey Semashev 8 */ 9 /*! 10 * \file atomic/detail/platform.hpp 11 * 12 * This header defines macros for the target platform detection 13 */ 14 15 #ifndef BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_ 16 #define BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_ 17 18 #include <boost/atomic/detail/config.hpp> 19 20 #ifdef BOOST_HAS_PRAGMA_ONCE 21 #pragma once 22 #endif 23 24 #if defined(__GNUC__) && defined(__arm__) 25 26 // Newer gcc versions define __ARM_ARCH. Older ones don't, so we have to deduce ARM arch version from a bunch of version-specific macros. 27 #if defined(__ARM_ARCH) 28 #define BOOST_ATOMIC_DETAIL_ARM_ARCH __ARM_ARCH 29 #elif defined(__ARM_ARCH_8A__) 30 #define BOOST_ATOMIC_DETAIL_ARM_ARCH 8 31 #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) ||\ 32 defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) ||\ 33 defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7S__) 34 #define BOOST_ATOMIC_DETAIL_ARM_ARCH 7 35 #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) ||\ 36 defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) ||\ 37 defined(__ARM_ARCH_6ZK__) 38 #define BOOST_ATOMIC_DETAIL_ARM_ARCH 6 39 #else 40 // We are not interested in older versions - they don't support atomic ops 41 #define BOOST_ATOMIC_DETAIL_ARM_ARCH 0 42 #endif 43 44 #endif // defined(__GNUC__) && defined(__arm__) 45 46 #if !defined(BOOST_ATOMIC_FORCE_FALLBACK) 47 48 // Determine the target platform. 49 // The target platform describes the compiler and target architecture. It can be used by more generic backends, such as the ones 50 // based on compiler intrinsics, to implement specialized operations in a non-generic way. 51 52 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) 53 54 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_x86 55 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_x86 56 57 #elif defined(__GNUC__) && defined(__aarch64__) 58 59 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_aarch64 60 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_aarch64 61 62 #elif defined(__GNUC__) && defined(__arm__) && (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 6) 63 64 #if (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 8) 65 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_aarch32 66 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_aarch32 67 #else 68 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_arm 69 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_arm 70 #endif 71 72 #elif defined(__GNUC__) && (defined(__POWERPC__) || defined(__PPC__)) 73 74 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_ppc 75 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_ppc 76 77 #elif (defined(__GNUC__) || defined(__SUNPRO_CC)) && (defined(__sparcv8plus) || defined(__sparc_v9__)) 78 79 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_sparc 80 81 #elif defined(__GNUC__) && defined(__alpha__) 82 83 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_alpha 84 85 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) 86 87 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_x86 88 89 #elif defined(_MSC_VER) && _MSC_VER >= 1700 && (defined(_M_ARM) || defined(_M_ARM64)) 90 91 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_arm 92 93 #endif 94 95 // Compiler-based backends 96 97 // IBM XL C++ Compiler has to be checked before GCC/Clang as it pretends to be one but does not support __atomic* intrinsics. 98 // It does support GCC inline assembler though. 99 #if !(defined(__ibmxl__) || defined(__IBMCPP__)) &&\ 100 ((defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 407)) ||\ 101 (defined(BOOST_CLANG) && ((__clang_major__ * 100 + __clang_minor__) >= 302))) &&\ 102 (\ 103 (__GCC_ATOMIC_BOOL_LOCK_FREE + 0) == 2 ||\ 104 (__GCC_ATOMIC_CHAR_LOCK_FREE + 0) == 2 ||\ 105 (__GCC_ATOMIC_SHORT_LOCK_FREE + 0) == 2 ||\ 106 (__GCC_ATOMIC_INT_LOCK_FREE + 0) == 2 ||\ 107 (__GCC_ATOMIC_LONG_LOCK_FREE + 0) == 2 ||\ 108 (__GCC_ATOMIC_LLONG_LOCK_FREE + 0) == 2\ 109 ) 110 111 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_atomic 112 113 // GCC __sync* instrinsics backend is less efficient than asm-based backends, so use it only when nothing better is available. 114 #elif !defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND) &&\ 115 defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 401) &&\ 116 (\ 117 defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) ||\ 118 defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) ||\ 119 defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) ||\ 120 defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) ||\ 121 defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16)\ 122 ) 123 124 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_sync 125 126 #endif 127 128 // OS-based backends 129 130 #if !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND) && !defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND) 131 132 #if defined(__linux__) && defined(__arm__) 133 134 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND linux_arm 135 136 #elif defined(BOOST_WINDOWS) || defined(_WIN32_CE) 137 138 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND windows 139 140 #endif 141 142 #endif // !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND) 143 144 // Waiting and notifying operations backends 145 #if defined(BOOST_WINDOWS) 146 147 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND windows 148 149 #else // defined(BOOST_WINDOWS) 150 151 #include <boost/atomic/detail/futex.hpp> 152 153 #if defined(BOOST_ATOMIC_DETAIL_HAS_FUTEX) 154 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND futex 155 #elif defined(__FreeBSD__) 156 #include <sys/param.h> 157 // FreeBSD prior to 7.0 had _umtx_op with a different signature 158 #if defined(__FreeBSD_version) && __FreeBSD_version >= 700000 159 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND freebsd_umtx 160 #endif // defined(__FreeBSD_version) && __FreeBSD_version >= 700000 161 #elif defined(__DragonFly__) 162 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND dragonfly_umtx 163 #endif 164 165 #endif // defined(BOOST_WINDOWS) 166 167 #endif // !defined(BOOST_ATOMIC_FORCE_FALLBACK) 168 169 #if !defined(BOOST_ATOMIC_DETAIL_FP_BACKEND) 170 #define BOOST_ATOMIC_DETAIL_FP_BACKEND generic 171 #define BOOST_ATOMIC_DETAIL_FP_BACKEND_GENERIC 172 #endif 173 174 #if !defined(BOOST_ATOMIC_DETAIL_EXTRA_BACKEND) 175 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND generic 176 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_GENERIC 177 #endif 178 179 #if !defined(BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND) 180 #define BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND generic 181 #define BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND_GENERIC 182 #endif 183 184 #if !defined(BOOST_ATOMIC_DETAIL_WAIT_BACKEND) 185 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND generic 186 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND_GENERIC 187 #endif 188 189 #if defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND) 190 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND).hpp> 191 #endif 192 #if defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND) 193 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_CORE_BACKEND).hpp> 194 #endif 195 #define BOOST_ATOMIC_DETAIL_FP_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_FP_BACKEND).hpp> 196 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_EXTRA_BACKEND).hpp> 197 #define BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND).hpp> 198 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_WAIT_BACKEND).hpp> 199 200 #endif // BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_ 201