1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtCore module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QATOMIC_ARMV6_H
43 #define QATOMIC_ARMV6_H
48 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_ALWAYS_NATIVE
50 inline bool QBasicAtomicInt::isReferenceCountingNative()
52 inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
55 #define Q_ATOMIC_INT_TEST_AND_SET_IS_ALWAYS_NATIVE
57 inline bool QBasicAtomicInt::isTestAndSetNative()
59 inline bool QBasicAtomicInt::isTestAndSetWaitFree()
62 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_ALWAYS_NATIVE
64 inline bool QBasicAtomicInt::isFetchAndStoreNative()
66 inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
69 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_ALWAYS_NATIVE
71 inline bool QBasicAtomicInt::isFetchAndAddNative()
73 inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
76 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_ALWAYS_NATIVE
79 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::isTestAndSetNative()
82 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::isTestAndSetWaitFree()
85 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_ALWAYS_NATIVE
88 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::isFetchAndStoreNative()
91 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::isFetchAndStoreWaitFree()
94 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_ALWAYS_NATIVE
97 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::isFetchAndAddNative()
100 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::isFetchAndAddWaitFree()
105 inline bool QBasicAtomicInt::ref()
107 register int newValue
;
110 "ldrex %[newValue], [%[_q_value]]\n"
111 "add %[newValue], %[newValue], #1\n"
112 "strex %[result], %[newValue], [%[_q_value]]\n"
113 "teq %[result], #0\n"
115 : [newValue
] "=&r" (newValue
),
116 [result
] "=&r" (result
),
118 : [_q_value
] "r" (&_q_value
)
120 return newValue
!= 0;
123 inline bool QBasicAtomicInt::deref()
125 register int newValue
;
128 "ldrex %[newValue], [%[_q_value]]\n"
129 "sub %[newValue], %[newValue], #1\n"
130 "strex %[result], %[newValue], [%[_q_value]]\n"
131 "teq %[result], #0\n"
133 : [newValue
] "=&r" (newValue
),
134 [result
] "=&r" (result
),
136 : [_q_value
] "r" (&_q_value
)
138 return newValue
!= 0;
141 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue
, int newValue
)
145 "ldrex %[result], [%[_q_value]]\n"
146 "eors %[result], %[result], %[expectedValue]\n"
147 "strexeq %[result], %[newValue], [%[_q_value]]\n"
148 "teqeq %[result], #1\n"
150 : [result
] "=&r" (result
),
152 : [expectedValue
] "r" (expectedValue
),
153 [newValue
] "r" (newValue
),
154 [_q_value
] "r" (&_q_value
)
159 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue
)
161 register int originalValue
;
164 "ldrex %[originalValue], [%[_q_value]]\n"
165 "strex %[result], %[newValue], [%[_q_value]]\n"
166 "teq %[result], #0\n"
168 : [originalValue
] "=&r" (originalValue
),
169 [result
] "=&r" (result
),
171 : [newValue
] "r" (newValue
),
172 [_q_value
] "r" (&_q_value
)
174 return originalValue
;
177 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd
)
179 register int originalValue
;
180 register int newValue
;
183 "ldrex %[originalValue], [%[_q_value]]\n"
184 "add %[newValue], %[originalValue], %[valueToAdd]\n"
185 "strex %[result], %[newValue], [%[_q_value]]\n"
186 "teq %[result], #0\n"
188 : [originalValue
] "=&r" (originalValue
),
189 [newValue
] "=&r" (newValue
),
190 [result
] "=&r" (result
),
192 : [valueToAdd
] "r" (valueToAdd
),
193 [_q_value
] "r" (&_q_value
)
195 return originalValue
;
198 template <typename T
>
199 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::testAndSetOrdered(T
*expectedValue
, T
*newValue
)
203 "ldrex %[result], [%[_q_value]]\n"
204 "eors %[result], %[result], %[expectedValue]\n"
205 "strexeq %[result], %[newValue], [%[_q_value]]\n"
206 "teqeq %[result], #1\n"
208 : [result
] "=&r" (result
),
210 : [expectedValue
] "r" (expectedValue
),
211 [newValue
] "r" (newValue
),
212 [_q_value
] "r" (&_q_value
)
217 template <typename T
>
218 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndStoreOrdered(T
*newValue
)
220 register T
*originalValue
;
223 "ldrex %[originalValue], [%[_q_value]]\n"
224 "strex %[result], %[newValue], [%[_q_value]]\n"
225 "teq %[result], #0\n"
227 : [originalValue
] "=&r" (originalValue
),
228 [result
] "=&r" (result
),
230 : [newValue
] "r" (newValue
),
231 [_q_value
] "r" (&_q_value
)
233 return originalValue
;
236 template <typename T
>
237 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndAddOrdered(qptrdiff valueToAdd
)
239 register T
*originalValue
;
240 register T
*newValue
;
243 "ldrex %[originalValue], [%[_q_value]]\n"
244 "add %[newValue], %[originalValue], %[valueToAdd]\n"
245 "strex %[result], %[newValue], [%[_q_value]]\n"
246 "teq %[result], #0\n"
248 : [originalValue
] "=&r" (originalValue
),
249 [newValue
] "=&r" (newValue
),
250 [result
] "=&r" (result
),
252 : [valueToAdd
] "r" (valueToAdd
* sizeof(T
)),
253 [_q_value
] "r" (&_q_value
)
255 return originalValue
;
261 // RVCT inline assembly documentation:
262 // http://www.keil.com/support/man/docs/armcc/armcc_chdcffdb.htm
263 // RVCT embedded assembly documentation:
264 // http://www.keil.com/support/man/docs/armcc/armcc_chddbeib.htm
266 // save our pragma state and switch to ARM mode
270 inline bool QBasicAtomicInt::ref()
272 register int newValue
;
276 ldrex newValue
, [&_q_value
]
277 add newValue
, newValue
, #1
278 strex result
, newValue
, [&_q_value
]
282 return newValue
!= 0;
285 inline bool QBasicAtomicInt::deref()
287 register int newValue
;
291 ldrex newValue
, [&_q_value
]
292 sub newValue
, newValue
, #1
293 strex result
, newValue
, [&_q_value
]
297 return newValue
!= 0;
300 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue
, int newValue
)
305 ldrex result
, [&_q_value
]
306 eors result
, result
, expectedValue
307 strexeq result
, newValue
, [&_q_value
]
314 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue
)
316 register int originalValue
;
320 ldrex originalValue
, [&_q_value
]
321 strex result
, newValue
, [&_q_value
]
325 return originalValue
;
328 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd
)
330 register int originalValue
;
331 register int newValue
;
335 ldrex originalValue
, [&_q_value
]
336 add newValue
, originalValue
, valueToAdd
337 strex result
, newValue
, [&_q_value
]
341 return originalValue
;
344 template <typename T
>
345 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::testAndSetOrdered(T
*expectedValue
, T
*newValue
)
350 ldrex result
, [&_q_value
]
351 eors result
, result
, expectedValue
352 strexeq result
, newValue
, [&_q_value
]
359 template <typename T
>
360 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndStoreOrdered(T
*newValue
)
362 register T
*originalValue
;
366 ldrex originalValue
, [&_q_value
]
367 strex result
, newValue
, [&_q_value
]
371 return originalValue
;
374 template <typename T
>
375 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndAddOrdered(qptrdiff valueToAdd
)
377 register T
*originalValue
;
378 register T
*newValue
;
382 ldrex originalValue
, [&_q_value
]
383 add newValue
, originalValue
, valueToAdd
* sizeof(T
)
384 strex result
, newValue
, [&_q_value
]
388 return originalValue
;
391 // go back to the previous pragma state (probably Thumb mode)
397 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue
, int newValue
)
399 return testAndSetOrdered(expectedValue
, newValue
);
402 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue
, int newValue
)
404 return testAndSetOrdered(expectedValue
, newValue
);
407 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue
, int newValue
)
409 return testAndSetOrdered(expectedValue
, newValue
);
412 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue
)
414 return fetchAndStoreOrdered(newValue
);
417 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue
)
419 return fetchAndStoreOrdered(newValue
);
422 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue
)
424 return fetchAndStoreOrdered(newValue
);
427 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd
)
429 return fetchAndAddOrdered(valueToAdd
);
432 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd
)
434 return fetchAndAddOrdered(valueToAdd
);
437 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd
)
439 return fetchAndAddOrdered(valueToAdd
);
442 template <typename T
>
443 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::testAndSetRelaxed(T
*expectedValue
, T
*newValue
)
445 return testAndSetOrdered(expectedValue
, newValue
);
448 template <typename T
>
449 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::testAndSetAcquire(T
*expectedValue
, T
*newValue
)
451 return testAndSetOrdered(expectedValue
, newValue
);
454 template <typename T
>
455 Q_INLINE_TEMPLATE
bool QBasicAtomicPointer
<T
>::testAndSetRelease(T
*expectedValue
, T
*newValue
)
457 return testAndSetOrdered(expectedValue
, newValue
);
460 template <typename T
>
461 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndStoreRelaxed(T
*newValue
)
463 return fetchAndStoreOrdered(newValue
);
466 template <typename T
>
467 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndStoreAcquire(T
*newValue
)
469 return fetchAndStoreOrdered(newValue
);
472 template <typename T
>
473 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndStoreRelease(T
*newValue
)
475 return fetchAndStoreOrdered(newValue
);
478 template <typename T
>
479 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndAddRelaxed(qptrdiff valueToAdd
)
481 return fetchAndAddOrdered(valueToAdd
);
484 template <typename T
>
485 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndAddAcquire(qptrdiff valueToAdd
)
487 return fetchAndAddOrdered(valueToAdd
);
490 template <typename T
>
491 Q_INLINE_TEMPLATE T
*QBasicAtomicPointer
<T
>::fetchAndAddRelease(qptrdiff valueToAdd
)
493 return fetchAndAddOrdered(valueToAdd
);
500 #endif // QATOMIC_ARMV6_H