1typedef unsigned char __v4qi __attribute__ ((__vector_size__ (4)));
2typedef unsigned char __v8qi __attribute__ ((__vector_size__ (8)));
3
4extern void abort (void);
5
6static void
7compare64 (int n, void *p, unsigned long long val)
8{
9  unsigned long long *x = (unsigned long long *) p;
10
11  if (*x != val)
12    abort();
13}
14
15static void
16compare32 (int n, void *p, unsigned int val)
17{
18  unsigned int *x = (unsigned int *) p;
19  if (*x != val)
20    abort();
21}
22
23#define V4QI_TEST(N, elt0, elt1, elt2, elt3)	\
24static void \
25test_v4qi_##N (unsigned char a, unsigned char b, unsigned char c, unsigned char d) \
26{ \
27  __v4qi v = { (elt0), (elt1), (elt2), (elt3) };	\
28  compare32(N, &v, ((int)(elt0) << 24) | \
29	           ((int)(elt1) << 16) | \
30	           ((int)(elt2) << 8) | ((int)(elt3)));	\
31}
32
33V4QI_TEST(1, a, a, a, a)
34V4QI_TEST(2, b, b, b, b)
35V4QI_TEST(3, a, b, c, d)
36V4QI_TEST(4, d, c, b, a)
37V4QI_TEST(5, a, 0, 0, 0)
38V4QI_TEST(6, b, 1, 1, b)
39V4QI_TEST(7, c, 5, d, 5)
40V4QI_TEST(8, 0x20, 0x30, b, a)
41V4QI_TEST(9, 0x40, 0x50, 0x60, 0x70)
42V4QI_TEST(10, 0x40, 0x50, 0x60, c)
43
44#define V8QI_TEST(N, elt0, elt1, elt2, elt3, elt4, elt5, elt6, elt7) \
45static void \
46test_v8qi_##N (unsigned char a, unsigned char b, unsigned char c, unsigned char d, \
47               unsigned char e, unsigned char f, unsigned char g, unsigned char h) \
48{ \
49  __v8qi v = { (elt0), (elt1), (elt2), (elt3), \
50	       (elt4), (elt5), (elt6), (elt7) }; \
51  compare64(N, &v, ((long long)(elt0) << 56) | \
52	           ((long long)(elt1) << 48) | \
53	           ((long long)(elt2) << 40) | \
54	           ((long long)(elt3) << 32) | \
55	           ((long long)(elt4) << 24) | \
56	           ((long long)(elt5) << 16) | \
57	           ((long long)(elt6) << 8) | \
58	           ((long long)(elt7) << 0)); \
59}
60
61V8QI_TEST(1, a, a, a, a, a, a, a, a)
62V8QI_TEST(2, a, b, c, d, e, f, g, h)
63V8QI_TEST(3, h, g, f, e, d, c, b, a)
64V8QI_TEST(4, a, b, a, b, a, b, a, b)
65V8QI_TEST(5, c, b, c, b, c, b, c, a)
66V8QI_TEST(6, a, 0, 0, 0, 0, 0, 0, 0)
67V8QI_TEST(7, b, 1, b, 1, b, 1, b, 1)
68V8QI_TEST(8, c, d, 0x20, a, 0x21, b, 0x23, c)
69V8QI_TEST(9, 1, 2, 3, 4, 5, 6, 7, 8)
70V8QI_TEST(10, a, a, b, b, c, c, d, d)
71
72unsigned char a8 = 0x33;
73unsigned char b8 = 0x55;
74unsigned char c8 = 0x77;
75unsigned char d8 = 0x99;
76unsigned char e8 = 0x11;
77unsigned char f8 = 0x22;
78unsigned char g8 = 0x44;
79unsigned char h8 = 0x66;
80
81int main(void)
82{
83  test_v4qi_1 (a8, b8, c8, d8);
84  test_v4qi_2 (a8, b8, c8, d8);
85  test_v4qi_3 (a8, b8, c8, d8);
86  test_v4qi_4 (a8, b8, c8, d8);
87  test_v4qi_5 (a8, b8, c8, d8);
88  test_v4qi_6 (a8, b8, c8, d8);
89  test_v4qi_7 (a8, b8, c8, d8);
90  test_v4qi_8 (a8, b8, c8, d8);
91  test_v4qi_9 (a8, b8, c8, d8);
92  test_v4qi_10 (a8, b8, c8, d8);
93
94  test_v8qi_1 (a8, b8, c8, d8, e8, f8, g8, h8);
95  test_v8qi_2 (a8, b8, c8, d8, e8, f8, g8, h8);
96  test_v8qi_3 (a8, b8, c8, d8, e8, f8, g8, h8);
97  test_v8qi_4 (a8, b8, c8, d8, e8, f8, g8, h8);
98  test_v8qi_5 (a8, b8, c8, d8, e8, f8, g8, h8);
99  test_v8qi_6 (a8, b8, c8, d8, e8, f8, g8, h8);
100  test_v8qi_7 (a8, b8, c8, d8, e8, f8, g8, h8);
101  test_v8qi_8 (a8, b8, c8, d8, e8, f8, g8, h8);
102  test_v8qi_9 (a8, b8, c8, d8, e8, f8, g8, h8);
103  test_v8qi_10 (a8, b8, c8, d8, e8, f8, g8, h8);
104  return 0;
105}
106