Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / tests / tcg / x86_64 / adox.c
blob36be644c8bc5a43c6c2558f7f22268a7b627c3fe
1 /* See if ADOX give expected results */
3 #include <assert.h>
4 #include <stdint.h>
5 #include <stdbool.h>
7 static uint64_t adoxq(bool *c_out, uint64_t a, uint64_t b, bool c)
9 asm ("addl $0x7fffffff, %k1\n\t"
10 "adoxq %2, %0\n\t"
11 "seto %b1"
12 : "+r"(a), "=&r"(c) : "r"(b), "1"((int)c));
13 *c_out = c;
14 return a;
17 static uint64_t adoxl(bool *c_out, uint64_t a, uint64_t b, bool c)
19 asm ("addl $0x7fffffff, %k1\n\t"
20 "adoxl %k2, %k0\n\t"
21 "seto %b1"
22 : "+r"(a), "=&r"(c) : "r"(b), "1"((int)c));
23 *c_out = c;
24 return a;
27 int main()
29 uint64_t r;
30 bool c;
32 r = adoxq(&c, 0, 0, 0);
33 assert(r == 0);
34 assert(c == 0);
36 r = adoxl(&c, 0, 0, 0);
37 assert(r == 0);
38 assert(c == 0);
40 r = adoxl(&c, 0x100000000, 0, 0);
41 assert(r == 0);
42 assert(c == 0);
44 r = adoxq(&c, 0, 0, 1);
45 assert(r == 1);
46 assert(c == 0);
48 r = adoxl(&c, 0, 0, 1);
49 assert(r == 1);
50 assert(c == 0);
52 r = adoxq(&c, -1, -1, 0);
53 assert(r == -2);
54 assert(c == 1);
56 r = adoxl(&c, -1, -1, 0);
57 assert(r == 0xfffffffe);
58 assert(c == 1);
60 r = adoxq(&c, -1, -1, 1);
61 assert(r == -1);
62 assert(c == 1);
64 r = adoxl(&c, -1, -1, 1);
65 assert(r == 0xffffffff);
66 assert(c == 1);
68 return 0;