]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/powerpc32/atomic-machine.h
1 /* Atomic operations. PowerPC32 version.
2 Copyright (C) 2003-2023 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 <https://www.gnu.org/licenses/>. */
19 /* POWER6 adds a "Mutex Hint" to the Load and Reserve instruction.
20 This is a hint to the hardware to expect additional updates adjacent
21 to the lock word or not. If we are acquiring a Mutex, the hint
22 should be true. Otherwise we releasing a Mutex or doing a simple
23 atomic operation. In that case we don't expect additional updates
24 adjacent to the lock word after the Store Conditional and the hint
27 #if defined _ARCH_PWR6 || defined _ARCH_PWR6X
28 # define MUTEX_HINT_ACQ ",1"
29 # define MUTEX_HINT_REL ",0"
31 # define MUTEX_HINT_ACQ
32 # define MUTEX_HINT_REL
35 #define __HAVE_64B_ATOMICS 0
36 #define USE_ATOMIC_COMPILER_BUILTINS 0
37 #define ATOMIC_EXCHANGE_USES_CAS 1
40 * The 32-bit exchange_bool is different on powerpc64 because the subf
41 * does signed 64-bit arithmetic while the lwarx is 32-bit unsigned
42 * (a load word and zero (high 32) form). So powerpc64 has a slightly
43 * different version in sysdeps/powerpc/powerpc64/atomic-machine.h.
45 #define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
49 "1: lwarx %0,0,%1" MUTEX_HINT_ACQ "\n" \
54 "2: " __ARCH_ACQ_INSTR \
56 : "b" (mem), "r" (oldval), "r" (newval) \
61 /* Powerpc32 processors don't implement the 64-bit (doubleword) forms of
62 load and reserve (ldarx) and store conditional (stdcx.) instructions.
63 So for powerpc32 we stub out the 64-bit forms. */
64 #define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
67 #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
68 (abort (), (__typeof (*mem)) 0)
70 #define __arch_compare_and_exchange_val_64_rel(mem, newval, oldval) \
71 (abort (), (__typeof (*mem)) 0)
73 #define __arch_atomic_exchange_64_acq(mem, value) \
74 ({ abort (); (*mem) = (value); })
76 #define __arch_atomic_exchange_64_rel(mem, value) \
77 ({ abort (); (*mem) = (value); })
79 #define __arch_atomic_exchange_and_add_64(mem, value) \
80 ({ abort (); (*mem) = (value); })
82 #define __arch_atomic_exchange_and_add_64_acq(mem, value) \
83 ({ abort (); (*mem) = (value); })
85 #define __arch_atomic_exchange_and_add_64_rel(mem, value) \
86 ({ abort (); (*mem) = (value); })
88 #define __arch_atomic_increment_val_64(mem) \
89 ({ abort (); (*mem)++; })
91 #define __arch_atomic_decrement_val_64(mem) \
92 ({ abort (); (*mem)--; })
94 #define __arch_atomic_decrement_if_positive_64(mem) \
95 ({ abort (); (*mem)--; })
99 * Newer powerpc64 processors support the new "light weight" sync (lwsync)
100 * So if the build is using -mcpu=[power4,power5,power5+,970] we can
103 # define atomic_read_barrier() __asm ("lwsync" ::: "memory")
105 * "light weight" sync can also be used for the release barrier.
107 # define __ARCH_REL_INSTR "lwsync"
108 # define atomic_write_barrier() __asm ("lwsync" ::: "memory")
111 * Older powerpc32 processors don't support the new "light weight"
112 * sync (lwsync). So the only safe option is to use normal sync
113 * for all powerpc32 applications.
115 # define atomic_read_barrier() __asm ("sync" ::: "memory")
116 # define atomic_write_barrier() __asm ("sync" ::: "memory")
120 * Include the rest of the atomic ops macros which are common to both
121 * powerpc32 and powerpc64.
123 #include_next <atomic-machine.h>