xref: /freebsd/contrib/llvm-project/openmp/runtime/src/kmp_platform.h (revision a0ca4af9455b844c5e094fc1b09b1390ffa979fc)
1 /*
2  * kmp_platform.h -- header for determining operating system and architecture
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef KMP_PLATFORM_H
14 #define KMP_PLATFORM_H
15 
16 /* ---------------------- Operating system recognition ------------------- */
17 
18 #define KMP_OS_LINUX 0
19 #define KMP_OS_DRAGONFLY 0
20 #define KMP_OS_FREEBSD 0
21 #define KMP_OS_NETBSD 0
22 #define KMP_OS_OPENBSD 0
23 #define KMP_OS_DARWIN 0
24 #define KMP_OS_WINDOWS 0
25 #define KMP_OS_HURD 0
26 #define KMP_OS_SOLARIS 0
27 #define KMP_OS_WASI 0
28 #define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
29 
30 #ifdef _WIN32
31 #undef KMP_OS_WINDOWS
32 #define KMP_OS_WINDOWS 1
33 #endif
34 
35 #if (defined __APPLE__ && defined __MACH__)
36 #undef KMP_OS_DARWIN
37 #define KMP_OS_DARWIN 1
38 #endif
39 
40 // in some ppc64 linux installations, only the second condition is met
41 #if (defined __linux)
42 #undef KMP_OS_LINUX
43 #define KMP_OS_LINUX 1
44 #elif (defined __linux__)
45 #undef KMP_OS_LINUX
46 #define KMP_OS_LINUX 1
47 #else
48 #endif
49 
50 #if (defined __DragonFly__)
51 #undef KMP_OS_DRAGONFLY
52 #define KMP_OS_DRAGONFLY 1
53 #endif
54 
55 #if (defined __FreeBSD__)
56 #undef KMP_OS_FREEBSD
57 #define KMP_OS_FREEBSD 1
58 #endif
59 
60 #if (defined __NetBSD__)
61 #undef KMP_OS_NETBSD
62 #define KMP_OS_NETBSD 1
63 #endif
64 
65 #if (defined __OpenBSD__)
66 #undef KMP_OS_OPENBSD
67 #define KMP_OS_OPENBSD 1
68 #endif
69 
70 #if (defined __GNU__)
71 #undef KMP_OS_HURD
72 #define KMP_OS_HURD 1
73 #endif
74 
75 #if (defined __sun__ && defined __svr4__)
76 #undef KMP_OS_SOLARIS
77 #define KMP_OS_SOLARIS 1
78 #endif
79 
80 #if (defined __wasi__) || (defined __EMSCRIPTEN__)
81 #undef KMP_OS_WASI
82 #define KMP_OS_WASI 1
83 #endif
84 
85 #if (defined _AIX)
86 #undef KMP_OS_AIX
87 #define KMP_OS_AIX 1
88 #endif
89 
90 #if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD +   \
91               KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD +  \
92               KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX)
93 #error Unknown OS
94 #endif
95 
96 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD ||     \
97     KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS ||        \
98     KMP_OS_WASI || KMP_OS_AIX
99 #undef KMP_OS_UNIX
100 #define KMP_OS_UNIX 1
101 #endif
102 
103 /* ---------------------- Architecture recognition ------------------- */
104 
105 #define KMP_ARCH_X86 0
106 #define KMP_ARCH_X86_64 0
107 #define KMP_ARCH_AARCH64 0
108 #define KMP_ARCH_PPC64_ELFv1 0
109 #define KMP_ARCH_PPC64_ELFv2 0
110 #define KMP_ARCH_PPC64_XCOFF 0
111 #define KMP_ARCH_PPC_XCOFF 0
112 #define KMP_ARCH_MIPS 0
113 #define KMP_ARCH_MIPS64 0
114 #define KMP_ARCH_RISCV64 0
115 #define KMP_ARCH_LOONGARCH64 0
116 #define KMP_ARCH_VE 0
117 #define KMP_ARCH_S390X 0
118 
119 #if KMP_OS_WINDOWS
120 #if defined(_M_AMD64) || defined(__x86_64)
121 #undef KMP_ARCH_X86_64
122 #define KMP_ARCH_X86_64 1
123 #elif defined(__aarch64__) || defined(_M_ARM64)
124 #undef KMP_ARCH_AARCH64
125 #define KMP_ARCH_AARCH64 1
126 #elif defined(__arm__) || defined(_M_ARM)
127 #undef KMP_ARCH_ARMV7
128 #define KMP_ARCH_ARMV7 1
129 #else
130 #undef KMP_ARCH_X86
131 #define KMP_ARCH_X86 1
132 #endif
133 #endif
134 
135 #if KMP_OS_UNIX
136 #if defined __x86_64
137 #undef KMP_ARCH_X86_64
138 #define KMP_ARCH_X86_64 1
139 #elif defined __i386
140 #undef KMP_ARCH_X86
141 #define KMP_ARCH_X86 1
142 #elif defined __powerpc64__
143 #if defined(_CALL_ELF)
144 #if _CALL_ELF == 2
145 #undef KMP_ARCH_PPC64_ELFv2
146 #define KMP_ARCH_PPC64_ELFv2 1
147 #else
148 #undef KMP_ARCH_PPC64_ELFv1
149 #define KMP_ARCH_PPC64_ELFv1 1
150 #endif
151 #elif defined KMP_OS_AIX
152 #undef KMP_ARCH_PPC64_XCOFF
153 #define KMP_ARCH_PPC64_XCOFF 1
154 #endif
155 #elif defined(__powerpc__) && defined(KMP_OS_AIX)
156 #undef KMP_ARCH_PPC_XCOFF
157 #define KMP_ARCH_PPC_XCOFF 1
158 #undef KMP_ARCH_PPC
159 #define KMP_ARCH_PPC 1
160 #elif defined __aarch64__
161 #undef KMP_ARCH_AARCH64
162 #define KMP_ARCH_AARCH64 1
163 #elif defined __mips__
164 #if defined __mips64
165 #undef KMP_ARCH_MIPS64
166 #define KMP_ARCH_MIPS64 1
167 #else
168 #undef KMP_ARCH_MIPS
169 #define KMP_ARCH_MIPS 1
170 #endif
171 #elif defined __riscv && __riscv_xlen == 64
172 #undef KMP_ARCH_RISCV64
173 #define KMP_ARCH_RISCV64 1
174 #elif defined __loongarch__ && __loongarch_grlen == 64
175 #undef KMP_ARCH_LOONGARCH64
176 #define KMP_ARCH_LOONGARCH64 1
177 #elif defined __ve__
178 #undef KMP_ARCH_VE
179 #define KMP_ARCH_VE 1
180 #elif defined __s390x__
181 #undef KMP_ARCH_S390X
182 #define KMP_ARCH_S390X 1
183 #endif
184 #endif
185 
186 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) ||                     \
187     defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7VE__)
188 #define KMP_ARCH_ARMV7 1
189 #endif
190 
191 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) ||                      \
192     defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) ||                    \
193     defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) ||                   \
194     defined(__ARM_ARCH_6ZK__)
195 #define KMP_ARCH_ARMV6 1
196 #endif
197 
198 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) ||                     \
199     defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) ||                   \
200     defined(__ARM_ARCH_5TEJ__)
201 #define KMP_ARCH_ARMV5 1
202 #endif
203 
204 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) ||                      \
205     defined(__ARM_ARCH_4T__)
206 #define KMP_ARCH_ARMV4 1
207 #endif
208 
209 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) ||                      \
210     defined(__ARM_ARCH_3M__)
211 #define KMP_ARCH_ARMV3 1
212 #endif
213 
214 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
215 #define KMP_ARCH_ARMV2 1
216 #endif
217 
218 #if defined(KMP_ARCH_ARMV2)
219 #define KMP_ARCH_ARM 1
220 #endif
221 
222 #if defined(__wasm32__)
223 #define KMP_ARCH_WASM 1
224 #endif
225 
226 #define KMP_ARCH_PPC64                                                         \
227   (KMP_ARCH_PPC64_ELFv2 || KMP_ARCH_PPC64_ELFv1 || KMP_ARCH_PPC64_XCOFF)
228 
229 #if defined(__MIC__) || defined(__MIC2__)
230 #define KMP_MIC 1
231 #if __MIC2__ || __KNC__
232 #define KMP_MIC1 0
233 #define KMP_MIC2 1
234 #else
235 #define KMP_MIC1 1
236 #define KMP_MIC2 0
237 #endif
238 #else
239 #define KMP_MIC 0
240 #define KMP_MIC1 0
241 #define KMP_MIC2 0
242 #endif
243 
244 /* Specify 32 bit architectures here */
245 #define KMP_32_BIT_ARCH                                                        \
246   (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM ||           \
247    KMP_ARCH_PPC)
248 
249 // Platforms which support Intel(R) Many Integrated Core Architecture
250 #define KMP_MIC_SUPPORTED                                                      \
251   ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
252 
253 // TODO: Fixme - This is clever, but really fugly
254 #if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 +     \
255               KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 +             \
256               KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE +          \
257               KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC)
258 #error Unknown or unsupported architecture
259 #endif
260 
261 #endif // KMP_PLATFORM_H
262