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 #define CONST4 (4)
18 #define CONST5 (5)
19 #define CONST6 (6)
20 #define CONST7 (7)
21 #define CONST8 (8)
22 #define CONST9 (9)
23 #define CONSTA (10)
24 #define CONSTB (11)
25 #define CONSTC (12)
26 #define CONSTD (13)
27 #define CONSTE (14)
28 #define CONSTF (15)
29
30
31 /* Test that indices > length of vector are applied modulo the vector
32 length. */
33
34 /* Test for vector residing in register. */
c0(vector unsigned char v,unsigned char x)35 vector unsigned char c0 (vector unsigned char v, unsigned char x)
36 {
37 return vec_insert (x, v, 0);
38 }
39
c9(vector unsigned char v,unsigned char x)40 vector unsigned char c9 (vector unsigned char v, unsigned char x)
41 {
42 return vec_insert (x, v, 9);
43 }
44
c21(vector unsigned char v,unsigned char x)45 vector unsigned char c21 (vector unsigned char v, unsigned char x)
46 {
47 return vec_insert (x, v, 21);
48 }
49
c30(vector unsigned char v,unsigned char x)50 vector unsigned char c30 (vector unsigned char v, unsigned char x)
51 {
52 return vec_insert (x, v, 30);
53 }
54
55 /* Test for vector residing in memory. */
mc0(vector unsigned char * vp,unsigned char x)56 vector unsigned char mc0 (vector unsigned char *vp, unsigned char x)
57 {
58 return vec_insert (x, *vp, 0);
59 }
60
mc9(vector unsigned char * vp,unsigned char x)61 vector unsigned char mc9 (vector unsigned char *vp, unsigned char x)
62 {
63 return vec_insert (x, *vp, 9);
64 }
65
mc21(vector unsigned char * vp,unsigned char x)66 vector unsigned char mc21 (vector unsigned char *vp, unsigned char x)
67 {
68 return vec_insert (x, *vp, 21);
69 }
70
mc30(vector unsigned char * vp,unsigned char x)71 vector unsigned char mc30 (vector unsigned char *vp, unsigned char x)
72 {
73 return vec_insert (x, *vp, 30);
74 }
75
76 /* Test the same with variable indices. */
77
78 /* Test for variable selector and vector residing in register. */
79 __attribute__((noinline))
ci(vector unsigned char v,int i,unsigned char x)80 vector unsigned char ci (vector unsigned char v, int i, unsigned char x)
81 {
82 return vec_insert (x, v, i);
83 }
84
85 /* Test for variable selector and vector residing in memory. */
86 __attribute__((noinline))
mci(vector unsigned char * vp,int i,unsigned char x)87 vector unsigned char mci (vector unsigned char *vp, int i, unsigned char x)
88 {
89 return vec_insert (x, *vp, i);
90 }
91
92
main(int argc,char * argv[])93 int main (int argc, char *argv[]) {
94 vector unsigned char cv = { CONST0, CONST1, CONST2, CONST3,
95 CONST4, CONST5, CONST6, CONST7,
96 CONST8, CONST9, CONSTA, CONSTB,
97 CONSTC, CONSTD, CONSTE, CONSTF };
98 cv = c0 (cv, CONST3);
99 if (cv [0] != CONST3)
100 abort ();
101
102 cv = c9 (cv, CONST2);
103 if (cv [9] != CONST2)
104 abort ();
105
106 cv = c21 (cv, CONSTF);
107 if (cv [5] != CONSTF)
108 abort ();
109
110 cv = c30 (cv, CONST3);
111 if (cv [14] != CONST3)
112 abort ();
113
114 cv = mc0 (&cv, CONST4);
115 if (cv [0] != CONST4)
116 abort ();
117
118 cv = mc9 (&cv, CONST3);
119 if (cv [9] != CONST3)
120 abort ();
121
122 cv = mc21 (&cv, CONST1);
123 if (cv [5] != CONST1)
124 abort ();
125
126 cv = mc30 (&cv, CONSTC);
127 if (cv [14] != CONSTC)
128 abort ();
129
130 cv = ci (cv, 8, CONSTD);
131 if (cv [8] != CONSTD)
132 abort ();
133
134 cv = ci (cv, 13, CONST5);
135 if (cv [13] != CONST5)
136 abort ();
137
138 cv = ci (cv, 23, CONST6);
139 if (cv [7] != CONST6)
140 abort ();
141
142 cv = ci (cv, 31, CONST7);
143 if (cv [15] != CONST7)
144 abort ();
145
146 cv = mci (&cv, 5, CONST8);
147 if (cv [5] != CONST8)
148 abort ();
149
150 cv = mci (&cv, 12, CONST9);
151 if (cv [12] != CONST9)
152 abort ();
153
154 cv = mci (&cv, 25, CONSTA);
155 if (cv [9] != CONSTA)
156 abort ();
157
158 cv = mci (&cv, 16, CONSTB);
159 if (cv [0] != CONSTB)
160 abort ();
161
162 return 0;
163 }
164