Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / x86_64 / cmpxchg.c
blob589173516122a4ff2020cc4ea5708b022b294210
1 #include <assert.h>
3 static int mem;
5 static unsigned long test_cmpxchgb(unsigned long orig)
7 unsigned long ret;
8 mem = orig;
9 asm("cmpxchgb %b[cmp],%[mem]"
10 : [ mem ] "+m"(mem), [ rax ] "=a"(ret)
11 : [ cmp ] "r"(0x77), "a"(orig));
12 return ret;
15 static unsigned long test_cmpxchgw(unsigned long orig)
17 unsigned long ret;
18 mem = orig;
19 asm("cmpxchgw %w[cmp],%[mem]"
20 : [ mem ] "+m"(mem), [ rax ] "=a"(ret)
21 : [ cmp ] "r"(0x7777), "a"(orig));
22 return ret;
25 static unsigned long test_cmpxchgl(unsigned long orig)
27 unsigned long ret;
28 mem = orig;
29 asm("cmpxchgl %[cmp],%[mem]"
30 : [ mem ] "+m"(mem), [ rax ] "=a"(ret)
31 : [ cmp ] "r"(0x77777777u), "a"(orig));
32 return ret;
35 int main()
37 unsigned long test = 0xdeadbeef12345678ull;
38 assert(test == test_cmpxchgb(test));
39 assert(test == test_cmpxchgw(test));
40 assert(test == test_cmpxchgl(test));
41 return 0;