Qt 4.8
qatomic_armv6.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_ARMV6_H
43 #define QATOMIC_ARMV6_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 #ifndef Q_CC_RVCT
105 
106 #ifndef Q_DATA_MEMORY_BARRIER
107 # define Q_DATA_MEMORY_BARRIER asm volatile("":::"memory")
108 #endif
109 #ifndef Q_COMPILER_MEMORY_BARRIER
110 # define Q_COMPILER_MEMORY_BARRIER asm volatile("":::"memory")
111 #endif
112 
113 inline bool QBasicAtomicInt::ref()
114 {
115  register int newValue;
116  register int result;
117  asm volatile("0:\n"
118  "ldrex %[newValue], [%[_q_value]]\n"
119  "add %[newValue], %[newValue], #1\n"
120  "strex %[result], %[newValue], [%[_q_value]]\n"
121  "teq %[result], #0\n"
122  "bne 0b\n"
123  : [newValue] "=&r" (newValue),
124  [result] "=&r" (result),
125  "+m" (_q_value)
126  : [_q_value] "r" (&_q_value)
127  : "cc", "memory");
128  return newValue != 0;
129 }
130 
131 inline bool QBasicAtomicInt::deref()
132 {
133  register int newValue;
134  register int result;
135  asm volatile("0:\n"
136  "ldrex %[newValue], [%[_q_value]]\n"
137  "sub %[newValue], %[newValue], #1\n"
138  "strex %[result], %[newValue], [%[_q_value]]\n"
139  "teq %[result], #0\n"
140  "bne 0b\n"
141  : [newValue] "=&r" (newValue),
142  [result] "=&r" (result),
143  "+m" (_q_value)
144  : [_q_value] "r" (&_q_value)
145  : "cc", "memory");
146  return newValue != 0;
147 }
148 
149 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
150 {
151  register int result;
152  asm volatile("0:\n"
153  "ldrex %[result], [%[_q_value]]\n"
154  "eors %[result], %[result], %[expectedValue]\n"
155  "itt eq\n"
156  "strexeq %[result], %[newValue], [%[_q_value]]\n"
157  "teqeq %[result], #1\n"
158  "beq 0b\n"
159  : [result] "=&r" (result),
160  "+m" (_q_value)
161  : [expectedValue] "r" (expectedValue),
162  [newValue] "r" (newValue),
163  [_q_value] "r" (&_q_value)
164  : "cc");
165  return result == 0;
166 }
167 
168 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
169 {
170  register int originalValue;
171  register int result;
172  asm volatile("0:\n"
173  "ldrex %[originalValue], [%[_q_value]]\n"
174  "strex %[result], %[newValue], [%[_q_value]]\n"
175  "teq %[result], #0\n"
176  "bne 0b\n"
177  : [originalValue] "=&r" (originalValue),
178  [result] "=&r" (result),
179  "+m" (_q_value)
180  : [newValue] "r" (newValue),
181  [_q_value] "r" (&_q_value)
182  : "cc");
183  return originalValue;
184 }
185 
186 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
187 {
188  register int originalValue;
189  register int newValue;
190  register int result;
191  asm volatile("0:\n"
192  "ldrex %[originalValue], [%[_q_value]]\n"
193  "add %[newValue], %[originalValue], %[valueToAdd]\n"
194  "strex %[result], %[newValue], [%[_q_value]]\n"
195  "teq %[result], #0\n"
196  "bne 0b\n"
197  : [originalValue] "=&r" (originalValue),
198  [newValue] "=&r" (newValue),
199  [result] "=&r" (result),
200  "+m" (_q_value)
201  : [valueToAdd] "r" (valueToAdd),
202  [_q_value] "r" (&_q_value)
203  : "cc");
204  return originalValue;
205 }
206 
207 template <typename T>
208 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
209 {
210  register T *result;
211  asm volatile("0:\n"
212  "ldrex %[result], [%[_q_value]]\n"
213  "eors %[result], %[result], %[expectedValue]\n"
214  "itt eq\n"
215  "strexeq %[result], %[newValue], [%[_q_value]]\n"
216  "teqeq %[result], #1\n"
217  "beq 0b\n"
218  : [result] "=&r" (result),
219  "+m" (_q_value)
220  : [expectedValue] "r" (expectedValue),
221  [newValue] "r" (newValue),
222  [_q_value] "r" (&_q_value)
223  : "cc");
224  return result == 0;
225 }
226 
227 template <typename T>
229 {
230  register T *originalValue;
231  register int result;
232  asm volatile("0:\n"
233  "ldrex %[originalValue], [%[_q_value]]\n"
234  "strex %[result], %[newValue], [%[_q_value]]\n"
235  "teq %[result], #0\n"
236  "bne 0b\n"
237  : [originalValue] "=&r" (originalValue),
238  [result] "=&r" (result),
239  "+m" (_q_value)
240  : [newValue] "r" (newValue),
241  [_q_value] "r" (&_q_value)
242  : "cc");
243  return originalValue;
244 }
245 
246 template <typename T>
248 {
249  register T *originalValue;
250  register T *newValue;
251  register int result;
252  asm volatile("0:\n"
253  "ldrex %[originalValue], [%[_q_value]]\n"
254  "add %[newValue], %[originalValue], %[valueToAdd]\n"
255  "strex %[result], %[newValue], [%[_q_value]]\n"
256  "teq %[result], #0\n"
257  "bne 0b\n"
258  : [originalValue] "=&r" (originalValue),
259  [newValue] "=&r" (newValue),
260  [result] "=&r" (result),
261  "+m" (_q_value)
262  : [valueToAdd] "r" (valueToAdd * sizeof(T)),
263  [_q_value] "r" (&_q_value)
264  : "cc");
265  return originalValue;
266 }
267 
268 #else
269 // This is Q_CC_RVCT
270 
271 // RVCT inline assembly documentation:
272 // http://www.keil.com/support/man/docs/armcc/armcc_chdcffdb.htm
273 // RVCT embedded assembly documentation:
274 // http://www.keil.com/support/man/docs/armcc/armcc_chddbeib.htm
275 
276 #if __TARGET_ARCH_THUMB-0 < 4
277 // save our pragma state and switch to ARM mode (unless using Thumb2)
278 # pragma push
279 # pragma arm
280 #endif
281 
282 #ifndef Q_DATA_MEMORY_BARRIER
283 # define Q_DATA_MEMORY_BARRIER __schedule_barrier()
284 #endif
285 #ifndef Q_COMPILER_MEMORY_BARRIER
286 # define Q_COMPILER_MEMORY_BARRIER __schedule_barrier()
287 #endif
288 
289 inline bool QBasicAtomicInt::ref()
290 {
291  register int newValue;
292  register int result;
293  retry:
294  __asm {
295  ldrex newValue, [&_q_value]
296  add newValue, newValue, #1
297  strex result, newValue, [&_q_value]
298  teq result, #0
299  bne retry
300  }
301  return newValue != 0;
302 }
303 
304 inline bool QBasicAtomicInt::deref()
305 {
306  register int newValue;
307  register int result;
308  retry:
309  __asm {
310  ldrex newValue, [&_q_value]
311  sub newValue, newValue, #1
312  strex result, newValue, [&_q_value]
313  teq result, #0
314  bne retry
315  }
316  return newValue != 0;
317 }
318 
319 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
320 {
321  register int result;
322  retry:
323  __asm {
324  ldrex result, [&_q_value]
325  eors result, result, expectedValue
326  strexeq result, newValue, [&_q_value]
327  teqeq result, #1
328  beq retry
329  }
330  return result == 0;
331 }
332 
333 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
334 {
335  register int originalValue;
336  register int result;
337  retry:
338  __asm {
339  ldrex originalValue, [&_q_value]
340  strex result, newValue, [&_q_value]
341  teq result, #0
342  bne retry
343  }
344  return originalValue;
345 }
346 
347 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
348 {
349  register int originalValue;
350  register int newValue;
351  register int result;
352  retry:
353  __asm {
354  ldrex originalValue, [&_q_value]
355  add newValue, originalValue, valueToAdd
356  strex result, newValue, [&_q_value]
357  teq result, #0
358  bne retry
359  }
360  return originalValue;
361 }
362 
363 template <typename T>
364 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
365 {
366  register T *result;
367  retry:
368  __asm {
369  ldrex result, [&_q_value]
370  eors result, result, expectedValue
371  strexeq result, newValue, [&_q_value]
372  teqeq result, #1
373  beq retry
374  }
375  return result == 0;
376 }
377 
378 template <typename T>
380 {
381  register T *originalValue;
382  register int result;
383  retry:
384  __asm {
385  ldrex originalValue, [&_q_value]
386  strex result, newValue, [&_q_value]
387  teq result, #0
388  bne retry
389  }
390  return originalValue;
391 }
392 
393 template <typename T>
395 {
396  register T *originalValue;
397  register T *newValue;
398  register int result;
399  retry:
400  __asm {
401  ldrex originalValue, [&_q_value]
402  add newValue, originalValue, valueToAdd * sizeof(T)
403  strex result, newValue, [&_q_value]
404  teq result, #0
405  bne retry
406  }
407  return originalValue;
408 }
409 
410 #if __TARGET_ARCH_THUMB-0 < 4
411 # pragma pop
412 #endif
413 
414 #endif
415 
416 // common code
417 
418 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
419 {
420  bool returnValue = testAndSetRelaxed(expectedValue, newValue);
422  return returnValue;
423 }
424 
425 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
426 {
428  return testAndSetRelaxed(expectedValue, newValue);
429 }
430 
431 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
432 {
434  bool returnValue = testAndSetRelaxed(expectedValue, newValue);
436  return returnValue;
437 }
438 
439 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
440 {
441  int returnValue = fetchAndStoreRelaxed(newValue);
443  return returnValue;
444 }
445 
446 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
447 {
449  return fetchAndStoreRelaxed(newValue);
450 }
451 
452 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
453 {
455  int returnValue = fetchAndStoreRelaxed(newValue);
457  return returnValue;
458 }
459 
460 
461 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
462 {
463  int returnValue = fetchAndAddRelaxed(valueToAdd);
465  return returnValue;
466 }
467 
468 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
469 {
471  return fetchAndAddRelaxed(valueToAdd);
472 }
473 
474 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
475 {
477  int returnValue = fetchAndAddRelaxed(valueToAdd);
479  return returnValue;
480 }
481 
482 template <typename T>
483 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
484 {
485  bool returnValue = testAndSetRelaxed(expectedValue, newValue);
487  return returnValue;
488 }
489 
490 template <typename T>
491 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
492 {
494  return testAndSetRelaxed(expectedValue, newValue);
495 }
496 
497 template <typename T>
498 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
499 {
501  bool returnValue = testAndSetAcquire(expectedValue, newValue);
503  return returnValue;
504 }
505 
506 template <typename T>
508 {
509  T *returnValue = fetchAndStoreRelaxed(newValue);
511  return returnValue;
512 }
513 
514 template <typename T>
516 {
518  return fetchAndStoreRelaxed(newValue);
519 }
520 
521 template <typename T>
523 {
525  T *returnValue = fetchAndStoreRelaxed(newValue);
527  return returnValue;
528 }
529 
530 template <typename T>
532 {
533  T *returnValue = fetchAndAddRelaxed(valueToAdd);
535  return returnValue;
536 }
537 
538 template <typename T>
540 {
542  return fetchAndAddRelaxed(valueToAdd);
543 }
544 
545 template <typename T>
547 {
549  T *returnValue = fetchAndAddRelaxed(valueToAdd);
551  return returnValue;
552 }
553 
554 #undef Q_DATA_MEMORY_BARRIER
555 #undef Q_COMPILER_MEMORY_BARRIER
556 
558 
560 
561 #endif // QATOMIC_ARMV6_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 add(aName)
#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()
#define Q_COMPILER_MEMORY_BARRIER
bool testAndSetRelease(int expectedValue, int newValue)
#define Q_DATA_MEMORY_BARRIER
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)