25 #include <cppmyth_config.h> 29 #if defined __arm__ && (!defined __thumb__ || defined __thumb2__) 34 #elif defined (__ARM_ARCH_3__) || defined (__ARM_ARCH_3M__) 36 #elif defined (__ARM_ARCH_4__) || defined (__ARM_ARCH_4T__) 38 #elif defined (__ARM_ARCH_5__) || defined (__ARM_ARCH_5E__) \ 39 || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5TE__) \ 40 || defined(__ARM_ARCH_5TEJ__) 42 #elif defined (__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ 43 || defined (__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \ 44 || defined (__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) 46 #elif defined (__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ 47 || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ 48 || defined(__ARM_ARCH_7EM__) 60 typedef volatile T atomic_t;
62 atomic(T val) : m_val(val) {}
77 typedef volatile int atomic_t;
79 atomic(
int val) : m_val(val) {}
81 int __attribute__((always_inline)) load()
86 int __attribute__((always_inline)) operator()()
91 int __attribute__((always_inline)) add_fetch(
int amount)
104 :
"=&r" (__val),
"=m" (m_val),
"=&r" (temp)
105 :
"r" (amount),
"m" (m_val));
109 #elif defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__ || defined __x86_64__ 111 "lock xaddl %0, (%1);" 113 :
"r" (&m_val),
"0" (amount)
119 #elif defined __powerpc__ || defined __ppc__ || defined __ppc64__ 128 :
"r" (&m_val),
"r" (amount)
131 #elif defined __sparc__ || defined __sparc64__ 132 atomic_t __old, __new = m_val;
136 __new = __old + amount;
141 :
"" (__new),
"r" (&m_val),
"r" (__old)
144 while (__new != __old);
145 __val = __old + amount;
147 #elif (defined __ARM_ARCH && __ARM_ARCH == 7) 150 "1: ldrex %0, [%1]\n" 152 " strex r1, %0, [%1]\n" 157 :
"r" (&m_val),
"r" (amount)
160 #elif (defined __ARM_ARCH && __ARM_ARCH == 6) 162 "mcr p15, 0, %0, c7, c10, 5" 163 : :
"r" (0) :
"memory");
165 "1: ldrex %0, [%1]\n" 167 " strex r1, %0, [%1]\n" 171 :
"r" (&m_val),
"r" (amount)
174 "mcr p15, 0, %0, c7, c10, 5" 175 : :
"r" (0) :
"memory");
177 #elif (defined __ARM_ARCH && __ARM_ARCH < 6) 182 " swp %2, %1, [%3]\n" 184 " swpne %0, %2, [%3]\n" 186 :
"=&r" (tmp1),
"=&r" (__val),
"=&r" (tmp2)
187 :
"r" (&m_val),
"r" (amount)
190 #elif defined __aarch64__ 195 " add %w0, %w0, %w3\n" 196 " stlxr %w1, %w0, %2\n" 199 :
"=&r" (__val),
"=&r" (tmp),
"+Q" (m_val)
205 #ifndef ATOMIC_NOATOMIC 206 #define ATOMIC_NOATOMIC 208 __val = m_val += amount;
214 int __attribute__((always_inline)) operator++()
219 int __attribute__((always_inline)) sub_fetch(
int amount)
232 :
"=&r" (__val),
"=m" (m_val),
"=&r" (temp)
233 :
"r" (amount),
"m" (m_val));
237 #elif defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__ || defined __x86_64__ 239 "lock xaddl %0, (%1);" 241 :
"r" (&m_val),
"0" (-amount)
247 #elif defined __powerpc__ || defined __ppc__ || defined __ppc64__ 256 :
"r" (&m_val),
"r" (amount)
259 #elif defined __sparc__ || defined __sparc64__ 260 atomic_t __old, __new = m_val;
264 __new = __old - amount;
269 :
"" (__new),
"r" (&m_val),
"r" (__old)
272 while (__new != __old);
273 __val = __old - amount;
275 #elif (defined __ARM_ARCH && __ARM_ARCH == 7) 278 "1: ldrex %0, [%1]\n" 280 " strex r1, %0, [%1]\n" 285 :
"r" (&m_val),
"r" (amount)
288 #elif (defined __ARM_ARCH && __ARM_ARCH == 6) 290 "mcr p15, 0, %0, c7, c10, 5" 291 : :
"r" (0) :
"memory");
293 "1: ldrex %0, [%1]\n" 295 " strex r1, %0, [%1]\n" 299 :
"r" (&m_val),
"r" (amount)
302 "mcr p15, 0, %0, c7, c10, 5" 303 : :
"r" (0) :
"memory");
305 #elif (defined __ARM_ARCH && __ARM_ARCH < 6) 310 " swp %2, %1, [%3]\n" 312 " swpne %0, %2, [%3]\n" 314 :
"=&r" (tmp1),
"=&r" (__val),
"=&r" (tmp2)
315 :
"r" (&m_val),
"r" (-amount)
318 #elif defined __aarch64__ 323 " sub %w0, %w0, %w3\n" 324 " stlxr %w1, %w0, %2\n" 327 :
"=&r" (__val),
"=&r" (tmp),
"+Q" (m_val)
333 #ifndef ATOMIC_NOATOMIC 334 #define ATOMIC_NOATOMIC 336 __val = m_val -= amount;
342 int __attribute__((always_inline)) operator--()
353 #ifndef ATOMIC_NOATOMIC 354 #define ATOMIC_NOATOMIC