]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/arm/atomic-machine.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / arm / atomic-machine.h
CommitLineData
f3bdd5f8 1/* Atomic operations. Pure ARM version.
2b778ceb 2 Copyright (C) 2002-2021 Free Software Foundation, Inc.
f3bdd5f8
RM
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
5a82c748 17 <https://www.gnu.org/licenses/>. */
f3bdd5f8
RM
18
19#include <stdint.h>
20
21typedef int8_t atomic8_t;
22typedef uint8_t uatomic8_t;
23typedef int_fast8_t atomic_fast8_t;
24typedef uint_fast8_t uatomic_fast8_t;
25
26typedef int32_t atomic32_t;
27typedef uint32_t uatomic32_t;
28typedef int_fast32_t atomic_fast32_t;
29typedef uint_fast32_t uatomic_fast32_t;
30
31typedef intptr_t atomicptr_t;
32typedef uintptr_t uatomicptr_t;
33typedef intmax_t atomic_max_t;
34typedef uintmax_t uatomic_max_t;
35
1ea339b6
TR
36#define __HAVE_64B_ATOMICS 0
37#define USE_ATOMIC_COMPILER_BUILTINS 0
12d2dd70 38#define ATOMIC_EXCHANGE_USES_CAS 1
1ea339b6 39
f3bdd5f8
RM
40void __arm_link_error (void);
41
f3bdd5f8
RM
42#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
43# define atomic_full_barrier() __sync_synchronize ()
44#else
45# define atomic_full_barrier() __arm_assisted_full_barrier ()
46#endif
47
de071d19 48/* An OS-specific atomic-machine.h file will define this macro if
f3bdd5f8
RM
49 the OS can provide something. If not, we'll fail to build
50 with a compiler that doesn't supply the operation. */
51#ifndef __arm_assisted_full_barrier
52# define __arm_assisted_full_barrier() __arm_link_error()
53#endif
54
d70d6205
MK
55/* Use the atomic builtins provided by GCC in case the backend provides
56 a pattern to do this efficiently. */
9f9f2724 57#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
f3bdd5f8 58
d70d6205
MK
59# define atomic_exchange_acq(mem, value) \
60 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
61
62# define atomic_exchange_rel(mem, value) \
63 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
64
65/* Atomic exchange (without compare). */
66
67# define __arch_exchange_8_int(mem, newval, model) \
68 (__arm_link_error (), (typeof (*mem)) 0)
69
70# define __arch_exchange_16_int(mem, newval, model) \
71 (__arm_link_error (), (typeof (*mem)) 0)
72
73# define __arch_exchange_32_int(mem, newval, model) \
74 __atomic_exchange_n (mem, newval, model)
75
76# define __arch_exchange_64_int(mem, newval, model) \
77 (__arm_link_error (), (typeof (*mem)) 0)
78
79/* Compare and exchange with "acquire" semantics, ie barrier after. */
80
81# define atomic_compare_and_exchange_bool_acq(mem, new, old) \
82 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
83 mem, new, old, __ATOMIC_ACQUIRE)
84
85# define atomic_compare_and_exchange_val_acq(mem, new, old) \
86 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
87 mem, new, old, __ATOMIC_ACQUIRE)
88
89/* Compare and exchange with "release" semantics, ie barrier before. */
90
d70d6205
MK
91# define atomic_compare_and_exchange_val_rel(mem, new, old) \
92 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
93 mem, new, old, __ATOMIC_RELEASE)
94
95/* Compare and exchange.
96 For all "bool" routines, we return FALSE if exchange succesful. */
97
98# define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
57977c4b 99 ({__arm_link_error (); 0; })
d70d6205
MK
100
101# define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
57977c4b 102 ({__arm_link_error (); 0; })
d70d6205
MK
103
104# define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
105 ({ \
106 typeof (*mem) __oldval = (oldval); \
107 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
108 model, __ATOMIC_RELAXED); \
109 })
110
111# define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
57977c4b 112 ({__arm_link_error (); 0; })
d70d6205
MK
113
114# define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
115 ({__arm_link_error (); oldval; })
116
117# define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
118 ({__arm_link_error (); oldval; })
119
120# define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
121 ({ \
122 typeof (*mem) __oldval = (oldval); \
123 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
124 model, __ATOMIC_RELAXED); \
125 __oldval; \
126 })
127
128# define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
129 ({__arm_link_error (); oldval; })
130
f3bdd5f8
RM
131#else
132# define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
eaf6f205 133 __arm_assisted_compare_and_exchange_val_32_acq ((mem), (newval), (oldval))
f3bdd5f8
RM
134#endif
135
9f9f2724 136#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
f3bdd5f8
RM
137/* We don't support atomic operations on any non-word types.
138 So make them link errors. */
d70d6205 139# define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
f3bdd5f8
RM
140 ({ __arm_link_error (); oldval; })
141
d70d6205 142# define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
f3bdd5f8
RM
143 ({ __arm_link_error (); oldval; })
144
d70d6205 145# define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
f3bdd5f8 146 ({ __arm_link_error (); oldval; })
d70d6205 147#endif
f3bdd5f8 148
de071d19 149/* An OS-specific atomic-machine.h file will define this macro if
f3bdd5f8
RM
150 the OS can provide something. If not, we'll fail to build
151 with a compiler that doesn't supply the operation. */
152#ifndef __arm_assisted_compare_and_exchange_val_32_acq
153# define __arm_assisted_compare_and_exchange_val_32_acq(mem, newval, oldval) \
154 ({ __arm_link_error (); oldval; })
155#endif