LLVM OpenMP* Runtime Library
kmp_platform.h
1 /*
2  * kmp_platform.h -- header for determining operating system and architecture
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 // The LLVM Compiler Infrastructure
8 //
9 // This file is dual licensed under the MIT and the University of Illinois Open
10 // Source Licenses. See LICENSE.txt for details.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef KMP_PLATFORM_H
15 #define KMP_PLATFORM_H
16 
17 /* ---------------------- Operating system recognition ------------------- */
18 
19 #define KMP_OS_LINUX 0
20 #define KMP_OS_DRAGONFLY 0
21 #define KMP_OS_FREEBSD 0
22 #define KMP_OS_NETBSD 0
23 #define KMP_OS_OPENBSD 0
24 #define KMP_OS_DARWIN 0
25 #define KMP_OS_WINDOWS 0
26 #define KMP_OS_CNK 0
27 #define KMP_OS_HURD 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 __bgq__)
71 #undef KMP_OS_CNK
72 #define KMP_OS_CNK 1
73 #endif
74 
75 #if (defined __GNU__)
76 #undef KMP_OS_HURD
77 #define KMP_OS_HURD 1
78 #endif
79 
80 #if (1 != \
81  KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \
82  KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD)
83 #error Unknown OS
84 #endif
85 
86 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
87  KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD
88 #undef KMP_OS_UNIX
89 #define KMP_OS_UNIX 1
90 #endif
91 
92 /* ---------------------- Architecture recognition ------------------- */
93 
94 #define KMP_ARCH_X86 0
95 #define KMP_ARCH_X86_64 0
96 #define KMP_ARCH_AARCH64 0
97 #define KMP_ARCH_PPC64_BE 0
98 #define KMP_ARCH_PPC64_LE 0
99 #define KMP_ARCH_PPC64 (KMP_ARCH_PPC64_LE || KMP_ARCH_PPC64_BE)
100 #define KMP_ARCH_MIPS 0
101 #define KMP_ARCH_MIPS64 0
102 #define KMP_ARCH_LOONGARCH64 0
103 
104 #if KMP_OS_WINDOWS
105 #if defined(_M_AMD64) || defined(__x86_64)
106 #undef KMP_ARCH_X86_64
107 #define KMP_ARCH_X86_64 1
108 #else
109 #undef KMP_ARCH_X86
110 #define KMP_ARCH_X86 1
111 #endif
112 #endif
113 
114 #if KMP_OS_UNIX
115 #if defined __x86_64
116 #undef KMP_ARCH_X86_64
117 #define KMP_ARCH_X86_64 1
118 #elif defined __i386
119 #undef KMP_ARCH_X86
120 #define KMP_ARCH_X86 1
121 #elif defined __powerpc64__
122 #if defined __LITTLE_ENDIAN__
123 #undef KMP_ARCH_PPC64_LE
124 #define KMP_ARCH_PPC64_LE 1
125 #else
126 #undef KMP_ARCH_PPC64_BE
127 #define KMP_ARCH_PPC64_BE 1
128 #endif
129 #elif defined __aarch64__
130 #undef KMP_ARCH_AARCH64
131 #define KMP_ARCH_AARCH64 1
132 #elif defined __mips__
133 #if defined __mips64
134 #undef KMP_ARCH_MIPS64
135 #define KMP_ARCH_MIPS64 1
136 #else
137 #undef KMP_ARCH_MIPS
138 #define KMP_ARCH_MIPS 1
139 #endif
140 #elif defined __loongarch__ && defined __loongarch64
141 #undef KMP_ARCH_LOONGARCH64
142 #define KMP_ARCH_LOONGARCH64 1
143 #endif
144 #endif
145 
146 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || \
147  defined(__ARM_ARCH_7A__)
148 #define KMP_ARCH_ARMV7 1
149 #endif
150 
151 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) || \
152  defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \
153  defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || \
154  defined(__ARM_ARCH_6ZK__)
155 #define KMP_ARCH_ARMV6 1
156 #endif
157 
158 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) || \
159  defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
160  defined(__ARM_ARCH_5TEJ__)
161 #define KMP_ARCH_ARMV5 1
162 #endif
163 
164 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) || \
165  defined(__ARM_ARCH_4T__)
166 #define KMP_ARCH_ARMV4 1
167 #endif
168 
169 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) || \
170  defined(__ARM_ARCH_3M__)
171 #define KMP_ARCH_ARMV3 1
172 #endif
173 
174 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
175 #define KMP_ARCH_ARMV2 1
176 #endif
177 
178 #if defined(KMP_ARCH_ARMV2)
179 #define KMP_ARCH_ARM 1
180 #endif
181 
182 #if defined(__MIC__) || defined(__MIC2__)
183 #define KMP_MIC 1
184 #if __MIC2__ || __KNC__
185 #define KMP_MIC1 0
186 #define KMP_MIC2 1
187 #else
188 #define KMP_MIC1 1
189 #define KMP_MIC2 0
190 #endif
191 #else
192 #define KMP_MIC 0
193 #define KMP_MIC1 0
194 #define KMP_MIC2 0
195 #endif
196 
197 /* Specify 32 bit architectures here */
198 #define KMP_32_BIT_ARCH (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS)
199 
200 // Platforms which support Intel(R) Many Integrated Core Architecture
201 #define KMP_MIC_SUPPORTED \
202  ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
203 
204 // TODO: Fixme - This is clever, but really fugly
205 #if (1 != \
206  KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
207  KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 +KMP_ARCH_LOONGARCH64)
208 #error Unknown or unsupported architecture
209 #endif
210 
211 #endif // KMP_PLATFORM_H