32 #ifndef MADNESS_WORLD_ATOMICINT_H__INCLUDED
33 #define MADNESS_WORLD_ATOMICINT_H__INCLUDED
49 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
50 # if (__GNUC__ >= 5) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
51 # define MADNESS_GCC_48_OR_HIGHER
55 #if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
56 # if (__clang_major__ >= 4) || (__clang_major__ == 3 && __clang_minor__ >= 3)
57 # define MADNESS_CLANG_33_OR_HIGHER
61 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300)
62 #define MADNESS_ICC_130_OR_HIGHER
68 #if !defined(__bgq__) && (__cplusplus >= 201103L)
69 # if defined(MADNESS_GCC_48_OR_HIGHER) || defined(MADNESS_CLANG_33_OR_HIGHER)
70 # define HAVE_CXX_ATOMICS
74 #ifdef MADNESS_GCC_48_OR_HIGHER
75 #undef MADNESS_GCC_48_OR_HIGHER
78 #ifdef MADNESS_ICC_130_OR_HIGHER
79 #undef MADNESS_ICC_130_OR_HIGHER
82 #ifdef MADNESS_CLANG_33_OR_HIGHER
83 #undef MADNESS_CLANG_33_OR_HIGHER
86 #if defined(HAVE_CXX_ATOMICS)
87 # define MADATOMIC_USE_CXX
90 #elif defined(HAVE_IBMBGP) && !defined(MADATOMIC_USE_GCC)
91 # define MADATOMIC_USE_BGP
92 #elif defined(HAVE_IBMBGQ)
93 # define MADATOMIC_USE_BGQ
94 #elif defined(USE_X86_32_ASM) || defined(USE_X86_64_ASM) || defined(X86_64) || defined(X86_32)
95 # define MADATOMIC_USE_X86_ASM
97 # define MADATOMIC_USE_GCC
100 #if defined(MADATOMIC_USE_CXX)
102 #elif defined(MADATOMIC_USE_BGP)
103 # include <bpcore/bgp_atomic_ops.h>
104 #elif defined (MADATOMIC_USE_BGQ)
106 #elif defined(MADATOMIC_USE_AIX)
107 # include <sys/atomic_op.h>
108 #elif defined(MADATOMIC_USE_GCC)
109 # ifdef GCC_ATOMICS_IN_BITS
110 # include <bits/atomicity.h>
112 # include <ext/atomicity.h>
130 #if defined(MADATOMIC_USE_CXX)
132 #elif defined(MADATOMIC_USE_BGP)
134 #elif defined(MADATOMIC_USE_BGQ)
149 #if defined(MADATOMIC_USE_CXX)
150 return value.fetch_add(i,std::memory_order_seq_cst);
151 #elif defined(MADATOMIC_USE_GCC)
152 return __gnu_cxx::__exchange_and_add(&
value,i);
153 #elif defined(MADATOMIC_USE_X86_ASM)
154 __asm__ __volatile__(
"lock; xaddl %0,%1" :
"=r"(i) :
"m"(
value),
"0"(i));
156 #elif defined(MADATOMIC_USE_AIX)
157 return fetch_and_add(&
value,i);
158 #elif defined(MADATOMIC_USE_BGP)
159 return _bgp_fetch_and_add(&
value,i);
160 #elif defined(MADATOMIC_USE_BGQ)
161 return FetchAndAddSigned32(&
value,i);
163 # error ... atomic exchange_and_add operator must be implemented for this platform;
170 operator int()
const volatile {
173 #if defined(MADATOMIC_USE_CXX)
174 return value.load(std::memory_order_seq_cst);
175 #elif defined(MADATOMIC_USE_BGP)
176 int result =
value.atom;
177 __asm__ __volatile__ (
"" : : :
"memory");
179 #elif defined (MADATOMIC_USE_BGQ)
181 __asm__ __volatile__ (
"" : : :
"memory");
186 __asm__ __volatile__ (
"" : : :
"memory");
200 #if defined(MADATOMIC_USE_CXX)
201 value.store(other,std::memory_order_seq_cst);
202 #elif defined(MADATOMIC_USE_BGP)
204 __asm__ __volatile__ (
"" : : :
"memory");
206 #elif defined (MADATOMIC_USE_BGQ)
207 __asm__ __volatile__ (
"" : : :
"memory");
210 __asm__ __volatile__ (
"" : : :
"memory");
230 #if defined(MADATOMIC_USE_CXX)
241 #if defined(MADATOMIC_USE_CXX)
252 #if defined(MADATOMIC_USE_CXX)
263 #if defined(MADATOMIC_USE_CXX)
275 #if defined(MADATOMIC_USE_CXX)
276 return (
value.fetch_add(inc, std::memory_order_seq_cst) + inc);
287 #if defined(MADATOMIC_USE_CXX)
288 return (
value.fetch_sub(dec, std::memory_order_seq_cst) - dec);
298 return ((*
this)-- == 1);
308 inline int compare_and_swap(
int compare,
int newval) {
309 #if defined(MADATOMIC_USE_CXX)
310 #warning The C++11 implementation of compare-and-swap has never been tested.
311 std::bool swapped =
value.compare_exchange_strong_explicit(&
compare, newval,
312 std::memory_order_seq_cst,
313 std::memory_order_seq_cst);
318 #elif defined(MADATOMIC_USE_GCC)
319 return __sync_val_compare_and_swap(&
value,
compare, newval);
320 #elif defined(MADATOMIC_USE_BGP)
322 #elif defined(MADATOMIC_USE_BGQ)
325 #error ... atomic exchange_and_add operator must be implemented for this platform;
An integer with atomic set, get, read+increment, read+decrement, and decrement+test operations.
Definition: atomicint.h:126
int operator--()
Decrements the counter and returns the decremented value.
Definition: atomicint.h:240
atomic_int value
The atomic integer.
Definition: atomicint.h:141
int operator-=(const int dec)
Subtract dec and return the new value.
Definition: atomicint.h:286
volatile int atomic_int
Storage type for the atomic integer.
Definition: atomicint.h:139
AtomicInt & operator=(const AtomicInt &other)
Sets the value of the counter, with fences to ensure that operations are not moved to either side of ...
Definition: atomicint.h:221
int operator++()
Increments the counter and returns the incremented value.
Definition: atomicint.h:262
int operator=(int other)
Definition: atomicint.h:197
int exchange_and_add(int i)
Definition: atomicint.h:148
int operator+=(const int inc)
Add value and return the new value.
Definition: atomicint.h:274
bool dec_and_test()
Decrements the counter and returns true if the new value is zero,.
Definition: atomicint.h:297
int operator--(int)
Decrements the counter and returns the original value.
Definition: atomicint.h:229
int operator++(int)
Increments the counter and returns the original value.
Definition: atomicint.h:251
Macros and tools pertaining to the configuration of MADNESS.
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
int compare(World &world, functionT test, functionT exact, const char *str)
Definition: testdiff1D.cc:19