]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/aarch64/atomic-machine.h
1 /* Copyright (C) 2003-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
19 #ifndef _AARCH64_ATOMIC_MACHINE_H
20 #define _AARCH64_ATOMIC_MACHINE_H 1
22 #define __HAVE_64B_ATOMICS 1
23 #define USE_ATOMIC_COMPILER_BUILTINS 1
24 #define ATOMIC_EXCHANGE_USES_CAS 0
26 /* Compare and exchange.
27 For all "bool" routines, we return FALSE if exchange successful. */
29 # define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
31 typeof (*mem) __oldval = (oldval); \
32 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
33 model, __ATOMIC_RELAXED); \
36 # define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
38 typeof (*mem) __oldval = (oldval); \
39 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
40 model, __ATOMIC_RELAXED); \
43 # define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
45 typeof (*mem) __oldval = (oldval); \
46 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
47 model, __ATOMIC_RELAXED); \
50 # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
52 typeof (*mem) __oldval = (oldval); \
53 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
54 model, __ATOMIC_RELAXED); \
57 # define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
59 typeof (*mem) __oldval = (oldval); \
60 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
61 model, __ATOMIC_RELAXED); \
65 # define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
67 typeof (*mem) __oldval = (oldval); \
68 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
69 model, __ATOMIC_RELAXED); \
73 # define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
75 typeof (*mem) __oldval = (oldval); \
76 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
77 model, __ATOMIC_RELAXED); \
81 # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
83 typeof (*mem) __oldval = (oldval); \
84 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
85 model, __ATOMIC_RELAXED); \
90 /* Compare and exchange with "acquire" semantics, ie barrier after. */
92 # define atomic_compare_and_exchange_bool_acq(mem, new, old) \
93 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
94 mem, new, old, __ATOMIC_ACQUIRE)
96 # define atomic_compare_and_exchange_val_acq(mem, new, old) \
97 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
98 mem, new, old, __ATOMIC_ACQUIRE)
100 /* Compare and exchange with "release" semantics, ie barrier before. */
102 # define atomic_compare_and_exchange_val_rel(mem, new, old) \
103 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
104 mem, new, old, __ATOMIC_RELEASE)
107 /* Atomic exchange (without compare). */
109 # define __arch_exchange_8_int(mem, newval, model) \
110 __atomic_exchange_n (mem, newval, model)
112 # define __arch_exchange_16_int(mem, newval, model) \
113 __atomic_exchange_n (mem, newval, model)
115 # define __arch_exchange_32_int(mem, newval, model) \
116 __atomic_exchange_n (mem, newval, model)
118 # define __arch_exchange_64_int(mem, newval, model) \
119 __atomic_exchange_n (mem, newval, model)
121 # define atomic_exchange_acq(mem, value) \
122 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
124 # define atomic_exchange_rel(mem, value) \
125 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
128 /* Atomically add value and return the previous (unincremented) value. */
130 # define __arch_exchange_and_add_8_int(mem, value, model) \
131 __atomic_fetch_add (mem, value, model)
133 # define __arch_exchange_and_add_16_int(mem, value, model) \
134 __atomic_fetch_add (mem, value, model)
136 # define __arch_exchange_and_add_32_int(mem, value, model) \
137 __atomic_fetch_add (mem, value, model)
139 # define __arch_exchange_and_add_64_int(mem, value, model) \
140 __atomic_fetch_add (mem, value, model)
142 # define atomic_exchange_and_add_acq(mem, value) \
143 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
146 # define atomic_exchange_and_add_rel(mem, value) \
147 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
151 #define atomic_full_barrier() __sync_synchronize()