caps_arch_gcc_arm.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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) 2009 Phil Endecott
  8. * Copyright (c) 2013 Tim Blechmann
  9. * ARM Code by Phil Endecott, based on other architectures.
  10. * Copyright (c) 2014, 2020, 2022 Andrey Semashev
  11. */
  12. /*!
  13. * \file atomic/detail/caps_arch_gcc_arm.hpp
  14. *
  15. * This header defines feature capabilities macros
  16. */
  17. #ifndef BOOST_ATOMIC_DETAIL_CAPS_ARCH_GCC_ARM_HPP_INCLUDED_
  18. #define BOOST_ATOMIC_DETAIL_CAPS_ARCH_GCC_ARM_HPP_INCLUDED_
  19. #include <boost/atomic/detail/config.hpp>
  20. #include <boost/atomic/detail/platform.hpp>
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. #if defined(__ARMEL__) || \
  25. (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
  26. (defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
  27. defined(BOOST_WINDOWS)
  28. #define BOOST_ATOMIC_DETAIL_ARM_LITTLE_ENDIAN
  29. #elif defined(__ARMEB__) || \
  30. defined(__ARM_BIG_ENDIAN) || \
  31. (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
  32. (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__))
  33. #define BOOST_ATOMIC_DETAIL_ARM_BIG_ENDIAN
  34. #else
  35. #include <boost/predef/other/endian.h>
  36. #if BOOST_ENDIAN_LITTLE_BYTE
  37. #define BOOST_ATOMIC_DETAIL_ARM_LITTLE_ENDIAN
  38. #elif BOOST_ENDIAN_BIG_BYTE
  39. #define BOOST_ATOMIC_DETAIL_ARM_BIG_ENDIAN
  40. #else
  41. #error "Boost.Atomic: Failed to determine ARM endianness, the target platform is not supported. Please, report to the developers (patches are welcome)."
  42. #endif
  43. #endif
  44. #if defined(__GNUC__) && defined(__arm__) && (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 6)
  45. #if BOOST_ATOMIC_DETAIL_ARM_ARCH > 6
  46. // ARMv7 and later have dmb instruction
  47. #define BOOST_ATOMIC_DETAIL_ARM_HAS_DMB 1
  48. #endif
  49. #if defined(__ARM_FEATURE_LDREX)
  50. #if (__ARM_FEATURE_LDREX & 1)
  51. #define BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXB_STREXB 1
  52. #endif
  53. #if (__ARM_FEATURE_LDREX & 2)
  54. #define BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXH_STREXH 1
  55. #endif
  56. #if (__ARM_FEATURE_LDREX & 8)
  57. #define BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXD_STREXD 1
  58. #endif
  59. #else // defined(__ARM_FEATURE_LDREX)
  60. #if !(defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6Z__))
  61. // ARMv6k and ARMv7 have 8 and 16-bit ldrex/strex variants, but at least GCC 4.7 fails to compile them. GCC 4.9 is known to work.
  62. #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 409
  63. #define BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXB_STREXB 1
  64. #define BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXH_STREXH 1
  65. #endif
  66. #if !(((defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__)) && defined(__thumb__)) || defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7M__))
  67. // ARMv6k and ARMv7 except ARMv7-M have 64-bit ldrex/strex variants.
  68. // Unfortunately, GCC (at least 4.7.3 on Ubuntu) does not allocate register pairs properly when targeting ARMv6k Thumb,
  69. // which is required for ldrexd/strexd instructions, so we disable 64-bit support. When targeting ARMv6k ARM
  70. // or ARMv7 (both ARM and Thumb 2) it works as expected.
  71. #define BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXD_STREXD 1
  72. #endif
  73. #endif // !(defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6Z__))
  74. #endif // defined(__ARM_FEATURE_LDREX)
  75. #endif // defined(__GNUC__) && defined(__arm__) && (BOOST_ATOMIC_DETAIL_ARM_ARCH >= 6)
  76. #define BOOST_ATOMIC_INT8_LOCK_FREE 2
  77. #define BOOST_ATOMIC_INT16_LOCK_FREE 2
  78. #define BOOST_ATOMIC_INT32_LOCK_FREE 2
  79. #if defined(BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXD_STREXD)
  80. #define BOOST_ATOMIC_INT64_LOCK_FREE 2
  81. #endif
  82. #define BOOST_ATOMIC_POINTER_LOCK_FREE 2
  83. #define BOOST_ATOMIC_THREAD_FENCE 2
  84. #define BOOST_ATOMIC_SIGNAL_FENCE 2
  85. #endif // BOOST_ATOMIC_DETAIL_CAPS_ARCH_GCC_ARM_HPP_INCLUDED_