3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * Test for correctness of composite floating-point comparisons.
25 * Written by Paolo Bonzini, 26th May 2004.
26 * This file is originally a part of the GCC testsuite.
35 #if CONFIG_POST & CONFIG_SYS_POST_FPU
39 #define TEST(c) if ((c) != ok) failed++
40 #define ORD(a, b) (!__builtin_isunordered ((a), (b)))
41 #define UNORD(a, b) (__builtin_isunordered ((a), (b)))
42 #define UNEQ(a, b) (__builtin_isunordered ((a), (b)) || ((a) == (b)))
43 #define UNLT(a, b) (__builtin_isunordered ((a), (b)) || ((a) < (b)))
44 #define UNLE(a, b) (__builtin_isunordered ((a), (b)) || ((a) <= (b)))
45 #define UNGT(a, b) (__builtin_isunordered ((a), (b)) || ((a) > (b)))
46 #define UNGE(a, b) (__builtin_isunordered ((a), (b)) || ((a) >= (b)))
47 #define LTGT(a, b) (__builtin_islessgreater ((a), (b)))
53 static void iuneq (float x, float y, int ok)
57 TEST (UNLE (x, y) && UNGE (x,y));
60 static void ieq (float x, float y, int ok)
62 TEST (ORD (x, y) && UNEQ (x, y));
65 static void iltgt (float x, float y, int ok)
67 TEST (!UNEQ (x, y)); /* Not optimizable. */
68 TEST (LTGT (x, y)); /* Same, __builtin_islessgreater does not trap. */
69 TEST (ORD (x, y) && (UNLT (x, y) || UNGT (x,y)));
72 static void ine (float x, float y, int ok)
74 TEST (UNLT (x, y) || UNGT (x, y));
77 static void iunlt (float x, float y, int ok)
80 TEST (UNORD (x, y) || (x < y));
83 static void ilt (float x, float y, int ok)
85 TEST (ORD (x, y) && UNLT (x, y)); /* Not optimized */
86 TEST ((x <= y) && (x != y));
87 TEST ((x <= y) && (y != x));
88 TEST ((x != y) && (x <= y)); /* Not optimized */
89 TEST ((y != x) && (x <= y)); /* Not optimized */
92 static void iunle (float x, float y, int ok)
95 TEST (UNORD (x, y) || (x <= y));
98 static void ile (float x, float y, int ok)
100 TEST (ORD (x, y) && UNLE (x, y)); /* Not optimized */
101 TEST ((x < y) || (x == y));
102 TEST ((y > x) || (x == y));
103 TEST ((x == y) || (x < y)); /* Not optimized */
104 TEST ((y == x) || (x < y)); /* Not optimized */
107 static void iungt (float x, float y, int ok)
110 TEST (UNORD (x, y) || (x > y));
113 static void igt (float x, float y, int ok)
115 TEST (ORD (x, y) && UNGT (x, y)); /* Not optimized */
116 TEST ((x >= y) && (x != y));
117 TEST ((x >= y) && (y != x));
118 TEST ((x != y) && (x >= y)); /* Not optimized */
119 TEST ((y != x) && (x >= y)); /* Not optimized */
122 static void iunge (float x, float y, int ok)
125 TEST (UNORD (x, y) || (x >= y));
128 static void ige (float x, float y, int ok)
130 TEST (ORD (x, y) && UNGE (x, y)); /* Not optimized */
131 TEST ((x > y) || (x == y));
132 TEST ((y < x) || (x == y));
133 TEST ((x == y) || (x > y)); /* Not optimized */
134 TEST ((y == x) || (x > y)); /* Not optimized */
137 int fpu_post_test_math6 (void)
139 pinf = __builtin_inf ();
140 ninf = -__builtin_inf ();
141 NaN = __builtin_nan ("");
143 iuneq (ninf, pinf, 0);
145 iuneq (pinf, ninf, 0);
154 iltgt (ninf, pinf, 1);
156 iltgt (pinf, ninf, 1);
165 iunlt (NaN, ninf, 1);
166 iunlt (pinf, NaN, 1);
167 iunlt (pinf, ninf, 0);
168 iunlt (pinf, pinf, 0);
169 iunlt (ninf, ninf, 0);
178 iunle (NaN, ninf, 1);
179 iunle (pinf, NaN, 1);
180 iunle (pinf, ninf, 0);
181 iunle (pinf, pinf, 1);
182 iunle (ninf, ninf, 1);
191 iungt (NaN, ninf, 1);
192 iungt (pinf, NaN, 1);
193 iungt (pinf, ninf, 1);
194 iungt (pinf, pinf, 0);
195 iungt (ninf, ninf, 0);
204 iunge (NaN, ninf, 1);
205 iunge (pinf, NaN, 1);
206 iunge (ninf, pinf, 0);
207 iunge (pinf, pinf, 1);
208 iunge (ninf, ninf, 1);
218 post_log ("Error in FPU math6 test\n");
224 #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */