Skip to content

Commit 9f0cbea

Browse files
segherpaulusmack
authored andcommitted
[POWERPC] Implement atomic{, 64}_{read, write}() without volatile
Instead, use asm() like all other atomic operations already do. Also use inline functions instead of macros; this actually improves code generation (some code becomes a little smaller, probably because of improved alias information -- just a few hundred bytes total on a default kernel build, nothing shocking). Signed-off-by: Segher Boessenkool <segher@kernel.crashing.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent c6d4267 commit 9f0cbea

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

include/asm-powerpc/atomic.h

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* PowerPC atomic operations
66
*/
77

8-
typedef struct { volatile int counter; } atomic_t;
8+
typedef struct { int counter; } atomic_t;
99

1010
#ifdef __KERNEL__
1111
#include <linux/compiler.h>
@@ -15,8 +15,19 @@ typedef struct { volatile int counter; } atomic_t;
1515

1616
#define ATOMIC_INIT(i) { (i) }
1717

18-
#define atomic_read(v) ((v)->counter)
19-
#define atomic_set(v,i) (((v)->counter) = (i))
18+
static __inline__ int atomic_read(const atomic_t *v)
19+
{
20+
int t;
21+
22+
__asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
23+
24+
return t;
25+
}
26+
27+
static __inline__ void atomic_set(atomic_t *v, int i)
28+
{
29+
__asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
30+
}
2031

2132
static __inline__ void atomic_add(int a, atomic_t *v)
2233
{
@@ -240,12 +251,23 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
240251

241252
#ifdef __powerpc64__
242253

243-
typedef struct { volatile long counter; } atomic64_t;
254+
typedef struct { long counter; } atomic64_t;
244255

245256
#define ATOMIC64_INIT(i) { (i) }
246257

247-
#define atomic64_read(v) ((v)->counter)
248-
#define atomic64_set(v,i) (((v)->counter) = (i))
258+
static __inline__ long atomic64_read(const atomic64_t *v)
259+
{
260+
long t;
261+
262+
__asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
263+
264+
return t;
265+
}
266+
267+
static __inline__ void atomic64_set(atomic64_t *v, long i)
268+
{
269+
__asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
270+
}
249271

250272
static __inline__ void atomic64_add(long a, atomic64_t *v)
251273
{

0 commit comments

Comments
 (0)