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)
6 * Copyright (c) 2009 Helge Bahmann
7 * Copyright (c) 2014-2018, 2020 Andrey Semashev
10 * \file atomic/detail/platform.hpp
12 * This header defines macros for the target platform detection
15 #ifndef BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_
16 #define BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_
18 #include <boost/atomic/detail/config.hpp>
20 #ifdef BOOST_HAS_PRAGMA_ONCE
24 #if defined(__GNUC__) && defined(__arm__)
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
40 // We are not interested in older versions - they don't support atomic ops
41 #define BOOST_ATOMIC_DETAIL_ARM_ARCH 0
44 #endif // defined(__GNUC__) && defined(__arm__)
46 #if !defined(BOOST_ATOMIC_FORCE_FALLBACK)
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.
52 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
54 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_x86
55 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_x86
57 #elif defined(__GNUC__) && defined(__aarch64__)
59 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_aarch64
60 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_aarch64
62 #elif defined(__GNUC__) && defined(__arm__) && (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 6)
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
68 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_arm
69 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_arm
72 #elif defined(__GNUC__) && (defined(__POWERPC__) || defined(__PPC__))
74 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_ppc
75 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_ppc
77 #elif (defined(__GNUC__) || defined(__SUNPRO_CC)) && (defined(__sparcv8plus) || defined(__sparc_v9__))
79 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_sparc
81 #elif defined(__GNUC__) && defined(__alpha__)
83 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_alpha
85 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
87 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_x86
89 #elif defined(_MSC_VER) && _MSC_VER >= 1700 && (defined(_M_ARM) || defined(_M_ARM64))
91 #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_arm
95 // Compiler-based backends
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))) &&\
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\
111 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_atomic
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) &&\
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)\
124 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_sync
130 #if !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND) && !defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND)
132 #if defined(__linux__) && defined(__arm__)
134 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND linux_arm
136 #elif defined(BOOST_WINDOWS) || defined(_WIN32_CE)
138 #define BOOST_ATOMIC_DETAIL_CORE_BACKEND windows
142 #endif // !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND)
144 // Waiting and notifying operations backends
145 #if defined(BOOST_WINDOWS)
147 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND windows
149 #else // defined(BOOST_WINDOWS)
151 #include <boost/atomic/detail/futex.hpp>
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
165 #endif // defined(BOOST_WINDOWS)
167 #endif // !defined(BOOST_ATOMIC_FORCE_FALLBACK)
169 #if !defined(BOOST_ATOMIC_DETAIL_FP_BACKEND)
170 #define BOOST_ATOMIC_DETAIL_FP_BACKEND generic
171 #define BOOST_ATOMIC_DETAIL_FP_BACKEND_GENERIC
174 #if !defined(BOOST_ATOMIC_DETAIL_EXTRA_BACKEND)
175 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND generic
176 #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_GENERIC
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
184 #if !defined(BOOST_ATOMIC_DETAIL_WAIT_BACKEND)
185 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND generic
186 #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND_GENERIC
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>
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>
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>
200 #endif // BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_