2 * Copyright IBM Corp. 1999, 2011
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 #ifndef __ASM_CMPXCHG_H
8 #define __ASM_CMPXCHG_H
10 #include <linux/mmdebug.h>
11 #include <linux/types.h>
12 #include <linux/bug.h>
14 #define cmpxchg(ptr, o, n) \
16 __typeof__(*(ptr)) __o = (o); \
17 __typeof__(*(ptr)) __n = (n); \
18 (__typeof__(*(ptr))) __sync_val_compare_and_swap((ptr),__o,__n);\
21 #define cmpxchg64 cmpxchg
22 #define cmpxchg_local cmpxchg
23 #define cmpxchg64_local cmpxchg
25 #define xchg(ptr, x) \
27 __typeof__(ptr) __ptr = (ptr); \
28 __typeof__(*(ptr)) __old; \
31 } while (!__sync_bool_compare_and_swap(__ptr, __old, x)); \
35 #define __HAVE_ARCH_CMPXCHG
37 #define __cmpxchg_double_op(p1, p2, o1, o2, n1, n2, insn) \
39 register __typeof__(*(p1)) __old1 asm("2") = (o1); \
40 register __typeof__(*(p2)) __old2 asm("3") = (o2); \
41 register __typeof__(*(p1)) __new1 asm("4") = (n1); \
42 register __typeof__(*(p2)) __new2 asm("5") = (n2); \
45 insn " %[old],%[new],%[ptr]\n" \
48 : [cc] "=d" (cc), [old] "+d" (__old1), "+d" (__old2) \
49 : [new] "d" (__new1), "d" (__new2), \
50 [ptr] "Q" (*(p1)), "Q" (*(p2)) \
55 #define __cmpxchg_double_4(p1, p2, o1, o2, n1, n2) \
56 __cmpxchg_double_op(p1, p2, o1, o2, n1, n2, "cds")
58 #define __cmpxchg_double_8(p1, p2, o1, o2, n1, n2) \
59 __cmpxchg_double_op(p1, p2, o1, o2, n1, n2, "cdsg")
61 extern void __cmpxchg_double_called_with_bad_pointer(void);
63 #define __cmpxchg_double(p1, p2, o1, o2, n1, n2) \
66 switch (sizeof(*(p1))) { \
68 __ret = __cmpxchg_double_4(p1, p2, o1, o2, n1, n2); \
71 __ret = __cmpxchg_double_8(p1, p2, o1, o2, n1, n2); \
74 __cmpxchg_double_called_with_bad_pointer(); \
79 #define cmpxchg_double(p1, p2, o1, o2, n1, n2) \
81 __typeof__(p1) __p1 = (p1); \
82 __typeof__(p2) __p2 = (p2); \
83 BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \
84 BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \
85 VM_BUG_ON((unsigned long)((__p1) + 1) != (unsigned long)(__p2));\
86 __cmpxchg_double_8(__p1, __p2, o1, o2, n1, n2); \
89 #define system_has_cmpxchg_double() 1
91 #endif /* __ASM_CMPXCHG_H */