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