xref: /qemu/tests/tcg/s390x/vxeh2_vlstr.c (revision c4b8ffcb)
1 /*
2  * vxeh2_vlstr: vector-enhancements facility 2 vector load/store reversed *
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 vler(S390Vector *v1, const void *va, uint8_t m3)
13 {
14     asm volatile("vler %[v1], 0(%[va]), %[m3]\n"
15                 : [v1] "+v" (v1->v)
16                 : [va]  "a" (va)
17                 , [m3]  "i" (m3)
18                 : "memory");
19 }
20 
21 static inline void vster(S390Vector *v1, const void *va, uint8_t m3)
22 {
23     asm volatile("vster %[v1], 0(%[va]), %[m3]\n"
24                 : [va] "+a" (va)
25                 : [v1]  "v" (v1->v)
26                 , [m3]  "i" (m3)
27                 : "memory");
28 }
29 
30 static inline void vlbr(S390Vector *v1, void *va, const uint8_t m3)
31 {
32     asm volatile("vlbr %[v1], 0(%[va]), %[m3]\n"
33                 : [v1] "+v" (v1->v)
34                 : [va]  "a" (va)
35                 , [m3]  "i" (m3)
36                 : "memory");
37 }
38 
39 static inline void vstbr(S390Vector *v1, void *va, const uint8_t m3)
40 {
41     asm volatile("vstbr %[v1], 0(%[va]), %[m3]\n"
42                 : [va] "+a" (va)
43                 : [v1]  "v" (v1->v)
44                 , [m3]  "i" (m3)
45                 : "memory");
46 }
47 
48 
49 static inline void vlebrh(S390Vector *v1, void *va, const uint8_t m3)
50 {
51     asm volatile("vlebrh %[v1], 0(%[va]), %[m3]\n"
52                 : [v1] "+v" (v1->v)
53                 : [va]  "a" (va)
54                 , [m3]  "i" (m3)
55                 : "memory");
56 }
57 
58 static inline void vstebrh(S390Vector *v1, void *va, const uint8_t m3)
59 {
60     asm volatile("vstebrh %[v1], 0(%[va]), %[m3]\n"
61                 : [va] "+a" (va)
62                 : [v1]  "v" (v1->v)
63                 , [m3]  "i" (m3)
64                 : "memory");
65 }
66 
67 static inline void vllebrz(S390Vector *v1, void *va, const uint8_t m3)
68 {
69     asm volatile("vllebrz %[v1], 0(%[va]), %[m3]\n"
70                 : [v1] "+v" (v1->v)
71                 : [va]  "a" (va)
72                 , [m3]  "i" (m3)
73                 : "memory");
74 }
75 
76 static inline void vlbrrep(S390Vector *v1, void *va, const uint8_t m3)
77 {
78     asm volatile("vlbrrep %[v1], 0(%[va]), %[m3]\n"
79                 : [v1] "+v" (v1->v)
80                 : [va]  "a" (va)
81                 , [m3]  "i" (m3)
82                 : "memory");
83 }
84 
85 int main(int argc, char *argv[])
86 {
87     S390Vector vd = { .d[0] = 0, .d[1] = 0 };
88     S390Vector vs = { .d[0] = 0x8FEEDDCCBBAA9988ull,
89                       .d[1] = 0x7766554433221107ull };
90 
91     const S390Vector vt_v_er16 = {
92         .h[0] = 0x1107, .h[1] = 0x3322, .h[2] = 0x5544, .h[3] = 0x7766,
93         .h[4] = 0x9988, .h[5] = 0xBBAA, .h[6] = 0xDDCC, .h[7] = 0x8FEE };
94 
95     const S390Vector vt_v_br16 = {
96         .h[0] = 0xEE8F, .h[1] = 0xCCDD, .h[2] = 0xAABB, .h[3] = 0x8899,
97         .h[4] = 0x6677, .h[5] = 0x4455, .h[6] = 0x2233, .h[7] = 0x0711 };
98 
99     int ix;
100     uint64_t ss64 = 0xFEEDFACE0BADBEEFull, sd64 = 0;
101 
102     vler(&vd, &vs, ES16);
103     vtst(vd, vt_v_er16);
104 
105     vster(&vs, &vd, ES16);
106     vtst(vd, vt_v_er16);
107 
108     vlbr(&vd, &vs, ES16);
109     vtst(vd, vt_v_br16);
110 
111     vstbr(&vs, &vd, ES16);
112     vtst(vd, vt_v_br16);
113 
114     vlebrh(&vd, &ss64, 5);
115     if (0xEDFE != vd.h[5]) {
116         return 1;
117     }
118 
119     vstebrh(&vs, (uint8_t *)&sd64 + 4, 7);
120     if (0x0000000007110000ull != sd64) {
121         return 1;
122     }
123 
124     vllebrz(&vd, (uint8_t *)&ss64 + 3, 2);
125     for (ix = 0; ix < 4; ix++) {
126         if (vd.w[ix] != (ix != 1 ? 0 : 0xBEAD0BCE)) {
127             return 1;
128         }
129     }
130 
131     vlbrrep(&vd, (uint8_t *)&ss64 + 4, 1);
132     for (ix = 0; ix < 8; ix++) {
133         if (0xAD0B != vd.h[ix]) {
134             return 1;
135         }
136     }
137 
138     return 0;
139 }
140