config.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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) 2012 Hartmut Kaiser
  7. * Copyright (c) 2014-2018, 2020-2025 Andrey Semashev
  8. */
  9. /*!
  10. * \file atomic/detail/config.hpp
  11. *
  12. * This header defines configuraion macros for Boost.Atomic
  13. */
  14. #ifndef BOOST_ATOMIC_DETAIL_CONFIG_HPP_INCLUDED_
  15. #define BOOST_ATOMIC_DETAIL_CONFIG_HPP_INCLUDED_
  16. #include <boost/config.hpp>
  17. #ifdef BOOST_HAS_PRAGMA_ONCE
  18. #pragma once
  19. #endif
  20. #if defined(__SANITIZE_THREAD__)
  21. #define BOOST_ATOMIC_DETAIL_TSAN
  22. #elif defined(__has_feature)
  23. #if __has_feature(thread_sanitizer)
  24. #define BOOST_ATOMIC_DETAIL_TSAN
  25. #endif
  26. #endif
  27. // Instrumentation macros to make TSan aware of the memory order semantics of asm blocks
  28. #if defined(BOOST_ATOMIC_DETAIL_TSAN)
  29. extern "C" {
  30. void __tsan_acquire(void*);
  31. void __tsan_release(void*);
  32. } // extern "C"
  33. #define BOOST_ATOMIC_DETAIL_TSAN_ACQUIRE(ptr, mo) \
  34. { if ((static_cast< unsigned int >(mo) & static_cast< unsigned int >(memory_order_acquire)) != 0u) __tsan_acquire((void*)(ptr)); }
  35. #define BOOST_ATOMIC_DETAIL_TSAN_RELEASE(ptr, mo) \
  36. { if ((static_cast< unsigned int >(mo) & static_cast< unsigned int >(memory_order_release)) != 0u) __tsan_release((void*)(ptr)); }
  37. #else // defined(BOOST_ATOMIC_DETAIL_TSAN)
  38. #define BOOST_ATOMIC_DETAIL_TSAN_ACQUIRE(ptr, mo)
  39. #define BOOST_ATOMIC_DETAIL_TSAN_RELEASE(ptr, mo)
  40. #endif // defined(BOOST_ATOMIC_DETAIL_TSAN)
  41. #if defined(__CUDACC__)
  42. // nvcc does not support alternatives ("q,m") in asm statement constraints
  43. #define BOOST_ATOMIC_DETAIL_NO_ASM_CONSTRAINT_ALTERNATIVES
  44. // nvcc does not support condition code register ("cc") clobber in asm statements
  45. #define BOOST_ATOMIC_DETAIL_NO_ASM_CLOBBER_CC
  46. #endif
  47. #if !defined(BOOST_ATOMIC_DETAIL_NO_ASM_CLOBBER_CC)
  48. #define BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC "cc"
  49. #define BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "cc",
  50. #else
  51. #define BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  52. #define BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA
  53. #endif
  54. #if (defined(__i386__) || defined(__x86_64__)) && (defined(__clang__) || (defined(BOOST_GCC) && BOOST_GCC < 40500) || defined(__SUNPRO_CC))
  55. // This macro indicates that the compiler does not support allocating eax:edx or rax:rdx register pairs ("A") in asm blocks
  56. #define BOOST_ATOMIC_DETAIL_X86_NO_ASM_AX_DX_PAIRS
  57. #endif
  58. #if defined(__i386__) && (defined(__PIC__) || defined(__PIE__)) && !(defined(__clang__) || (defined(BOOST_GCC) && BOOST_GCC >= 50100))
  59. // This macro indicates that asm blocks should preserve ebx value unchanged. Some compilers are able to maintain ebx themselves
  60. // around the asm blocks. For those compilers we don't need to save/restore ebx in asm blocks.
  61. #define BOOST_ATOMIC_DETAIL_X86_ASM_PRESERVE_EBX
  62. #endif
  63. #if defined(BOOST_NO_CXX11_ALIGNAS) ||\
  64. (defined(BOOST_GCC) && BOOST_GCC < 40900) ||\
  65. (defined(BOOST_MSVC) && BOOST_MSVC < 1910 && defined(_M_IX86))
  66. // gcc prior to 4.9 doesn't support alignas with a constant expression as an argument.
  67. // MSVC 14.0 does support alignas, but in 32-bit mode emits "error C2719: formal parameter with requested alignment of N won't be aligned" for N > 4,
  68. // when aligned types are used in function arguments, even though the std::max_align_t type has alignment of 8.
  69. #define BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS
  70. #endif
  71. // Enable pointer/reference casts between storage and value when possible.
  72. // Note: Despite that MSVC does not employ strict aliasing rules for optimizations
  73. // and does not require an explicit markup for types that may alias, we still don't
  74. // enable the optimization for this compiler because at least MSVC-8 and 9 are known
  75. // to generate broken code sometimes when casts are used.
  76. #define BOOST_ATOMIC_DETAIL_MAY_ALIAS BOOST_MAY_ALIAS
  77. #if !defined(BOOST_NO_MAY_ALIAS)
  78. #define BOOST_ATOMIC_DETAIL_STORAGE_TYPE_MAY_ALIAS
  79. #endif
  80. #if defined(__GCC_ASM_FLAG_OUTPUTS__)
  81. // The compiler supports output values in flag registers.
  82. // See: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html, Section 6.44.3.
  83. #define BOOST_ATOMIC_DETAIL_ASM_HAS_FLAG_OUTPUTS
  84. #endif
  85. #if defined(__has_builtin)
  86. #if __has_builtin(__builtin_constant_p)
  87. #define BOOST_ATOMIC_DETAIL_IS_CONSTANT(x) __builtin_constant_p(x)
  88. #endif
  89. #if __has_builtin(__builtin_clear_padding)
  90. #define BOOST_ATOMIC_DETAIL_CLEAR_PADDING(x) __builtin_clear_padding(x)
  91. #elif __has_builtin(__builtin_zero_non_value_bits)
  92. #define BOOST_ATOMIC_DETAIL_CLEAR_PADDING(x) __builtin_zero_non_value_bits(x)
  93. #endif
  94. #endif
  95. #if !defined(BOOST_ATOMIC_DETAIL_IS_CONSTANT) && defined(__GNUC__)
  96. #define BOOST_ATOMIC_DETAIL_IS_CONSTANT(x) __builtin_constant_p(x)
  97. #endif
  98. #if !defined(BOOST_ATOMIC_DETAIL_IS_CONSTANT)
  99. #define BOOST_ATOMIC_DETAIL_IS_CONSTANT(x) false
  100. #endif
  101. #if !defined(BOOST_ATOMIC_DETAIL_CLEAR_PADDING) && defined(BOOST_MSVC) && BOOST_MSVC >= 1927
  102. // Note that as of MSVC 19.29 this intrinsic does not clear padding in unions:
  103. // https://developercommunity.visualstudio.com/t/__builtin_zero_non_value_bits-does-not-c/1551510
  104. #define BOOST_ATOMIC_DETAIL_CLEAR_PADDING(x) __builtin_zero_non_value_bits(x)
  105. #endif
  106. #if !defined(BOOST_ATOMIC_DETAIL_CLEAR_PADDING)
  107. #define BOOST_ATOMIC_NO_CLEAR_PADDING
  108. #define BOOST_ATOMIC_DETAIL_CLEAR_PADDING(x)
  109. #endif
  110. #if (defined(__BYTE_ORDER__) && defined(__FLOAT_WORD_ORDER__) && __BYTE_ORDER__ == __FLOAT_WORD_ORDER__) ||\
  111. defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_AMD64) || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC)
  112. // This macro indicates that integer and floating point endianness is the same
  113. #define BOOST_ATOMIC_DETAIL_INT_FP_ENDIAN_MATCH
  114. #endif
  115. #endif // BOOST_ATOMIC_DETAIL_CONFIG_HPP_INCLUDED_