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