1
/* Atomic operations. PowerPC32 version.
2
Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
3
This file is part of the GNU C Library.
4
Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003.
6
The GNU C Library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
The GNU C Library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with the GNU C Library; if not, write to the Free
18
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21
/* POWER6 adds a "Mutex Hint" to the Load and Reserve instruction.
22
This is a hint to the hardware to expect additional updates adjacent
23
to the lock word or not. If we are acquiring a Mutex, the hint
24
should be true. Otherwise we releasing a Mutex or doing a simple
25
atomic operation. In that case we don't expect addtional updates
26
adjacent to the lock word after the Store Conditional and the hint
29
#if defined _ARCH_PWR6 || defined _ARCH_PWR6X
30
# define MUTEX_HINT_ACQ ",1"
31
# define MUTEX_HINT_REL ",0"
33
# define MUTEX_HINT_ACQ
34
# define MUTEX_HINT_REL
38
* The 32-bit exchange_bool is different on powerpc64 because the subf
39
* does signed 64-bit arthmatic while the lwarx is 32-bit unsigned
40
* (a load word and zero (high 32) form). So powerpc64 has a slightly
41
* different version in sysdeps/powerpc/powerpc64/bits/atomic.h.
43
#define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
47
"1: lwarx %0,0,%1" MUTEX_HINT_ACQ "\n" \
52
"2: " __ARCH_ACQ_INSTR \
54
: "b" (mem), "r" (oldval), "r" (newval) \
59
#define __arch_compare_and_exchange_bool_32_rel(mem, newval, oldval) \
62
__asm __volatile (__ARCH_REL_INSTR "\n" \
63
"1: lwarx %0,0,%1" MUTEX_HINT_REL "\n" \
70
: "b" (mem), "r" (oldval), "r" (newval) \
75
/* Powerpc32 processors don't implement the 64-bit (doubleword) forms of
76
load and reserve (ldarx) and store conditional (stdcx.) instructions.
77
So for powerpc32 we stub out the 64-bit forms. */
78
#define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
81
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
82
(abort (), (__typeof (*mem)) 0)
84
#define __arch_compare_and_exchange_bool_64_rel(mem, newval, oldval) \
87
#define __arch_compare_and_exchange_val_64_rel(mem, newval, oldval) \
88
(abort (), (__typeof (*mem)) 0)
90
#define __arch_atomic_exchange_64_acq(mem, value) \
91
({ abort (); (*mem) = (value); })
93
#define __arch_atomic_exchange_64_rel(mem, value) \
94
({ abort (); (*mem) = (value); })
96
#define __arch_atomic_exchange_and_add_64(mem, value) \
97
({ abort (); (*mem) = (value); })
99
#define __arch_atomic_increment_val_64(mem) \
100
({ abort (); (*mem)++; })
102
#define __arch_atomic_decrement_val_64(mem) \
103
({ abort (); (*mem)--; })
105
#define __arch_atomic_decrement_if_positive_64(mem) \
106
({ abort (); (*mem)--; })
110
* Newer powerpc64 processors support the new "light weight" sync (lwsync)
111
* So if the build is using -mcpu=[power4,power5,power5+,970] we can
114
# define atomic_read_barrier() __asm ("lwsync" ::: "memory")
116
* "light weight" sync can also be used for the release barrier.
119
# define __ARCH_REL_INSTR "lwsync"
123
* Older powerpc32 processors don't support the new "light weight"
124
* sync (lwsync). So the only safe option is to use normal sync
125
* for all powerpc32 applications.
127
# define atomic_read_barrier() __asm ("sync" ::: "memory")
131
* Include the rest of the atomic ops macros which are common to both
132
* powerpc32 and powerpc64.
134
#include_next <bits/atomic.h>