]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mips/atomic-machine.h
1 /* Low-level functions for atomic operations. Mips version.
2 Copyright (C) 2005-2018 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 <http://www.gnu.org/licenses/>. */
19 #ifndef _MIPS_ATOMIC_MACHINE_H
20 #define _MIPS_ATOMIC_MACHINE_H 1
26 typedef int32_t atomic32_t
;
27 typedef uint32_t uatomic32_t
;
28 typedef int_fast32_t atomic_fast32_t
;
29 typedef uint_fast32_t uatomic_fast32_t
;
31 typedef int64_t atomic64_t
;
32 typedef uint64_t uatomic64_t
;
33 typedef int_fast64_t atomic_fast64_t
;
34 typedef uint_fast64_t uatomic_fast64_t
;
36 typedef intptr_t atomicptr_t
;
37 typedef uintptr_t uatomicptr_t
;
38 typedef intmax_t atomic_max_t
;
39 typedef uintmax_t uatomic_max_t
;
41 #if _MIPS_SIM == _ABIO32 && __mips < 2
42 #define MIPS_PUSH_MIPS2 ".set mips2\n\t"
44 #define MIPS_PUSH_MIPS2
47 #if _MIPS_SIM == _ABIO32 || _MIPS_SIM == _ABIN32
48 #define __HAVE_64B_ATOMICS 0
50 #define __HAVE_64B_ATOMICS 1
53 /* See the comments in <sys/asm.h> about the use of the sync instruction. */
55 # define MIPS_SYNC sync
58 #define MIPS_SYNC_STR_2(X) #X
59 #define MIPS_SYNC_STR_1(X) MIPS_SYNC_STR_2(X)
60 #define MIPS_SYNC_STR MIPS_SYNC_STR_1(MIPS_SYNC)
62 #define USE_ATOMIC_COMPILER_BUILTINS 1
64 /* MIPS is an LL/SC machine. However, XLP has a direct atomic exchange
65 instruction which will be used by __atomic_exchange_n. */
67 # define ATOMIC_EXCHANGE_USES_CAS 0
69 # define ATOMIC_EXCHANGE_USES_CAS 1
72 /* Compare and exchange.
73 For all "bool" routines, we return FALSE if exchange succesful. */
75 #define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
78 #define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
81 #define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
83 typeof (*mem) __oldval = (oldval); \
84 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
85 model, __ATOMIC_RELAXED); \
88 #define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
89 (abort (), (typeof(*mem)) 0)
91 #define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
92 (abort (), (typeof(*mem)) 0)
94 #define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
96 typeof (*mem) __oldval = (oldval); \
97 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
98 model, __ATOMIC_RELAXED); \
102 #if _MIPS_SIM == _ABIO32
103 /* We can't do an atomic 64-bit operation in O32. */
104 # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
106 # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
107 (abort (), (typeof(*mem)) 0)
109 # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
110 __arch_compare_and_exchange_bool_32_int (mem, newval, oldval, model)
111 # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
112 __arch_compare_and_exchange_val_32_int (mem, newval, oldval, model)
115 /* Compare and exchange with "acquire" semantics, ie barrier after. */
117 #define atomic_compare_and_exchange_bool_acq(mem, new, old) \
118 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
119 mem, new, old, __ATOMIC_ACQUIRE)
121 #define atomic_compare_and_exchange_val_acq(mem, new, old) \
122 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
123 mem, new, old, __ATOMIC_ACQUIRE)
125 /* Compare and exchange with "release" semantics, ie barrier before. */
127 #define atomic_compare_and_exchange_val_rel(mem, new, old) \
128 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
129 mem, new, old, __ATOMIC_RELEASE)
132 /* Atomic exchange (without compare). */
134 #define __arch_exchange_8_int(mem, newval, model) \
135 (abort (), (typeof(*mem)) 0)
137 #define __arch_exchange_16_int(mem, newval, model) \
138 (abort (), (typeof(*mem)) 0)
140 #define __arch_exchange_32_int(mem, newval, model) \
141 __atomic_exchange_n (mem, newval, model)
143 #if _MIPS_SIM == _ABIO32
144 /* We can't do an atomic 64-bit operation in O32. */
145 # define __arch_exchange_64_int(mem, newval, model) \
146 (abort (), (typeof(*mem)) 0)
148 # define __arch_exchange_64_int(mem, newval, model) \
149 __atomic_exchange_n (mem, newval, model)
152 #define atomic_exchange_acq(mem, value) \
153 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
155 #define atomic_exchange_rel(mem, value) \
156 __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
159 /* Atomically add value and return the previous (unincremented) value. */
161 #define __arch_exchange_and_add_8_int(mem, value, model) \
162 (abort (), (typeof(*mem)) 0)
164 #define __arch_exchange_and_add_16_int(mem, value, model) \
165 (abort (), (typeof(*mem)) 0)
167 #define __arch_exchange_and_add_32_int(mem, value, model) \
168 __atomic_fetch_add (mem, value, model)
170 #if _MIPS_SIM == _ABIO32
171 /* We can't do an atomic 64-bit operation in O32. */
172 # define __arch_exchange_and_add_64_int(mem, value, model) \
173 (abort (), (typeof(*mem)) 0)
175 # define __arch_exchange_and_add_64_int(mem, value, model) \
176 __atomic_fetch_add (mem, value, model)
179 #define atomic_exchange_and_add_acq(mem, value) \
180 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
183 #define atomic_exchange_and_add_rel(mem, value) \
184 __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
187 /* TODO: More atomic operations could be implemented efficiently; only the
188 basic requirements are done. */
191 # define atomic_full_barrier() __sync_synchronize ()
193 #else /* !__mips16 */
194 # define atomic_full_barrier() \
195 __asm__ __volatile__ (".set push\n\t" \
197 MIPS_SYNC_STR "\n\t" \
198 ".set pop" : : : "memory")
199 #endif /* !__mips16 */
201 #endif /* atomic-machine.h */