memcheck/tests/sh-mem-random.c: Set huge_addr to 240GB
[valgrind.git] / memcheck / tests / s390x / vstrc.c
blob268e2f8586875e82ce7a05f6963dd8812ca6d489
1 #include <stdio.h>
2 #include <string.h>
4 #define VECTOR __attribute__ ((vector_size (16)))
6 typedef char VECTOR char_v;
8 struct vstrc_char_rng {
9 unsigned char range[16];
10 unsigned char flags[16];
13 #define RNG_FLAG_EQ 0x80
14 #define RNG_FLAG_LT 0x40
15 #define RNG_FLAG_GT 0x20
16 #define RNG_FLAG_ANY 0xe0
17 #define RNG_FLAG_NONE 0x00
19 volatile char tmp;
20 static const char *hex_digit = "0123456789abcdefGHIJKLMNOPQRSTUV";
22 static void test_vstrc_char(const char *str, const struct vstrc_char_rng *rng,
23 int expect_res, int expect_cc)
25 int cc;
26 char_v v1;
27 char_v v2 = *(const char_v *) str;
28 char_v v3 = *(const char_v *) rng->range;
29 char_v v4 = *(const char_v *) rng->flags;
31 __asm__(
32 "cr 0,0\n\t" /* Clear CC */
33 "vstrc %[v1],%[v2],%[v3],%[v4],0,3\n\t"
34 "ipm %[cc]\n\t"
35 "srl %[cc],28"
36 : [v1] "=v" (v1),
37 [cc] "=d" (cc)
38 : [v2] "v" (v2),
39 [v3] "v" (v3),
40 [v4] "v" (v4)
41 : "cc");
43 tmp = hex_digit[v1[7] & 0x1f];
44 if (expect_res >= 0 && v1[7] != expect_res)
45 printf("result %u != %d\n", v1[7], expect_res);
47 tmp = hex_digit[cc & 0xf];
48 if (expect_cc >= 0 && cc != expect_cc)
49 printf("CC %d != %d\n", cc, expect_cc);
52 int main()
54 struct vstrc_char_rng rng;
55 char buf[16];
57 memset(rng.flags, RNG_FLAG_NONE, 16);
59 rng.range[4] = 'z';
60 rng.flags[4] = RNG_FLAG_GT | RNG_FLAG_EQ;
61 rng.flags[5] = RNG_FLAG_ANY;
62 /* OK: match at the 'z' */
63 test_vstrc_char("find the z", &rng, 9, 2);
65 rng.flags[12] = RNG_FLAG_GT | RNG_FLAG_EQ;
66 rng.flags[13] = RNG_FLAG_LT | RNG_FLAG_EQ;
67 /* Bad: undefined range */
68 test_vstrc_char("undefined", &rng, -1, -1);
70 rng.range[12] = 'a';
71 rng.range[13] = 'c';
72 /* OK: match at the 'a' */
73 test_vstrc_char("get the abc", &rng, 8, 2);
75 rng.flags[12] = RNG_FLAG_LT;
76 rng.flags[13] = RNG_FLAG_GT;
77 /* OK: no match up to null terminator */
78 test_vstrc_char("no match", &rng, 8, 0);
80 /* OK: no match, no null terminator */
81 test_vstrc_char("0123456789abcdef", &rng, 16, 3);
83 buf[0] = 'x';
84 /* Bad: undefined string */
85 test_vstrc_char(buf, &rng, -1, -1);
87 buf[1] = 'z';
88 /* Bad: valid match, but CC undefined */
89 test_vstrc_char(buf, &rng, 1, -1);
91 return 0;