917dbf2f471941457adcfff198f25c1f08747ce9
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 #ifndef __SIZEOF_LONG__
33 #define __SIZEOF_LONG__ 8
35 #define __SIZEOF_LONG__ 4
40 #define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
43 #define uatomic_set(addr, v) \
45 ACCESS_ONCE(*(addr)) = (v); \
48 #define uatomic_read(addr) ACCESS_ONCE(*(addr))
50 static inline __attribute__((always_inline
))
51 unsigned int uatomic_exchange_32(volatile unsigned int *addr
, unsigned int val
)
58 : "=&r"(result
), "=m" (*addr
)
59 : "r"(val
), "m" (*addr
)
65 #if (BITS_PER_LONG == 64)
67 static inline __attribute__((always_inline
))
68 unsigned long uatomic_exchange_64(volatile unsigned long *addr
,
76 : "=&r"(result
), "=m" (*addr
)
77 : "r"(val
), "m" (*addr
)
85 static inline __attribute__((always_inline
))
86 unsigned long _uatomic_exchange(volatile void *addr
, unsigned long val
, int len
)
90 return uatomic_exchange_32(addr
, val
);
91 #if (BITS_PER_LONG == 64)
93 return uatomic_exchange_64(addr
, val
);
96 __asm__
__volatile__(".long 0xd00d00");
102 #define uatomic_xchg(addr, v) \
103 (__typeof__(*(addr))) _uatomic_exchange((addr), (unsigned long)(v), \
107 static inline __attribute__((always_inline
))
108 void uatomic_add_32(volatile unsigned int *addr
, unsigned int val
)
110 unsigned int result
, old
;
112 __asm__
__volatile__(
118 : "=&r"(old
), "+m" (*addr
),
124 #if (BITS_PER_LONG == 64)
126 static inline __attribute__((always_inline
))
127 void uatomic_add_64(volatile unsigned long *addr
, unsigned long val
)
129 unsigned long result
, old
;
131 __asm__
__volatile__(
137 : "=&r"(old
), "+m" (*addr
),
145 static inline __attribute__((always_inline
))
146 void _uatomic_add(void *addr
, unsigned long val
, int len
)
150 uatomic_add_32(addr
, val
);
152 #if (BITS_PER_LONG == 64)
154 uatomic_add_64(addr
, val
);
158 __asm__
__volatile__(".long 0xd00d00");
164 #define uatomic_add(addr, val) \
165 _uatomic_add((addr), (unsigned long)(val), sizeof(*(addr)))
167 static inline __attribute__((always_inline
))
168 unsigned int uatomic_cmpxchg_32(volatile unsigned int *addr
, unsigned int old
,
171 __asm__
__volatile__(
173 : "+r"(old
), "+m"(*addr
)
180 #if (BITS_PER_LONG == 64)
182 static inline __attribute__((always_inline
))
183 unsigned long uatomic_cmpxchg_64(volatile unsigned long *addr
,
184 unsigned long old
, unsigned long new)
186 __asm__
__volatile__(
188 : "+r"(old
), "+m"(*addr
)
197 unsigned long _uatomic_cmpxchg(void *addr
, unsigned long old
,
198 unsigned long new, int len
)
202 return uatomic_cmpxchg_32(addr
, old
, new);
203 #if (BITS_PER_LONG == 64)
205 return uatomic_cmpxchg_64(addr
, old
, new);
208 __asm__
__volatile__(".long 0xd00d00");
214 #define uatomic_cmpxchg(addr, old, new) \
215 (__typeof__(*(addr))) _uatomic_cmpxchg((addr), \
216 (unsigned long)(old), \
217 (unsigned long)(new), \
220 #endif /* _URCU_ARCH_ATOMIC_S390_H */
This page took 0.03593 seconds and 4 git commands to generate.