LLVM OpenMP* Runtime Library
kmp_platform.h
1 /*
2  * kmp_platform.h -- header for determining operating system and architecture
3  */
4 
5 
6 //===----------------------------------------------------------------------===//
7 //
8 // The LLVM Compiler Infrastructure
9 //
10 // This file is dual licensed under the MIT and the University of Illinois Open
11 // Source Licenses. See LICENSE.txt for details.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 
16 #ifndef KMP_PLATFORM_H
17 #define KMP_PLATFORM_H
18 
19 /* ---------------------- Operating system recognition ------------------- */
20 
21 #define KMP_OS_LINUX 0
22 #define KMP_OS_FREEBSD 0
23 #define KMP_OS_NETBSD 0
24 #define KMP_OS_DARWIN 0
25 #define KMP_OS_WINDOWS 0
26 #define KMP_OS_CNK 0
27 #define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
28 
29 #ifdef _WIN32
30 #undef KMP_OS_WINDOWS
31 #define KMP_OS_WINDOWS 1
32 #endif
33 
34 #if (defined __APPLE__ && defined __MACH__)
35 #undef KMP_OS_DARWIN
36 #define KMP_OS_DARWIN 1
37 #endif
38 
39 // in some ppc64 linux installations, only the second condition is met
40 #if (defined __linux)
41 #undef KMP_OS_LINUX
42 #define KMP_OS_LINUX 1
43 #elif (defined __linux__)
44 #undef KMP_OS_LINUX
45 #define KMP_OS_LINUX 1
46 #else
47 #endif
48 
49 #if (defined __FreeBSD__)
50 #undef KMP_OS_FREEBSD
51 #define KMP_OS_FREEBSD 1
52 #endif
53 
54 #if (defined __NetBSD__)
55 #undef KMP_OS_NETBSD
56 #define KMP_OS_NETBSD 1
57 #endif
58 
59 #if (defined __bgq__)
60 #undef KMP_OS_CNK
61 #define KMP_OS_CNK 1
62 #endif
63 
64 #if (1 != \
65  KMP_OS_LINUX + KMP_OS_FREEBSD + KMP_OS_NETBSD + KMP_OS_DARWIN + \
66  KMP_OS_WINDOWS)
67 #error Unknown OS
68 #endif
69 
70 #if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DARWIN
71 #undef KMP_OS_UNIX
72 #define KMP_OS_UNIX 1
73 #endif
74 
75 /* ---------------------- Architecture recognition ------------------- */
76 
77 #define KMP_ARCH_X86 0
78 #define KMP_ARCH_X86_64 0
79 #define KMP_ARCH_AARCH64 0
80 #define KMP_ARCH_PPC64_BE 0
81 #define KMP_ARCH_PPC64_LE 0
82 #define KMP_ARCH_PPC64 (KMP_ARCH_PPC64_LE || KMP_ARCH_PPC64_BE)
83 #define KMP_ARCH_MIPS 0
84 #define KMP_ARCH_MIPS64 0
85 
86 #if KMP_OS_WINDOWS
87 #if defined _M_AMD64
88 #undef KMP_ARCH_X86_64
89 #define KMP_ARCH_X86_64 1
90 #else
91 #undef KMP_ARCH_X86
92 #define KMP_ARCH_X86 1
93 #endif
94 #endif
95 
96 #if KMP_OS_UNIX
97 #if defined __x86_64
98 #undef KMP_ARCH_X86_64
99 #define KMP_ARCH_X86_64 1
100 #elif defined __i386
101 #undef KMP_ARCH_X86
102 #define KMP_ARCH_X86 1
103 #elif defined __powerpc64__
104 #if defined __LITTLE_ENDIAN__
105 #undef KMP_ARCH_PPC64_LE
106 #define KMP_ARCH_PPC64_LE 1
107 #else
108 #undef KMP_ARCH_PPC64_BE
109 #define KMP_ARCH_PPC64_BE 1
110 #endif
111 #elif defined __aarch64__
112 #undef KMP_ARCH_AARCH64
113 #define KMP_ARCH_AARCH64 1
114 #elif defined __mips__
115 #if defined __mips64
116 #undef KMP_ARCH_MIPS64
117 #define KMP_ARCH_MIPS64 1
118 #else
119 #undef KMP_ARCH_MIPS
120 #define KMP_ARCH_MIPS 1
121 #endif
122 #endif
123 #endif
124 
125 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || \
126  defined(__ARM_ARCH_7A__)
127 #define KMP_ARCH_ARMV7 1
128 #endif
129 
130 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) || \
131  defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \
132  defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || \
133  defined(__ARM_ARCH_6ZK__)
134 #define KMP_ARCH_ARMV6 1
135 #endif
136 
137 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) || \
138  defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
139  defined(__ARM_ARCH_5TEJ__)
140 #define KMP_ARCH_ARMV5 1
141 #endif
142 
143 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) || \
144  defined(__ARM_ARCH_4T__)
145 #define KMP_ARCH_ARMV4 1
146 #endif
147 
148 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) || \
149  defined(__ARM_ARCH_3M__)
150 #define KMP_ARCH_ARMV3 1
151 #endif
152 
153 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
154 #define KMP_ARCH_ARMV2 1
155 #endif
156 
157 #if defined(KMP_ARCH_ARMV2)
158 #define KMP_ARCH_ARM 1
159 #endif
160 
161 #if defined(__MIC__) || defined(__MIC2__)
162 #define KMP_MIC 1
163 #if __MIC2__ || __KNC__
164 #define KMP_MIC1 0
165 #define KMP_MIC2 1
166 #else
167 #define KMP_MIC1 1
168 #define KMP_MIC2 0
169 #endif
170 #else
171 #define KMP_MIC 0
172 #define KMP_MIC1 0
173 #define KMP_MIC2 0
174 #endif
175 
176 /* Specify 32 bit architectures here */
177 #define KMP_32_BIT_ARCH (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS)
178 
179 // Platforms which support Intel(R) Many Integrated Core Architecture
180 #define KMP_MIC_SUPPORTED \
181  ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
182 
183 // TODO: Fixme - This is clever, but really fugly
184 #if (1 != \
185  KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
186  KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64)
187 #error Unknown or unsupported architecture
188 #endif
189 
190 #endif // KMP_PLATFORM_H