1 /* { dg-do run { target lp64 } } */
2 /* { dg-skip-if "" { powerpc*-*-darwin* } } */
3 /* { dg-require-effective-target vsx_hw } */
4 /* { dg-options "-mvsx -O2" } */
12 static int errors
= 0;
26 unsigned long scalar
[2];
27 vector
bool long vect
;
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])
37 printf ("%s failed!\n", name
);
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])
54 printf ("%s failed!\n", name
);
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])
69 printf ("%s failed!\n", name
);
78 /* Vec functions taking a single argument. */
80 vabs (vector
double arg
)
86 vceil_d (vector
double arg
)
88 return vec_ceil (arg
);
92 vceil_f (vector
float arg
)
94 return vec_ceil (arg
);
98 vfloor_d (vector
double arg
)
100 return vec_floor (arg
);
104 vfloor_f (vector
float arg
)
106 return vec_floor (arg
);
110 vnearbyint_d (vector
double arg
)
112 return vec_nearbyint (arg
);
116 vnearbyint_f (vector
float arg
)
118 return vec_nearbyint (arg
);
122 vrint_f (vector
float arg
)
124 return vec_rint (arg
);
128 vrint_d (vector
double arg
)
130 return vec_rint (arg
);
134 vsqrt_f (vector
float arg
)
136 return vec_sqrt (arg
);
140 vsqrt_d (vector
double arg
)
142 return vec_sqrt (arg
);
145 /* Single argument tests with double args */
150 vector
double (*func
) (vector
double);
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" },
178 printf ("\nSingle argument tests with double args:\n");
181 for (i
= 0; i
< sizeof (arg1_tests_d
) / sizeof (arg1_tests_d
[0]); i
++)
184 u
.vect
= arg1_tests_d
[i
].func (arg1_tests_d
[i
].input
.vect
);
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],
193 arg1_tests_d
[i
].input
.scalar
[0],
194 arg1_tests_d
[i
].input
.scalar
[1]);
197 do_test_d (&arg1_tests_d
[i
].result
, &u
, arg1_tests_d
[i
].name
);
203 /* Single argument tests with float args. */
208 vector
float (*func
) (vector
float);
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" },
231 printf ("\nSingle argument tests with float args:\n");
234 for (i
= 0; i
< sizeof (arg1_tests_f
) / sizeof (arg1_tests_f
[0]); i
++)
237 u
.vect
= arg1_tests_f
[i
].func (arg1_tests_f
[i
].input
.vect
);
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],
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]);
256 do_test_f (&arg1_tests_f
[i
].result
, &u
, arg1_tests_f
[i
].name
);
263 /* Vect functions taking 2 arguments. */
265 vadd (vector
double arg1
, vector
double arg2
)
267 return vec_add (arg1
, arg2
);
271 vadd2 (vector
double arg1
, vector
double arg2
)
277 vsub (vector
double arg1
, vector
double arg2
)
279 return vec_sub (arg1
, arg2
);
283 vsub2 (vector
double arg1
, vector
double arg2
)
289 vmul (vector
double arg1
, vector
double arg2
)
291 return vec_mul (arg1
, arg2
);
295 vmul2 (vector
double arg1
, vector
double arg2
)
301 vdiv (vector
double arg1
, vector
double arg2
)
303 return vec_div (arg1
, arg2
);
307 vdiv2 (vector
double arg1
, vector
double arg2
)
313 vmax (vector
double arg1
, vector
double arg2
)
315 return vec_max (arg1
, arg2
);
319 vmin (vector
double arg1
, vector
double arg2
)
321 return vec_min (arg1
, arg2
);
324 /* 2 argument tests. */
328 union args_d input
[2];
329 vector
double (*func
) (vector
double, vector
double);
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" },
357 printf ("\nTwo argument tests:\n");
360 for (i
= 0; i
< sizeof (arg2_tests
) / sizeof (arg2_tests
[0]); i
++)
363 u
.vect
= arg2_tests
[i
].func (arg2_tests
[i
].input
[0].vect
,
364 arg2_tests
[i
].input
[1].vect
);
367 printf ("test %-16s: expected { %4g, %4g }, got { %4g, %4g }, input { %4g, %4g }, { %4g, %4g }\n",
369 arg2_tests
[i
].result
.scalar
[0],
370 arg2_tests
[i
].result
.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]);
379 do_test_d (&arg2_tests
[i
].result
, &u
, arg2_tests
[i
].name
);
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. */
424 union args_d input
[2];
425 vector
bool long (*func
) (vector
double, vector
double);
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" },
454 printf ("\nComparison tests:\n");
457 for (i
= 0; i
< sizeof (argcmp_tests
) / sizeof (argcmp_tests
[0]); i
++)
460 u
.vect
= argcmp_tests
[i
].func (argcmp_tests
[i
].input
[0].vect
,
461 argcmp_tests
[i
].input
[1].vect
);
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],
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]);
476 do_ltest (&argcmp_tests
[i
].result
, &u
, argcmp_tests
[i
].name
);
484 main (int argc
, char *argv
[])
494 printf ("There were %d error(s)\n", errors
);
498 printf ("There were no errors\n");