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