xref: /openbmc/qemu/tests/tcg/s390x/vxeh2_vstrs.c (revision a75b180f)
1 /*
2  * Test the VSTRS instruction.
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  */
6 #include <assert.h>
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "vx.h"
11 
12 static inline __attribute__((__always_inline__)) int
13 vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
14       const S390Vector *v4, const uint8_t m5, const uint8_t m6)
15 {
16     int cc;
17 
18     asm("vstrs %[v1],%[v2],%[v3],%[v4],%[m5],%[m6]\n"
19         "ipm %[cc]"
20         : [v1] "=v" (v1->v)
21         , [cc] "=r" (cc)
22         : [v2] "v" (v2->v)
23         , [v3] "v" (v3->v)
24         , [v4] "v" (v4->v)
25         , [m5] "i" (m5)
26         , [m6]  "i" (m6)
27         : "cc");
28 
29     return (cc >> 28) & 3;
30 }
31 
32 static void test_ignored_match(void)
33 {
34     S390Vector v1;
35     S390Vector v2 = {.d[0] = 0x222000205e410000ULL, .d[1] = 0};
36     S390Vector v3 = {.d[0] = 0x205e410000000000ULL, .d[1] = 0};
37     S390Vector v4 = {.d[0] = 3, .d[1] = 0};
38 
39     assert(vstrs(&v1, &v2, &v3, &v4, 0, 2) == 1);
40     assert(v1.d[0] == 16);
41     assert(v1.d[1] == 0);
42 }
43 
44 static void test_empty_needle(void)
45 {
46     S390Vector v1;
47     S390Vector v2 = {.d[0] = 0x5300000000000000ULL, .d[1] = 0};
48     S390Vector v3 = {.d[0] = 0, .d[1] = 0};
49     S390Vector v4 = {.d[0] = 0, .d[1] = 0};
50 
51     assert(vstrs(&v1, &v2, &v3, &v4, 0, 0) == 2);
52     assert(v1.d[0] == 0);
53     assert(v1.d[1] == 0);
54 }
55 
56 static void test_max_length(void)
57 {
58     S390Vector v1;
59     S390Vector v2 = {.d[0] = 0x1122334455667700ULL, .d[1] = 0};
60     S390Vector v3 = {.d[0] = 0, .d[1] = 0};
61     S390Vector v4 = {.d[0] = 16, .d[1] = 0};
62 
63     assert(vstrs(&v1, &v2, &v3, &v4, 0, 0) == 3);
64     assert(v1.d[0] == 7);
65     assert(v1.d[1] == 0);
66 }
67 
68 static void test_no_match(void)
69 {
70     S390Vector v1;
71     S390Vector v2 = {.d[0] = 0xffffff000fffff00ULL, .d[1] = 0x82b};
72     S390Vector v3 = {.d[0] = 0xfffffffeffffffffULL,
73                      .d[1] = 0xffffffff00000000ULL};
74     S390Vector v4 = {.d[0] = 11, .d[1] = 0};
75 
76     assert(vstrs(&v1, &v2, &v3, &v4, 0, 2) == 1);
77     assert(v1.d[0] == 16);
78     assert(v1.d[1] == 0);
79 }
80 
81 int main(void)
82 {
83     test_ignored_match();
84     test_empty_needle();
85     test_max_length();
86     test_no_match();
87     return EXIT_SUCCESS;
88 }
89