1 /* { dg-do run } */
2 /* { dg-require-effective-target p8vector_hw } */
3 /* { dg-options "-mpower8-vector" } */
4 
5 #include <altivec.h> // vector
6 #include <stdlib.h>
7 
8 #ifdef DEBUG
9 #include <stdio.h>
10 #endif
11 
12 void abort (void);
13 
main()14 int main() {
15   vector signed int vec_si_arg1, vec_si_arg2;
16   vector signed int vec_si_expected, vec_si_result;
17   vector unsigned int vec_ui_arg1, vec_ui_arg2;
18   vector unsigned int vec_ui_expected, vec_ui_result;
19   vector signed long long vec_sll_arg1, vec_sll_arg2;
20   vector signed long long vec_sll_expected, vec_sll_result;
21   vector unsigned long long vec_ull_arg1, vec_ull_arg2;
22   vector unsigned long long vec_ull_expected, vec_ull_result;
23   vector bool long long vec_bll_arg1, vec_bll_arg2;
24   vector bool long long vec_bll_expected, vec_bll_result;
25   vector float vec_f_arg1, vec_f_arg2;
26   vector float vec_f_expected, vec_f_result;
27   vector double vec_d_arg1, vec_d_arg2;
28   vector double vec_d_expected, vec_d_result;
29   int i;
30   unsigned long long int value;
31 
32   /* Tests for vec_mergeo, Merges the odd-numbered halves of two vectors.  */
33   vec_si_arg1 = (vector int){-100, -101, 102, 103};
34   vec_si_arg2 = (vector int){200, 201, 202, 203};
35 
36   vec_si_result = vec_mergeo (vec_si_arg1, vec_si_arg2);
37 
38   vec_si_expected = (vector int){-101, 201, 103, 203};
39 
40   for (i = 0; i < 4; i++)
41     if (vec_si_result[i] != vec_si_expected[i])
42 #ifdef DEBUG
43       printf("ERROR vec_mergeo(): vec_si_result[%d] = %d, vec_si_expected[%d] = %d\n",
44 	     i, vec_si_result[i], i, vec_si_expected[i]);
45 #else
46       abort();
47 #endif
48 
49   vec_ui_arg1 = (vector unsigned int){100, 101, 102, 103};
50   vec_ui_arg2 = (vector unsigned int){200, 201, 202, 203};
51 
52   vec_ui_result = vec_mergeo (vec_ui_arg1, vec_ui_arg2);
53 
54   vec_ui_expected = (vector unsigned int){101, 201, 103, 203};
55 
56   for (i = 0; i < 4; i++)
57     if (vec_ui_result[i] != vec_ui_expected[i])
58 #ifdef DEBUG
59       printf("ERROR vec_mergeo(): vec_ui_result[%d] = %d, vec_ui_expected[%d] = %d\n",
60 	     i, vec_ui_result[i], i, vec_ui_expected[i]);
61 #else
62       abort();
63 #endif
64 
65   vec_sll_arg1 = (vector long long int){-300, -301};
66   vec_sll_arg2 = (vector long long int){400, 401};
67 
68   vec_sll_result = vec_mergeo (vec_sll_arg1, vec_sll_arg2);
69 
70   vec_sll_expected = (vector long long int){-301, 401};
71 
72   for (i = 0; i < 2; i++)
73     if (vec_sll_result[i] != vec_sll_expected[i])
74 #ifdef DEBUG
75       printf("ERROR vec_mergeo(): vec_sll_result[%d] = %lld, vec_sll_expected[%d] = %lld\n",
76 	     i, (long long int)vec_sll_result[i],
77 	     i, (long long int)vec_sll_expected[i]);
78 #else
79       abort();
80 #endif
81 
82   vec_ull_arg1 = (vector unsigned long long int){500, 501};
83   vec_ull_arg2 = (vector unsigned long long int){600, 601};
84 
85   vec_ull_result = vec_mergeo (vec_ull_arg1, vec_ull_arg2);
86 
87   vec_ull_expected = (vector unsigned long long int){501, 601};
88 
89   for (i = 0; i < 2; i++)
90     if (vec_ull_result[i] != vec_ull_expected[i])
91 #ifdef DEBUG
92       printf("ERROR vec_mergeo(): vec_ull_result[%d] = %lld, vec_ull_expected[%d] = %lld\n",
93 	     i, (unsigned long long int)vec_ull_result[i],
94 	     i, (unsigned long long int)vec_ull_expected[i]);
95 #else
96       abort();
97 #endif
98 
99   vec_bll_arg1 = (vector bool long long){0, 0};
100   vec_bll_arg2 = (vector bool long long){1, 1};
101 
102   vec_bll_result = vec_mergeo (vec_bll_arg1, vec_bll_arg2);
103 
104   vec_bll_expected = (vector bool long long){0, 1};
105 
106   for (i = 0; i < 2; i++)
107     if (vec_bll_result[i] != vec_bll_expected[i])
108 #ifdef DEBUG
109       printf("ERROR vec_mergeo(): vec_bll_result[%d] = %lld, vec_bll_expected[%d] = %lld\n",
110 	     i, vec_ull_result[i],
111 	     i, vec_ull_expected[i]);
112 #else
113       abort();
114 #endif
115 
116   vec_f_arg1 = (vector float){100.0, 101.1, 102.2, 103.3};
117   vec_f_arg2 = (vector float){200.0, 201.1, 202.2, 203.3};
118 
119   vec_f_result = vec_mergeo (vec_f_arg1, vec_f_arg2);
120 
121   vec_f_expected = (vector float){101.1, 201.1, 103.3, 203.3};
122 
123   for (i = 0; i < 4; i++)
124     if (vec_f_result[i] != vec_f_expected[i])
125 #ifdef DEBUG
126       printf("ERROR vec_mergeo(): vec_f_result[%d] = %f, vec_f_expected[%d] = %f\n",
127 	     i, vec_f_result[i], i, vec_f_expected[i]);
128 #else
129       abort();
130 #endif
131 
132   vec_d_arg1 = (vector double){300.0, 301.1};
133   vec_d_arg2 = (vector double){400.0, 401.1};
134 
135   vec_d_result = vec_mergeo (vec_d_arg1, vec_d_arg2);
136 
137   vec_d_expected = (vector double){301.1, 401.1};
138 
139   for (i = 0; i < 2; i++)
140     if (vec_d_result[i] != vec_d_expected[i])
141 #ifdef DEBUG
142       printf("ERROR vec_mergeo(): vec_d_result[%d] = %f, vec_d_expected[%d] = %f\n",
143 	     i, vec_d_result[i], i, vec_d_expected[i]);
144 #else
145       abort();
146 #endif
147 
148   /* Tests for vec_mergee, Merges the even-numbered halves of two vectors.  */
149   vec_si_arg1 = (vector int){-100, -101, 102, 103};
150   vec_si_arg2 = (vector int){200, 201, 202, 203};
151 
152   vec_si_result = vec_mergee (vec_si_arg1, vec_si_arg2);
153 
154   vec_si_expected = (vector int){-100, 200, 102, 202};
155 
156   for (i = 0; i < 4; i++)
157     if (vec_si_result[i] != vec_si_expected[i])
158 #ifdef DEBUG
159       printf("ERROR vec_mergee(): vec_si_result[%d] = %d, vec_si_expected[%d] = %d\n",
160 	     i, vec_si_result[i], i, vec_si_expected[i]);
161 #else
162       abort();
163 #endif
164 
165   vec_ui_arg1 = (vector unsigned int){100, 101, 102, 103};
166   vec_ui_arg2 = (vector unsigned int){200, 201, 202, 203};
167 
168   vec_ui_result = vec_mergee (vec_ui_arg1, vec_ui_arg2);
169 
170   vec_ui_expected = (vector unsigned int){100, 200, 102, 202};
171 
172   for (i = 0; i < 4; i++)
173     if (vec_ui_result[i] != vec_ui_expected[i])
174 #ifdef DEBUG
175       printf("ERROR vec_mergee(): vec_ui_result[%d] = %d, vec_ui_expected[%d] = %d\n",
176 	     i, vec_ui_result[i], i, vec_ui_expected[i]);
177 #else
178       abort();
179 #endif
180 
181   vec_sll_arg1 = (vector signed long long int){-300, -301};
182   vec_sll_arg2 = (vector signed long long int){400, 401};
183 
184   vec_sll_result = vec_mergee (vec_sll_arg1, vec_sll_arg2);
185 
186   vec_sll_expected = (vector signed long long int){-300, 400};
187 
188   for (i = 0; i < 2; i++)
189     if (vec_sll_result[i] != vec_sll_expected[i])
190 #ifdef DEBUG
191 	printf("ERROR vec_mergee(): vec_sll_result[%d] = %lld, vec_sll_expected[%d] = %lld\n",
192 		i, (signed long long int)vec_sll_result[i],
193 		i, (signed long long int)vec_sll_expected[i]);
194 #else
195       abort();
196 #endif
197 
198   vec_ull_arg1 = (vector unsigned long long int){500, 501};
199   vec_ull_arg2 = (vector unsigned long long int){600, 601};
200 
201   vec_ull_result = vec_mergee (vec_ull_arg1, vec_ull_arg2);
202 
203   vec_ull_expected = (vector unsigned long long int){500, 600};
204 
205   for (i = 0; i < 2; i++)
206     if (vec_ull_result[i] != vec_ull_expected[i])
207 #ifdef DEBUG
208 	printf("ERROR vec_mergee(): vec_ull_result[%d] = %lld, vec_ull_expected[%d] = %lld\n",
209 	       i, (unsigned long long int)vec_ull_result[i],
210 	       i, (unsigned long long int)vec_ull_expected[i]);
211 #else
212       abort();
213 #endif
214 
215   vec_bll_arg1 = (vector bool long long){0, 0};
216   vec_bll_arg2 = (vector bool long long){1, 1};
217 
218   vec_bll_result = vec_mergee (vec_bll_arg1, vec_bll_arg2);
219 
220   vec_bll_expected = (vector bool long long){0, 1};
221 
222   for (i = 0; i < 2; i++)
223     if (vec_bll_result[i] != vec_bll_expected[i])
224 #ifdef DEBUG
225       printf("ERROR vec_mergee(): vec_bll_result[%d] = %lld, vec_bll_expected[%d] = %lld\n",
226 	     i, vec_ull_result[i],
227 	     i, vec_ull_expected[i]);
228 #else
229       abort();
230 #endif
231 
232   vec_f_arg1 = (vector float){100.0, 101.1, 102.2, 103.3};
233   vec_f_arg2 = (vector float){200.0, 201.1, 202.2, 203.3};
234 
235   vec_f_result = vec_mergee (vec_f_arg1, vec_f_arg2);
236 
237   vec_f_expected = (vector float){100.0, 200.0, 102.2, 202.2};
238 
239   for (i = 0; i < 4; i++)
240     if (vec_f_result[i] != vec_f_expected[i])
241 #ifdef DEBUG
242       printf("ERROR vec_mergee(): vec_f_result[%d] = %f, vec_f_expected[%d] = %f\n",
243 	     i, vec_f_result[i], i, vec_f_expected[i]);
244 #else
245       abort();
246 #endif
247 
248   vec_d_arg1 = (vector double){300.0, 301.1};
249   vec_d_arg2 = (vector double){400.0, 401.1};
250 
251   vec_d_result = vec_mergee (vec_d_arg1, vec_d_arg2);
252 
253   vec_d_expected = (vector double){300.0, 400.0};
254 
255   for (i = 0; i < 2; i++)
256     if (vec_d_result[i] != vec_d_expected[i])
257 #ifdef DEBUG
258       printf("ERROR vec_mergee(): vec_d_result[%d] = %f, vec_d_expected[%d] = %f\n",
259 	     i, vec_d_result[i], i, vec_d_expected[i]);
260 #else
261       abort();
262 #endif
263 }
264