xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 2003-2016 Free Software Foundation, Inc. |
| 2 | |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library. If not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef _AARCH64_ATOMIC_MACHINE_H |
| 20 | #define _AARCH64_ATOMIC_MACHINE_H 1 |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | |
| 24 | typedef int8_t atomic8_t; |
| 25 | typedef int16_t atomic16_t; |
| 26 | typedef int32_t atomic32_t; |
| 27 | typedef int64_t atomic64_t; |
| 28 | |
| 29 | typedef uint8_t uatomic8_t; |
| 30 | typedef uint16_t uatomic16_t; |
| 31 | typedef uint32_t uatomic32_t; |
| 32 | typedef uint64_t uatomic64_t; |
| 33 | |
| 34 | typedef intptr_t atomicptr_t; |
| 35 | typedef uintptr_t uatomicptr_t; |
| 36 | typedef intmax_t atomic_max_t; |
| 37 | typedef uintmax_t uatomic_max_t; |
| 38 | |
| 39 | #define __HAVE_64B_ATOMICS 1 |
| 40 | #define USE_ATOMIC_COMPILER_BUILTINS 1 |
| 41 | |
| 42 | /* Compare and exchange. |
| 43 | For all "bool" routines, we return FALSE if exchange succesful. */ |
| 44 | |
| 45 | # define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \ |
| 46 | ({ \ |
| 47 | typeof (*mem) __oldval = (oldval); \ |
| 48 | !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 49 | model, __ATOMIC_RELAXED); \ |
| 50 | }) |
| 51 | |
| 52 | # define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \ |
| 53 | ({ \ |
| 54 | typeof (*mem) __oldval = (oldval); \ |
| 55 | !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 56 | model, __ATOMIC_RELAXED); \ |
| 57 | }) |
| 58 | |
| 59 | # define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \ |
| 60 | ({ \ |
| 61 | typeof (*mem) __oldval = (oldval); \ |
| 62 | !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 63 | model, __ATOMIC_RELAXED); \ |
| 64 | }) |
| 65 | |
| 66 | # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \ |
| 67 | ({ \ |
| 68 | typeof (*mem) __oldval = (oldval); \ |
| 69 | !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 70 | model, __ATOMIC_RELAXED); \ |
| 71 | }) |
| 72 | |
| 73 | # define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \ |
| 74 | ({ \ |
| 75 | typeof (*mem) __oldval = (oldval); \ |
| 76 | __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 77 | model, __ATOMIC_RELAXED); \ |
| 78 | __oldval; \ |
| 79 | }) |
| 80 | |
| 81 | # define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \ |
| 82 | ({ \ |
| 83 | typeof (*mem) __oldval = (oldval); \ |
| 84 | __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 85 | model, __ATOMIC_RELAXED); \ |
| 86 | __oldval; \ |
| 87 | }) |
| 88 | |
| 89 | # define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \ |
| 90 | ({ \ |
| 91 | typeof (*mem) __oldval = (oldval); \ |
| 92 | __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 93 | model, __ATOMIC_RELAXED); \ |
| 94 | __oldval; \ |
| 95 | }) |
| 96 | |
| 97 | # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \ |
| 98 | ({ \ |
| 99 | typeof (*mem) __oldval = (oldval); \ |
| 100 | __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ |
| 101 | model, __ATOMIC_RELAXED); \ |
| 102 | __oldval; \ |
| 103 | }) |
| 104 | |
| 105 | |
| 106 | /* Compare and exchange with "acquire" semantics, ie barrier after. */ |
| 107 | |
| 108 | # define atomic_compare_and_exchange_bool_acq(mem, new, old) \ |
| 109 | __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \ |
| 110 | mem, new, old, __ATOMIC_ACQUIRE) |
| 111 | |
| 112 | # define atomic_compare_and_exchange_val_acq(mem, new, old) \ |
| 113 | __atomic_val_bysize (__arch_compare_and_exchange_val, int, \ |
| 114 | mem, new, old, __ATOMIC_ACQUIRE) |
| 115 | |
| 116 | /* Compare and exchange with "release" semantics, ie barrier before. */ |
| 117 | |
| 118 | # define atomic_compare_and_exchange_bool_rel(mem, new, old) \ |
| 119 | __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \ |
| 120 | mem, new, old, __ATOMIC_RELEASE) |
| 121 | |
| 122 | # define atomic_compare_and_exchange_val_rel(mem, new, old) \ |
| 123 | __atomic_val_bysize (__arch_compare_and_exchange_val, int, \ |
| 124 | mem, new, old, __ATOMIC_RELEASE) |
| 125 | |
| 126 | |
| 127 | /* Atomic exchange (without compare). */ |
| 128 | |
| 129 | # define __arch_exchange_8_int(mem, newval, model) \ |
| 130 | __atomic_exchange_n (mem, newval, model) |
| 131 | |
| 132 | # define __arch_exchange_16_int(mem, newval, model) \ |
| 133 | __atomic_exchange_n (mem, newval, model) |
| 134 | |
| 135 | # define __arch_exchange_32_int(mem, newval, model) \ |
| 136 | __atomic_exchange_n (mem, newval, model) |
| 137 | |
| 138 | # define __arch_exchange_64_int(mem, newval, model) \ |
| 139 | __atomic_exchange_n (mem, newval, model) |
| 140 | |
| 141 | # define atomic_exchange_acq(mem, value) \ |
| 142 | __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE) |
| 143 | |
| 144 | # define atomic_exchange_rel(mem, value) \ |
| 145 | __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE) |
| 146 | |
| 147 | |
| 148 | /* Atomically add value and return the previous (unincremented) value. */ |
| 149 | |
| 150 | # define __arch_exchange_and_add_8_int(mem, value, model) \ |
| 151 | __atomic_fetch_add (mem, value, model) |
| 152 | |
| 153 | # define __arch_exchange_and_add_16_int(mem, value, model) \ |
| 154 | __atomic_fetch_add (mem, value, model) |
| 155 | |
| 156 | # define __arch_exchange_and_add_32_int(mem, value, model) \ |
| 157 | __atomic_fetch_add (mem, value, model) |
| 158 | |
| 159 | # define __arch_exchange_and_add_64_int(mem, value, model) \ |
| 160 | __atomic_fetch_add (mem, value, model) |
| 161 | |
| 162 | # define atomic_exchange_and_add_acq(mem, value) \ |
| 163 | __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \ |
| 164 | __ATOMIC_ACQUIRE) |
| 165 | |
| 166 | # define atomic_exchange_and_add_rel(mem, value) \ |
| 167 | __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \ |
| 168 | __ATOMIC_RELEASE) |
| 169 | |
| 170 | /* Barrier macro. */ |
| 171 | #define atomic_full_barrier() __sync_synchronize() |
| 172 | |
| 173 | #endif |