aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/s390x/div.c
blob: 6ad9900e082279ee7e24321c522924672b178cdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <assert.h>
#include <stdint.h>

static void test_dr(void)
{
    register int32_t r0 asm("r0") = -1;
    register int32_t r1 asm("r1") = -4241;
    int32_t b = 101, q, r;

    asm("dr %[r0],%[b]"
        : [r0] "+r" (r0), [r1] "+r" (r1)
        : [b] "r" (b)
        : "cc");
    q = r1;
    r = r0;
    assert(q == -41);
    assert(r == -100);
}

static void test_dlr(void)
{
    register uint32_t r0 asm("r0") = 0;
    register uint32_t r1 asm("r1") = 4243;
    uint32_t b = 101, q, r;

    asm("dlr %[r0],%[b]"
        : [r0] "+r" (r0), [r1] "+r" (r1)
        : [b] "r" (b)
        : "cc");
    q = r1;
    r = r0;
    assert(q == 42);
    assert(r == 1);
}

static void test_dsgr(void)
{
    register int64_t r0 asm("r0") = -1;
    register int64_t r1 asm("r1") = -4241;
    int64_t b = 101, q, r;

    asm("dsgr %[r0],%[b]"
        : [r0] "+r" (r0), [r1] "+r" (r1)
        : [b] "r" (b)
        : "cc");
    q = r1;
    r = r0;
    assert(q == -41);
    assert(r == -100);
}

static void test_dlgr(void)
{
    register uint64_t r0 asm("r0") = 0;
    register uint64_t r1 asm("r1") = 4243;
    uint64_t b = 101, q, r;

    asm("dlgr %[r0],%[b]"
        : [r0] "+r" (r0), [r1] "+r" (r1)
        : [b] "r" (b)
        : "cc");
    q = r1;
    r = r0;
    assert(q == 42);
    assert(r == 1);
}

int main(void)
{
    test_dr();
    test_dlr();
    test_dsgr();
    test_dlgr();
    return 0;
}