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