Qt 4.8
qatomic_sh4a.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_SH4A_H
43 #define QATOMIC_SH4A_H
44 
46 
48 
49 
51 
53 
54 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
55 
57 { return true; }
59 { return false; }
60 
61 #define Q_ATOMIC_INT_TEST_AND_SET_IS_ALWAYS_NATIVE
62 
64 { return true; }
66 { return false; }
67 
68 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
69 
71 { return true; }
73 { return false; }
74 
75 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_ALWAYS_NATIVE
76 
78 { return true; }
80 { return false; }
81 
82 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
83 
84 template <typename T>
86 { return true; }
87 template <typename T>
89 { return false; }
90 
91 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
92 
93 template <typename T>
95 { return true; }
96 template <typename T>
98 { return false; }
99 
100 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_ALWAYS_NATIVE
101 
102 template <typename T>
104 { return true; }
105 template <typename T>
107 { return false; }
108 
110 
111 #if !defined(Q_CC_GNU)
112 # error "SH-4A support has not been added for this compiler"
113 #else
114 
115 inline bool QBasicAtomicInt::ref()
116 {
117  register int newValue asm("r0");
118  asm volatile("0:\n"
119  "movli.l @%[_q_value], %[newValue]\n"
120  "add #1,%[newValue]\n"
121  "movco.l %[newValue], @%[_q_value]\n"
122  "bf 0b\n"
123  : [newValue] "=&r" (newValue),
124  "+m" (_q_value)
125  : [_q_value] "r" (&_q_value)
126  : "cc", "memory");
127  return newValue != 0;
128 }
129 
130 inline bool QBasicAtomicInt::deref()
131 {
132  register int newValue asm("r0");
133  asm volatile("0:\n"
134  "movli.l @%[_q_value], %[newValue]\n"
135  "add #-1,%[newValue]\n"
136  "movco.l %[newValue], @%[_q_value]\n"
137  "bf 0b\n"
138  : [newValue] "=&r" (newValue),
139  "+m" (_q_value)
140  : [_q_value] "r" (&_q_value)
141  : "cc", "memory");
142  return newValue != 0;
143 }
144 
145 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
146 {
147  register int result;
148  asm volatile("0:\n"
149  "movli.l @%[_q_value], r0\n"
150  "xor %[expectedValue], r0\n"
151  "cmp/eq #0, r0\n"
152  "bf/s 0f\n"
153  "mov r0, %[result]\n"
154  "mov %[newValue], r0\n"
155  "movco.l r0, @%[_q_value]\n"
156  "bf 0b\n"
157  "0:\n"
158  : [result] "=&r" (result),
159  "+m" (_q_value)
160  : [_q_value] "r" (&_q_value),
161  [expectedValue] "r" (expectedValue),
162  [newValue] "r" (newValue)
163  : "r0", "cc", "memory");
164  return result == 0;
165 }
166 
167 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
168 {
169  register int result;
170  asm volatile("0:\n"
171  "movli.l @%[_q_value], r0\n"
172  "xor %[expectedValue], r0\n"
173  "cmp/eq #0, r0\n"
174  "bf/s 0f\n"
175  "mov r0, %[result]\n"
176  "mov %[newValue], r0\n"
177  "movco.l r0, @%[_q_value]\n"
178  "bf 0b\n"
179  "synco\n"
180  "0:\n"
181  : [result] "=&r" (result),
182  "+m" (_q_value)
183  : [_q_value] "r" (&_q_value),
184  [expectedValue] "r" (expectedValue),
185  [newValue] "r" (newValue)
186  : "r0", "cc", "memory");
187  return result == 0;
188 }
189 
190 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
191 {
192  register int result;
193  asm volatile("synco\n"
194  "0:\n"
195  "movli.l @%[_q_value], r0\n"
196  "xor %[expectedValue], r0\n"
197  "cmp/eq #0, r0\n"
198  "bf/s 0f\n"
199  "mov r0, %[result]\n"
200  "mov %[newValue], r0\n"
201  "movco.l r0, @%[_q_value]\n"
202  "bf 0b\n"
203  "0:\n"
204  : [result] "=&r" (result),
205  "+m" (_q_value)
206  : [_q_value] "r" (&_q_value),
207  [expectedValue] "r" (expectedValue),
208  [newValue] "r" (newValue)
209  : "r0", "cc", "memory");
210  return result == 0;
211 }
212 
213 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
214 {
215  return testAndSetAcquire(expectedValue, newValue);
216 }
217 
218 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
219 {
220  register int originalValue;
221  asm volatile("0:\n"
222  "movli.l @%[_q_value], r0\n"
223  "mov r0, %[originalValue]\n"
224  "mov %[newValue], r0\n"
225  "movco.l r0, @%[_q_value]\n"
226  "bf 0b\n"
227  : [originalValue] "=&r" (originalValue),
228  "+m" (_q_value)
229  : [_q_value] "r" (&_q_value),
230  [newValue] "r" (newValue)
231  : "r0", "cc", "memory");
232  return originalValue;
233 }
234 
235 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
236 {
237  register int originalValue;
238  asm volatile("0:\n"
239  "movli.l @%[_q_value], r0\n"
240  "mov r0, %[originalValue]\n"
241  "mov %[newValue], r0\n"
242  "movco.l r0, @%[_q_value]\n"
243  "bf 0b\n"
244  "synco\n"
245  : [originalValue] "=&r" (originalValue),
246  "+m" (_q_value)
247  : [_q_value] "r" (&_q_value),
248  [newValue] "r" (newValue)
249  : "r0", "cc", "memory");
250  return originalValue;
251 }
252 
253 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
254 {
255  register int originalValue;
256  asm volatile("synco\n"
257  "0:\n"
258  "movli.l @%[_q_value], r0\n"
259  "mov r0, %[originalValue]\n"
260  "mov %[newValue], r0\n"
261  "movco.l r0, @%[_q_value]\n"
262  "bf 0b\n"
263  : [originalValue] "=&r" (originalValue),
264  "+m" (_q_value)
265  : [_q_value] "r" (&_q_value),
266  [newValue] "r" (newValue)
267  : "r0", "cc", "memory");
268  return originalValue;
269 }
270 
271 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
272 {
273  return fetchAndStoreAcquire(newValue);
274 }
275 
276 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
277 {
278  register int originalValue;
279  asm volatile("0:\n"
280  "movli.l @%[_q_value], r0\n"
281  "mov r0, %[originalValue]\n"
282  "add %[valueToAdd], r0\n"
283  "movco.l r0, @%[_q_value]\n"
284  "bf 0b\n"
285  : [originalValue] "=&r" (originalValue),
286  "+m" (_q_value)
287  : [_q_value] "r" (&_q_value),
288  [valueToAdd] "r" (valueToAdd)
289  : "r0", "cc", "memory");
290  return originalValue;
291 }
292 
293 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
294 {
295  register int originalValue;
296  asm volatile("0:\n"
297  "movli.l @%[_q_value], r0\n"
298  "mov r0, %[originalValue]\n"
299  "add %[valueToAdd], r0\n"
300  "movco.l r0, @%[_q_value]\n"
301  "bf 0b\n"
302  "synco\n"
303  : [originalValue] "=&r" (originalValue),
304  "+m" (_q_value)
305  : [_q_value] "r" (&_q_value),
306  [valueToAdd] "r" (valueToAdd)
307  : "r0", "cc", "memory");
308  return originalValue;
309 }
310 
311 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
312 {
313  register int originalValue;
314  asm volatile("synco\n"
315  "0:\n"
316  "movli.l @%[_q_value], r0\n"
317  "mov r0, %[originalValue]\n"
318  "add %[valueToAdd], r0\n"
319  "movco.l r0, @%[_q_value]\n"
320  "bf 0b\n"
321  : [originalValue] "=&r" (originalValue),
322  "+m" (_q_value)
323  : [_q_value] "r" (&_q_value),
324  [valueToAdd] "r" (valueToAdd)
325  : "r0", "cc", "memory");
326  return originalValue;
327 }
328 
329 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
330 {
331  return fetchAndAddAcquire(valueToAdd);
332 }
333 
334 template <typename T>
335 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
336 {
337  register T *result;
338  asm volatile("0:\n"
339  "movli.l @%[_q_value], r0\n"
340  "xor %[expectedValue], r0\n"
341  "cmp/eq #0, r0\n"
342  "bf/s 0f\n"
343  "mov r0, %[result]\n"
344  "mov %[newValue], r0\n"
345  "movco.l r0, @%[_q_value]\n"
346  "bf 0b\n"
347  "0:\n"
348  : [result] "=&r" (result),
349  "+m" (_q_value)
350  : [_q_value] "r" (&_q_value),
351  [expectedValue] "r" (expectedValue),
352  [newValue] "r" (newValue)
353  : "r0", "cc", "memory");
354  return result == 0;
355 }
356 
357 template <typename T>
358 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
359 {
360  register T *result;
361  asm volatile("0:\n"
362  "movli.l @%[_q_value], r0\n"
363  "xor %[expectedValue], r0\n"
364  "cmp/eq #0, r0\n"
365  "bf/s 0f\n"
366  "mov r0, %[result]\n"
367  "mov %[newValue], r0\n"
368  "movco.l r0, @%[_q_value]\n"
369  "bf 0b\n"
370  "synco\n"
371  "0:\n"
372  : [result] "=&r" (result),
373  "+m" (_q_value)
374  : [_q_value] "r" (&_q_value),
375  [expectedValue] "r" (expectedValue),
376  [newValue] "r" (newValue)
377  : "r0", "cc", "memory");
378  return result == 0;
379 }
380 
381 template <typename T>
382 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
383 {
384  register T *result;
385  asm volatile("synco\n"
386  "0:\n"
387  "movli.l @%[_q_value], r0\n"
388  "xor %[expectedValue], r0\n"
389  "cmp/eq #0, r0\n"
390  "bf/s 0f\n"
391  "mov r0, %[result]\n"
392  "mov %[newValue], r0\n"
393  "movco.l r0, @%[_q_value]\n"
394  "bf 0b\n"
395  "0:\n"
396  : [result] "=&r" (result),
397  "+m" (_q_value)
398  : [_q_value] "r" (&_q_value),
399  [expectedValue] "r" (expectedValue),
400  [newValue] "r" (newValue)
401  : "r0", "cc", "memory");
402  return result == 0;
403 }
404 
405 template <typename T>
406 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
407 {
408  return testAndSetAcquire(expectedValue, newValue);
409 }
410 
411 template <typename T>
413 {
414  register T *originalValue;
415  asm volatile("0:\n"
416  "movli.l @%[_q_value], r0\n"
417  "mov r0, %[originalValue]\n"
418  "mov %[newValue], r0\n"
419  "movco.l r0, @%[_q_value]\n"
420  "bf 0b\n"
421  : [originalValue] "=&r" (originalValue),
422  "+m" (_q_value)
423  : [_q_value] "r" (&_q_value),
424  [newValue] "r" (newValue)
425  : "r0", "cc", "memory");
426  return originalValue;
427 }
428 
429 template <typename T>
431 {
432  register T *originalValue;
433  asm volatile("0:\n"
434  "movli.l @%[_q_value], r0\n"
435  "mov r0, %[originalValue]\n"
436  "mov %[newValue], r0\n"
437  "movco.l r0, @%[_q_value]\n"
438  "bf 0b\n"
439  "synco\n"
440  : [originalValue] "=&r" (originalValue),
441  "+m" (_q_value)
442  : [_q_value] "r" (&_q_value),
443  [newValue] "r" (newValue)
444  : "r0", "cc", "memory");
445  return originalValue;
446 }
447 
448 template <typename T>
450 {
451  register T *originalValue;
452  asm volatile("synco\n"
453  "0:\n"
454  "movli.l @%[_q_value], r0\n"
455  "mov r0, %[originalValue]\n"
456  "mov %[newValue], r0\n"
457  "movco.l r0, @%[_q_value]\n"
458  "bf 0b\n"
459  : [originalValue] "=&r" (originalValue),
460  "+m" (_q_value)
461  : [_q_value] "r" (&_q_value),
462  [newValue] "r" (newValue)
463  : "r0", "cc", "memory");
464  return originalValue;
465 }
466 
467 template <typename T>
469 {
470  return fetchAndStoreAcquire(newValue);
471 }
472 
473 template <typename T>
475 {
476  register T *originalValue;
477  asm volatile("0:\n"
478  "movli.l @%[_q_value], r0\n"
479  "mov r0, %[originalValue]\n"
480  "add %[valueToAdd], r0\n"
481  "movco.l r0, @%[_q_value]\n"
482  "bf 0b\n"
483  : [originalValue] "=&r" (originalValue),
484  "+m" (_q_value)
485  : [_q_value] "r" (&_q_value),
486  [valueToAdd] "r" (valueToAdd * sizeof(T))
487  : "r0", "cc", "memory");
488  return originalValue;
489 }
490 
491 template <typename T>
493 {
494  register T *originalValue;
495  asm volatile("0:\n"
496  "movli.l @%[_q_value], r0\n"
497  "mov r0, %[originalValue]\n"
498  "add %[valueToAdd], r0\n"
499  "movco.l r0, @%[_q_value]\n"
500  "bf 0b\n"
501  "synco\n"
502  : [originalValue] "=&r" (originalValue),
503  "+m" (_q_value)
504  : [_q_value] "r" (&_q_value),
505  [valueToAdd] "r" (valueToAdd * sizeof(T))
506  : "r0", "cc", "memory");
507  return originalValue;
508 }
509 
510 template <typename T>
512 {
513  register T *originalValue;
514  asm volatile("synco\n"
515  "0:\n"
516  "movli.l @%[_q_value], r0\n"
517  "mov r0, %[originalValue]\n"
518  "add %[valueToAdd], r0\n"
519  "movco.l r0, @%[_q_value]\n"
520  "bf 0b\n"
521  : [originalValue] "=&r" (originalValue),
522  "+m" (_q_value)
523  : [_q_value] "r" (&_q_value),
524  [valueToAdd] "r" (valueToAdd * sizeof(T))
525  : "r0", "cc", "memory");
526  return originalValue;
527 }
528 
529 template <typename T>
531 {
532  return fetchAndAddAcquire(valueToAdd);
533 }
534 
535 #endif // Q_CC_GNU
536 
537 #endif // QATOMIC_SH4A_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)
T * fetchAndAddOrdered(qptrdiff valueToAdd)
bool testAndSetAcquire(int expectedValue, int newValue)
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)
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)