Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / s390x / vistr.c
blob7ed59b94b85724258ead8ae6f1e9278e140c0e08
1 #include <stdio.h>
2 #include <string.h>
4 #define VECTOR __attribute__ ((vector_size (16)))
6 typedef char VECTOR char_v;
8 volatile char tmp;
9 static const char *hex_digit = "0123456789abcdef";
11 static char_v to_char_vec(const char *str, char_v *maskp)
13 char buf[17];
14 char_v v;
15 char_v mask = {0};
17 for (int i = 0; i < sizeof(buf); i++) {
18 char ch = str[i];
19 if (ch == '\0')
20 break;
21 else if (ch == '$') {
22 buf[i] = '\0';
23 mask[i] = -1;
24 } else if (ch != '~') {
25 buf[i] = ch;
26 mask[i] = -1;
29 v = *(char_v *) buf;
30 *maskp = mask;
31 return v;
34 static void test_vistr_char(const char *str, const char *expect_res,
35 int expect_cc)
37 int cc, count;
38 char_v v1, mask;
39 char_v v2 = to_char_vec(str, &mask);
40 char_v exp_v1 = to_char_vec(expect_res, &mask);
41 char equal[16];
43 __asm__(
44 "cr 0,0\n\t" /* Clear CC */
45 "vistr %[v1],%[v2],0,1\n\t"
46 "ipm %[cc]\n\t"
47 "srl %[cc],28"
48 : [v1] "=v" (v1),
49 [cc] "=d" (cc)
50 : [v2] "v" (v2)
51 : "cc");
53 *(char_v *) equal = (v1 & mask) == (exp_v1 & mask);
54 if (memchr(equal, 0, sizeof(equal)))
55 printf("Result doesn't match `%s'\n", expect_res);
57 count = 0;
58 for (int i = 0; i < 16; i++) {
59 if (v1[i] == 0) count++;
61 tmp = hex_digit[count];
63 tmp = hex_digit[cc & 0xf];
64 if (expect_cc >= 0 && cc != expect_cc)
65 printf("CC %d != %d\n", cc, expect_cc);
68 int main()
70 test_vistr_char("terminated$====~", "terminated$$$$$$", 0);
71 test_vistr_char("undef~~~~~~~~~~~", "undef", -1);
72 test_vistr_char("undef, 2nd half~", "undef, 2nd half", -1);
73 test_vistr_char("Not. Terminated.", "Not. Terminated.", 3);
74 test_vistr_char("partiallyOK~~$~~", "partiallyOK~~$$$", 0);
75 return 0;