xref: /openbmc/qemu/tests/tcg/s390x/div.c (revision bad5cfcd)
1 #include <assert.h>
2 #include <stdint.h>
3 
4 static void test_dr(void)
5 {
6     register int32_t r0 asm("r0") = -1;
7     register int32_t r1 asm("r1") = -4241;
8     int32_t b = 101, q, r;
9 
10     asm("dr %[r0],%[b]"
11         : [r0] "+r" (r0), [r1] "+r" (r1)
12         : [b] "r" (b)
13         : "cc");
14     q = r1;
15     r = r0;
16     assert(q == -41);
17     assert(r == -100);
18 }
19 
20 static void test_dlr(void)
21 {
22     register uint32_t r0 asm("r0") = 0;
23     register uint32_t r1 asm("r1") = 4243;
24     uint32_t b = 101, q, r;
25 
26     asm("dlr %[r0],%[b]"
27         : [r0] "+r" (r0), [r1] "+r" (r1)
28         : [b] "r" (b)
29         : "cc");
30     q = r1;
31     r = r0;
32     assert(q == 42);
33     assert(r == 1);
34 }
35 
36 static void test_dsgr(void)
37 {
38     register int64_t r0 asm("r0") = -1;
39     register int64_t r1 asm("r1") = -4241;
40     int64_t b = 101, q, r;
41 
42     asm("dsgr %[r0],%[b]"
43         : [r0] "+r" (r0), [r1] "+r" (r1)
44         : [b] "r" (b)
45         : "cc");
46     q = r1;
47     r = r0;
48     assert(q == -41);
49     assert(r == -100);
50 }
51 
52 static void test_dlgr(void)
53 {
54     register uint64_t r0 asm("r0") = 0;
55     register uint64_t r1 asm("r1") = 4243;
56     uint64_t b = 101, q, r;
57 
58     asm("dlgr %[r0],%[b]"
59         : [r0] "+r" (r0), [r1] "+r" (r1)
60         : [b] "r" (b)
61         : "cc");
62     q = r1;
63     r = r0;
64     assert(q == 42);
65     assert(r == 1);
66 }
67 
68 int main(void)
69 {
70     test_dr();
71     test_dlr();
72     test_dsgr();
73     test_dlgr();
74     return 0;
75 }
76