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