summaryrefslogtreecommitdiff
path: root/boost/atomic/detail/extra_ops_gcc_x86.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/atomic/detail/extra_ops_gcc_x86.hpp')
-rw-r--r--boost/atomic/detail/extra_ops_gcc_x86.hpp486
1 files changed, 380 insertions, 106 deletions
diff --git a/boost/atomic/detail/extra_ops_gcc_x86.hpp b/boost/atomic/detail/extra_ops_gcc_x86.hpp
index 59b39064d2..ee2cd02a88 100644
--- a/boost/atomic/detail/extra_ops_gcc_x86.hpp
+++ b/boost/atomic/detail/extra_ops_gcc_x86.hpp
@@ -36,6 +36,16 @@ struct gcc_x86_extra_operations_common :
typedef Base base_type;
typedef typename base_type::storage_type storage_type;
+ static BOOST_FORCEINLINE storage_type add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
+ {
+ return static_cast< storage_type >(Base::fetch_add(storage, v, order) + v);
+ }
+
+ static BOOST_FORCEINLINE storage_type sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
+ {
+ return static_cast< storage_type >(Base::fetch_sub(storage, v, order) - v);
+ }
+
static BOOST_FORCEINLINE bool bit_test_and_set(storage_type volatile& storage, unsigned int bit_number, memory_order) BOOST_NOEXCEPT
{
bool res;
@@ -110,43 +120,109 @@ struct gcc_x86_extra_operations_common :
};
template< typename Base, bool Signed >
-struct extra_operations< Base, 1u, Signed > :
+struct extra_operations< Base, 1u, Signed, true > :
public gcc_x86_extra_operations_common< Base >
{
typedef gcc_x86_extra_operations_common< Base > base_type;
typedef typename base_type::storage_type storage_type;
- typedef typename make_storage_type< 4u, Signed >::type temp_storage_type;
+ typedef typename make_storage_type< 4u >::type temp_storage_type;
-#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, result)\
- temp_storage_type new_val;\
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, original, result)\
__asm__ __volatile__\
(\
".align 16\n\t"\
- "1: movzbl %[res], %2\n\t"\
+ "1: movzbl %[orig], %2\n\t"\
op " %b2\n\t"\
"lock; cmpxchgb %b2, %[storage]\n\t"\
"jne 1b"\
- : [res] "+a" (result), [storage] "+m" (storage), "=&q" (new_val)\
+ : [orig] "+a" (original), [storage] "+m" (storage), "=&q" (result)\
: \
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
)
static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("negb", res);
- return res;
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negb", original, result);
+ return original;
}
static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("notb", res);
- return res;
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notb", original, result);
+ return original;
+ }
+
+ static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negb", original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notb", original, result);
+ return static_cast< storage_type >(result);
+ }
+
+#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, argument, original, result)\
+ __asm__ __volatile__\
+ (\
+ ".align 16\n\t"\
+ "1: mov %[arg], %2\n\t"\
+ op " %%al, %b2\n\t"\
+ "lock; cmpxchgb %b2, %[storage]\n\t"\
+ "jne 1b"\
+ : [orig] "+a" (original), [storage] "+m" (storage), "=&q" (result)\
+ : [arg] "ir" ((temp_storage_type)argument)\
+ : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
+ )
+
+ static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("andb", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("orb", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("xorb", v, original, result);
+ return static_cast< storage_type >(result);
}
#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+ static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!negate(storage, order);
+ }
+
+ static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!bitwise_complement(storage, order);
+ }
+
static BOOST_FORCEINLINE void opaque_add(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
{
if (BOOST_ATOMIC_DETAIL_IS_CONSTANT(v) && v == 1)
@@ -259,7 +335,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; incb %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -269,7 +345,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; addb %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -280,7 +356,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; incb %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -291,7 +367,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; addb %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -310,7 +386,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; decb %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -320,7 +396,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; subb %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -331,7 +407,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; decb %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -342,7 +418,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; subb %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -359,7 +435,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; andb %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -367,7 +443,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; andb %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -383,7 +459,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; orb %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -391,7 +467,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; orb %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -407,7 +483,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; xorb %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -415,7 +491,7 @@ struct extra_operations< Base, 1u, Signed > :
__asm__ __volatile__
(
"lock; xorb %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -426,43 +502,109 @@ struct extra_operations< Base, 1u, Signed > :
};
template< typename Base, bool Signed >
-struct extra_operations< Base, 2u, Signed > :
+struct extra_operations< Base, 2u, Signed, true > :
public gcc_x86_extra_operations_common< Base >
{
typedef gcc_x86_extra_operations_common< Base > base_type;
typedef typename base_type::storage_type storage_type;
- typedef typename make_storage_type< 4u, Signed >::type temp_storage_type;
+ typedef typename make_storage_type< 4u >::type temp_storage_type;
-#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, result)\
- temp_storage_type new_val;\
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, original, result)\
__asm__ __volatile__\
(\
".align 16\n\t"\
- "1: movzwl %[res], %2\n\t"\
+ "1: movzwl %[orig], %2\n\t"\
op " %w2\n\t"\
"lock; cmpxchgw %w2, %[storage]\n\t"\
"jne 1b"\
- : [res] "+a" (result), [storage] "+m" (storage), "=&q" (new_val)\
+ : [orig] "+a" (original), [storage] "+m" (storage), "=&q" (result)\
: \
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
)
static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("negw", res);
- return res;
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negw", original, result);
+ return original;
}
static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("notw", res);
- return res;
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notw", original, result);
+ return original;
+ }
+
+ static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negw", original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notw", original, result);
+ return static_cast< storage_type >(result);
+ }
+
+#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, argument, original, result)\
+ __asm__ __volatile__\
+ (\
+ ".align 16\n\t"\
+ "1: mov %[arg], %2\n\t"\
+ op " %%ax, %w2\n\t"\
+ "lock; cmpxchgw %w2, %[storage]\n\t"\
+ "jne 1b"\
+ : [orig] "+a" (original), [storage] "+m" (storage), "=&q" (result)\
+ : [arg] "ir" ((temp_storage_type)argument)\
+ : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
+ )
+
+ static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("andw", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("orw", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ temp_storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("xorw", v, original, result);
+ return static_cast< storage_type >(result);
}
#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+ static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!negate(storage, order);
+ }
+
+ static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!bitwise_complement(storage, order);
+ }
+
static BOOST_FORCEINLINE void opaque_add(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
{
if (BOOST_ATOMIC_DETAIL_IS_CONSTANT(v) && v == 1)
@@ -575,7 +717,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; incw %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -585,7 +727,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; addw %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -596,7 +738,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; incw %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -607,7 +749,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; addw %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -626,7 +768,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; decw %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -636,7 +778,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; subw %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -647,7 +789,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; decw %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -658,7 +800,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; subw %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -675,7 +817,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; andw %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -683,7 +825,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; andw %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -699,7 +841,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; orw %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -707,7 +849,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; orw %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -723,7 +865,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; xorw %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "iq" (v)
: "memory"
);
@@ -731,7 +873,7 @@ struct extra_operations< Base, 2u, Signed > :
__asm__ __volatile__
(
"lock; xorw %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "iq" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -742,42 +884,108 @@ struct extra_operations< Base, 2u, Signed > :
};
template< typename Base, bool Signed >
-struct extra_operations< Base, 4u, Signed > :
+struct extra_operations< Base, 4u, Signed, true > :
public gcc_x86_extra_operations_common< Base >
{
typedef gcc_x86_extra_operations_common< Base > base_type;
typedef typename base_type::storage_type storage_type;
-#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, result)\
- storage_type new_val;\
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, original, result)\
__asm__ __volatile__\
(\
".align 16\n\t"\
- "1: mov %[res], %[new_val]\n\t"\
- op " %[new_val]\n\t"\
- "lock; cmpxchgl %[new_val], %[storage]\n\t"\
+ "1: mov %[orig], %[res]\n\t"\
+ op " %[res]\n\t"\
+ "lock; cmpxchgl %[res], %[storage]\n\t"\
"jne 1b"\
- : [res] "+a" (result), [storage] "+m" (storage), [new_val] "=&r" (new_val)\
+ : [orig] "+a" (original), [storage] "+m" (storage), [res] "=&r" (result)\
: \
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
)
static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("negl", res);
- return res;
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negl", original, result);
+ return original;
}
static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("notl", res);
- return res;
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notl", original, result);
+ return original;
+ }
+
+ static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negl", original, result);
+ return result;
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notl", original, result);
+ return result;
+ }
+
+#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, argument, original, result)\
+ __asm__ __volatile__\
+ (\
+ ".align 16\n\t"\
+ "1: mov %[arg], %[res]\n\t"\
+ op " %%eax, %[res]\n\t"\
+ "lock; cmpxchgl %[res], %[storage]\n\t"\
+ "jne 1b"\
+ : [orig] "+a" (original), [storage] "+m" (storage), [res] "=&r" (result)\
+ : [arg] "ir" (argument)\
+ : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
+ )
+
+ static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("andl", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("orl", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("xorl", v, original, result);
+ return static_cast< storage_type >(result);
}
#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+ static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!negate(storage, order);
+ }
+
+ static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!bitwise_complement(storage, order);
+ }
+
static BOOST_FORCEINLINE void opaque_add(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
{
if (BOOST_ATOMIC_DETAIL_IS_CONSTANT(v) && v == 1)
@@ -890,7 +1098,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; incl %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -900,7 +1108,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; addl %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "ir" (v)
: "memory"
);
@@ -911,7 +1119,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; incl %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -922,7 +1130,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; addl %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "ir" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -941,7 +1149,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; decl %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -951,7 +1159,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; subl %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "ir" (v)
: "memory"
);
@@ -962,7 +1170,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; decl %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -973,7 +1181,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; subl %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "ir" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -990,7 +1198,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; andl %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "ir" (v)
: "memory"
);
@@ -998,7 +1206,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; andl %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "ir" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1014,7 +1222,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; orl %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "ir" (v)
: "memory"
);
@@ -1022,7 +1230,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; orl %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "ir" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1038,7 +1246,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; xorl %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "ir" (v)
: "memory"
);
@@ -1046,7 +1254,7 @@ struct extra_operations< Base, 4u, Signed > :
__asm__ __volatile__
(
"lock; xorl %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "ir" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1059,42 +1267,108 @@ struct extra_operations< Base, 4u, Signed > :
#if defined(__x86_64__)
template< typename Base, bool Signed >
-struct extra_operations< Base, 8u, Signed > :
+struct extra_operations< Base, 8u, Signed, true > :
public gcc_x86_extra_operations_common< Base >
{
typedef gcc_x86_extra_operations_common< Base > base_type;
typedef typename base_type::storage_type storage_type;
-#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, result)\
- storage_type new_val;\
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, original, result)\
__asm__ __volatile__\
(\
".align 16\n\t"\
- "1: mov %[res], %[new_val]\n\t"\
- op " %[new_val]\n\t"\
- "lock; cmpxchgq %[new_val], %[storage]\n\t"\
+ "1: mov %[orig], %[res]\n\t"\
+ op " %[res]\n\t"\
+ "lock; cmpxchgq %[res], %[storage]\n\t"\
"jne 1b"\
- : [res] "+a" (result), [storage] "+m" (storage), [new_val] "=&r" (new_val)\
+ : [orig] "+a" (original), [storage] "+m" (storage), [res] "=&r" (result)\
: \
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
)
static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("negq", res);
- return res;
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negq", original, result);
+ return original;
}
static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
{
- storage_type res = storage;
- BOOST_ATOMIC_DETAIL_CAS_LOOP("notq", res);
- return res;
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notq", original, result);
+ return original;
+ }
+
+ static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("negq", original, result);
+ return result;
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("notq", original, result);
+ return result;
+ }
+
+#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+
+#define BOOST_ATOMIC_DETAIL_CAS_LOOP(op, argument, original, result)\
+ __asm__ __volatile__\
+ (\
+ ".align 16\n\t"\
+ "1: mov %[arg], %[res]\n\t"\
+ op " %%rax, %[res]\n\t"\
+ "lock; cmpxchgq %[res], %[storage]\n\t"\
+ "jne 1b"\
+ : [orig] "+a" (original), [storage] "+m" (storage), [res] "=&r" (result)\
+ : [arg] "r" (argument)\
+ : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"\
+ )
+
+ static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("andq", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("orq", v, original, result);
+ return static_cast< storage_type >(result);
+ }
+
+ static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
+ {
+ storage_type original = storage;
+ storage_type result;
+ BOOST_ATOMIC_DETAIL_CAS_LOOP("xorq", v, original, result);
+ return static_cast< storage_type >(result);
}
#undef BOOST_ATOMIC_DETAIL_CAS_LOOP
+ static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!negate(storage, order);
+ }
+
+ static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
+ {
+ return !!bitwise_complement(storage, order);
+ }
+
static BOOST_FORCEINLINE void opaque_add(storage_type volatile& storage, storage_type v, memory_order) BOOST_NOEXCEPT
{
if (BOOST_ATOMIC_DETAIL_IS_CONSTANT(v) && v == 1)
@@ -1207,7 +1481,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; incq %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -1217,7 +1491,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; addq %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "er" (v)
: "memory"
);
@@ -1228,7 +1502,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; incq %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1239,7 +1513,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; addq %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "er" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1258,7 +1532,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; decq %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
:
: "memory"
);
@@ -1268,7 +1542,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; subq %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "er" (v)
: "memory"
);
@@ -1279,7 +1553,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; decq %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
:
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1290,7 +1564,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; subq %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "er" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1307,7 +1581,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; andq %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "er" (v)
: "memory"
);
@@ -1315,7 +1589,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; andq %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "er" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1331,7 +1605,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; orq %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "er" (v)
: "memory"
);
@@ -1339,7 +1613,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; orq %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "er" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"
@@ -1355,7 +1629,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; xorq %[argument], %[storage]\n\t"
- : [storage] "+m" (storage), [result] "=@ccz" (res)
+ : [storage] "+m" (storage), [result] "=@ccnz" (res)
: [argument] "er" (v)
: "memory"
);
@@ -1363,7 +1637,7 @@ struct extra_operations< Base, 8u, Signed > :
__asm__ __volatile__
(
"lock; xorq %[argument], %[storage]\n\t"
- "setz %[result]\n\t"
+ "setnz %[result]\n\t"
: [storage] "+m" (storage), [result] "=q" (res)
: [argument] "er" (v)
: BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory"