222 #endif // ARM 223 } 224 225 template<> 226 template<typename T> 227 inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest, 228 T exchange_value, 229 atomic_memory_order order) const { 230 STATIC_ASSERT(8 == sizeof(T)); 231 T result = __sync_lock_test_and_set (dest, exchange_value); 232 __sync_synchronize(); 233 return result; 234 } 235 236 // No direct support for cmpxchg of bytes; emulate using int. 237 template<> 238 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {}; 239 240 template<> 241 template<typename T> 242 inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value, 243 T volatile* dest, 244 T compare_value, 245 atomic_memory_order order) const { 246 STATIC_ASSERT(4 == sizeof(T)); 247 #ifdef ARM 248 return cmpxchg_using_helper<int>(arm_compare_and_swap, exchange_value, dest, compare_value); 249 #else 250 #ifdef M68K 251 return cmpxchg_using_helper<int>(m68k_compare_and_swap, exchange_value, dest, compare_value); 252 #else 253 return __sync_val_compare_and_swap(dest, compare_value, exchange_value); 254 #endif // M68K 255 #endif // ARM 256 } 257 258 template<> 259 template<typename T> 260 inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, 261 T volatile* dest, 262 T compare_value, 263 atomic_memory_order order) const { 264 STATIC_ASSERT(8 == sizeof(T)); 265 return __sync_val_compare_and_swap(dest, compare_value, exchange_value); 266 } 267 268 template<> 269 template<typename T> 270 inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { 271 STATIC_ASSERT(8 == sizeof(T)); 272 volatile int64_t dest; 273 os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(src), reinterpret_cast<volatile int64_t*>(&dest)); 274 return PrimitiveConversions::cast<T>(dest); 275 } 276 277 template<> 278 template<typename T> 279 inline void Atomic::PlatformStore<8>::operator()(T volatile* dest, 280 T store_value) const { 281 STATIC_ASSERT(8 == sizeof(T)); 282 os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(&store_value), reinterpret_cast<volatile int64_t*>(dest)); | 222 #endif // ARM 223 } 224 225 template<> 226 template<typename T> 227 inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest, 228 T exchange_value, 229 atomic_memory_order order) const { 230 STATIC_ASSERT(8 == sizeof(T)); 231 T result = __sync_lock_test_and_set (dest, exchange_value); 232 __sync_synchronize(); 233 return result; 234 } 235 236 // No direct support for cmpxchg of bytes; emulate using int. 237 template<> 238 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {}; 239 240 template<> 241 template<typename T> 242 inline T Atomic::PlatformCmpxchg<4>::operator()(T volatile* dest, 243 T compare_value, 244 T exchange_value, 245 atomic_memory_order order) const { 246 STATIC_ASSERT(4 == sizeof(T)); 247 #ifdef ARM 248 return cmpxchg_using_helper<int>(arm_compare_and_swap, dest, compare_value, exchange_value); 249 #else 250 #ifdef M68K 251 return cmpxchg_using_helper<int>(m68k_compare_and_swap, dest, compare_value, exchange_value); 252 #else 253 return __sync_val_compare_and_swap(dest, compare_value, exchange_value); 254 #endif // M68K 255 #endif // ARM 256 } 257 258 template<> 259 template<typename T> 260 inline T Atomic::PlatformCmpxchg<8>::operator()(T volatile* dest, 261 T compare_value, 262 T exchange_value, 263 atomic_memory_order order) const { 264 STATIC_ASSERT(8 == sizeof(T)); 265 return __sync_val_compare_and_swap(dest, compare_value, exchange_value); 266 } 267 268 template<> 269 template<typename T> 270 inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { 271 STATIC_ASSERT(8 == sizeof(T)); 272 volatile int64_t dest; 273 os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(src), reinterpret_cast<volatile int64_t*>(&dest)); 274 return PrimitiveConversions::cast<T>(dest); 275 } 276 277 template<> 278 template<typename T> 279 inline void Atomic::PlatformStore<8>::operator()(T volatile* dest, 280 T store_value) const { 281 STATIC_ASSERT(8 == sizeof(T)); 282 os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(&store_value), reinterpret_cast<volatile int64_t*>(dest)); |