atomic-machine.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Copyright (C) 2003-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <stdint.h>
  15. #include <ia64intrin.h>
  16. typedef int8_t atomic8_t;
  17. typedef uint8_t uatomic8_t;
  18. typedef int_fast8_t atomic_fast8_t;
  19. typedef uint_fast8_t uatomic_fast8_t;
  20. typedef int16_t atomic16_t;
  21. typedef uint16_t uatomic16_t;
  22. typedef int_fast16_t atomic_fast16_t;
  23. typedef uint_fast16_t uatomic_fast16_t;
  24. typedef int32_t atomic32_t;
  25. typedef uint32_t uatomic32_t;
  26. typedef int_fast32_t atomic_fast32_t;
  27. typedef uint_fast32_t uatomic_fast32_t;
  28. typedef int64_t atomic64_t;
  29. typedef uint64_t uatomic64_t;
  30. typedef int_fast64_t atomic_fast64_t;
  31. typedef uint_fast64_t uatomic_fast64_t;
  32. typedef intptr_t atomicptr_t;
  33. typedef uintptr_t uatomicptr_t;
  34. typedef intmax_t atomic_max_t;
  35. typedef uintmax_t uatomic_max_t;
  36. #define __HAVE_64B_ATOMICS 1
  37. #define USE_ATOMIC_COMPILER_BUILTINS 0
  38. /* XXX Is this actually correct? */
  39. #define ATOMIC_EXCHANGE_USES_CAS 0
  40. #define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \
  41. (abort (), 0)
  42. #define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \
  43. (abort (), 0)
  44. #define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
  45. (!__sync_bool_compare_and_swap ((mem), (int) (long) (oldval), \
  46. (int) (long) (newval)))
  47. #define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
  48. (!__sync_bool_compare_and_swap ((mem), (long) (oldval), \
  49. (long) (newval)))
  50. #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
  51. (abort (), (__typeof (*mem)) 0)
  52. #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
  53. (abort (), (__typeof (*mem)) 0)
  54. #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
  55. __sync_val_compare_and_swap ((mem), (int) (long) (oldval), \
  56. (int) (long) (newval))
  57. #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
  58. __sync_val_compare_and_swap ((mem), (long) (oldval), (long) (newval))
  59. /* Atomically store newval and return the old value. */
  60. #define atomic_exchange_acq(mem, value) \
  61. __sync_lock_test_and_set (mem, value)
  62. #define atomic_exchange_rel(mem, value) \
  63. (__sync_synchronize (), __sync_lock_test_and_set (mem, value))
  64. #define atomic_exchange_and_add(mem, value) \
  65. __sync_fetch_and_add ((mem), (value))
  66. #define atomic_decrement_if_positive(mem) \
  67. ({ __typeof (*mem) __oldval, __val; \
  68. __typeof (mem) __memp = (mem); \
  69. \
  70. __val = (*__memp); \
  71. do \
  72. { \
  73. __oldval = __val; \
  74. if (__builtin_expect (__val <= 0, 0)) \
  75. break; \
  76. __val = atomic_compare_and_exchange_val_acq (__memp, __oldval - 1, \
  77. __oldval); \
  78. } \
  79. while (__builtin_expect (__val != __oldval, 0)); \
  80. __oldval; })
  81. #define atomic_bit_test_set(mem, bit) \
  82. ({ __typeof (*mem) __oldval, __val; \
  83. __typeof (mem) __memp = (mem); \
  84. __typeof (*mem) __mask = ((__typeof (*mem)) 1 << (bit)); \
  85. \
  86. __val = (*__memp); \
  87. do \
  88. { \
  89. __oldval = __val; \
  90. __val = atomic_compare_and_exchange_val_acq (__memp, \
  91. __oldval | __mask, \
  92. __oldval); \
  93. } \
  94. while (__builtin_expect (__val != __oldval, 0)); \
  95. __oldval & __mask; })
  96. #define atomic_full_barrier() __sync_synchronize ()