1 #ifndef _URCU_ARCH_ATOMIC_S390_H
2 #define _URCU_ARCH_ATOMIC_S390_H
5 * Atomic exchange operations for the S390 architecture. Based on information
6 * taken from the Principles of Operation Appendix A "Conditional Swapping
7 * Instructions (CS, CDS)".
9 * Copyright (c) 2009 Novell, Inc.
10 * Author: Jan Blunck <jblunck@suse.de>
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to
14 * deal in the Software without restriction, including without limitation the
15 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 * sell copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 #include <urcu/compiler.h>
32 #include <urcu/system.h>
34 #ifndef __SIZEOF_LONG__
36 #define __SIZEOF_LONG__ 8
38 #define __SIZEOF_LONG__ 4
43 #define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
46 #define uatomic_set(addr, v) STORE_SHARED(*(addr), (v))
47 #define uatomic_read(addr) LOAD_SHARED(*(addr))
49 static inline __attribute__((always_inline
))
50 unsigned int uatomic_exchange_32(volatile unsigned int *addr
, unsigned int val
)
57 : "=&r"(result
), "=m" (*addr
)
58 : "r"(val
), "m" (*addr
)
64 #if (BITS_PER_LONG == 64)
66 static inline __attribute__((always_inline
))
67 unsigned long uatomic_exchange_64(volatile unsigned long *addr
,
75 : "=&r"(result
), "=m" (*addr
)
76 : "r"(val
), "m" (*addr
)
84 static inline __attribute__((always_inline
))
85 unsigned long _uatomic_exchange(volatile void *addr
, unsigned long val
, int len
)
89 return uatomic_exchange_32(addr
, val
);
90 #if (BITS_PER_LONG == 64)
92 return uatomic_exchange_64(addr
, val
);
95 __asm__
__volatile__(".long 0xd00d00");
101 #define uatomic_xchg(addr, v) \
102 (__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
106 static inline __attribute__((always_inline
))
107 void uatomic_add_32(volatile unsigned int *addr
, unsigned int val
)
109 unsigned int result
, old
;
111 __asm__
__volatile__(
117 : "=&r"(old
), "+m" (*addr
),
123 #if (BITS_PER_LONG == 64)
125 static inline __attribute__((always_inline
))
126 void uatomic_add_64(volatile unsigned long *addr
, unsigned long val
)
128 unsigned long result
, old
;
130 __asm__
__volatile__(
136 : "=&r"(old
), "+m" (*addr
),
144 static inline __attribute__((always_inline
))
145 void _uatomic_add(void *addr
, unsigned long val
, int len
)
149 uatomic_add_32(addr
, val
);
151 #if (BITS_PER_LONG == 64)
153 uatomic_add_64(addr
, val
);
157 __asm__
__volatile__(".long 0xd00d00");
163 #define uatomic_add(addr, val) \
164 _uatomic_add((addr), (unsigned long)(val), sizeof(*(addr)))
166 static inline __attribute__((always_inline
))
167 unsigned int uatomic_cmpxchg_32(volatile unsigned int *addr
, unsigned int old
,
170 __asm__
__volatile__(
172 : "+r"(old
), "+m"(*addr
)
179 #if (BITS_PER_LONG == 64)
181 static inline __attribute__((always_inline
))
182 unsigned long uatomic_cmpxchg_64(volatile unsigned long *addr
,
183 unsigned long old
, unsigned long new)
185 __asm__
__volatile__(
187 : "+r"(old
), "+m"(*addr
)
196 unsigned long _uatomic_cmpxchg(void *addr
, unsigned long old
,
197 unsigned long new, int len
)
201 return uatomic_cmpxchg_32(addr
, old
, new);
202 #if (BITS_PER_LONG == 64)
204 return uatomic_cmpxchg_64(addr
, old
, new);
207 __asm__
__volatile__(".long 0xd00d00");
213 #define uatomic_cmpxchg(addr, old, new) \
214 (__typeof__(*(addr))) _uatomic_cmpxchg((addr), \
215 (unsigned long)(old), \
216 (unsigned long)(new), \
219 #define URCU_CAS_AVAIL() 1
221 #endif /* _URCU_ARCH_ATOMIC_S390_H */
This page took 0.036113 seconds and 5 git commands to generate.