__asm__ __volatile__(
"lock; addb %1, %0"
: "=m"(*__hp(addr))
- : "q" ((unsigned char)val));
+ : "iq" ((unsigned char)val)
+ : "memory");
return;
}
case 2:
__asm__ __volatile__(
"lock; addw %1, %0"
: "=m"(*__hp(addr))
- : "r" ((unsigned short)val));
+ : "ir" ((unsigned short)val)
+ : "memory");
return;
}
case 4:
__asm__ __volatile__(
"lock; addl %1, %0"
: "=m"(*__hp(addr))
- : "r" ((unsigned int)val));
+ : "ir" ((unsigned int)val)
+ : "memory");
return;
}
#if (BITS_PER_LONG == 64)
__asm__ __volatile__(
"lock; addq %1, %0"
: "=m"(*__hp(addr))
- : "r" ((unsigned long)val));
+ : "er" ((unsigned long)val)
+ : "memory");
return;
}
#endif
static struct testvals vals;
-int main(int argc, void **argv)
+#define do_test(ptr) \
+do { \
+ __typeof__(*ptr) v; \
+ \
+ atomic_add(ptr, 10); \
+ assert(*ptr == 10); \
+ atomic_add(ptr, -11); \
+ assert(*ptr == (__typeof__(*ptr))-1U); \
+ v = cmpxchg(ptr, -1, 22); \
+ assert(*ptr == 22); \
+ assert(v == (__typeof__(*ptr))-1U); \
+ v = cmpxchg(ptr, 33, 44); \
+ assert(*ptr == 22); \
+ assert(v == 22); \
+ v = xchg(ptr, 55); \
+ assert(*ptr == 55); \
+ assert(v == 22); \
+} while (0)
+
+int main(int argc, char **argv)
{
- atomic_add(&vals.c, 10);
- assert(vals.c == 10);
- atomic_add(&vals.c, -11);
- assert((char)vals.c == -1);
+ do_test(&vals.c);
+ do_test(&vals.s);
+ do_test(&vals.i);
+ do_test(&vals.l);
+ printf("Atomic ops test OK\n");
+
+ return 0;
}