2 * kmp_platform.h -- header for determining operating system and architecture
5 //===----------------------------------------------------------------------===//
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
11 //===----------------------------------------------------------------------===//
13 #ifndef KMP_PLATFORM_H
14 #define KMP_PLATFORM_H
16 /* ---------------------- Operating system recognition ------------------- */
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
26 #define KMP_OS_SOLARIS 0
28 #define KMP_OS_EMSCRIPTEN 0
29 #define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
33 #define KMP_OS_WINDOWS 1
36 #if (defined __APPLE__ && defined __MACH__)
38 #define KMP_OS_DARWIN 1
41 // in some ppc64 linux installations, only the second condition is met
44 #define KMP_OS_LINUX 1
45 #elif (defined __linux__)
47 #define KMP_OS_LINUX 1
48 #elif defined(__EMSCRIPTEN__)
50 #undef KMP_OS_EMSCRIPTEN
51 #define KMP_OS_LINUX 1
52 #define KMP_OS_EMSCRIPTEN 1
56 #if (defined __DragonFly__)
57 #undef KMP_OS_DRAGONFLY
58 #define KMP_OS_DRAGONFLY 1
61 #if (defined __FreeBSD__)
63 #define KMP_OS_FREEBSD 1
66 #if (defined __NetBSD__)
68 #define KMP_OS_NETBSD 1
71 #if (defined __OpenBSD__)
73 #define KMP_OS_OPENBSD 1
81 #if (defined __sun__ && defined __svr4__)
83 #define KMP_OS_SOLARIS 1
86 #if (defined __wasi__)
96 #if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \
97 KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD + \
98 KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX)
102 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
103 KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS || \
104 KMP_OS_WASI || KMP_OS_AIX
106 #define KMP_OS_UNIX 1
109 /* ---------------------- Architecture recognition ------------------- */
111 #define KMP_ARCH_X86 0
112 #define KMP_ARCH_X86_64 0
113 #define KMP_ARCH_AARCH64 0
114 #define KMP_ARCH_AARCH64_32 0
115 #define KMP_ARCH_PPC64_ELFv1 0
116 #define KMP_ARCH_PPC64_ELFv2 0
117 #define KMP_ARCH_PPC64_XCOFF 0
118 #define KMP_ARCH_PPC_XCOFF 0
119 #define KMP_ARCH_MIPS 0
120 #define KMP_ARCH_MIPS64 0
121 #define KMP_ARCH_RISCV64 0
122 #define KMP_ARCH_LOONGARCH64 0
123 #define KMP_ARCH_VE 0
124 #define KMP_ARCH_S390X 0
127 #if defined(_M_AMD64) || defined(__x86_64)
128 #undef KMP_ARCH_X86_64
129 #define KMP_ARCH_X86_64 1
130 #elif defined(__aarch64__) || defined(_M_ARM64)
131 #undef KMP_ARCH_AARCH64
132 #define KMP_ARCH_AARCH64 1
133 #elif defined(__arm__) || defined(_M_ARM)
134 #undef KMP_ARCH_ARMV7
135 #define KMP_ARCH_ARMV7 1
138 #define KMP_ARCH_X86 1
144 #undef KMP_ARCH_X86_64
145 #define KMP_ARCH_X86_64 1
148 #define KMP_ARCH_X86 1
149 #elif defined __powerpc64__
150 #if defined(_CALL_ELF)
152 #undef KMP_ARCH_PPC64_ELFv2
153 #define KMP_ARCH_PPC64_ELFv2 1
155 #undef KMP_ARCH_PPC64_ELFv1
156 #define KMP_ARCH_PPC64_ELFv1 1
158 #elif defined KMP_OS_AIX
159 #undef KMP_ARCH_PPC64_XCOFF
160 #define KMP_ARCH_PPC64_XCOFF 1
162 #elif defined(__powerpc__) && defined(KMP_OS_AIX)
163 #undef KMP_ARCH_PPC_XCOFF
164 #define KMP_ARCH_PPC_XCOFF 1
166 #define KMP_ARCH_PPC 1
167 #elif defined __ARM64_ARCH_8_32__
168 #undef KMP_ARCH_AARCH64_32
169 #define KMP_ARCH_AARCH64_32 1
170 #elif defined __aarch64__
171 #undef KMP_ARCH_AARCH64
172 #define KMP_ARCH_AARCH64 1
173 #elif defined __mips__
175 #undef KMP_ARCH_MIPS64
176 #define KMP_ARCH_MIPS64 1
179 #define KMP_ARCH_MIPS 1
181 #elif defined __riscv && __riscv_xlen == 64
182 #undef KMP_ARCH_RISCV64
183 #define KMP_ARCH_RISCV64 1
184 #elif defined __loongarch__ && __loongarch_grlen == 64
185 #undef KMP_ARCH_LOONGARCH64
186 #define KMP_ARCH_LOONGARCH64 1
189 #define KMP_ARCH_VE 1
190 #elif defined __s390x__
191 #undef KMP_ARCH_S390X
192 #define KMP_ARCH_S390X 1
196 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || \
197 defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7VE__)
198 #define KMP_ARCH_ARMV7 1
201 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) || \
202 defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \
203 defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || \
204 defined(__ARM_ARCH_6ZK__)
205 #define KMP_ARCH_ARMV6 1
208 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) || \
209 defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
210 defined(__ARM_ARCH_5TEJ__)
211 #define KMP_ARCH_ARMV5 1
214 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) || \
215 defined(__ARM_ARCH_4T__)
216 #define KMP_ARCH_ARMV4 1
219 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) || \
220 defined(__ARM_ARCH_3M__)
221 #define KMP_ARCH_ARMV3 1
224 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
225 #define KMP_ARCH_ARMV2 1
228 #if defined(KMP_ARCH_ARMV2)
229 #define KMP_ARCH_ARM 1
232 #if defined(__wasm32__)
233 #define KMP_ARCH_WASM 1
236 #define KMP_ARCH_PPC64 \
237 (KMP_ARCH_PPC64_ELFv2 || KMP_ARCH_PPC64_ELFv1 || KMP_ARCH_PPC64_XCOFF)
239 #if defined(__MIC__) || defined(__MIC2__)
241 #if __MIC2__ || __KNC__
254 /* Specify 32 bit architectures here */
255 #define KMP_32_BIT_ARCH \
256 (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM || \
257 KMP_ARCH_PPC || KMP_ARCH_AARCH64_32)
259 // Platforms which support Intel(R) Many Integrated Core Architecture
260 #define KMP_MIC_SUPPORTED \
261 ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
263 // TODO: Fixme - This is clever, but really fugly
264 #if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
265 KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \
266 KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE + \
267 KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC + \
269 #error Unknown or unsupported architecture
272 #endif // KMP_PLATFORM_H