drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / none / tests / x86 / xadd.c
blob78c495b1fd9f05fcc097f129dc2e2e4255f1b52e
2 #include "config.h"
3 #include <stdio.h>
4 #include <assert.h>
6 /* Simple test program, no race.
7 Tests the 'xadd' exchange-and-add instruction with {r,r} operands, which is rarely generated by compilers. */
9 #undef PLAT_x86_linux
10 #undef PLAT_amd64_linux
11 #undef PLAT_ppc32_linux
12 #undef PLAT_ppc64_linux
14 #if defined(__i386__)
15 # define PLAT_x86_linux 1
16 #elif defined(__x86_64__)
17 # define PLAT_amd64_linux 1
18 #endif
21 #if defined(PLAT_amd64_linux) || defined(PLAT_x86_linux)
22 # define XADD_R_R(_addr,_lval) \
23 __asm__ __volatile__( \
24 "xadd %1, %0" \
25 : /*out*/ "=r"(_lval),"=r"(_addr) \
26 : /*in*/ "0"(_lval),"1"(_addr) \
27 : "flags" \
29 #else
30 # error "Unsupported architecture"
31 #endif
33 int main ( void )
35 long d = 20, s = 2;
36 long xadd_r_r_res;
37 #define XADD_R_R_RES 42
39 XADD_R_R(s, d);
40 xadd_r_r_res = s + d;
41 assert(xadd_r_r_res == XADD_R_R_RES);
43 if (xadd_r_r_res == XADD_R_R_RES)
44 printf("success\n");
45 else
46 printf("failure\n");
48 return xadd_r_r_res;