| 1 |
/* Test type-generic builtins with __fp16 arguments. |
| 2 |
Except as otherwise noted, they should behave exactly |
| 3 |
the same as those with float arguments. */ |
| 4 |
|
| 5 |
/* { dg-do run } */ |
| 6 |
/* { dg-options "-mfp16-format=ieee -std=gnu99" } */ |
| 7 |
|
| 8 |
#include <stdlib.h> |
| 9 |
#include <math.h> |
| 10 |
|
| 11 |
volatile __fp16 h1, h2; |
| 12 |
volatile float f1, f2; |
| 13 |
|
| 14 |
void |
| 15 |
set1 (double x) |
| 16 |
{ |
| 17 |
h1 = x; |
| 18 |
f1 = h1; |
| 19 |
} |
| 20 |
|
| 21 |
void |
| 22 |
set2 (double x, double y) |
| 23 |
{ |
| 24 |
h1 = x; |
| 25 |
f1 = h1; |
| 26 |
h2 = y; |
| 27 |
f2 = h2; |
| 28 |
} |
| 29 |
|
| 30 |
#define test1(p,x) \ |
| 31 |
set1 (x); \ |
| 32 |
hp = (p (h1) ? 1 : 0); \ |
| 33 |
fp = (p (f1) ? 1 : 0); \ |
| 34 |
if (hp ^ fp) abort () |
| 35 |
|
| 36 |
#define test2(p,x,y) \ |
| 37 |
set2 (x,y); \ |
| 38 |
hp = (p (h1, h2) ? 1 : 0); \ |
| 39 |
fp = (p (f1, f2) ? 1 : 0); \ |
| 40 |
if (hp ^ fp) abort () |
| 41 |
|
| 42 |
int |
| 43 |
main (void) |
| 44 |
{ |
| 45 |
int hp, fp; |
| 46 |
|
| 47 |
test1 (__builtin_isfinite, 17.0); |
| 48 |
test1 (__builtin_isfinite, INFINITY); |
| 49 |
test1 (__builtin_isinf, -0.5); |
| 50 |
test1 (__builtin_isinf, INFINITY); |
| 51 |
test1 (__builtin_isnan, 493.0); |
| 52 |
test1 (__builtin_isnan, NAN); |
| 53 |
test1 (__builtin_isnormal, 3.14159); |
| 54 |
|
| 55 |
test2 (__builtin_isgreater, 5.0, 3.0); |
| 56 |
test2 (__builtin_isgreater, 3.0, 5.0); |
| 57 |
test2 (__builtin_isgreater, 73.5, 73.5); |
| 58 |
test2 (__builtin_isgreater, 1.0, NAN); |
| 59 |
|
| 60 |
test2 (__builtin_isgreaterequal, 5.0, 3.0); |
| 61 |
test2 (__builtin_isgreaterequal, 3.0, 5.0); |
| 62 |
test2 (__builtin_isgreaterequal, 73.5, 73.5); |
| 63 |
test2 (__builtin_isgreaterequal, 1.0, NAN); |
| 64 |
|
| 65 |
test2 (__builtin_isless, 5.0, 3.0); |
| 66 |
test2 (__builtin_isless, 3.0, 5.0); |
| 67 |
test2 (__builtin_isless, 73.5, 73.5); |
| 68 |
test2 (__builtin_isless, 1.0, NAN); |
| 69 |
|
| 70 |
test2 (__builtin_islessequal, 5.0, 3.0); |
| 71 |
test2 (__builtin_islessequal, 3.0, 5.0); |
| 72 |
test2 (__builtin_islessequal, 73.5, 73.5); |
| 73 |
test2 (__builtin_islessequal, 1.0, NAN); |
| 74 |
|
| 75 |
test2 (__builtin_islessgreater, 5.0, 3.0); |
| 76 |
test2 (__builtin_islessgreater, 3.0, 5.0); |
| 77 |
test2 (__builtin_islessgreater, 73.5, 73.5); |
| 78 |
test2 (__builtin_islessgreater, 1.0, NAN); |
| 79 |
|
| 80 |
test2 (__builtin_isunordered, 5.0, 3.0); |
| 81 |
test2 (__builtin_isunordered, 3.0, 5.0); |
| 82 |
test2 (__builtin_isunordered, 73.5, 73.5); |
| 83 |
test2 (__builtin_isunordered, 1.0, NAN); |
| 84 |
|
| 85 |
/* Test that __builtin_isnormal recognizes a denormalized __fp16 value, |
| 86 |
even if it's representable as a normalized float. */ |
| 87 |
h1 = 5.96046E-8; |
| 88 |
if (__builtin_isnormal (h1)) |
| 89 |
abort (); |
| 90 |
|
| 91 |
return 0; |
| 92 |
} |