xref: /openbmc/qemu/tests/tcg/s390x/vxeh2_vcvt.c (revision 75bbe5e5)
1 /*
2  * vxeh2_vcvt: vector-enhancements facility 2 vector convert *
3  */
4 #include <stdint.h>
5 #include "vx.h"
6 
7 #define M_S 8
8 #define M4_XxC 4
9 #define M4_def M4_XxC
10 
11 static inline void vcfps(S390Vector *v1, S390Vector *v2,
12     const uint8_t m3,  const uint8_t m4,  const uint8_t m5)
13 {
14     asm volatile("vcfps %[v1], %[v2], %[m3], %[m4], %[m5]\n"
15                 : [v1] "=v" (v1->v)
16                 : [v2]  "v" (v2->v)
17                 , [m3]  "i" (m3)
18                 , [m4]  "i" (m4)
19                 , [m5]  "i" (m5));
20 }
21 
22 static inline void vcfpl(S390Vector *v1, S390Vector *v2,
23     const uint8_t m3,  const uint8_t m4,  const uint8_t m5)
24 {
25     asm volatile("vcfpl %[v1], %[v2], %[m3], %[m4], %[m5]\n"
26                 : [v1] "=v" (v1->v)
27                 : [v2]  "v" (v2->v)
28                 , [m3]  "i" (m3)
29                 , [m4]  "i" (m4)
30                 , [m5]  "i" (m5));
31 }
32 
33 static inline void vcsfp(S390Vector *v1, S390Vector *v2,
34     const uint8_t m3,  const uint8_t m4,  const uint8_t m5)
35 {
36     asm volatile("vcsfp %[v1], %[v2], %[m3], %[m4], %[m5]\n"
37                 : [v1] "=v" (v1->v)
38                 : [v2]  "v" (v2->v)
39                 , [m3]  "i" (m3)
40                 , [m4]  "i" (m4)
41                 , [m5]  "i" (m5));
42 }
43 
44 static inline void vclfp(S390Vector *v1, S390Vector *v2,
45     const uint8_t m3,  const uint8_t m4,  const uint8_t m5)
46 {
47     asm volatile("vclfp %[v1], %[v2], %[m3], %[m4], %[m5]\n"
48                 : [v1] "=v" (v1->v)
49                 : [v2]  "v" (v2->v)
50                 , [m3]  "i" (m3)
51                 , [m4]  "i" (m4)
52                 , [m5]  "i" (m5));
53 }
54 
55 int main(int argc, char *argv[])
56 {
57     S390Vector vd;
58     S390Vector vs_i32 = { .w[0] = 1, .w[1] = 64, .w[2] = 1024, .w[3] = -10 };
59     S390Vector vs_u32 = { .w[0] = 2, .w[1] = 32, .w[2] = 4096, .w[3] = 8888 };
60     S390Vector vs_f32 = { .f[0] = 3.987, .f[1] = 5.123,
61                           .f[2] = 4.499, .f[3] = 0.512 };
62 
63     vd.d[0] = vd.d[1] = 0;
64     vcfps(&vd, &vs_i32, 2, M4_def, 0);
65     if (1 != vd.f[0] || 1024 != vd.f[2] || 64 != vd.f[1] || -10 != vd.f[3]) {
66         return 1;
67     }
68 
69     vd.d[0] = vd.d[1] = 0;
70     vcfpl(&vd, &vs_u32, 2, M4_def, 0);
71     if (2 != vd.f[0] || 4096 != vd.f[2] || 32 != vd.f[1] || 8888 != vd.f[3]) {
72         return 1;
73     }
74 
75     vd.d[0] = vd.d[1] = 0;
76     vcsfp(&vd, &vs_f32, 2, M4_def, 0);
77     if (4 != vd.w[0] || 4 != vd.w[2] || 5 != vd.w[1] || 1 != vd.w[3]) {
78         return 1;
79     }
80 
81     vd.d[0] = vd.d[1] = 0;
82     vclfp(&vd, &vs_f32, 2, M4_def, 0);
83     if (4 != vd.w[0] || 4 != vd.w[2] || 5 != vd.w[1] || 1 != vd.w[3]) {
84         return 1;
85     }
86 
87     return 0;
88 }
89