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/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 #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,unsigned short x)27 vector unsigned short s3 (vector unsigned short v, unsigned short x)
28 {
29   return vec_insert (x, v, 3);
30 }
31 
s7(vector unsigned short v,unsigned short x)32 vector unsigned short s7 (vector unsigned short v, unsigned short x)
33 {
34   return vec_insert (x, v, 7);
35 }
36 
s21(vector unsigned short v,unsigned short x)37 vector unsigned short s21 (vector unsigned short v, unsigned short x)
38 {
39   return vec_insert (x, v, 21);
40 }
41 
s30(vector unsigned short v,unsigned short x)42 vector unsigned short s30 (vector unsigned short v, unsigned short x)
43 {
44   return vec_insert (x, v, 30);
45 }
46 
47 /* Test for vector residing in memory.  */
ms3(vector unsigned short * vp,unsigned short x)48 vector unsigned short ms3 (vector unsigned short *vp, unsigned short x)
49 {
50   return vec_insert (x, *vp, 3);
51 }
52 
ms7(vector unsigned short * vp,unsigned short x)53 vector unsigned short ms7 (vector unsigned short *vp, unsigned short x)
54 {
55   return vec_insert (x, *vp, 7);
56 }
57 
ms21(vector unsigned short * vp,unsigned short x)58 vector unsigned short ms21 (vector unsigned short *vp, unsigned short x)
59 {
60   return vec_insert (x, *vp, 21);
61 }
62 
ms30(vector unsigned short * vp,unsigned short x)63 vector unsigned short ms30 (vector unsigned short *vp, unsigned short x)
64 {
65   return vec_insert (x, *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,unsigned short x)72 vector unsigned short ci (vector unsigned short v, int i, unsigned short x)
73 {
74   return vec_insert (x, v, i);
75 }
76 
77 /* Test for variable selector and vector residing in memory.  */
78 __attribute__((noinline))
mci(vector unsigned short * vp,int i,unsigned short x)79 vector unsigned short mci (vector unsigned short *vp, int i, unsigned short x)
80 {
81   return vec_insert (x, *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 
89   sv = s3 (sv, CONST1);
90   if (sv [3] != CONST1)
91     abort ();
92 
93   sv = s7 (sv, CONST2);
94   if (sv [7] != CONST2)
95     abort ();
96 
97   sv = s21 (sv, CONST3);
98   if (sv [5] != CONST3)
99     abort ();
100 
101   sv = s30 (sv, CONST4);
102   if (sv [6] != CONST4)
103     abort ();
104 
105   sv = ms3 (&sv, CONST5);
106   if (sv [3] != CONST5)
107     abort ();
108 
109   sv = ms7 (&sv, CONST6);
110   if (sv [7] != CONST6)
111     abort ();
112 
113   sv = ms21 (&sv, CONST7);
114   if (sv [5] != CONST7)
115     abort ();
116 
117   sv = ms30 (&sv, CONST0);
118   if (sv [6] != CONST0)
119     abort ();
120 
121   sv = ci (sv, 5, CONST1);
122   if (sv [5] != CONST1)
123     abort ();
124 
125   sv = ci (sv, 2, CONST3);
126   if (sv [2] != CONST3)
127     abort ();
128 
129   sv = ci (sv, 15, CONST2);
130   if (sv [7] != CONST2)
131     abort ();
132 
133   sv = ci (sv, 28, CONST5);
134   if (sv [4] != CONST5)
135     abort ();
136 
137   sv = mci (&sv, 5, CONST4);
138   if (sv [5] != CONST4)
139     abort ();
140 
141   sv = mci (&sv, 12, CONST6);
142   if (sv [4] != CONST6)
143     abort ();
144 
145   sv = mci (&sv, 25, CONST7);
146   if (sv [1] != CONST7)
147     abort ();
148 
149   sv = mci (&sv, 16, CONST4);
150   if (sv [0] != CONST4)
151     abort ();
152 
153   return 0;
154 }
155