xref: /openbmc/qemu/tests/tcg/s390x/vxeh2_vs.c (revision 764a6ee9)
1 /*
2  * vxeh2_vs: vector-enhancements facility 2 vector shift
3  */
4 #include <stdint.h>
5 #include "vx.h"
6 
7 #define vtst(v1, v2) \
8     if (v1.d[0] != v2.d[0] || v1.d[1] != v2.d[1]) { \
9         return 1;     \
10     }
11 
12 static inline void vsl(S390Vector *v1, S390Vector *v2, S390Vector *v3)
13 {
14     asm volatile("vsl %[v1], %[v2], %[v3]\n"
15                 : [v1] "=v" (v1->v)
16                 : [v2]  "v" (v2->v)
17                 , [v3]  "v" (v3->v));
18 }
19 
20 static inline void vsra(S390Vector *v1, S390Vector *v2, S390Vector *v3)
21 {
22     asm volatile("vsra %[v1], %[v2], %[v3]\n"
23                 : [v1] "=v" (v1->v)
24                 : [v2]  "v" (v2->v)
25                 , [v3]  "v" (v3->v));
26 }
27 
28 static inline void vsrl(S390Vector *v1, S390Vector *v2, S390Vector *v3)
29 {
30     asm volatile("vsrl %[v1], %[v2], %[v3]\n"
31                 : [v1] "=v" (v1->v)
32                 : [v2]  "v" (v2->v)
33                 , [v3]  "v" (v3->v));
34 }
35 
36 static inline void vsld(S390Vector *v1, S390Vector *v2,
37     S390Vector *v3, const uint8_t I)
38 {
39     asm volatile("vsld %[v1], %[v2], %[v3], %[I]\n"
40                 : [v1] "=v" (v1->v)
41                 : [v2]  "v" (v2->v)
42                 , [v3]  "v" (v3->v)
43                 , [I]   "i" (I & 7));
44 }
45 
46 static inline void vsrd(S390Vector *v1, S390Vector *v2,
47     S390Vector *v3, const uint8_t I)
48 {
49     asm volatile("vsrd %[v1], %[v2], %[v3], %[I]\n"
50                 : [v1] "=v" (v1->v)
51                 : [v2]  "v" (v2->v)
52                 , [v3]  "v" (v3->v)
53                 , [I]   "i" (I & 7));
54 }
55 
56 int main(int argc, char *argv[])
57 {
58     const S390Vector vt_vsl  = { .d[0] = 0x7FEDBB32D5AA311Dull,
59                                  .d[1] = 0xBB65AA10912220C0ull };
60     const S390Vector vt_vsra = { .d[0] = 0xF1FE6E7399AA5466ull,
61                                  .d[1] = 0x0E762A5188221044ull };
62     const S390Vector vt_vsrl = { .d[0] = 0x11FE6E7399AA5466ull,
63                                  .d[1] = 0x0E762A5188221044ull };
64     const S390Vector vt_vsld = { .d[0] = 0x7F76EE65DD54CC43ull,
65                                  .d[1] = 0xBB32AA2199108838ull };
66     const S390Vector vt_vsrd = { .d[0] = 0x0E060802040E000Aull,
67                                  .d[1] = 0x0C060802040E000Aull };
68     S390Vector vs  = { .d[0] = 0x8FEEDDCCBBAA9988ull,
69                        .d[1] = 0x7766554433221107ull };
70     S390Vector  vd = { .d[0] = 0, .d[1] = 0 };
71     S390Vector vsi = { .d[0] = 0, .d[1] = 0 };
72 
73     for (int ix = 0; ix < 16; ix++) {
74         vsi.b[ix] = (1 + (5 ^ ~ix)) & 7;
75     }
76 
77     vsl(&vd, &vs, &vsi);
78     vtst(vd, vt_vsl);
79 
80     vsra(&vd, &vs, &vsi);
81     vtst(vd, vt_vsra);
82 
83     vsrl(&vd, &vs, &vsi);
84     vtst(vd, vt_vsrl);
85 
86     vsld(&vd, &vs, &vsi, 3);
87     vtst(vd, vt_vsld);
88 
89     vsrd(&vd, &vs, &vsi, 15);
90     vtst(vd, vt_vsrd);
91 
92     return 0;
93 }
94