gcc/ChangeLog:
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / builtins-5-p9-runnable.c
blob3bb46839a5f1d94ae6c763678292c52404170df6
1 /* { dg-do run { target { powerpc*-*-* && p9vector_hw } } } */
2 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power9" } } */
3 /* { dg-options "-mcpu=power9 -O2" } */
5 #include <stdint.h>
6 #include <stdio.h>
7 #include <inttypes.h>
8 #include <altivec.h> // vector
10 #define TRUE 1
11 #define FALSE 0
13 #ifdef DEBUG
14 #include <stdio.h>
15 #endif
17 void abort (void);
19 int result_wrong(vector unsigned char vec_expected,
20 vector unsigned char vec_actual)
22 int i;
24 for (i=0; i<16; i++)
25 if (vec_expected[i] != vec_actual[i])
26 return TRUE;
28 return FALSE;
31 int main() {
32 int i, j;
33 size_t size;
34 unsigned char data_uc[100];
35 vector unsigned char store_data_uc;
36 unsigned char *address;
37 vector unsigned char *datap;
39 vector unsigned char vec_uc_expected1, vec_uc_result1;
40 vector int data_int;
42 for (i=0; i<100; i++)
43 data_uc[i] = i+1;
46 /* VEC_XL_LEN */
48 size = 8;
49 vec_uc_result1 = vec_xl_len (data_uc, size);
51 vec_uc_expected1 = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
52 0, 0, 0, 0, 0, 0, 0, 0};
54 if (result_wrong (vec_uc_expected1, vec_uc_result1))
56 #ifdef DEBUG
57 printf("Error: result does not match expected result\n");
58 printf("vec_xl_len (%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
59 size);
61 for (i=0; i<16; i++)
62 printf(" %d,",vec_uc_expected1[i]);
64 printf("\nvec_xl_len (%d): vec_uc_result1[0] to vec_uc_result1[15]\n",
65 size);
67 for (i=0; i<16; i++)
68 printf(" %d,", vec_uc_result1[i]);
70 printf("\n\n");
71 #else
72 abort();
73 #endif
77 /* VEC_XL_LEN_R */
78 size = 8;
79 vec_uc_result1 = vec_xl_len_r(data_uc, size);
81 vec_uc_expected1 = (vector unsigned char){8, 7, 6, 5, 4, 3, 2, 1,
82 0, 0, 0, 0, 0, 0, 0, 0,};
84 if (result_wrong (vec_uc_expected1, vec_uc_result1))
86 #ifdef DEBUG
87 printf("Error: result does not match expected result\n");
88 printf("vec_xl_len_r(%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
89 size);
91 for (i=0; i<16; i++)
92 printf(" %d,", vec_uc_expected1[i]);
94 printf("\nvec_xl_len_r(%d): vec_uc_result1[0] to vec_uc_result1[15]\n",
95 size);
97 for (i=0; i<16; i++)
98 printf(" %d,", vec_uc_result1[i]);
100 printf("\n\n");
101 #else
102 abort();
103 #endif
107 size = 4;
108 vec_uc_result1 = vec_xl_len_r(data_uc, size);
110 vec_uc_expected1 = (vector unsigned char){ 4, 3, 2, 1, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0 };
113 if (result_wrong (vec_uc_expected1, vec_uc_result1))
115 #ifdef DEBUG
116 printf("Error: result does not match expected result\n");
117 printf("vec_xl_len_r(%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
118 size);
120 for (i=0; i<16; i++)
121 printf(" %d,", vec_uc_expected1[i]);
123 printf("\nvec_xl_len_r(%d): vec_uc_result1[0] to vec_uc_result1[15]\n",
124 size);
126 for (i=0; i<16; i++)
127 printf(" %d,", vec_uc_result1[i]);
129 printf("\n\n");
130 #else
131 abort();
132 #endif
135 size = 2;
136 vec_uc_result1 = vec_xl_len_r(data_uc, size);
138 vec_uc_expected1 = (vector unsigned char){ 2, 1, 0, 0, 0, 0, 0, 0,
139 0, 0, 0, 0, 0, 0, 0, 0 };
141 if (result_wrong (vec_uc_expected1, vec_uc_result1))
143 #ifdef DEBUG
144 printf("Error: result does not match expected result\n");
145 printf("vec_xl_len_r(%d): vec_uc_expected1[0] to vec_uc_expected1[15]\n",
146 size);
147 for (i=0; i<16; i++)
148 printf(" %d,", vec_uc_expected1[i]);
150 printf("\nvec_xl_len_r(%d) vec_uc_result1[0] to vec_uc_result1[15]\n",
151 size);
153 for (i=0; i<16; i++)
154 printf(" %d,", vec_uc_result1[i]);
156 printf("\n\n");
157 #else
158 abort();
159 #endif
163 /* VEC_XST_LEN */
164 vec_uc_expected1 = (vector unsigned char){ 1, 2, 0, 0, 0, 0, 0, 0,
165 0, 0, 0, 0, 0, 0, 0, 0 };
166 store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
167 9, 10, 11, 12, 13, 14, 15, 16 };
168 size = 2;
170 for (i=0; i<16; i++)
171 vec_uc_result1[i] = 0;
173 address = &vec_uc_result1[0];
174 vec_xst_len (store_data_uc, address, size);
176 if (result_wrong (vec_uc_expected1, vec_uc_result1))
178 #ifdef DEBUG
179 printf("Error: result does not match expected result\n");
180 printf("vec_xst_len (%d) vec_uc_result1[0] to vec_uc_result1[15]\n",
181 size);
183 for (i=0; i<16; i++)
184 printf(" %d,", vec_uc_expected1[i]);
186 printf("\nvec_xst_len (%d) store_data_uc[0] to store_data_uc[15]\n",
187 size);
189 for (i=0; i<16; i++)
190 printf(" %d,", vec_uc_result1[i]);
192 printf("\n\n");
193 #else
194 abort();
195 #endif
198 vec_uc_expected1 = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
199 9, 10, 11, 12, 13, 14, 0, 0 };
200 store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
201 9, 10, 11, 12, 13, 14, 15, 16 };
202 size = 14;
204 for (i=0; i<16; i++)
205 vec_uc_result1[i] = 0;
207 address = &vec_uc_result1[0];
209 vec_xst_len (store_data_uc, address, size);
211 if (result_wrong (vec_uc_expected1, vec_uc_result1))
213 #ifdef DEBUG
214 printf("Error: result does not match expected result\n");
215 printf("vec_xst_len (%d) vec_uc_result1[0] to vec_uc_result1[15]\n",
216 size);
218 for (i=0; i<16; i++)
219 printf(" %d,", vec_uc_expected1[i]);
221 printf("\nvec_xst_len (%d) store_data_uc[0] to store_data_uc[15]\n",
222 size);
224 for (i=0; i<16; i++)
225 printf(" %d,", vec_uc_result1[i]);
227 printf("\n\n");
228 #else
229 abort();
230 #endif
233 /* VEC_XST_LEN_R */
234 vec_uc_expected1 = (vector unsigned char){ 16, 15, 14, 13, 12, 11, 10, 9,
235 8, 7, 6, 5, 4, 3, 2, 1 };
236 store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
237 9, 10, 11, 12, 13, 14, 15, 16 };
238 vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0 };
241 size = 16;
243 address = &vec_uc_result1[0];
245 vec_xst_len_r(store_data_uc, address, size);
247 if (result_wrong (vec_uc_expected1, vec_uc_result1))
249 #ifdef DEBUG
250 printf("Error: result does not match expected result\n");
251 printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
252 size);
254 for (i=0; i<16; i++)
255 printf(" %d,", vec_uc_expected1[i]);
257 printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
259 for (i=0; i<16; i++)
260 printf(" %d,", vec_uc_result1[i]);
262 printf("\n\n");
263 #else
264 abort();
265 #endif
268 vec_uc_expected1 = (vector unsigned char){ 2, 1, 0, 0, 0, 0, 0, 0,
269 0, 0, 0, 0, 0, 0, 0, 0 };
270 store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
271 9, 10, 11, 12, 13, 14, 15, 16 };
272 vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0,
273 0, 0, 0, 0, 0, 0, 0, 0 };
275 size = 2;
277 address = &vec_uc_result1[0];
279 vec_xst_len_r(store_data_uc, address, size);
281 if (result_wrong (vec_uc_expected1, vec_uc_result1))
283 #ifdef DEBUG
284 printf("Error: result does not match expected result\n");
285 printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
286 size);
288 for (i=0; i<16; i++)
289 printf(" %d,", vec_uc_expected1[i]);
291 printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
293 for (i=0; i<16; i++)
294 printf(" %d,", vec_uc_result1[i]);
296 printf("\n\n");
297 #else
298 abort();
299 #endif
302 vec_uc_expected1 = (vector unsigned char){ 16, 15, 14, 13, 12, 11, 10, 9,
303 8, 7, 6, 5, 4, 3, 2, 1 };
304 store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
305 9, 10, 11, 12, 13, 14, 15, 16 };
306 vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0,
307 0, 0, 0, 0, 0, 0, 0, 0 };
309 size = 16;
311 address = &vec_uc_result1[0];
313 vec_xst_len_r(store_data_uc, address, size);
315 if (result_wrong (vec_uc_expected1, vec_uc_result1))
317 #ifdef DEBUG
318 printf("Error: result does not match expected result\n");
319 printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
320 size);
322 for (i=0; i<16; i++)
323 printf(" %d,", vec_uc_expected1[i]);
325 printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
327 for (i=0; i<16; i++)
328 printf(" %d,", vec_uc_result1[i]);
330 printf("\n\n");
331 #else
332 abort();
333 #endif
336 vec_uc_expected1 = (vector unsigned char){ 14, 13, 12, 11, 10, 9, 8, 7,
337 6, 5, 4, 3, 2, 1, 0, 0 };
338 store_data_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8,
339 9, 10, 11, 12, 13, 14, 15, 16 };
340 vec_uc_result1 = (vector unsigned char){ 0, 0, 0, 0, 0, 0, 0, 0,
341 0, 0, 0, 0, 0, 0, 0, 0 };
343 size = 14;
345 address = &vec_uc_result1[0];
347 vec_xst_len_r(store_data_uc, address, size);
349 if (result_wrong (vec_uc_expected1, vec_uc_result1))
351 #ifdef DEBUG
352 printf("Error: result does not match expected result\n");
353 printf("vec_xst_len_r(%d) vec_uc_expected1[0] to vec_uc_expected1[15]\n",
354 size);
356 for (i=0; i<16; i++)
357 printf(" %d,", vec_uc_expected1[i]);
359 printf("\nvec_xst_len_r(%d) result[0] to result[15]\n", size);
361 for (i=0; i<16; i++)
362 printf(" %d,", vec_uc_result1[i]);
364 printf("\n\n");
365 #else
366 abort();
367 #endif