kmp_platform.h 5.2 KB

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