| 1 |
void abort (void); |
| 2 |
void exit (int); |
| 3 |
|
| 4 |
#ifndef FLOAT |
| 5 |
#define FLOAT double |
| 6 |
#endif |
| 7 |
|
| 8 |
/* Like fp-cmp-4.c, but test that the cmove patterns are correct. */ |
| 9 |
|
| 10 |
static FLOAT |
| 11 |
test_isunordered(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 12 |
{ |
| 13 |
return __builtin_isunordered(x, y) ? a : b; |
| 14 |
} |
| 15 |
|
| 16 |
static FLOAT |
| 17 |
test_not_isunordered(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 18 |
{ |
| 19 |
return !__builtin_isunordered(x, y) ? a : b; |
| 20 |
} |
| 21 |
|
| 22 |
static FLOAT |
| 23 |
test_isless(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 24 |
{ |
| 25 |
return __builtin_isless(x, y) ? a : b; |
| 26 |
} |
| 27 |
|
| 28 |
static FLOAT |
| 29 |
test_not_isless(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 30 |
{ |
| 31 |
return !__builtin_isless(x, y) ? a : b; |
| 32 |
} |
| 33 |
|
| 34 |
static FLOAT |
| 35 |
test_islessequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 36 |
{ |
| 37 |
return __builtin_islessequal(x, y) ? a : b; |
| 38 |
} |
| 39 |
|
| 40 |
static FLOAT |
| 41 |
test_not_islessequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 42 |
{ |
| 43 |
return !__builtin_islessequal(x, y) ? a : b; |
| 44 |
} |
| 45 |
|
| 46 |
static FLOAT |
| 47 |
test_isgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 48 |
{ |
| 49 |
return __builtin_isgreater(x, y) ? a : b; |
| 50 |
} |
| 51 |
|
| 52 |
static FLOAT |
| 53 |
test_not_isgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 54 |
{ |
| 55 |
return !__builtin_isgreater(x, y) ? a : b; |
| 56 |
} |
| 57 |
|
| 58 |
static FLOAT |
| 59 |
test_isgreaterequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 60 |
{ |
| 61 |
return __builtin_isgreaterequal(x, y) ? a : b; |
| 62 |
} |
| 63 |
|
| 64 |
static FLOAT |
| 65 |
test_not_isgreaterequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 66 |
{ |
| 67 |
return !__builtin_isgreaterequal(x, y) ? a : b; |
| 68 |
} |
| 69 |
|
| 70 |
static FLOAT |
| 71 |
test_islessgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 72 |
{ |
| 73 |
return __builtin_islessgreater(x, y) ? a : b; |
| 74 |
} |
| 75 |
|
| 76 |
static FLOAT |
| 77 |
test_not_islessgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b) |
| 78 |
{ |
| 79 |
return !__builtin_islessgreater(x, y) ? a : b; |
| 80 |
} |
| 81 |
|
| 82 |
static void |
| 83 |
one_test(FLOAT x, FLOAT y, int expected, |
| 84 |
FLOAT (*pos) (FLOAT, FLOAT, FLOAT, FLOAT), |
| 85 |
FLOAT (*neg) (FLOAT, FLOAT, FLOAT, FLOAT)) |
| 86 |
{ |
| 87 |
if (((*pos)(x, y, 1.0, 2.0) == 1.0) != expected) |
| 88 |
abort (); |
| 89 |
if (((*neg)(x, y, 3.0, 4.0) == 4.0) != expected) |
| 90 |
abort (); |
| 91 |
} |
| 92 |
|
| 93 |
#define NAN (0.0 / 0.0) |
| 94 |
#define INF (1.0 / 0.0) |
| 95 |
|
| 96 |
int |
| 97 |
main() |
| 98 |
{ |
| 99 |
struct try |
| 100 |
{ |
| 101 |
FLOAT x, y; |
| 102 |
int result[6]; |
| 103 |
}; |
| 104 |
|
| 105 |
static struct try const data[] = |
| 106 |
{ |
| 107 |
{ NAN, NAN, { 1, 0, 0, 0, 0, 0 } }, |
| 108 |
{ 0.0, NAN, { 1, 0, 0, 0, 0, 0 } }, |
| 109 |
{ NAN, 0.0, { 1, 0, 0, 0, 0, 0 } }, |
| 110 |
{ 0.0, 0.0, { 0, 0, 1, 0, 1, 0 } }, |
| 111 |
{ 1.0, 2.0, { 0, 1, 1, 0, 0, 1 } }, |
| 112 |
{ 2.0, 1.0, { 0, 0, 0, 1, 1, 1 } }, |
| 113 |
{ INF, 0.0, { 0, 0, 0, 1, 1, 1 } }, |
| 114 |
{ 1.0, INF, { 0, 1, 1, 0, 0, 1 } }, |
| 115 |
{ INF, INF, { 0, 0, 1, 0, 1, 0 } }, |
| 116 |
{ 0.0, -INF, { 0, 0, 0, 1, 1, 1 } }, |
| 117 |
{ -INF, 1.0, { 0, 1, 1, 0, 0, 1 } }, |
| 118 |
{ -INF, -INF, { 0, 0, 1, 0, 1, 0 } }, |
| 119 |
{ INF, -INF, { 0, 0, 0, 1, 1, 1 } }, |
| 120 |
{ -INF, INF, { 0, 1, 1, 0, 0, 1 } }, |
| 121 |
}; |
| 122 |
|
| 123 |
struct test |
| 124 |
{ |
| 125 |
FLOAT (*pos)(FLOAT, FLOAT, FLOAT, FLOAT); |
| 126 |
FLOAT (*neg)(FLOAT, FLOAT, FLOAT, FLOAT); |
| 127 |
}; |
| 128 |
|
| 129 |
static struct test const tests[] = |
| 130 |
{ |
| 131 |
{ test_isunordered, test_not_isunordered }, |
| 132 |
{ test_isless, test_not_isless }, |
| 133 |
{ test_islessequal, test_not_islessequal }, |
| 134 |
{ test_isgreater, test_not_isgreater }, |
| 135 |
{ test_isgreaterequal, test_not_isgreaterequal }, |
| 136 |
{ test_islessgreater, test_not_islessgreater } |
| 137 |
}; |
| 138 |
|
| 139 |
const int n = sizeof(data) / sizeof(data[0]); |
| 140 |
int i, j; |
| 141 |
|
| 142 |
for (i = 0; i < n; ++i) |
| 143 |
for (j = 0; j < 6; ++j) |
| 144 |
one_test (data[i].x, data[i].y, data[i].result[j], |
| 145 |
tests[j].pos, tests[j].neg); |
| 146 |
|
| 147 |
exit (0); |
| 148 |
} |