]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
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 | |
20effc67 | 7 | * Copyright (c) 2014-2018, 2020 Andrey Semashev |
b32b8144 FG |
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 | ||
20effc67 | 54 | #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_x86 |
b32b8144 FG |
55 | #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_x86 |
56 | ||
20effc67 | 57 | #elif defined(__GNUC__) && defined(__aarch64__) |
b32b8144 | 58 | |
20effc67 TL |
59 | #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_aarch64 |
60 | #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_aarch64 | |
b32b8144 | 61 | |
20effc67 | 62 | #elif defined(__GNUC__) && defined(__arm__) && (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 6) |
b32b8144 | 63 | |
20effc67 TL |
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 | |
b32b8144 | 69 | #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_arm |
20effc67 TL |
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 | |
b32b8144 FG |
76 | |
77 | #elif (defined(__GNUC__) || defined(__SUNPRO_CC)) && (defined(__sparcv8plus) || defined(__sparc_v9__)) | |
78 | ||
20effc67 | 79 | #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_sparc |
b32b8144 FG |
80 | |
81 | #elif defined(__GNUC__) && defined(__alpha__) | |
82 | ||
20effc67 | 83 | #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_alpha |
b32b8144 FG |
84 | |
85 | #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) | |
86 | ||
20effc67 | 87 | #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_x86 |
b32b8144 FG |
88 | |
89 | #elif defined(_MSC_VER) && _MSC_VER >= 1700 && (defined(_M_ARM) || defined(_M_ARM64)) | |
90 | ||
20effc67 | 91 | #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_arm |
b32b8144 FG |
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 | ||
20effc67 | 111 | #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_atomic |
b32b8144 | 112 | |
20effc67 TL |
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) &&\ | |
b32b8144 FG |
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 | ||
20effc67 | 124 | #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_sync |
b32b8144 FG |
125 | |
126 | #endif | |
127 | ||
128 | // OS-based backends | |
129 | ||
20effc67 | 130 | #if !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND) && !defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND) |
b32b8144 FG |
131 | |
132 | #if defined(__linux__) && defined(__arm__) | |
133 | ||
20effc67 | 134 | #define BOOST_ATOMIC_DETAIL_CORE_BACKEND linux_arm |
b32b8144 FG |
135 | |
136 | #elif defined(BOOST_WINDOWS) || defined(_WIN32_CE) | |
137 | ||
20effc67 | 138 | #define BOOST_ATOMIC_DETAIL_CORE_BACKEND windows |
b32b8144 FG |
139 | |
140 | #endif | |
141 | ||
20effc67 | 142 | #endif // !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND) |
b32b8144 | 143 | |
20effc67 TL |
144 | // Waiting and notifying operations backends |
145 | #if defined(BOOST_WINDOWS) | |
b32b8144 | 146 | |
20effc67 TL |
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 | |
b32b8144 FG |
163 | #endif |
164 | ||
20effc67 TL |
165 | #endif // defined(BOOST_WINDOWS) |
166 | ||
167 | #endif // !defined(BOOST_ATOMIC_FORCE_FALLBACK) | |
168 | ||
11fdf7f2 TL |
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 | ||
b32b8144 FG |
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 | ||
11fdf7f2 TL |
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 | ||
20effc67 TL |
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 | |
11fdf7f2 | 195 | #define BOOST_ATOMIC_DETAIL_FP_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_FP_BACKEND).hpp> |
b32b8144 | 196 | #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_EXTRA_BACKEND).hpp> |
11fdf7f2 | 197 | #define BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND).hpp> |
20effc67 | 198 | #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_WAIT_BACKEND).hpp> |
b32b8144 FG |
199 | |
200 | #endif // BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_ |