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_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
27 
28 #ifdef _WIN32
29 #undef KMP_OS_WINDOWS
30 #define KMP_OS_WINDOWS 1
31 #endif
32 
33 #if (defined __APPLE__ && defined __MACH__)
34 #undef KMP_OS_DARWIN
35 #define KMP_OS_DARWIN 1
36 #endif
37 
38 // in some ppc64 linux installations, only the second condition is met
39 #if (defined __linux)
40 #undef KMP_OS_LINUX
41 #define KMP_OS_LINUX 1
42 #elif (defined __linux__)
43 #undef KMP_OS_LINUX
44 #define KMP_OS_LINUX 1
45 #else
46 #endif
47 
48 #if (defined __DragonFly__)
49 #undef KMP_OS_DRAGONFLY
50 #define KMP_OS_DRAGONFLY 1
51 #endif
52 
53 #if (defined __FreeBSD__)
54 #undef KMP_OS_FREEBSD
55 #define KMP_OS_FREEBSD 1
56 #endif
57 
58 #if (defined __NetBSD__)
59 #undef KMP_OS_NETBSD
60 #define KMP_OS_NETBSD 1
61 #endif
62 
63 #if (defined __OpenBSD__)
64 #undef KMP_OS_OPENBSD
65 #define KMP_OS_OPENBSD 1
66 #endif
67 
68 #if (defined __GNU__)
69 #undef KMP_OS_HURD
70 #define KMP_OS_HURD 1
71 #endif
72 
73 #if (1 !=                                                                      \
74      KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD +        \
75          KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD)
76 #error Unknown OS
77 #endif
78 
79 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD ||     \
80         KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD
81 #undef KMP_OS_UNIX
82 #define KMP_OS_UNIX 1
83 #endif
84 
85 /* ---------------------- Architecture recognition ------------------- */
86 
87 #define KMP_ARCH_X86 0
88 #define KMP_ARCH_X86_64 0
89 #define KMP_ARCH_AARCH64 0
90 #define KMP_ARCH_PPC64_ELFv1 0
91 #define KMP_ARCH_PPC64_ELFv2 0
92 #define KMP_ARCH_PPC64 (KMP_ARCH_PPC64_ELFv2 || KMP_ARCH_PPC64_ELFv1)
93 #define KMP_ARCH_MIPS 0
94 #define KMP_ARCH_MIPS64 0
95 #define KMP_ARCH_RISCV64 0
96 
97 #if KMP_OS_WINDOWS
98 #if defined(_M_AMD64) || defined(__x86_64)
99 #undef KMP_ARCH_X86_64
100 #define KMP_ARCH_X86_64 1
101 #else
102 #undef KMP_ARCH_X86
103 #define KMP_ARCH_X86 1
104 #endif
105 #endif
106 
107 #if KMP_OS_UNIX
108 #if defined __x86_64
109 #undef KMP_ARCH_X86_64
110 #define KMP_ARCH_X86_64 1
111 #elif defined __i386
112 #undef KMP_ARCH_X86
113 #define KMP_ARCH_X86 1
114 #elif defined __powerpc64__
115 #if defined(_CALL_ELF) && _CALL_ELF == 2
116 #undef KMP_ARCH_PPC64_ELFv2
117 #define KMP_ARCH_PPC64_ELFv2 1
118 #else
119 #undef KMP_ARCH_PPC64_ELFv1
120 #define KMP_ARCH_PPC64_ELFv1 1
121 #endif
122 #elif defined __aarch64__
123 #undef KMP_ARCH_AARCH64
124 #define KMP_ARCH_AARCH64 1
125 #elif defined __mips__
126 #if defined __mips64
127 #undef KMP_ARCH_MIPS64
128 #define KMP_ARCH_MIPS64 1
129 #else
130 #undef KMP_ARCH_MIPS
131 #define KMP_ARCH_MIPS 1
132 #endif
133 #elif defined __riscv && __riscv_xlen == 64
134 #undef KMP_ARCH_RISCV64
135 #define KMP_ARCH_RISCV64 1
136 #endif
137 #endif
138 
139 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) ||                     \
140     defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7VE__)
141 #define KMP_ARCH_ARMV7 1
142 #endif
143 
144 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) ||                      \
145     defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) ||                    \
146     defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) ||                   \
147     defined(__ARM_ARCH_6ZK__)
148 #define KMP_ARCH_ARMV6 1
149 #endif
150 
151 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) ||                     \
152     defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) ||                   \
153     defined(__ARM_ARCH_5TEJ__)
154 #define KMP_ARCH_ARMV5 1
155 #endif
156 
157 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) ||                      \
158     defined(__ARM_ARCH_4T__)
159 #define KMP_ARCH_ARMV4 1
160 #endif
161 
162 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) ||                      \
163     defined(__ARM_ARCH_3M__)
164 #define KMP_ARCH_ARMV3 1
165 #endif
166 
167 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
168 #define KMP_ARCH_ARMV2 1
169 #endif
170 
171 #if defined(KMP_ARCH_ARMV2)
172 #define KMP_ARCH_ARM 1
173 #endif
174 
175 #if defined(__MIC__) || defined(__MIC2__)
176 #define KMP_MIC 1
177 #if __MIC2__ || __KNC__
178 #define KMP_MIC1 0
179 #define KMP_MIC2 1
180 #else
181 #define KMP_MIC1 1
182 #define KMP_MIC2 0
183 #endif
184 #else
185 #define KMP_MIC 0
186 #define KMP_MIC1 0
187 #define KMP_MIC2 0
188 #endif
189 
190 /* Specify 32 bit architectures here */
191 #define KMP_32_BIT_ARCH (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS)
192 
193 // Platforms which support Intel(R) Many Integrated Core Architecture
194 #define KMP_MIC_SUPPORTED                                                      \
195   ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
196 
197 // TODO: Fixme - This is clever, but really fugly
198 #if (1 !=                                                                      \
199      KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 +          \
200      KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + KMP_ARCH_RISCV64)
201 #error Unknown or unsupported architecture
202 #endif
203 
204 #endif // KMP_PLATFORM_H
205