1 /* { dg-do run } */
2 /* { dg-require-effective-target vmx_hw } */
3 /* { dg-options "-maltivec" } */
4
5 /* This test should run the same on any target that supports altivec/dfp
6 instructions. Intentionally not specifying cpu in order to test
7 all code generation paths. */
8
9 #include <altivec.h>
10
11 extern void abort (void);
12
13 #define CONST0 (0)
14 #define CONST1 (1)
15 #define CONST2 (2)
16 #define CONST3 (3)
17 #define CONST4 (4)
18 #define CONST5 (5)
19 #define CONST6 (6)
20 #define CONST7 (7)
21
22
23 /* Test that indices > length of vector are applied modulo the vector
24 length. */
25
26 /* Test for vector residing in register. */
s3(vector unsigned short v)27 unsigned short s3 (vector unsigned short v)
28 {
29 return __builtin_vec_extract (v, 3);
30 }
31
s7(vector unsigned short v)32 unsigned short s7 (vector unsigned short v)
33 {
34 return __builtin_vec_extract (v, 7);
35 }
36
s21(vector unsigned short v)37 unsigned short s21 (vector unsigned short v)
38 {
39 return __builtin_vec_extract (v, 21);
40 }
41
s30(vector unsigned short v)42 unsigned short s30 (vector unsigned short v)
43 {
44 return __builtin_vec_extract (v, 30);
45 }
46
47 /* Test for vector residing in memory. */
ms3(vector unsigned short * vp)48 unsigned short ms3 (vector unsigned short *vp)
49 {
50 return __builtin_vec_extract (*vp, 3);
51 }
52
ms7(vector unsigned short * vp)53 unsigned short ms7 (vector unsigned short *vp)
54 {
55 return __builtin_vec_extract (*vp, 7);
56 }
57
ms21(vector unsigned short * vp)58 unsigned short ms21 (vector unsigned short *vp)
59 {
60 return __builtin_vec_extract (*vp, 21);
61 }
62
ms30(vector unsigned short * vp)63 unsigned short ms30 (vector unsigned short *vp)
64 {
65 return __builtin_vec_extract (*vp, 30);
66 }
67
68 /* Test the same with variable indices. */
69
70 /* Test for variable selector and vector residing in register. */
71 __attribute__((noinline))
ci(vector unsigned short v,int i)72 unsigned short ci (vector unsigned short v, int i)
73 {
74 return __builtin_vec_extract (v, i);
75 }
76
77 /* Test for variable selector and vector residing in memory. */
78 __attribute__((noinline))
mci(vector unsigned short * vp,int i)79 unsigned short mci (vector unsigned short *vp, int i)
80 {
81 return __builtin_vec_extract (*vp, i);
82 }
83
84
main(int argc,unsigned short * argv[])85 int main (int argc, unsigned short *argv[]) {
86 vector unsigned short sv = {
87 CONST0, CONST1, CONST2, CONST3, CONST4, CONST5, CONST6, CONST7 };
88 unsigned short s;
89
90 s = s3 (sv);
91 if (s != CONST3)
92 abort ();
93
94 s = s7 (sv);
95 if (s != CONST7)
96 abort ();
97
98 s = s21 (sv);
99 if (s != CONST5)
100 abort ();
101
102 s = s30 (sv);
103 if (s != CONST6)
104 abort ();
105
106 s = ms3 (&sv);
107 if (s != CONST3)
108 abort ();
109
110 s = ms7 (&sv);
111 if (s != CONST7)
112 abort ();
113
114 s = ms21 (&sv);
115 if (s != CONST5)
116 abort ();
117
118 s = ms30 (&sv);
119 if (s != CONST6)
120 abort ();
121
122 s = ci (sv, 5);
123 if (s != CONST5)
124 abort ();
125
126 s = ci (sv, 2);
127 if (s != CONST2)
128 abort ();
129
130 s = ci (sv, 15);
131 if (s != CONST7)
132 abort ();
133
134 s = ci (sv, 28);
135 if (s != CONST4)
136 abort ();
137
138 s = mci (&sv, 5);
139 if (s != CONST5)
140 abort ();
141
142 s = mci (&sv, 12);
143 if (s != CONST4)
144 abort ();
145
146 s = mci (&sv, 25);
147 if (s != CONST1)
148 abort ();
149
150 s = mci (&sv, 16);
151 if (s != CONST0)
152 abort ();
153
154 return 0;
155 }
156