| 1 |
/* { dg-do run { target { powerpc*-*-* } } } */ |
| 2 |
/* { dg-require-effective-target p9vector_hw } */ |
| 3 |
/* { dg-options "-mdejagnu-cpu=power9" } */ |
| 4 |
|
| 5 |
#include <altivec.h> |
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
/* Flags to select tests: |
| 9 |
0x40 Test for NaN |
| 10 |
0x20 Test for +Infinity |
| 11 |
0x10 Test for -Infinity |
| 12 |
0x08 Test for +Zero |
| 13 |
0x04 Test for -Zero |
| 14 |
0x02 Test for +Denormal |
| 15 |
0x01 Test for -Denormal */ |
| 16 |
|
| 17 |
__vector bool int |
| 18 |
test_nan (__vector float *p) |
| 19 |
{ |
| 20 |
__vector float source = *p; |
| 21 |
|
| 22 |
return vec_test_data_class (source, 0x40); |
| 23 |
} |
| 24 |
|
| 25 |
__vector bool int |
| 26 |
test_infinity (__vector float *p) |
| 27 |
{ |
| 28 |
__vector float source = *p; |
| 29 |
|
| 30 |
return vec_test_data_class (source, 0x30); |
| 31 |
} |
| 32 |
|
| 33 |
__vector bool int |
| 34 |
test_zero (__vector float *p) |
| 35 |
{ |
| 36 |
__vector float source = *p; |
| 37 |
|
| 38 |
return vec_test_data_class (source, 0x0c); |
| 39 |
} |
| 40 |
|
| 41 |
__vector bool int |
| 42 |
test_denormal (__vector float *p) |
| 43 |
{ |
| 44 |
__vector float source = *p; |
| 45 |
|
| 46 |
return vec_test_data_class (source, 0x03); |
| 47 |
} |
| 48 |
|
| 49 |
float |
| 50 |
float_scalar_insert_exp (unsigned int significand, unsigned int exponent) |
| 51 |
{ |
| 52 |
float result; |
| 53 |
unsigned int *result_as_uip = (unsigned int *) &result; |
| 54 |
|
| 55 |
*result_as_uip = (significand & ~0x800000) | ((exponent & 0xff) << 23); |
| 56 |
return result; |
| 57 |
} |
| 58 |
|
| 59 |
int |
| 60 |
main () |
| 61 |
{ |
| 62 |
__vector float argument; |
| 63 |
__vector bool result; |
| 64 |
|
| 65 |
unsigned int signaling_significand = 0x00a00000; |
| 66 |
unsigned int quiet_significand = 0x00c00000; |
| 67 |
unsigned int one_significand = 0x00800000; |
| 68 |
unsigned int three_significand = 0x00c00000; |
| 69 |
unsigned int five_significand = 0x00a00000; |
| 70 |
unsigned int zero_significand = 0x00000000; |
| 71 |
unsigned int minus_zero_significand = 0x80000000; |
| 72 |
|
| 73 |
/* A NaN is represented with the maximum biased exponent value and a |
| 74 |
* non-zero fraction value. The sign bit ignored. If the |
| 75 |
* high-order bit of the fraction field is 0, then the NaN |
| 76 |
* is a Signaling NaN. Otherwise, it is a Quiet NaN. */ |
| 77 |
argument[0] = float_scalar_insert_exp (signaling_significand, 255); |
| 78 |
argument[1] = float_scalar_insert_exp (quiet_significand, 255); |
| 79 |
argument[2] = 1.0f; |
| 80 |
argument[3] = -0.07f; |
| 81 |
result = test_nan (&argument); |
| 82 |
if (!result[0] || !result[1] || result[2] || result[3]) |
| 83 |
abort (); |
| 84 |
|
| 85 |
/* Infinity is represented by a biased exponent value of: |
| 86 |
* 255 in single format |
| 87 |
* 2047 in double format |
| 88 |
* and a zero fraction value. The difference between +infinity and |
| 89 |
* -infinity is the value of the sign bit. */ |
| 90 |
argument[2] = float_scalar_insert_exp (zero_significand, 255); |
| 91 |
argument[3] = float_scalar_insert_exp (minus_zero_significand, 255); |
| 92 |
result = test_infinity (&argument); |
| 93 |
if (result[0] || result[1] || !result[2] || !result[3]) |
| 94 |
abort (); |
| 95 |
|
| 96 |
/* A Zero value has a biased exponent value of zero and a zero |
| 97 |
* fraction value. The sign may be either positive or negative. */ |
| 98 |
argument[1] = float_scalar_insert_exp (minus_zero_significand, 0); |
| 99 |
argument[2] = float_scalar_insert_exp (zero_significand, 0); |
| 100 |
result = test_zero (&argument); |
| 101 |
if (result[0] || !result[1] || !result[2] || result[3]) |
| 102 |
abort (); |
| 103 |
|
| 104 |
/* A Denormal number has a biased exponent value of zero and a |
| 105 |
* non-zero fraction value. */ |
| 106 |
argument[0] = float_scalar_insert_exp (five_significand, 0); |
| 107 |
argument[3] = float_scalar_insert_exp (three_significand, 0); |
| 108 |
result = test_denormal (&argument); |
| 109 |
if (!result[0] || result[1] || result[2] || !result[3]) |
| 110 |
abort (); |
| 111 |
} |