1 /* Low-level functions for atomic operations. ARC version.
2    Copyright (C) 2020-2021 Free Software Foundation, Inc.
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    <https://www.gnu.org/licenses/>.  */
18 
19 #ifndef _ARC_BITS_ATOMIC_H
20 #define _ARC_BITS_ATOMIC_H 1
21 
22 #define __HAVE_64B_ATOMICS 0
23 #define USE_ATOMIC_COMPILER_BUILTINS 1
24 
25 /* ARC does have legacy atomic EX reg, [mem] instruction but the micro-arch
26    is not as optimal as LLOCK/SCOND specially for SMP.  */
27 #define ATOMIC_EXCHANGE_USES_CAS 1
28 
29 #define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval)	\
30   (abort (), 0)
31 #define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval)	\
32   (abort (), 0)
33 #define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval)	\
34   (abort (), 0)
35 
36 #define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model)	\
37   (abort (), (__typeof (*mem)) 0)
38 #define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model)	\
39   (abort (), (__typeof (*mem)) 0)
40 #define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model)	\
41   (abort (), (__typeof (*mem)) 0)
42 
43 #define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model)	\
44   ({										\
45     typeof (*mem) __oldval = (oldval);                                  	\
46     __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,    	\
47                                  model, __ATOMIC_RELAXED);              	\
48     __oldval;                                                           	\
49   })
50 
51 #define atomic_compare_and_exchange_val_acq(mem, new, old)		\
52   __atomic_val_bysize (__arch_compare_and_exchange_val, int,		\
53 		       mem, new, old, __ATOMIC_ACQUIRE)
54 
55 #define atomic_full_barrier()  ({ asm volatile ("dmb 3":::"memory"); })
56 
57 #endif /* _ARC_BITS_ATOMIC_H */
58