1 #ifndef _URCU_ARCH_UATOMIC_SPARC64_H
2 #define _URCU_ARCH_UATOMIC_SPARC64_H
5 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
6 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
7 * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved.
8 * Copyright (c) 2009 Mathieu Desnoyers
10 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
11 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
13 * Permission is hereby granted to use or copy this program
14 * for any purpose, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
19 * Code inspired from libuatomic_ops-1.2, inherited in part from the
20 * Boehm-Demers-Weiser conservative garbage collector.
23 #include <urcu/compiler.h>
24 #include <urcu/system.h>
26 #ifndef __SIZEOF_LONG__
27 #if (defined(__sparc_v8__) || defined(__sparc_v9__))
28 #define __SIZEOF_LONG__ 8
30 #define __SIZEOF_LONG__ 4
35 #define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
38 #define uatomic_set(addr, v) STORE_SHARED(*(addr), (v))
39 #define uatomic_read(addr) LOAD_SHARED(*(addr))
43 static inline __attribute__((always_inline
))
44 unsigned long _uatomic_cmpxchg(void *addr
, unsigned long old
,
45 unsigned long _new
, int len
)
50 __asm__
__volatile__ (
51 "membar #StoreLoad | #LoadLoad\n\t"
53 "membar #StoreLoad | #StoreStore\n\t"
55 : "r" (addr
), "r" (old
)
60 #if (BITS_PER_LONG == 64)
63 __asm__
__volatile__ (
64 "membar #StoreLoad | #LoadLoad\n\t"
66 "membar #StoreLoad | #StoreStore\n\t"
68 : "r" (addr
), "r" (old
)
80 #define uatomic_cmpxchg(addr, old, _new) \
81 ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\
82 (unsigned long)(_new), \
87 static inline __attribute__((always_inline
))
88 unsigned long _uatomic_exchange(void *addr
, unsigned long val
, int len
)
93 unsigned int old
, oldt
;
95 oldt
= uatomic_read((unsigned int *)addr
);
98 oldt
= _uatomic_cmpxchg(addr
, old
, val
, 4);
99 } while (oldt
!= old
);
103 #if (BITS_PER_LONG == 64)
106 unsigned long old
, oldt
;
108 oldt
= uatomic_read((unsigned long *)addr
);
111 oldt
= _uatomic_cmpxchg(addr
, old
, val
, 8);
112 } while (oldt
!= old
);
122 #define uatomic_xchg(addr, v) \
123 ((__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
126 /* uatomic_add_return */
128 static inline __attribute__((always_inline
))
129 unsigned long _uatomic_add_return(void *addr
, unsigned long val
,
135 unsigned int old
, oldt
;
137 oldt
= uatomic_read((unsigned int *)addr
);
140 oldt
= _uatomic_cmpxchg(addr
, old
, old
+ val
, 4);
141 } while (oldt
!= old
);
145 #if (BITS_PER_LONG == 64)
148 unsigned long old
, oldt
;
150 oldt
= uatomic_read((unsigned long *)addr
);
153 oldt
= _uatomic_cmpxchg(addr
, old
, old
+ val
, 8);
154 } while (oldt
!= old
);
164 #define uatomic_add_return(addr, v) \
165 ((__typeof__(*(addr))) _uatomic_add_return((addr), \
166 (unsigned long)(v), \
169 /* uatomic_sub_return, uatomic_add, uatomic_sub, uatomic_inc, uatomic_dec */
171 #define uatomic_sub_return(addr, v) uatomic_add_return((addr), -(v))
173 #define uatomic_add(addr, v) (void)uatomic_add_return((addr), (v))
174 #define uatomic_sub(addr, v) (void)uatomic_sub_return((addr), (v))
176 #define uatomic_inc(addr) uatomic_add((addr), 1)
177 #define uatomic_dec(addr) uatomic_add((addr), -1)
179 #define URCU_CAS_AVAIL() 1
180 #define compat_uatomic_cmpxchg(ptr, old, _new) uatomic_cmpxchg(ptr, old, _new)
182 #endif /* _URCU_ARCH_UATOMIC_PPC_H */
This page took 0.042436 seconds and 4 git commands to generate.