[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / vsx-vector-5.c
blob37a324b6f897d758afa1219fdadb48e7232cfab4
1 /* { dg-do run { target lp64 } } */
2 /* { dg-skip-if "" { powerpc*-*-darwin* } } */
3 /* { dg-require-effective-target vsx_hw } */
4 /* { dg-options "-mvsx -O2" } */
6 #include <altivec.h>
7 #include <stdlib.h>
9 #ifdef DEBUG
10 #include <stdio.h>
12 static int errors = 0;
13 #endif
15 union args_d {
16 double scalar[2];
17 vector double vect;
20 union args_f {
21 float scalar[4];
22 vector float vect;
25 union largs {
26 unsigned long scalar[2];
27 vector bool long vect;
30 static void
31 do_test_d (union args_d *expected, union args_d *got, const char *name)
33 if (expected->scalar[0] != got->scalar[0]
34 || expected->scalar[1] != got->scalar[1])
36 #ifdef DEBUG
37 printf ("%s failed!\n", name);
38 errors++;
39 #else
40 abort ();
41 #endif
45 static void
46 do_test_f (union args_f *expected, union args_f *got, const char *name)
48 if (expected->scalar[0] != got->scalar[0]
49 || expected->scalar[1] != got->scalar[1]
50 || expected->scalar[2] != got->scalar[2]
51 || expected->scalar[3] != got->scalar[3])
53 #ifdef DEBUG
54 printf ("%s failed!\n", name);
55 errors++;
56 #else
57 abort ();
58 #endif
62 static void
63 do_ltest (union largs *expected, union largs *got, const char *name)
65 if (expected->scalar[0] != got->scalar[0]
66 || expected->scalar[1] != got->scalar[1])
68 #ifdef DEBUG
69 printf ("%s failed!\n", name);
70 errors++;
71 #else
72 abort ();
73 #endif
78 /* Vec functions taking a single argument. */
79 static vector double
80 vabs (vector double arg)
82 return vec_abs (arg);
85 static vector double
86 vceil_d (vector double arg)
88 return vec_ceil (arg);
91 static vector float
92 vceil_f (vector float arg)
94 return vec_ceil (arg);
97 static vector double
98 vfloor_d (vector double arg)
100 return vec_floor (arg);
103 static vector float
104 vfloor_f (vector float arg)
106 return vec_floor (arg);
109 static vector double
110 vnearbyint_d (vector double arg)
112 return vec_nearbyint (arg);
115 static vector float
116 vnearbyint_f (vector float arg)
118 return vec_nearbyint (arg);
121 static vector float
122 vrint_f (vector float arg)
124 return vec_rint (arg);
127 static vector double
128 vrint_d (vector double arg)
130 return vec_rint (arg);
133 static vector float
134 vsqrt_f (vector float arg)
136 return vec_sqrt (arg);
139 static vector double
140 vsqrt_d (vector double arg)
142 return vec_sqrt (arg);
145 /* Single argument tests with double args */
146 static struct
148 union args_d result;
149 union args_d input;
150 vector double (*func) (vector double);
151 const char *name;
152 } arg1_tests_d[] = {
153 /* result input function name */
154 { { 1.0, 2.0 }, { -1.0, 2.0 }, vabs, "vabs" },
155 { { 1.0, 2.0 }, { 1.0, -2.0 }, vabs, "vabs" },
156 { { 2.0, 2.0 }, { 1.1, 1.7 }, vceil_d, "vceil_d" },
157 { { -1.0, -1.0 }, { -1.1, -1.7 }, vceil_d, "vceil_d" },
158 { { -1.0, 2.0 }, { -1.5, 1.5 }, vceil_d, "vceil_d" },
159 { { 1.0, 1.0 }, { 1.1, 1.7 }, vfloor_d, "vfloor_d" },
160 { { -2.0, -2.0 }, { -1.1, -1.7 }, vfloor_d, "vfloor_d" },
161 { { -2.0, 1.0 }, { -1.5, 1.5 }, vfloor_d, "vfloor_d" },
162 { { 1.0, 2.0 }, { 1.1, 1.7 }, vnearbyint_d, "vnearbyint_d" },
163 { { -1.0, -2.0 }, { -1.1, -1.7 }, vnearbyint_d, "vnearbyint_d" },
164 { { -2.0, 2.0 }, { -1.5, 1.5 }, vnearbyint_d, "vnearbyint_d" },
165 { { 1.0, 2.0 }, { 1.1, 1.7 }, vrint_d, "vrint_d" },
166 { { -1.0, -2.0 }, { -1.1, -1.7 }, vrint_d, "vrint_d" },
167 { { -2.0, 2.0 }, { -1.5, 1.5 }, vrint_d, "vrint_d" },
169 { { 2.0, 4.0 }, { 4.0, 16.0 }, vsqrt_d, "vsqrt_d" },
172 static void
173 test_arg1_d (void)
175 unsigned i;
177 #ifdef DEBUG
178 printf ("\nSingle argument tests with double args:\n");
179 #endif
181 for (i = 0; i < sizeof (arg1_tests_d) / sizeof (arg1_tests_d[0]); i++)
183 union args_d u;
184 u.vect = arg1_tests_d[i].func (arg1_tests_d[i].input.vect);
186 #ifdef DEBUG
187 printf ("test %-16s: expected { %4g, %4g }, got { %4g, %4g }, input { %4g, %4g }\n",
188 arg1_tests_d[i].name,
189 arg1_tests_d[i].result.scalar[0],
190 arg1_tests_d[i].result.scalar[1],
191 u.scalar[0],
192 u.scalar[1],
193 arg1_tests_d[i].input.scalar[0],
194 arg1_tests_d[i].input.scalar[1]);
195 #endif
197 do_test_d (&arg1_tests_d[i].result, &u, arg1_tests_d[i].name);
200 return;
203 /* Single argument tests with float args. */
204 static struct
206 union args_f result;
207 union args_f input;
208 vector float (*func) (vector float);
209 const char *name;
210 } arg1_tests_f[] = {
211 /* result input function name */
212 { { 2.0, 2.0, 3.0, 3.0 }, { 1.05, 1.1, 2.2, 2.3 }, vceil_f, "vceil_f" },
213 { { -1.0, -1.0, -2.0, -2.0 }, { -1.1, -1.7, -2.1, -2.4 }, vceil_f, "vceil_f" },
214 { { 1.0, 1.0, 2.0, 2.0 }, { 1.05, 1.1, 2.2, 2.3 }, vfloor_f, "vfloor_f" },
215 { { -2.0, -2.0, -3.0, -3.0 }, { -1.1, -1.7, -2.1, -2.4 }, vfloor_f, "vfloor_f" },
216 { { 1.0, 2.0, -3.0, 3.0 }, { 1.1, 1.7, -3.1, 3.1 }, vnearbyint_f, "vnearbyint_f" },
217 { { -1.0, -2.0, -3.0, 3.0 }, { -1.1, -1.7, -2.9, 2.9 }, vnearbyint_f, "vnearbyint_f" },
218 { { -2.0, 2.0, -3.0, 3.0 }, { -1.5, 1.5, -2.55, 3.49 }, vnearbyint_f, "vnearbyint_f" },
219 { { 10.0, 18.0, 30.0, 40.0 }, { 10.1, 17.7, 30.0, 40.01 }, vrint_f, "vrint_f" },
220 { { -11.0, -18.0, -30.0, -40.0 }, { -11.1, -17.7, -30.0, -40.01 }, vrint_f, "vrint_f" },
222 { { 2.0, 4.0 }, { 4.0, 16.0 }, vsqrt_f, "vsqrt_f" },
225 static void
226 test_arg1_f (void)
228 unsigned i;
230 #ifdef DEBUG
231 printf ("\nSingle argument tests with float args:\n");
232 #endif
234 for (i = 0; i < sizeof (arg1_tests_f) / sizeof (arg1_tests_f[0]); i++)
236 union args_f u;
237 u.vect = arg1_tests_f[i].func (arg1_tests_f[i].input.vect);
239 #ifdef DEBUG
240 printf ("test %-16s: expected { %4g, %4g, %4g, %4g }, got { %4g, %4g, %4g, %4g }, input { %4g, %4g, %4g, %4g }\n",
241 arg1_tests_f[i].name,
242 arg1_tests_f[i].result.scalar[0],
243 arg1_tests_f[i].result.scalar[1],
244 arg1_tests_f[i].result.scalar[2],
245 arg1_tests_f[i].result.scalar[3],
246 u.scalar[0],
247 u.scalar[1],
248 u.scalar[2],
249 u.scalar[3],
250 arg1_tests_f[i].input.scalar[0],
251 arg1_tests_f[i].input.scalar[1],
252 arg1_tests_f[i].input.scalar[2],
253 arg1_tests_f[i].input.scalar[3]);
254 #endif
256 do_test_f (&arg1_tests_f[i].result, &u, arg1_tests_f[i].name);
259 return;
263 /* Vect functions taking 2 arguments. */
264 static vector double
265 vadd (vector double arg1, vector double arg2)
267 return vec_add (arg1, arg2);
270 static vector double
271 vadd2 (vector double arg1, vector double arg2)
273 return arg1 + arg2;
276 static vector double
277 vsub (vector double arg1, vector double arg2)
279 return vec_sub (arg1, arg2);
282 static vector double
283 vsub2 (vector double arg1, vector double arg2)
285 return arg1 - arg2;
288 static vector double
289 vmul (vector double arg1, vector double arg2)
291 return vec_mul (arg1, arg2);
294 static vector double
295 vmul2 (vector double arg1, vector double arg2)
297 return arg1 * arg2;
300 static vector double
301 vdiv (vector double arg1, vector double arg2)
303 return vec_div (arg1, arg2);
306 static vector double
307 vdiv2 (vector double arg1, vector double arg2)
309 return arg1 / arg2;
312 static vector double
313 vmax (vector double arg1, vector double arg2)
315 return vec_max (arg1, arg2);
318 static vector double
319 vmin (vector double arg1, vector double arg2)
321 return vec_min (arg1, arg2);
324 /* 2 argument tests. */
325 static struct
327 union args_d result;
328 union args_d input[2];
329 vector double (*func) (vector double, vector double);
330 const char *name;
331 } arg2_tests[] = {
332 /* result */
333 { { 4.0, 6.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vadd, "vadd" },
334 { { 4.0, -6.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vadd, "vadd" },
335 { { 4.0, 6.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vadd2, "vadd2" },
336 { { 4.0, -6.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vadd2, "vadd2" },
337 { { -2.0, -2.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vsub, "vsub" },
338 { { -2.0, 2.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vsub, "vsub" },
339 { { -2.0, -2.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vsub2, "vsub2" },
340 { { -2.0, 2.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vsub2, "vsub2" },
341 { { 6.0, 4.0 }, { { 2.0, 8.0 }, { 3.0, 0.5 } }, vmul, "vmul" },
342 { { 6.0, 4.0 }, { { 2.0, 8.0 }, { 3.0, 0.5 } }, vmul2, "vmul2" },
343 { { 2.0, 0.5 }, { { 6.0, 4.0 }, { 3.0, 8.0 } }, vdiv, "vdiv" },
344 { { 2.0, 0.5 }, { { 6.0, 4.0 }, { 3.0, 8.0 } }, vdiv2, "vdiv2" },
345 { { 3.0, 4.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vmax, "vmax" },
346 { { 1.0, 4.0 }, { { 1.0, -2.0 }, { -3.0, 4.0 } }, vmax, "vmax" },
347 { { 1.0, 2.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vmin, "vmin" },
348 { { -3.0, -2.0 }, { { 1.0, -2.0 }, { -3.0, 4.0 } }, vmin, "vmin" },
351 static void
352 test_arg2 (void)
354 unsigned i;
356 #ifdef DEBUG
357 printf ("\nTwo argument tests:\n");
358 #endif
360 for (i = 0; i < sizeof (arg2_tests) / sizeof (arg2_tests[0]); i++)
362 union args_d u;
363 u.vect = arg2_tests[i].func (arg2_tests[i].input[0].vect,
364 arg2_tests[i].input[1].vect);
366 #ifdef DEBUG
367 printf ("test %-16s: expected { %4g, %4g }, got { %4g, %4g }, input { %4g, %4g }, { %4g, %4g }\n",
368 arg2_tests[i].name,
369 arg2_tests[i].result.scalar[0],
370 arg2_tests[i].result.scalar[1],
371 u.scalar[0],
372 u.scalar[1],
373 arg2_tests[i].input[0].scalar[0],
374 arg2_tests[i].input[0].scalar[1],
375 arg2_tests[i].input[1].scalar[0],
376 arg2_tests[i].input[1].scalar[1]);
377 #endif
379 do_test_d (&arg2_tests[i].result, &u, arg2_tests[i].name);
382 return;
386 /* Comparisons, returnning a boolean vector. */
387 static vector bool long
388 vcmpeq (vector double arg1, vector double arg2)
390 return vec_cmpeq (arg1, arg2);
393 static vector bool long
394 vcmplt (vector double arg1, vector double arg2)
396 return vec_cmplt (arg1, arg2);
399 static vector bool long
400 vcmple (vector double arg1, vector double arg2)
402 return vec_cmple (arg1, arg2);
405 static vector bool long
406 vcmpgt (vector double arg1, vector double arg2)
408 return vec_cmpgt (arg1, arg2);
411 static vector bool long
412 vcmpge (vector double arg1, vector double arg2)
414 return vec_cmpge (arg1, arg2);
417 #define ONE 0xffffffffffffffffUL
418 #define ZERO 0x0000000000000000UL
420 /* comparison tests. */
421 static struct
423 union largs result;
424 union args_d input[2];
425 vector bool long (*func) (vector double, vector double);
426 const char *name;
427 } argcmp_tests[] = {
428 { { ONE, ZERO }, { { 1.0, 2.0 }, { 1.0, -2.0 } }, vcmpeq, "vcmpeq" },
429 { { ZERO, ONE }, { { -1.0, 2.0 }, { 1.0, 2.0 } }, vcmpeq, "vcmpeq" },
431 { { ONE, ONE }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmple, "vcmple" },
432 { { ONE, ONE }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmple, "vcmple" },
433 { { ZERO, ZERO }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmple, "vcmple" },
435 { { ZERO, ZERO }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmplt, "vcmplt" },
436 { { ONE, ONE }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmplt, "vcmplt" },
437 { { ZERO, ZERO }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmplt, "vcmplt" },
439 { { ZERO, ZERO }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmpgt, "vcmpgt" },
440 { { ZERO, ZERO }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmpgt, "vcmpgt" },
441 { { ONE, ONE }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmpgt, "vcmpgt" },
443 { { ONE, ONE }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmpge, "vcmpge" },
444 { { ZERO, ZERO }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmpge, "vcmpge" },
445 { { ONE, ONE }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmpge, "vcmpge" },
448 static void
449 test_argcmp (void)
451 unsigned i;
453 #ifdef DEBUG
454 printf ("\nComparison tests:\n");
455 #endif
457 for (i = 0; i < sizeof (argcmp_tests) / sizeof (argcmp_tests[0]); i++)
459 union largs u;
460 u.vect = argcmp_tests[i].func (argcmp_tests[i].input[0].vect,
461 argcmp_tests[i].input[1].vect);
463 #ifdef DEBUG
464 printf ("test %-16s: expected { 0x%016lx, 0x%016lx }, got { 0x%016lx, 0x%016lx }, input { %4g, %4g }, { %4g, %4g }\n",
465 argcmp_tests[i].name,
466 argcmp_tests[i].result.scalar[0],
467 argcmp_tests[i].result.scalar[1],
468 u.scalar[0],
469 u.scalar[1],
470 argcmp_tests[i].input[0].scalar[0],
471 argcmp_tests[i].input[0].scalar[1],
472 argcmp_tests[i].input[1].scalar[0],
473 argcmp_tests[i].input[1].scalar[1]);
474 #endif
476 do_ltest (&argcmp_tests[i].result, &u, argcmp_tests[i].name);
479 return;
484 main (int argc, char *argv[])
486 test_arg1_f ();
487 test_arg1_d ();
488 test_arg2 ();
489 test_argcmp ();
491 #ifdef DEBUG
492 if (errors)
494 printf ("There were %d error(s)\n", errors);
495 return errors;
497 else
498 printf ("There were no errors\n");
499 #endif
501 return 0;