8#ifndef INCLUDED_BSLS_ATOMICOPERATIONS_X64_ALL_GCC
9#define INCLUDED_BSLS_ATOMICOPERATIONS_X64_ALL_GCC
64#include <bsls_atomicoperations_default.h>
68#if defined(BSLS_PLATFORM_CPU_X86_64) \
69 && (defined(BSLS_PLATFORM_CMP_GNU) || defined(BSLS_PLATFORM_CMP_CLANG))
75struct AtomicOperations_X64_ALL_GCC;
76typedef AtomicOperations_X64_ALL_GCC AtomicOperations_Imp;
83struct Atomic_TypeTraits<AtomicOperations_X64_ALL_GCC>
87 volatile int d_value __attribute__((__aligned__(
sizeof(
int))));
92 volatile Types::Int64 d_value
93 __attribute__((__aligned__(
sizeof(Types::Int64))));
98 volatile unsigned int d_value
99 __attribute__((__aligned__(
sizeof(
unsigned int))));
104 volatile Types::Uint64 d_value
105 __attribute__((__aligned__(
sizeof(Types::Uint64))));
110 void *
volatile d_value __attribute__((__aligned__(
sizeof(
void *))));
118struct AtomicOperations_X64_ALL_GCC
119 : AtomicOperations_Default64<AtomicOperations_X64_ALL_GCC>
121 typedef Atomic_TypeTraits<AtomicOperations_X64_ALL_GCC> AtomicTypes;
125 static int getInt(
const AtomicTypes::Int *atomicInt);
127 static void setInt(AtomicTypes::Int *atomicInt,
int value);
129 static void setIntRelease(AtomicTypes::Int *atomicInt,
int value);
131 static int swapInt(AtomicTypes::Int *atomicInt,
int swapValue);
133 static int testAndSwapInt(AtomicTypes::Int *atomicInt,
137 static int addIntNv(AtomicTypes::Int *atomicInt,
int value);
141 static Types::Int64 getInt64(
const AtomicTypes::Int64 *atomicInt);
143 static void setInt64(AtomicTypes::Int64 *atomicInt, Types::Int64 value);
145 static void setInt64Release(AtomicTypes::Int64 *atomicInt,
148 static Types::Int64 swapInt64(AtomicTypes::Int64 *atomicInt,
149 Types::Int64 swapValue);
151 static Types::Int64 testAndSwapInt64(AtomicTypes::Int64 *atomicInt,
152 Types::Int64 compareValue,
153 Types::Int64 swapValue);
155 static Types::Int64 addInt64Nv(AtomicTypes::Int64 *atomicInt,
168int AtomicOperations_X64_ALL_GCC::
169 getInt(
const AtomicTypes::Int *atomicInt)
174 " movl %[obj], %[ret] \n\t"
177 : [obj]
"m" (*atomicInt)
184void AtomicOperations_X64_ALL_GCC::
185 setInt(AtomicTypes::Int *atomicInt,
int value)
188 " movl %[val], %[obj] \n\t"
191 : [obj]
"=m" (*atomicInt)
197void AtomicOperations_X64_ALL_GCC::
198 setIntRelease(AtomicTypes::Int *atomicInt,
int value)
201 " movl %[val], %[obj] \n\t"
203 : [obj]
"=m" (*atomicInt)
209int AtomicOperations_X64_ALL_GCC::
210 swapInt(AtomicTypes::Int *atomicInt,
int swapValue)
213 " lock xchgl %[val], %[obj] \n\t"
215 : [obj]
"=m" (*atomicInt),
216 [val]
"=r" (swapValue)
217 :
"1" (swapValue),
"m" (*atomicInt)
224int AtomicOperations_X64_ALL_GCC::
225 testAndSwapInt(AtomicTypes::Int *atomicInt,
229 return __sync_val_compare_and_swap(&atomicInt->d_value,
235int AtomicOperations_X64_ALL_GCC::
236 addIntNv(AtomicTypes::Int *atomicInt,
int value)
238 return __sync_add_and_fetch(&atomicInt->d_value, value);
243 getInt64(
const AtomicTypes::Int64 *atomicInt)
248 " movq %[obj], %[res] \n\t"
250 : [res]
"=r" (result)
251 : [obj]
"m" (*atomicInt)
258void AtomicOperations_X64_ALL_GCC::
259 setInt64(AtomicTypes::Int64 *atomicInt,
Types::Int64 value)
262 " movq %[val], %[obj] \n\t"
265 : [obj]
"=m" (*atomicInt)
271void AtomicOperations_X64_ALL_GCC::
272 setInt64Release(AtomicTypes::Int64 *atomicInt,
276 " movq %[val], %[obj] \n\t"
278 : [obj]
"=m" (*atomicInt)
285 swapInt64(AtomicTypes::Int64 *atomicInt,
289 " lock xchgq %[val], %[obj] \n\t"
291 : [val]
"+r" (swapValue),
292 [obj]
"=m" (*atomicInt)
301 testAndSwapInt64(AtomicTypes::Int64 *atomicInt,
305 return __sync_val_compare_and_swap(&atomicInt->d_value,
312 addInt64Nv(AtomicTypes::Int64 *atomicInt,
315 return __sync_add_and_fetch(&atomicInt->d_value, value);
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlt_iso8601util.h:691
long long Int64
Definition bsls_types.h:132