4 #define VECTOR __attribute__ ((vector_size (16)))
6 typedef char VECTOR char_v
;
9 static const char *hex_digit
= "0123456789abcdefGHIJKLMNOPQRSTUV";
11 static char_v
to_char_vec(const char *str
)
16 for (int i
= 0; i
< sizeof(buf
); i
++) {
29 static void test_vstrs_char(const char *haystack
, const char *needle
,
30 int expect_res
, int expect_cc
)
33 char_v v2val
= to_char_vec(haystack
);
34 char_v v3val
= to_char_vec(needle
);
36 register unsigned long VECTOR v4
__asm__("v4") = { strlen(needle
), 0 };
37 register char_v v1
__asm__("v1");
38 register char_v v2
__asm__("v2") = v2val
;
39 register char_v v3
__asm__("v3") = v3val
;
42 "cr 0,0\n\t" /* Clear CC */
43 ".short 0xe712,0x3020,0x408b\n\t" /* vstrs %v1,%v2,%v3,%v4,0,2 */
46 : "=v" (v1
), [cc
] "=d" (cc
)
47 : "v" (v2
), "v" (v3
), "v" (v4
)
50 tmp
= hex_digit
[v1
[7] & 0x1f];
51 if (expect_res
>= 0 && v1
[7] != expect_res
)
52 printf("result %u != %d\n", v1
[7], expect_res
);
54 tmp
= hex_digit
[cc
& 0xf];
55 if (expect_cc
>= 0 && cc
!= expect_cc
)
56 printf("CC %d != %d\n", cc
, expect_cc
);
61 test_vstrs_char("haystack$needle", "needle$haystack", 16, 1);
62 test_vstrs_char("haystack, needle", "needle, haystack", 10, 3);
63 test_vstrs_char("ABCDEFGH", "DEFGHI", -1, -1);
64 test_vstrs_char("match in UNDEF", "UN", 9, 2);
65 test_vstrs_char("after ~ UNDEF", "DEF", -1, -1);
66 test_vstrs_char("", "", 0, 2);