aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/s390x/vxeh2_vs.c
blob: b7ef419d79a032f6546bacd426edf7653990c470 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * vxeh2_vs: vector-enhancements facility 2 vector shift
 */
#include <stdint.h>
#include "vx.h"

#define vtst(v1, v2) \
    if (v1.d[0] != v2.d[0] || v1.d[1] != v2.d[1]) { \
        return 1;     \
    }

static inline void vsl(S390Vector *v1, S390Vector *v2, S390Vector *v3)
{
    asm volatile("vsl %[v1], %[v2], %[v3]\n"
                : [v1] "=v" (v1->v)
                : [v2]  "v" (v2->v)
                , [v3]  "v" (v3->v));
}

static inline void vsra(S390Vector *v1, S390Vector *v2, S390Vector *v3)
{
    asm volatile("vsra %[v1], %[v2], %[v3]\n"
                : [v1] "=v" (v1->v)
                : [v2]  "v" (v2->v)
                , [v3]  "v" (v3->v));
}

static inline void vsrl(S390Vector *v1, S390Vector *v2, S390Vector *v3)
{
    asm volatile("vsrl %[v1], %[v2], %[v3]\n"
                : [v1] "=v" (v1->v)
                : [v2]  "v" (v2->v)
                , [v3]  "v" (v3->v));
}

static inline void vsld(S390Vector *v1, S390Vector *v2,
    S390Vector *v3, const uint8_t I)
{
    asm volatile("vsld %[v1], %[v2], %[v3], %[I]\n"
                : [v1] "=v" (v1->v)
                : [v2]  "v" (v2->v)
                , [v3]  "v" (v3->v)
                , [I]   "i" (I & 7));
}

static inline void vsrd(S390Vector *v1, S390Vector *v2,
    S390Vector *v3, const uint8_t I)
{
    asm volatile("vsrd %[v1], %[v2], %[v3], %[I]\n"
                : [v1] "=v" (v1->v)
                : [v2]  "v" (v2->v)
                , [v3]  "v" (v3->v)
                , [I]   "i" (I & 7));
}

int main(int argc, char *argv[])
{
    const S390Vector vt_vsl  = { .d[0] = 0x7FEDBB32D5AA311Dull,
                                 .d[1] = 0xBB65AA10912220C0ull };
    const S390Vector vt_vsra = { .d[0] = 0xF1FE6E7399AA5466ull,
                                 .d[1] = 0x0E762A5188221044ull };
    const S390Vector vt_vsrl = { .d[0] = 0x11FE6E7399AA5466ull,
                                 .d[1] = 0x0E762A5188221044ull };
    const S390Vector vt_vsld = { .d[0] = 0x7F76EE65DD54CC43ull,
                                 .d[1] = 0xBB32AA2199108838ull };
    const S390Vector vt_vsrd = { .d[0] = 0x0E060802040E000Aull,
                                 .d[1] = 0x0C060802040E000Aull };
    S390Vector vs  = { .d[0] = 0x8FEEDDCCBBAA9988ull,
                       .d[1] = 0x7766554433221107ull };
    S390Vector  vd = { .d[0] = 0, .d[1] = 0 };
    S390Vector vsi = { .d[0] = 0, .d[1] = 0 };

    for (int ix = 0; ix < 16; ix++) {
        vsi.b[ix] = (1 + (5 ^ ~ix)) & 7;
    }

    vsl(&vd, &vs, &vsi);
    vtst(vd, vt_vsl);

    vsra(&vd, &vs, &vsi);
    vtst(vd, vt_vsra);

    vsrl(&vd, &vs, &vsi);
    vtst(vd, vt_vsrl);

    vsld(&vd, &vs, &vsi, 3);
    vtst(vd, vt_vsld);

    vsrd(&vd, &vs, &vsi, 15);
    vtst(vd, vt_vsrd);

    return 0;
}