platform.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * Copyright (c) 2009 Helge Bahmann
  7. * Copyright (c) 2014-2018, 2020 Andrey Semashev
  8. */
  9. /*!
  10. * \file atomic/detail/platform.hpp
  11. *
  12. * This header defines macros for the target platform detection
  13. */
  14. #ifndef BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_
  15. #define BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_
  16. #include <boost/atomic/detail/config.hpp>
  17. #ifdef BOOST_HAS_PRAGMA_ONCE
  18. #pragma once
  19. #endif
  20. #if defined(__GNUC__) && defined(__arm__)
  21. // Newer gcc versions define __ARM_ARCH. Older ones don't, so we have to deduce ARM arch version from a bunch of version-specific macros.
  22. #if defined(__ARM_ARCH)
  23. #define BOOST_ATOMIC_DETAIL_ARM_ARCH __ARM_ARCH
  24. #elif defined(__ARM_ARCH_8A__)
  25. #define BOOST_ATOMIC_DETAIL_ARM_ARCH 8
  26. #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) ||\
  27. defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) ||\
  28. defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7S__)
  29. #define BOOST_ATOMIC_DETAIL_ARM_ARCH 7
  30. #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) ||\
  31. defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) ||\
  32. defined(__ARM_ARCH_6ZK__)
  33. #define BOOST_ATOMIC_DETAIL_ARM_ARCH 6
  34. #else
  35. // We are not interested in older versions - they don't support atomic ops
  36. #define BOOST_ATOMIC_DETAIL_ARM_ARCH 0
  37. #endif
  38. #endif // defined(__GNUC__) && defined(__arm__)
  39. #if !defined(BOOST_ATOMIC_FORCE_FALLBACK)
  40. // Determine the target platform.
  41. // The target platform describes the compiler and target architecture. It can be used by more generic backends, such as the ones
  42. // based on compiler intrinsics, to implement specialized operations in a non-generic way.
  43. #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
  44. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_x86
  45. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_x86
  46. #elif defined(__GNUC__) && defined(__aarch64__)
  47. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_aarch64
  48. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_aarch64
  49. #elif defined(__GNUC__) && defined(__arm__) && (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 6)
  50. #if (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 8)
  51. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_aarch32
  52. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_aarch32
  53. #else
  54. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_arm
  55. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_arm
  56. #endif
  57. #elif defined(__GNUC__) && (defined(__POWERPC__) || defined(__PPC__))
  58. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_ppc
  59. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND gcc_ppc
  60. #elif (defined(__GNUC__) || defined(__SUNPRO_CC)) && (defined(__sparcv8plus) || defined(__sparc_v9__))
  61. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_sparc
  62. #elif defined(__GNUC__) && defined(__alpha__)
  63. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND gcc_alpha
  64. #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
  65. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_x86
  66. #elif defined(_MSC_VER) && _MSC_VER >= 1700 && (defined(_M_ARM) || defined(_M_ARM64))
  67. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND msvc_arm
  68. #endif
  69. // Compiler-based backends
  70. // IBM XL C++ Compiler has to be checked before GCC/Clang as it pretends to be one but does not support __atomic* intrinsics.
  71. // It does support GCC inline assembler though.
  72. #if !(defined(__ibmxl__) || defined(__IBMCPP__)) &&\
  73. ((defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 407)) ||\
  74. (defined(BOOST_CLANG) && ((__clang_major__ * 100 + __clang_minor__) >= 302))) &&\
  75. (\
  76. (__GCC_ATOMIC_BOOL_LOCK_FREE + 0) == 2 ||\
  77. (__GCC_ATOMIC_CHAR_LOCK_FREE + 0) == 2 ||\
  78. (__GCC_ATOMIC_SHORT_LOCK_FREE + 0) == 2 ||\
  79. (__GCC_ATOMIC_INT_LOCK_FREE + 0) == 2 ||\
  80. (__GCC_ATOMIC_LONG_LOCK_FREE + 0) == 2 ||\
  81. (__GCC_ATOMIC_LLONG_LOCK_FREE + 0) == 2\
  82. )
  83. #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_atomic
  84. // GCC __sync* instrinsics backend is less efficient than asm-based backends, so use it only when nothing better is available.
  85. #elif !defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND) &&\
  86. defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 401) &&\
  87. (\
  88. defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) ||\
  89. defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) ||\
  90. defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) ||\
  91. defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) ||\
  92. defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16)\
  93. )
  94. #define BOOST_ATOMIC_DETAIL_CORE_BACKEND gcc_sync
  95. #endif
  96. // OS-based backends
  97. #if !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND) && !defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND)
  98. #if defined(__linux__) && defined(__arm__)
  99. #define BOOST_ATOMIC_DETAIL_CORE_BACKEND linux_arm
  100. #elif defined(BOOST_WINDOWS) || defined(_WIN32_CE)
  101. #define BOOST_ATOMIC_DETAIL_CORE_BACKEND windows
  102. #endif
  103. #endif // !defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND)
  104. // Waiting and notifying operations backends
  105. #if defined(BOOST_WINDOWS)
  106. #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND windows
  107. #else // defined(BOOST_WINDOWS)
  108. #include <boost/atomic/detail/futex.hpp>
  109. #if defined(BOOST_ATOMIC_DETAIL_HAS_FUTEX)
  110. #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND futex
  111. #elif defined(__FreeBSD__)
  112. #include <sys/param.h>
  113. // FreeBSD prior to 7.0 had _umtx_op with a different signature
  114. #if defined(__FreeBSD_version) && __FreeBSD_version >= 700000
  115. #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND freebsd_umtx
  116. #endif // defined(__FreeBSD_version) && __FreeBSD_version >= 700000
  117. #elif defined(__DragonFly__)
  118. #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND dragonfly_umtx
  119. #endif
  120. #endif // defined(BOOST_WINDOWS)
  121. #endif // !defined(BOOST_ATOMIC_FORCE_FALLBACK)
  122. #if !defined(BOOST_ATOMIC_DETAIL_FP_BACKEND)
  123. #define BOOST_ATOMIC_DETAIL_FP_BACKEND generic
  124. #define BOOST_ATOMIC_DETAIL_FP_BACKEND_GENERIC
  125. #endif
  126. #if !defined(BOOST_ATOMIC_DETAIL_EXTRA_BACKEND)
  127. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND generic
  128. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_GENERIC
  129. #endif
  130. #if !defined(BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND)
  131. #define BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND generic
  132. #define BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND_GENERIC
  133. #endif
  134. #if !defined(BOOST_ATOMIC_DETAIL_WAIT_BACKEND)
  135. #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND generic
  136. #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND_GENERIC
  137. #endif
  138. #if defined(BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND)
  139. #define BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_CORE_ARCH_BACKEND).hpp>
  140. #endif
  141. #if defined(BOOST_ATOMIC_DETAIL_CORE_BACKEND)
  142. #define BOOST_ATOMIC_DETAIL_CORE_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_CORE_BACKEND).hpp>
  143. #endif
  144. #define BOOST_ATOMIC_DETAIL_FP_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_FP_BACKEND).hpp>
  145. #define BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_EXTRA_BACKEND).hpp>
  146. #define BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_EXTRA_FP_BACKEND).hpp>
  147. #define BOOST_ATOMIC_DETAIL_WAIT_BACKEND_HEADER(prefix) <BOOST_JOIN(prefix, BOOST_ATOMIC_DETAIL_WAIT_BACKEND).hpp>
  148. #endif // BOOST_ATOMIC_DETAIL_PLATFORM_HPP_INCLUDED_