Qt 4.8
qatomic_s390.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QATOMIC_S390_H
43 #define QATOMIC_S390_H
44 
46 
48 
49 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
50 
52 { return true; }
54 { return false; }
55 
56 #define Q_ATOMIC_INT_TEST_AND_SET_IS_ALWAYS_NATIVE
57 
59 { return true; }
61 { return false; }
62 
63 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
64 
66 { return true; }
68 { return false; }
69 
70 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_ALWAYS_NATIVE
71 
73 { return true; }
75 { return false; }
76 
77 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
78 
79 template <typename T>
81 { return true; }
82 template <typename T>
84 { return false; }
85 
86 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
87 
88 template <typename T>
90 { return true; }
91 template <typename T>
93 { return false; }
94 
95 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_ALWAYS_NATIVE
96 
97 template <typename T>
99 { return true; }
100 template <typename T>
102 { return false; }
103 
104 #ifdef __GNUC__
105 #define __GNU_EXTENSION __extension__
106 #else
107 #define __GNU_EXTENSION
108 #endif
109 
110 #define __CS_LOOP(ptr, op_val, op_string, pre, post) __GNU_EXTENSION ({ \
111  volatile int old_val, new_val; \
112  __asm__ __volatile__(pre \
113  " l %0,0(%3)\n" \
114  "0: lr %1,%0\n" \
115  op_string " %1,%4\n" \
116  " cs %0,%1,0(%3)\n" \
117  " jl 0b\n" \
118  post \
119  : "=&d" (old_val), "=&d" (new_val), \
120  "=m" (*ptr) \
121  : "a" (ptr), "d" (op_val), \
122  "m" (*ptr) \
123  : "cc", "memory" ); \
124  new_val; \
125 })
126 
127 #define __CS_OLD_LOOP(ptr, op_val, op_string, pre, post ) __GNU_EXTENSION ({ \
128  volatile int old_val, new_val; \
129  __asm__ __volatile__(pre \
130  " l %0,0(%3)\n" \
131  "0: lr %1,%0\n" \
132  op_string " %1,%4\n" \
133  " cs %0,%1,0(%3)\n" \
134  " jl 0b\n" \
135  post \
136  : "=&d" (old_val), "=&d" (new_val), \
137  "=m" (*ptr) \
138  : "a" (ptr), "d" (op_val), \
139  "m" (*ptr) \
140  : "cc", "memory" ); \
141  old_val; \
142 })
143 
144 #ifdef __s390x__
145 #define __CSG_OLD_LOOP(ptr, op_val, op_string, pre, post) __GNU_EXTENSION ({ \
146  long old_val, new_val; \
147  __asm__ __volatile__(pre \
148  " lg %0,0(%3)\n" \
149  "0: lgr %1,%0\n" \
150  op_string " %1,%4\n" \
151  " csg %0,%1,0(%3)\n" \
152  " jl 0b\n" \
153  post \
154  : "=&d" (old_val), "=&d" (new_val), \
155  "=m" (*ptr) \
156  : "a" (ptr), "d" (op_val), \
157  "m" (*ptr) \
158  : "cc", "memory" ); \
159  old_val; \
160 })
161 #endif
162 
163 inline bool QBasicAtomicInt::ref()
164 {
165  return __CS_LOOP(&_q_value, 1, "ar", "", "") != 0;
166 }
167 
168 inline bool QBasicAtomicInt::deref()
169 {
170  return __CS_LOOP(&_q_value, 1, "sr", "", "") != 0;
171 }
172 
173 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
174 {
175  int retval;
176  __asm__ __volatile__(
177  " lr %0,%3\n"
178  " cs %0,%4,0(%2)\n"
179  " ipm %0\n"
180  " srl %0,28\n"
181  "0:"
182  : "=&d" (retval), "=m" (_q_value)
183  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
184  "m" (_q_value) : "cc", "memory" );
185  return retval == 0;
186 }
187 
188 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
189 {
190  int retval;
191  __asm__ __volatile__(
192  " lr %0,%3\n"
193  " cs %0,%4,0(%2)\n"
194  " ipm %0\n"
195  " srl %0,28\n"
196  "0:\n"
197  " bcr 15,0\n"
198  : "=&d" (retval), "=m" (_q_value)
199  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
200  "m" (_q_value) : "cc", "memory" );
201  return retval == 0;
202 }
203 
204 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
205 {
206  int retval;
207  __asm__ __volatile__(
208  " bcr 15,0\n"
209  " lr %0,%3\n"
210  " cs %0,%4,0(%2)\n"
211  " ipm %0\n"
212  " srl %0,28\n"
213  "0:"
214  : "=&d" (retval), "=m" (_q_value)
215  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
216  "m" (_q_value) : "cc", "memory" );
217  return retval == 0;
218 }
219 
220 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
221 {
222  return testAndSetAcquire(expectedValue, newValue);
223 }
224 
225 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
226 {
227  return __CS_OLD_LOOP(&_q_value, newValue, "lr", "", "");
228 }
229 
230 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
231 {
232  return __CS_OLD_LOOP(&_q_value, newValue, "lr", "", "bcr 15,0\n");
233 }
234 
235 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
236 {
237  return __CS_OLD_LOOP(&_q_value, newValue, "lr", "bcr 15,0\n", "");
238 }
239 
240 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
241 {
242  return fetchAndStoreAcquire(newValue);
243 }
244 
245 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
246 {
247  return fetchAndAddOrdered(valueToAdd);
248 }
249 
250 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
251 {
252  return fetchAndAddOrdered(valueToAdd);
253 }
254 
255 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
256 {
257  return fetchAndAddOrdered(valueToAdd);
258 }
259 
260 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
261 {
262  return __CS_OLD_LOOP(&_q_value, valueToAdd, "ar", "", "bcr 15,0\n");
263 }
264 
265 template <typename T>
266 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
267 {
268  int retval;
269 
270 #ifndef __s390x__
271  __asm__ __volatile__(
272  " lr %0,%3\n"
273  " cs %0,%4,0(%2)\n"
274  " ipm %0\n"
275  " srl %0,28\n"
276  "0:"
277  : "=&d" (retval), "=m" (_q_value)
278  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
279  "m" (_q_value) : "cc", "memory" );
280 #else
281  __asm__ __volatile__(
282  " lgr %0,%3\n"
283  " csg %0,%4,0(%2)\n"
284  " ipm %0\n"
285  " srl %0,28\n"
286  "0:"
287  : "=&d" (retval), "=m" (_q_value)
288  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
289  "m" (_q_value) : "cc", "memory" );
290 #endif
291 
292  return retval == 0;
293 }
294 
295 template <typename T>
296 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
297 {
298  int retval;
299 
300 #ifndef __s390x__
301  __asm__ __volatile__(
302  " lr %0,%3\n"
303  " cs %0,%4,0(%2)\n"
304  " ipm %0\n"
305  " srl %0,28\n"
306  "0:\n"
307  " bcr 15,0\n"
308  : "=&d" (retval), "=m" (_q_value)
309  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
310  "m" (_q_value) : "cc", "memory" );
311 #else
312  __asm__ __volatile__(
313  " lgr %0,%3\n"
314  " csg %0,%4,0(%2)\n"
315  " ipm %0\n"
316  " srl %0,28\n"
317  "0:\n"
318  " bcr 15,0\n"
319  : "=&d" (retval), "=m" (_q_value)
320  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
321  "m" (_q_value) : "cc", "memory" );
322 #endif
323 
324  return retval == 0;
325 }
326 
327 template <typename T>
328 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
329 {
330  int retval;
331 
332 #ifndef __s390x__
333  __asm__ __volatile__(
334  " bcr 15,0\n"
335  " lr %0,%3\n"
336  " cs %0,%4,0(%2)\n"
337  " ipm %0\n"
338  " srl %0,28\n"
339  "0:"
340  : "=&d" (retval), "=m" (_q_value)
341  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
342  "m" (_q_value) : "cc", "memory" );
343 #else
344  __asm__ __volatile__(
345  " bcr 15,0\n"
346  " lgr %0,%3\n"
347  " csg %0,%4,0(%2)\n"
348  " ipm %0\n"
349  " srl %0,28\n"
350  "0:"
351  : "=&d" (retval), "=m" (_q_value)
352  : "a" (&_q_value), "d" (expectedValue) , "d" (newValue),
353  "m" (_q_value) : "cc", "memory" );
354 #endif
355 
356  return retval == 0;
357 }
358 
359 template <typename T>
360 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
361 {
362  return testAndSetAcquire(expectedValue, newValue);
363 }
364 
365 template <typename T>
367 {
368 #ifndef __s390x__
369  return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "", "");
370 #else
371  return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "", "");
372 #endif
373 }
374 
375 template <typename T>
377 {
378 #ifndef __s390x__
379  return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "", "bcr 15,0 \n");
380 #else
381  return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "", "bcr 15,0 \n");
382 #endif
383 }
384 
385 template <typename T>
387 {
388 #ifndef __s390x__
389  return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "bcr 15,0 \n", "");
390 #else
391  return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "bcr 15,0\n", "");
392 #endif
393 }
394 
395 template <typename T>
397 {
398  return fetchAndStoreAcquire(newValue);
399 }
400 
401 
402 template <typename T>
404 {
405  return fetchAndAddOrdered(valueToAdd);
406 }
407 
408 template <typename T>
410 {
411  return fetchAndAddOrdered(valueToAdd);
412 }
413 
414 template <typename T>
416 {
417  return fetchAndAddOrdered(valueToAdd);
418 }
419 
420 #undef __GNU_EXTENSION
421 
423 
425 
426 #endif // QATOMIC_S390_H
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:65
static bool isTestAndSetNative()
Definition: qatomic_alpha.h:58
int fetchAndStoreRelease(int newValue)
static bool isReferenceCountingNative()
Definition: qatomic_alpha.h:51
T * fetchAndAddRelaxed(qptrdiff valueToAdd)
volatile int _q_value
Definition: qbasicatomic.h:64
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:98
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
static bool isTestAndSetNative()
Definition: qatomic_alpha.h:80
static bool isFetchAndAddNative()
Definition: qatomic_alpha.h:72
T * fetchAndStoreRelease(T *newValue)
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:83
T * fetchAndAddRelease(qptrdiff valueToAdd)
bool testAndSetOrdered(T *expectedValue, T *newValue)
int fetchAndAddAcquire(int valueToAdd)
T * fetchAndAddAcquire(qptrdiff valueToAdd)
int fetchAndStoreRelaxed(int newValue)
bool testAndSetAcquire(int expectedValue, int newValue)
#define __CS_OLD_LOOP(ptr, op_val, op_string, pre, post)
Definition: qatomic_s390.h:127
bool testAndSetRelaxed(int expectedValue, int newValue)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int fetchAndStoreAcquire(int newValue)
QIntegerForSizeof< void * >::Signed qptrdiff
Definition: qglobal.h:987
T * fetchAndStoreOrdered(T *newValue)
#define Q_INLINE_TEMPLATE
Definition: qglobal.h:1713
int fetchAndAddRelease(int valueToAdd)
bool testAndSetOrdered(int expectedValue, int newValue)
T * fetchAndStoreAcquire(T *newValue)
static bool isFetchAndStoreWaitFree()
Definition: qatomic_alpha.h:67
static bool isTestAndSetWaitFree()
Definition: qatomic_alpha.h:60
static bool isReferenceCountingWaitFree()
Definition: qatomic_alpha.h:53
int fetchAndAddOrdered(int valueToAdd)
#define __CS_LOOP(ptr, op_val, op_string, pre, post)
Definition: qatomic_s390.h:110
static bool isFetchAndStoreWaitFree()
Definition: qatomic_alpha.h:92
static bool isFetchAndAddWaitFree()
Definition: qatomic_alpha.h:74
static bool isFetchAndAddWaitFree()
bool testAndSetRelease(int expectedValue, int newValue)
int fetchAndAddRelaxed(int valueToAdd)
int fetchAndStoreOrdered(int newValue)
bool testAndSetRelaxed(T *expectedValue, T *newValue)
bool testAndSetRelease(T *expectedValue, T *newValue)
#define QT_END_HEADER
Definition: qglobal.h:137
T * fetchAndStoreRelaxed(T *newValue)
static bool isFetchAndStoreNative()
Definition: qatomic_alpha.h:89
bool testAndSetAcquire(T *expectedValue, T *newValue)