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_SOLARIS 0 27 #define KMP_OS_WASI 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 __GNU__) 71 #undef KMP_OS_HURD 72 #define KMP_OS_HURD 1 73 #endif 74 75 #if (defined __sun__ && defined __svr4__) 76 #undef KMP_OS_SOLARIS 77 #define KMP_OS_SOLARIS 1 78 #endif 79 80 #if (defined __wasi__) || (defined __EMSCRIPTEN__) 81 #undef KMP_OS_WASI 82 #define KMP_OS_WASI 1 83 #endif 84 85 #if (defined _AIX) 86 #undef KMP_OS_AIX 87 #define KMP_OS_AIX 1 88 #endif 89 90 #if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \ 91 KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD + \ 92 KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX) 93 #error Unknown OS 94 #endif 95 96 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \ 97 KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS || \ 98 KMP_OS_WASI || KMP_OS_AIX 99 #undef KMP_OS_UNIX 100 #define KMP_OS_UNIX 1 101 #endif 102 103 /* ---------------------- Architecture recognition ------------------- */ 104 105 #define KMP_ARCH_X86 0 106 #define KMP_ARCH_X86_64 0 107 #define KMP_ARCH_AARCH64 0 108 #define KMP_ARCH_AARCH64_32 0 109 #define KMP_ARCH_PPC64_ELFv1 0 110 #define KMP_ARCH_PPC64_ELFv2 0 111 #define KMP_ARCH_PPC64_XCOFF 0 112 #define KMP_ARCH_PPC_XCOFF 0 113 #define KMP_ARCH_MIPS 0 114 #define KMP_ARCH_MIPS64 0 115 #define KMP_ARCH_RISCV64 0 116 #define KMP_ARCH_LOONGARCH64 0 117 #define KMP_ARCH_VE 0 118 #define KMP_ARCH_S390X 0 119 120 #if KMP_OS_WINDOWS 121 #if defined(_M_AMD64) || defined(__x86_64) 122 #undef KMP_ARCH_X86_64 123 #define KMP_ARCH_X86_64 1 124 #elif defined(__aarch64__) || defined(_M_ARM64) 125 #undef KMP_ARCH_AARCH64 126 #define KMP_ARCH_AARCH64 1 127 #elif defined(__arm__) || defined(_M_ARM) 128 #undef KMP_ARCH_ARMV7 129 #define KMP_ARCH_ARMV7 1 130 #else 131 #undef KMP_ARCH_X86 132 #define KMP_ARCH_X86 1 133 #endif 134 #endif 135 136 #if KMP_OS_UNIX 137 #if defined __x86_64 138 #undef KMP_ARCH_X86_64 139 #define KMP_ARCH_X86_64 1 140 #elif defined __i386 141 #undef KMP_ARCH_X86 142 #define KMP_ARCH_X86 1 143 #elif defined __powerpc64__ 144 #if defined(_CALL_ELF) 145 #if _CALL_ELF == 2 146 #undef KMP_ARCH_PPC64_ELFv2 147 #define KMP_ARCH_PPC64_ELFv2 1 148 #else 149 #undef KMP_ARCH_PPC64_ELFv1 150 #define KMP_ARCH_PPC64_ELFv1 1 151 #endif 152 #elif defined KMP_OS_AIX 153 #undef KMP_ARCH_PPC64_XCOFF 154 #define KMP_ARCH_PPC64_XCOFF 1 155 #endif 156 #elif defined(__powerpc__) && defined(KMP_OS_AIX) 157 #undef KMP_ARCH_PPC_XCOFF 158 #define KMP_ARCH_PPC_XCOFF 1 159 #undef KMP_ARCH_PPC 160 #define KMP_ARCH_PPC 1 161 #elif defined __ARM64_ARCH_8_32__ 162 #undef KMP_ARCH_AARCH64_32 163 #define KMP_ARCH_AARCH64_32 1 164 #elif defined __aarch64__ 165 #undef KMP_ARCH_AARCH64 166 #define KMP_ARCH_AARCH64 1 167 #elif defined __mips__ 168 #if defined __mips64 169 #undef KMP_ARCH_MIPS64 170 #define KMP_ARCH_MIPS64 1 171 #else 172 #undef KMP_ARCH_MIPS 173 #define KMP_ARCH_MIPS 1 174 #endif 175 #elif defined __riscv && __riscv_xlen == 64 176 #undef KMP_ARCH_RISCV64 177 #define KMP_ARCH_RISCV64 1 178 #elif defined __loongarch__ && __loongarch_grlen == 64 179 #undef KMP_ARCH_LOONGARCH64 180 #define KMP_ARCH_LOONGARCH64 1 181 #elif defined __ve__ 182 #undef KMP_ARCH_VE 183 #define KMP_ARCH_VE 1 184 #elif defined __s390x__ 185 #undef KMP_ARCH_S390X 186 #define KMP_ARCH_S390X 1 187 #endif 188 #endif 189 190 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || \ 191 defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7VE__) 192 #define KMP_ARCH_ARMV7 1 193 #endif 194 195 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) || \ 196 defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \ 197 defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || \ 198 defined(__ARM_ARCH_6ZK__) 199 #define KMP_ARCH_ARMV6 1 200 #endif 201 202 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) || \ 203 defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \ 204 defined(__ARM_ARCH_5TEJ__) 205 #define KMP_ARCH_ARMV5 1 206 #endif 207 208 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) || \ 209 defined(__ARM_ARCH_4T__) 210 #define KMP_ARCH_ARMV4 1 211 #endif 212 213 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) || \ 214 defined(__ARM_ARCH_3M__) 215 #define KMP_ARCH_ARMV3 1 216 #endif 217 218 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__) 219 #define KMP_ARCH_ARMV2 1 220 #endif 221 222 #if defined(KMP_ARCH_ARMV2) 223 #define KMP_ARCH_ARM 1 224 #endif 225 226 #if defined(__wasm32__) 227 #define KMP_ARCH_WASM 1 228 #endif 229 230 #define KMP_ARCH_PPC64 \ 231 (KMP_ARCH_PPC64_ELFv2 || KMP_ARCH_PPC64_ELFv1 || KMP_ARCH_PPC64_XCOFF) 232 233 #if defined(__MIC__) || defined(__MIC2__) 234 #define KMP_MIC 1 235 #if __MIC2__ || __KNC__ 236 #define KMP_MIC1 0 237 #define KMP_MIC2 1 238 #else 239 #define KMP_MIC1 1 240 #define KMP_MIC2 0 241 #endif 242 #else 243 #define KMP_MIC 0 244 #define KMP_MIC1 0 245 #define KMP_MIC2 0 246 #endif 247 248 /* Specify 32 bit architectures here */ 249 #define KMP_32_BIT_ARCH \ 250 (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM || \ 251 KMP_ARCH_PPC || KMP_ARCH_AARCH64_32) 252 253 // Platforms which support Intel(R) Many Integrated Core Architecture 254 #define KMP_MIC_SUPPORTED \ 255 ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS)) 256 257 // TODO: Fixme - This is clever, but really fugly 258 #if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \ 259 KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \ 260 KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE + \ 261 KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC + \ 262 KMP_ARCH_AARCH64_32) 263 #error Unknown or unsupported architecture 264 #endif 265 266 #endif // KMP_PLATFORM_H 267