qatomic_bfin.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtCore module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QATOMIC_BFIN_H
00043 #define QATOMIC_BFIN_H
00044 
00045 QT_BEGIN_HEADER
00046 
00047 QT_BEGIN_NAMESPACE
00048 
00049 #define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
00050 
00051 inline bool QBasicAtomicInt::isReferenceCountingNative()
00052 { return false; }
00053 inline bool QBasicAtomicInt::isReferenceCountingWaitFree()
00054 { return false; }
00055 
00056 #define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
00057 
00058 inline bool QBasicAtomicInt::isTestAndSetNative()
00059 { return false; }
00060 inline bool QBasicAtomicInt::isTestAndSetWaitFree()
00061 { return false; }
00062 
00063 #define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
00064 
00065 inline bool QBasicAtomicInt::isFetchAndStoreNative()
00066 { return false; }
00067 inline bool QBasicAtomicInt::isFetchAndStoreWaitFree()
00068 { return false; }
00069 
00070 #define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE
00071 
00072 inline bool QBasicAtomicInt::isFetchAndAddNative()
00073 { return false; }
00074 inline bool QBasicAtomicInt::isFetchAndAddWaitFree()
00075 { return false; }
00076 
00077 #define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
00078 
00079 template <typename T>
00080 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetNative()
00081 { return false; }
00082 template <typename T>
00083 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isTestAndSetWaitFree()
00084 { return false; }
00085 
00086 #define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
00087 
00088 template <typename T>
00089 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreNative()
00090 { return false; }
00091 template <typename T>
00092 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndStoreWaitFree()
00093 { return false; }
00094 
00095 #define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE
00096 
00097 template <typename T>
00098 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddNative()
00099 { return false; }
00100 template <typename T>
00101 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::isFetchAndAddWaitFree()
00102 { return false; }
00103 
00104 #if defined(Q_OS_LINUX) && defined(Q_CC_GNU)
00105 
00106 QT_BEGIN_INCLUDE_NAMESPACE
00107 #include <asm/fixed_code.h>
00108 QT_END_INCLUDE_NAMESPACE
00109 
00110 inline bool QBasicAtomicInt::ref()
00111 {
00112     int ret;
00113     asm volatile("R0 = 1;\n\t"
00114          "P0 = %3;\n\t"
00115                  "CALL (%2);\n\t"
00116                  "%0 = R0;"
00117                  : "=da" (ret), "=m" (_q_value)
00118                  : "a" (ATOMIC_ADD32), "da" (&_q_value), "m" (_q_value)
00119                  : "R0", "R1", "P0", "RETS", "memory");
00120     return ret != 0;
00121 }
00122 
00123 inline bool QBasicAtomicInt::deref()
00124 {
00125     int ret;
00126     asm volatile("R0 = 1;\n\t"
00127          "P0 = %3;\n\t"
00128                  "CALL (%2);\n\t"
00129                  "%0 = R0;"
00130                  : "=da" (ret), "=m" (_q_value)
00131                  : "a" (ATOMIC_SUB32), "da" (&_q_value), "m" (_q_value)
00132                  : "R0", "R1", "P0", "RETS", "memory");
00133     return ret != 0;
00134 }
00135 
00136 inline bool QBasicAtomicInt::testAndSetOrdered(int expectedValue, int newValue)
00137 {
00138     long int readval;
00139     asm volatile ("P0 = %2;\n\t"
00140           "R1 = %3;\n\t"
00141           "R2 = %4;\n\t"
00142           "CALL (%5);\n\t"
00143           "%0 = R0;\n\t"
00144           : "=da" (readval), "=m" (_q_value)
00145           : "da" (&_q_value),
00146           "da" (expectedValue),
00147           "da" (newValue),
00148           "a" (ATOMIC_CAS32),
00149           "m" (_q_value)
00150           : "P0", "R0", "R1", "R2", "RETS", "memory", "cc");
00151     return readval == expectedValue;
00152 }
00153 
00154 inline int QBasicAtomicInt::fetchAndStoreOrdered(int newValue)
00155 {
00156     asm volatile("R1 = %2;\n\t"
00157          "P0 = %4;\n\t"
00158                  "CALL (%3);\n\t"
00159                  "%0 = R0;"
00160                  : "=da" (newValue), "=m" (_q_value)
00161                  : "da" (newValue), "a" (ATOMIC_XCHG32), "da" (&_q_value), "m" (_q_value)
00162                  : "R0", "R1", "P0", "RETS", "memory");
00163     return newValue;
00164 }
00165 
00166 inline int QBasicAtomicInt::fetchAndAddOrdered(int valueToAdd)
00167 {
00168     int ret;
00169     asm volatile("R0 = %[val];\n\t"
00170          "P0 = %[qvalp];\n\t"
00171                  "CALL (%[addr]);\n\t"
00172                  "%[ret] = R1;"
00173                  : [ret] "=da" (ret), "=m" (_q_value)
00174                  : [addr] "a" (ATOMIC_ADD32), [qvalp] "da" (&_q_value), "m" (_q_value), [val] "da" (valueToAdd)
00175                  : "R0", "R1", "P0", "RETS", "memory");
00176     return ret;
00177 }
00178 
00179 template <typename T>
00180 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetOrdered(T *expectedValue, T *newValue)
00181 {
00182     T *readval;
00183     asm volatile ("P0 = %2;\n\t"
00184           "R1 = %3;\n\t"
00185           "R2 = %4;\n\t"
00186           "CALL (%5);\n\t"
00187           "%0 = R0;\n\t"
00188           : "=da" (readval), "=m" (_q_value)
00189           : "da" (&_q_value),
00190           "da" (expectedValue),
00191           "da" (newValue),
00192           "a" (ATOMIC_CAS32),
00193           "m" (_q_value)
00194           : "P0", "R0", "R1", "R2", "RETS", "memory", "cc");
00195     return readval == expectedValue;
00196 }
00197 
00198 template <typename T>
00199 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreOrdered(T *newValue)
00200 {
00201     asm volatile("R1 = %2;\n\t"
00202          "P0 = %4;\n\t"
00203                  "CALL (%3);\n\t"
00204                  "%0 = R0;"
00205                  : "=da" (newValue), "=m" (_q_value)
00206                  : "da" (newValue), "a" (ATOMIC_XCHG32), "da" (&_q_value), "m" (_q_value)
00207                  : "R0", "R1", "P0", "RETS", "memory");
00208     return newValue;
00209 }
00210 
00211 template <typename T>
00212 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddOrdered(qptrdiff valueToAdd)
00213 {
00214     T* ret;
00215     asm volatile("R0 = %[val];\n\t"
00216          "P0 = %[qvalp];\n\t"
00217                  "CALL (%[addr]);\n\t"
00218                  "%[ret] = R1;"
00219                  : [ret] "=da" (ret), "=m" (_q_value)
00220                  : [addr] "a" (ATOMIC_ADD32), [qvalp] "da" (&_q_value), "m" (_q_value), [val] "da" (valueToAdd * sizeof(T))
00221                  : "R0", "R1", "P0", "RETS", "memory");
00222     return ret;
00223 }
00224 
00225 
00226 #endif // Q_OS_LINUX && Q_CC_GNU
00227 
00228 // Test and set for integers
00229 
00230 inline bool QBasicAtomicInt::testAndSetRelaxed(int expectedValue, int newValue)
00231 {
00232     return testAndSetOrdered(expectedValue, newValue);
00233 }
00234 
00235 inline bool QBasicAtomicInt::testAndSetAcquire(int expectedValue, int newValue)
00236 {
00237     return testAndSetOrdered(expectedValue, newValue);
00238 }
00239 
00240 inline bool QBasicAtomicInt::testAndSetRelease(int expectedValue, int newValue)
00241 {
00242     return testAndSetOrdered(expectedValue, newValue);
00243 }
00244 
00245 // Fetch and store for integers
00246 
00247 inline int QBasicAtomicInt::fetchAndStoreRelaxed(int newValue)
00248 {
00249     return fetchAndStoreOrdered(newValue);
00250 }
00251 
00252 inline int QBasicAtomicInt::fetchAndStoreAcquire(int newValue)
00253 {
00254     return fetchAndStoreOrdered(newValue);
00255 }
00256 
00257 inline int QBasicAtomicInt::fetchAndStoreRelease(int newValue)
00258 {
00259     return fetchAndStoreOrdered(newValue);
00260 }
00261 
00262 // Fetch and add for integers
00263 
00264 inline int QBasicAtomicInt::fetchAndAddRelaxed(int valueToAdd)
00265 {
00266     return fetchAndAddOrdered(valueToAdd);
00267 }
00268 
00269 inline int QBasicAtomicInt::fetchAndAddAcquire(int valueToAdd)
00270 {
00271     return fetchAndAddOrdered(valueToAdd);
00272 }
00273 
00274 inline int QBasicAtomicInt::fetchAndAddRelease(int valueToAdd)
00275 {
00276     return fetchAndAddOrdered(valueToAdd);
00277 }
00278 
00279 // Test and set for pointers
00280 
00281 template <typename T>
00282 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelaxed(T *expectedValue, T *newValue)
00283 {
00284     return testAndSetOrdered(expectedValue, newValue);
00285 }
00286 
00287 template <typename T>
00288 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetAcquire(T *expectedValue, T *newValue)
00289 {
00290     return testAndSetOrdered(expectedValue, newValue);
00291 }
00292 
00293 template <typename T>
00294 Q_INLINE_TEMPLATE bool QBasicAtomicPointer<T>::testAndSetRelease(T *expectedValue, T *newValue)
00295 {
00296     return testAndSetOrdered(expectedValue, newValue);
00297 }
00298 
00299 // Fetch and store for pointers
00300 
00301 template <typename T>
00302 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelaxed(T *newValue)
00303 {
00304     return fetchAndStoreOrdered(newValue);
00305 }
00306 
00307 template <typename T>
00308 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreAcquire(T *newValue)
00309 {
00310     return fetchAndStoreOrdered(newValue);
00311 }
00312 
00313 template <typename T>
00314 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndStoreRelease(T *newValue)
00315 {
00316     return fetchAndStoreOrdered(newValue);
00317 }
00318 
00319 // Fetch and add for pointers
00320 
00321 template <typename T>
00322 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelaxed(qptrdiff valueToAdd)
00323 {
00324     return fetchAndAddOrdered(valueToAdd);
00325 }
00326 
00327 template <typename T>
00328 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddAcquire(qptrdiff valueToAdd)
00329 {
00330     return fetchAndAddOrdered(valueToAdd);
00331 }
00332 
00333 template <typename T>
00334 Q_INLINE_TEMPLATE T *QBasicAtomicPointer<T>::fetchAndAddRelease(qptrdiff valueToAdd)
00335 {
00336     return fetchAndAddOrdered(valueToAdd);
00337 }
00338 
00339 QT_END_NAMESPACE
00340 
00341 QT_END_HEADER
00342 
00343 #endif // QATOMIC_BFIN_H