1 /* Atomic operations. OpenRISC version.
2 Copyright (C) 2022-2023 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 __OR1K_ATOMIC_H_
20 #define __OR1K_ATOMIC_H_
21
22 #include <stdint.h>
23
24 #define __HAVE_64B_ATOMICS 0
25 #define USE_ATOMIC_COMPILER_BUILTINS 1
26 #define ATOMIC_EXCHANGE_USES_CAS 1
27
28 #define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
29 (abort (), 0)
30
31 #define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
32 (abort (), 0)
33
34 #define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
35 ({ \
36 typeof (*mem) __oldval = (oldval); \
37 !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
38 model, __ATOMIC_RELAXED); \
39 })
40
41 #define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
42 (abort (), 0)
43
44 #define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
45 (abort (), (__typeof (*mem)) 0)
46
47 #define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
48 (abort (), (__typeof (*mem)) 0)
49
50 #define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
51 ({ \
52 typeof (*mem) __oldval = (oldval); \
53 __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
54 model, __ATOMIC_RELAXED); \
55 __oldval; \
56 })
57
58 #define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
59 (abort (), (__typeof (*mem)) 0)
60
61 #define atomic_compare_and_exchange_bool_acq(mem, new, old) \
62 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
63 mem, new, old, __ATOMIC_ACQUIRE)
64
65 #define atomic_compare_and_exchange_val_acq(mem, new, old) \
66 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
67 mem, new, old, __ATOMIC_ACQUIRE)
68
69 #define atomic_full_barrier() ({ asm volatile ("l.msync" ::: "memory"); })
70
71 #endif /* atomic-machine.h */