1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
|
/* { dg-do run { target lp64 } } */
/* { dg-skip-if "" { powerpc*-*-darwin* } } */
/* { dg-require-effective-target powerpc_vsx_ok } */
/* { dg-options "-mvsx -O2" } */
/* This will run, and someday we should add the support to test whether we are
running on VSX hardware. */
#include <altivec.h>
#include <stdlib.h>
#ifdef DEBUG
#include <stdio.h>
static int errors = 0;
#endif
union args_d {
double scalar[2];
vector double vect;
};
union args_f {
float scalar[4];
vector float vect;
};
union largs {
unsigned long scalar[2];
vector bool long vect;
};
static void
do_test_d (union args_d *expected, union args_d *got, const char *name)
{
if (expected->scalar[0] != got->scalar[0]
|| expected->scalar[1] != got->scalar[1])
{
#ifdef DEBUG
printf ("%s failed!\n", name);
errors++;
#else
abort ();
#endif
}
}
static void
do_test_f (union args_f *expected, union args_f *got, const char *name)
{
if (expected->scalar[0] != got->scalar[0]
|| expected->scalar[1] != got->scalar[1]
|| expected->scalar[2] != got->scalar[2]
|| expected->scalar[3] != got->scalar[3])
{
#ifdef DEBUG
printf ("%s failed!\n", name);
errors++;
#else
abort ();
#endif
}
}
static void
do_ltest (union largs *expected, union largs *got, const char *name)
{
if (expected->scalar[0] != got->scalar[0]
|| expected->scalar[1] != got->scalar[1])
{
#ifdef DEBUG
printf ("%s failed!\n", name);
errors++;
#else
abort ();
#endif
}
}
/* Vec functions taking a single argument. */
static vector double
vabs (vector double arg)
{
return vec_abs (arg);
}
static vector double
vceil_d (vector double arg)
{
return vec_ceil (arg);
}
static vector float
vceil_f (vector float arg)
{
return vec_ceil (arg);
}
static vector double
vfloor_d (vector double arg)
{
return vec_floor (arg);
}
static vector float
vfloor_f (vector float arg)
{
return vec_floor (arg);
}
static vector double
vnearbyint_d (vector double arg)
{
return vec_nearbyint (arg);
}
static vector float
vnearbyint_f (vector float arg)
{
return vec_nearbyint (arg);
}
static vector float
vrint_f (vector float arg)
{
return vec_rint (arg);
}
static vector double
vrint_d (vector double arg)
{
return vec_rint (arg);
}
static vector float
vsqrt_f (vector float arg)
{
return vec_sqrt (arg);
}
static vector double
vsqrt_d (vector double arg)
{
return vec_sqrt (arg);
}
/* Single argument tests with double args */
static struct
{
union args_d result;
union args_d input;
vector double (*func) (vector double);
const char *name;
} arg1_tests_d[] = {
/* result input function name */
{ { 1.0, 2.0 }, { -1.0, 2.0 }, vabs, "vabs" },
{ { 1.0, 2.0 }, { 1.0, -2.0 }, vabs, "vabs" },
{ { 2.0, 2.0 }, { 1.1, 1.7 }, vceil_d, "vceil_d" },
{ { -1.0, -1.0 }, { -1.1, -1.7 }, vceil_d, "vceil_d" },
{ { -1.0, 2.0 }, { -1.5, 1.5 }, vceil_d, "vceil_d" },
{ { 1.0, 1.0 }, { 1.1, 1.7 }, vfloor_d, "vfloor_d" },
{ { -2.0, -2.0 }, { -1.1, -1.7 }, vfloor_d, "vfloor_d" },
{ { -2.0, 1.0 }, { -1.5, 1.5 }, vfloor_d, "vfloor_d" },
{ { 1.0, 2.0 }, { 1.1, 1.7 }, vnearbyint_d, "vnearbyint_d" },
{ { -1.0, -2.0 }, { -1.1, -1.7 }, vnearbyint_d, "vnearbyint_d" },
{ { -2.0, 2.0 }, { -1.5, 1.5 }, vnearbyint_d, "vnearbyint_d" },
{ { 1.0, 2.0 }, { 1.1, 1.7 }, vrint_d, "vrint_d" },
{ { -1.0, -2.0 }, { -1.1, -1.7 }, vrint_d, "vrint_d" },
{ { -2.0, 2.0 }, { -1.5, 1.5 }, vrint_d, "vrint_d" },
{ { 2.0, 4.0 }, { 4.0, 16.0 }, vsqrt_d, "vsqrt_d" },
};
static void
test_arg1_d (void)
{
unsigned i;
#ifdef DEBUG
printf ("\nSingle argument tests with double args:\n");
#endif
for (i = 0; i < sizeof (arg1_tests_d) / sizeof (arg1_tests_d[0]); i++)
{
union args_d u;
u.vect = arg1_tests_d[i].func (arg1_tests_d[i].input.vect);
#ifdef DEBUG
printf ("test %-16s: expected { %4g, %4g }, got { %4g, %4g }, input { %4g, %4g }\n",
arg1_tests_d[i].name,
arg1_tests_d[i].result.scalar[0],
arg1_tests_d[i].result.scalar[1],
u.scalar[0],
u.scalar[1],
arg1_tests_d[i].input.scalar[0],
arg1_tests_d[i].input.scalar[1]);
#endif
do_test_d (&arg1_tests_d[i].result, &u, arg1_tests_d[i].name);
}
return;
}
/* Single argument tests with float args. */
static struct
{
union args_f result;
union args_f input;
vector float (*func) (vector float);
const char *name;
} arg1_tests_f[] = {
/* result input function name */
{ { 2.0, 2.0, 3.0, 3.0 }, { 1.05, 1.1, 2.2, 2.3 }, vceil_f, "vceil_f" },
{ { -1.0, -1.0, -2.0, -2.0 }, { -1.1, -1.7, -2.1, -2.4 }, vceil_f, "vceil_f" },
{ { 1.0, 1.0, 2.0, 2.0 }, { 1.05, 1.1, 2.2, 2.3 }, vfloor_f, "vfloor_f" },
{ { -2.0, -2.0, -3.0, -3.0 }, { -1.1, -1.7, -2.1, -2.4 }, vfloor_f, "vfloor_f" },
{ { 1.0, 2.0, -3.0, 3.0 }, { 1.1, 1.7, -3.1, 3.1 }, vnearbyint_f, "vnearbyint_f" },
{ { -1.0, -2.0, -3.0, 3.0 }, { -1.1, -1.7, -2.9, 2.9 }, vnearbyint_f, "vnearbyint_f" },
{ { -2.0, 2.0, -3.0, 3.0 }, { -1.5, 1.5, -2.55, 3.49 }, vnearbyint_f, "vnearbyint_f" },
{ { 10.0, 18.0, 30.0, 40.0 }, { 10.1, 17.7, 30.0, 40.01 }, vrint_f, "vrint_f" },
{ { -11.0, -18.0, -30.0, -40.0 }, { -11.1, -17.7, -30.0, -40.01 }, vrint_f, "vrint_f" },
{ { 2.0, 4.0 }, { 4.0, 16.0 }, vsqrt_f, "vsqrt_f" },
};
static void
test_arg1_f (void)
{
unsigned i;
#ifdef DEBUG
printf ("\nSingle argument tests with float args:\n");
#endif
for (i = 0; i < sizeof (arg1_tests_f) / sizeof (arg1_tests_f[0]); i++)
{
union args_f u;
u.vect = arg1_tests_f[i].func (arg1_tests_f[i].input.vect);
#ifdef DEBUG
printf ("test %-16s: expected { %4g, %4g, %4g, %4g }, got { %4g, %4g, %4g, %4g }, input { %4g, %4g, %4g, %4g }\n",
arg1_tests_f[i].name,
arg1_tests_f[i].result.scalar[0],
arg1_tests_f[i].result.scalar[1],
arg1_tests_f[i].result.scalar[2],
arg1_tests_f[i].result.scalar[3],
u.scalar[0],
u.scalar[1],
u.scalar[2],
u.scalar[3],
arg1_tests_f[i].input.scalar[0],
arg1_tests_f[i].input.scalar[1],
arg1_tests_f[i].input.scalar[2],
arg1_tests_f[i].input.scalar[3]);
#endif
do_test_f (&arg1_tests_f[i].result, &u, arg1_tests_f[i].name);
}
return;
}
/* Vect functions taking 2 arguments. */
static vector double
vadd (vector double arg1, vector double arg2)
{
return vec_add (arg1, arg2);
}
static vector double
vadd2 (vector double arg1, vector double arg2)
{
return arg1 + arg2;
}
static vector double
vsub (vector double arg1, vector double arg2)
{
return vec_sub (arg1, arg2);
}
static vector double
vsub2 (vector double arg1, vector double arg2)
{
return arg1 - arg2;
}
static vector double
vmul (vector double arg1, vector double arg2)
{
return vec_mul (arg1, arg2);
}
static vector double
vmul2 (vector double arg1, vector double arg2)
{
return arg1 * arg2;
}
static vector double
vdiv (vector double arg1, vector double arg2)
{
return vec_div (arg1, arg2);
}
static vector double
vdiv2 (vector double arg1, vector double arg2)
{
return arg1 / arg2;
}
static vector double
vmax (vector double arg1, vector double arg2)
{
return vec_max (arg1, arg2);
}
static vector double
vmin (vector double arg1, vector double arg2)
{
return vec_min (arg1, arg2);
}
/* 2 argument tests. */
static struct
{
union args_d result;
union args_d input[2];
vector double (*func) (vector double, vector double);
const char *name;
} arg2_tests[] = {
/* result */
{ { 4.0, 6.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vadd, "vadd" },
{ { 4.0, -6.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vadd, "vadd" },
{ { 4.0, 6.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vadd2, "vadd2" },
{ { 4.0, -6.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vadd2, "vadd2" },
{ { -2.0, -2.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vsub, "vsub" },
{ { -2.0, 2.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vsub, "vsub" },
{ { -2.0, -2.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vsub2, "vsub2" },
{ { -2.0, 2.0 }, { { 1.0, -2.0 }, { 3.0, -4.0 } }, vsub2, "vsub2" },
{ { 6.0, 4.0 }, { { 2.0, 8.0 }, { 3.0, 0.5 } }, vmul, "vmul" },
{ { 6.0, 4.0 }, { { 2.0, 8.0 }, { 3.0, 0.5 } }, vmul2, "vmul2" },
{ { 2.0, 0.5 }, { { 6.0, 4.0 }, { 3.0, 8.0 } }, vdiv, "vdiv" },
{ { 2.0, 0.5 }, { { 6.0, 4.0 }, { 3.0, 8.0 } }, vdiv2, "vdiv2" },
{ { 3.0, 4.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vmax, "vmax" },
{ { 1.0, 4.0 }, { { 1.0, -2.0 }, { -3.0, 4.0 } }, vmax, "vmax" },
{ { 1.0, 2.0 }, { { 1.0, 2.0 }, { 3.0, 4.0 } }, vmin, "vmin" },
{ { -3.0, -2.0 }, { { 1.0, -2.0 }, { -3.0, 4.0 } }, vmin, "vmin" },
};
static void
test_arg2 (void)
{
unsigned i;
#ifdef DEBUG
printf ("\nTwo argument tests:\n");
#endif
for (i = 0; i < sizeof (arg2_tests) / sizeof (arg2_tests[0]); i++)
{
union args_d u;
u.vect = arg2_tests[i].func (arg2_tests[i].input[0].vect,
arg2_tests[i].input[1].vect);
#ifdef DEBUG
printf ("test %-16s: expected { %4g, %4g }, got { %4g, %4g }, input { %4g, %4g }, { %4g, %4g }\n",
arg2_tests[i].name,
arg2_tests[i].result.scalar[0],
arg2_tests[i].result.scalar[1],
u.scalar[0],
u.scalar[1],
arg2_tests[i].input[0].scalar[0],
arg2_tests[i].input[0].scalar[1],
arg2_tests[i].input[1].scalar[0],
arg2_tests[i].input[1].scalar[1]);
#endif
do_test_d (&arg2_tests[i].result, &u, arg2_tests[i].name);
}
return;
}
/* Comparisons, returnning a boolean vector. */
static vector bool long
vcmpeq (vector double arg1, vector double arg2)
{
return vec_cmpeq (arg1, arg2);
}
static vector bool long
vcmplt (vector double arg1, vector double arg2)
{
return vec_cmplt (arg1, arg2);
}
static vector bool long
vcmple (vector double arg1, vector double arg2)
{
return vec_cmple (arg1, arg2);
}
static vector bool long
vcmpgt (vector double arg1, vector double arg2)
{
return vec_cmpgt (arg1, arg2);
}
static vector bool long
vcmpge (vector double arg1, vector double arg2)
{
return vec_cmpge (arg1, arg2);
}
#define ONE 0xffffffffffffffffUL
#define ZERO 0x0000000000000000UL
/* comparison tests. */
static struct
{
union largs result;
union args_d input[2];
vector bool long (*func) (vector double, vector double);
const char *name;
} argcmp_tests[] = {
{ { ONE, ZERO }, { { 1.0, 2.0 }, { 1.0, -2.0 } }, vcmpeq, "vcmpeq" },
{ { ZERO, ONE }, { { -1.0, 2.0 }, { 1.0, 2.0 } }, vcmpeq, "vcmpeq" },
{ { ONE, ONE }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmple, "vcmple" },
{ { ONE, ONE }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmple, "vcmple" },
{ { ZERO, ZERO }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmple, "vcmple" },
{ { ZERO, ZERO }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmplt, "vcmplt" },
{ { ONE, ONE }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmplt, "vcmplt" },
{ { ZERO, ZERO }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmplt, "vcmplt" },
{ { ZERO, ZERO }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmpgt, "vcmpgt" },
{ { ZERO, ZERO }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmpgt, "vcmpgt" },
{ { ONE, ONE }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmpgt, "vcmpgt" },
{ { ONE, ONE }, { { 1.0, -2.0 }, { 1.0, -2.0 } }, vcmpge, "vcmpge" },
{ { ZERO, ZERO }, { { 1.0, -2.0 }, { 2.0, -1.0 } }, vcmpge, "vcmpge" },
{ { ONE, ONE }, { { 2.0, -1.0 }, { 1.0, -2.0 } }, vcmpge, "vcmpge" },
};
static void
test_argcmp (void)
{
unsigned i;
#ifdef DEBUG
printf ("\nComparison tests:\n");
#endif
for (i = 0; i < sizeof (argcmp_tests) / sizeof (argcmp_tests[0]); i++)
{
union largs u;
u.vect = argcmp_tests[i].func (argcmp_tests[i].input[0].vect,
argcmp_tests[i].input[1].vect);
#ifdef DEBUG
printf ("test %-16s: expected { 0x%016lx, 0x%016lx }, got { 0x%016lx, 0x%016lx }, input { %4g, %4g }, { %4g, %4g }\n",
argcmp_tests[i].name,
argcmp_tests[i].result.scalar[0],
argcmp_tests[i].result.scalar[1],
u.scalar[0],
u.scalar[1],
argcmp_tests[i].input[0].scalar[0],
argcmp_tests[i].input[0].scalar[1],
argcmp_tests[i].input[1].scalar[0],
argcmp_tests[i].input[1].scalar[1]);
#endif
do_ltest (&argcmp_tests[i].result, &u, argcmp_tests[i].name);
}
return;
}
int
main (int argc, char *argv[])
{
test_arg1_f ();
test_arg1_d ();
test_arg2 ();
test_argcmp ();
#ifdef DEBUG
if (errors)
{
printf ("There were %d error(s)\n", errors);
return errors;
}
else
printf ("There were no errors\n");
#endif
return 0;
}
|