xref: /openbmc/qemu/tests/tcg/x86_64/adox.c (revision ed75658a)
1 /* See if ADOX give expected results */
2 
3 #include <assert.h>
4 #include <stdint.h>
5 #include <stdbool.h>
6 
7 static uint64_t adoxq(bool *c_out, uint64_t a, uint64_t b, bool c)
8 {
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;
15 }
16 
17 static uint64_t adoxl(bool *c_out, uint64_t a, uint64_t b, bool c)
18 {
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;
25 }
26 
27 int main()
28 {
29     uint64_t r;
30     bool c;
31 
32     r = adoxq(&c, 0, 0, 0);
33     assert(r == 0);
34     assert(c == 0);
35 
36     r = adoxl(&c, 0, 0, 0);
37     assert(r == 0);
38     assert(c == 0);
39 
40     r = adoxl(&c, 0x100000000, 0, 0);
41     assert(r == 0);
42     assert(c == 0);
43 
44     r = adoxq(&c, 0, 0, 1);
45     assert(r == 1);
46     assert(c == 0);
47 
48     r = adoxl(&c, 0, 0, 1);
49     assert(r == 1);
50     assert(c == 0);
51 
52     r = adoxq(&c, -1, -1, 0);
53     assert(r == -2);
54     assert(c == 1);
55 
56     r = adoxl(&c, -1, -1, 0);
57     assert(r == 0xfffffffe);
58     assert(c == 1);
59 
60     r = adoxq(&c, -1, -1, 1);
61     assert(r == -1);
62     assert(c == 1);
63 
64     r = adoxl(&c, -1, -1, 1);
65     assert(r == 0xffffffff);
66     assert(c == 1);
67 
68     return 0;
69 }
70