]>
Commit | Line | Data |
---|---|---|
3b5ebe85 | 1 | /* Atomic operations. Sparc version. |
2b778ceb | 2 | Copyright (C) 2019-2021 Free Software Foundation, Inc. |
3b5ebe85 AZ |
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 _ATOMIC_MACHINE_H | |
20 | #define _ATOMIC_MACHINE_H 1 | |
21 | ||
22 | #include <stdint.h> | |
23 | ||
24 | typedef int8_t atomic8_t; | |
25 | typedef uint8_t uatomic8_t; | |
26 | typedef int_fast8_t atomic_fast8_t; | |
27 | typedef uint_fast8_t uatomic_fast8_t; | |
28 | ||
29 | typedef int16_t atomic16_t; | |
30 | typedef uint16_t uatomic16_t; | |
31 | typedef int_fast16_t atomic_fast16_t; | |
32 | typedef uint_fast16_t uatomic_fast16_t; | |
33 | ||
34 | typedef int32_t atomic32_t; | |
35 | typedef uint32_t uatomic32_t; | |
36 | typedef int_fast32_t atomic_fast32_t; | |
37 | typedef uint_fast32_t uatomic_fast32_t; | |
38 | ||
39 | typedef int64_t atomic64_t; | |
40 | typedef uint64_t uatomic64_t; | |
41 | typedef int_fast64_t atomic_fast64_t; | |
42 | typedef uint_fast64_t uatomic_fast64_t; | |
43 | ||
44 | typedef intptr_t atomicptr_t; | |
45 | typedef uintptr_t uatomicptr_t; | |
46 | typedef intmax_t atomic_max_t; | |
47 | typedef uintmax_t uatomic_max_t; | |
48 | ||
49 | #ifdef __arch64__ | |
50 | # define __HAVE_64B_ATOMICS 1 | |
51 | #else | |
52 | # define __HAVE_64B_ATOMICS 0 | |
53 | #endif | |
54 | #define USE_ATOMIC_COMPILER_BUILTINS 1 | |
55 | ||
56 | /* XXX Is this actually correct? */ | |
57 | #define ATOMIC_EXCHANGE_USES_CAS __HAVE_64B_ATOMICS | |
58 | ||
59 | /* Compare and exchange. | |
60 | For all "bool" routines, we return FALSE if exchange succesful. */ | |
61 | ||
62 | #define __arch_compare_and_exchange_val_int(mem, newval, oldval, model) \ | |
63 | ({ \ | |
64 | typeof (*mem) __oldval = (oldval); \ | |
65 | __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ | |
66 | model, __ATOMIC_RELAXED); \ | |
67 | __oldval; \ | |
68 | }) | |
69 | ||
70 | #define atomic_compare_and_exchange_val_acq(mem, new, old) \ | |
71 | ({ \ | |
72 | __typeof ((__typeof (*(mem))) *(mem)) __result; \ | |
73 | if (sizeof (*mem) == 4 \ | |
74 | || (__HAVE_64B_ATOMICS && sizeof (*mem) == 8)) \ | |
75 | __result = __arch_compare_and_exchange_val_int (mem, new, old, \ | |
76 | __ATOMIC_ACQUIRE); \ | |
77 | else \ | |
78 | abort (); \ | |
79 | __result; \ | |
80 | }) | |
81 | ||
82 | #ifdef __sparc_v9__ | |
83 | # define atomic_full_barrier() \ | |
84 | __asm __volatile ("membar #LoadLoad | #LoadStore" \ | |
85 | " | #StoreLoad | #StoreStore" : : : "memory") | |
86 | # define atomic_read_barrier() \ | |
87 | __asm __volatile ("membar #LoadLoad | #LoadStore" : : : "memory") | |
88 | # define atomic_write_barrier() \ | |
89 | __asm __volatile ("membar #LoadStore | #StoreStore" : : : "memory") | |
90 | ||
91 | extern void __cpu_relax (void); | |
92 | # define atomic_spin_nop() __cpu_relax () | |
93 | #endif | |
94 | ||
95 | #endif /* _ATOMIC_MACHINE_H */ |