host-config.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 2012-2015 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Atomic Library (libatomic).
  4. Libatomic is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* Included after all more target-specific host-config.h. */
  20. /* The target may have some OS specific way to implement compare-and-swap. */
  21. #if !defined(atomic_compare_exchange_n) && SIZE(HAVE_ATOMIC_CAS)
  22. # define atomic_compare_exchange_n __atomic_compare_exchange_n
  23. #endif
  24. #if !defined(atomic_compare_exchange_w) && WSIZE(HAVE_ATOMIC_CAS)
  25. # define atomic_compare_exchange_w __atomic_compare_exchange_n
  26. #endif
  27. /* For some targets, it may be significantly faster to avoid all barriers
  28. if the user only wants relaxed memory order. Sometimes we don't want
  29. the extra code bloat. In all cases, use the input to avoid warnings. */
  30. #if defined(WANT_SPECIALCASE_RELAXED) && !defined(__OPTIMIZE_SIZE__)
  31. # define maybe_specialcase_relaxed(x) ((x) == __ATOMIC_RELAXED)
  32. #else
  33. # define maybe_specialcase_relaxed(x) ((x) & 0)
  34. #endif
  35. /* Similar, but for targets for which the seq_cst model is sufficiently
  36. more expensive than the acq_rel model. */
  37. #if defined(WANT_SPECIALCASE_ACQREL) && !defined(__OPTIMIZE_SIZE__)
  38. # define maybe_specialcase_acqrel(x) ((x) != __ATOMIC_SEQ_CST)
  39. #else
  40. # define maybe_specialcase_acqrel(x) ((x) & 0)
  41. #endif
  42. /* The target may have some OS specific way to emit barriers. */
  43. #ifndef pre_post_barrier
  44. static inline void __attribute__((always_inline, artificial))
  45. pre_barrier(int model)
  46. {
  47. if (!maybe_specialcase_relaxed(model))
  48. {
  49. if (maybe_specialcase_acqrel(model))
  50. __atomic_thread_fence (__ATOMIC_ACQ_REL);
  51. else
  52. __atomic_thread_fence (__ATOMIC_SEQ_CST);
  53. }
  54. }
  55. static inline void __attribute__((always_inline, artificial))
  56. post_barrier(int model)
  57. {
  58. pre_barrier(model);
  59. }
  60. #define pre_post_barrier 1
  61. #endif /* pre_post_barrier */
  62. /* Similar, but assume that acq_rel is already handled via locks. */
  63. #ifndef pre_post_seq_barrier
  64. static inline void __attribute__((always_inline, artificial))
  65. pre_seq_barrier(int model)
  66. {
  67. }
  68. static inline void __attribute__((always_inline, artificial))
  69. post_seq_barrier(int model)
  70. {
  71. }
  72. #define pre_post_seq_barrier 1
  73. #endif