blob: f23c7ed8bb833a5e2aaec86dabad154189b95029 [file] [log] [blame]
Sergei Poselenov3190dbe2007-07-05 08:17:37 +02001/*
2 * Copyright (C) 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Sergei Poselenov3190dbe2007-07-05 08:17:37 +02006 */
7/*
8 * Test for correctness of composite floating-point comparisons.
9 * Written by Paolo Bonzini, 26th May 2004.
10 * This file is originally a part of the GCC testsuite.
11 */
12
13#include <common.h>
14
Sergei Poselenov3190dbe2007-07-05 08:17:37 +020015#include <post.h>
16
Yuri Tikhonov7ed66f72008-12-20 14:54:21 +030017GNU_FPOST_ATTR
18
Kumar Galafe6555b2011-01-25 03:00:08 -060019#if CONFIG_POST & CONFIG_SYS_POST_FPU
20
Sergei Poselenov3190dbe2007-07-05 08:17:37 +020021static int failed;
22
23#define TEST(c) if ((c) != ok) failed++
24#define ORD(a, b) (!__builtin_isunordered ((a), (b)))
25#define UNORD(a, b) (__builtin_isunordered ((a), (b)))
26#define UNEQ(a, b) (__builtin_isunordered ((a), (b)) || ((a) == (b)))
27#define UNLT(a, b) (__builtin_isunordered ((a), (b)) || ((a) < (b)))
28#define UNLE(a, b) (__builtin_isunordered ((a), (b)) || ((a) <= (b)))
29#define UNGT(a, b) (__builtin_isunordered ((a), (b)) || ((a) > (b)))
30#define UNGE(a, b) (__builtin_isunordered ((a), (b)) || ((a) >= (b)))
31#define LTGT(a, b) (__builtin_islessgreater ((a), (b)))
32
33static float pinf;
34static float ninf;
35static float NaN;
36
37static void iuneq (float x, float y, int ok)
38{
39 TEST (UNEQ (x, y));
40 TEST (!LTGT (x, y));
41 TEST (UNLE (x, y) && UNGE (x,y));
42}
43
44static void ieq (float x, float y, int ok)
45{
46 TEST (ORD (x, y) && UNEQ (x, y));
47}
48
49static void iltgt (float x, float y, int ok)
50{
51 TEST (!UNEQ (x, y)); /* Not optimizable. */
52 TEST (LTGT (x, y)); /* Same, __builtin_islessgreater does not trap. */
53 TEST (ORD (x, y) && (UNLT (x, y) || UNGT (x,y)));
54}
55
56static void ine (float x, float y, int ok)
57{
58 TEST (UNLT (x, y) || UNGT (x, y));
59}
60
61static void iunlt (float x, float y, int ok)
62{
63 TEST (UNLT (x, y));
64 TEST (UNORD (x, y) || (x < y));
65}
66
67static void ilt (float x, float y, int ok)
68{
69 TEST (ORD (x, y) && UNLT (x, y)); /* Not optimized */
70 TEST ((x <= y) && (x != y));
71 TEST ((x <= y) && (y != x));
72 TEST ((x != y) && (x <= y)); /* Not optimized */
73 TEST ((y != x) && (x <= y)); /* Not optimized */
74}
75
76static void iunle (float x, float y, int ok)
77{
78 TEST (UNLE (x, y));
79 TEST (UNORD (x, y) || (x <= y));
80}
81
82static void ile (float x, float y, int ok)
83{
84 TEST (ORD (x, y) && UNLE (x, y)); /* Not optimized */
85 TEST ((x < y) || (x == y));
86 TEST ((y > x) || (x == y));
87 TEST ((x == y) || (x < y)); /* Not optimized */
88 TEST ((y == x) || (x < y)); /* Not optimized */
89}
90
91static void iungt (float x, float y, int ok)
92{
93 TEST (UNGT (x, y));
94 TEST (UNORD (x, y) || (x > y));
95}
96
97static void igt (float x, float y, int ok)
98{
99 TEST (ORD (x, y) && UNGT (x, y)); /* Not optimized */
100 TEST ((x >= y) && (x != y));
101 TEST ((x >= y) && (y != x));
102 TEST ((x != y) && (x >= y)); /* Not optimized */
103 TEST ((y != x) && (x >= y)); /* Not optimized */
104}
105
106static void iunge (float x, float y, int ok)
107{
108 TEST (UNGE (x, y));
109 TEST (UNORD (x, y) || (x >= y));
110}
111
112static void ige (float x, float y, int ok)
113{
114 TEST (ORD (x, y) && UNGE (x, y)); /* Not optimized */
115 TEST ((x > y) || (x == y));
116 TEST ((y < x) || (x == y));
117 TEST ((x == y) || (x > y)); /* Not optimized */
118 TEST ((y == x) || (x > y)); /* Not optimized */
119}
120
121int fpu_post_test_math6 (void)
122{
123 pinf = __builtin_inf ();
124 ninf = -__builtin_inf ();
125 NaN = __builtin_nan ("");
126
127 iuneq (ninf, pinf, 0);
128 iuneq (NaN, NaN, 1);
129 iuneq (pinf, ninf, 0);
130 iuneq (1, 4, 0);
131 iuneq (3, 3, 1);
132 iuneq (5, 2, 0);
133
134 ieq (1, 4, 0);
135 ieq (3, 3, 1);
136 ieq (5, 2, 0);
137
138 iltgt (ninf, pinf, 1);
139 iltgt (NaN, NaN, 0);
140 iltgt (pinf, ninf, 1);
141 iltgt (1, 4, 1);
142 iltgt (3, 3, 0);
143 iltgt (5, 2, 1);
144
145 ine (1, 4, 1);
146 ine (3, 3, 0);
147 ine (5, 2, 1);
148
149 iunlt (NaN, ninf, 1);
150 iunlt (pinf, NaN, 1);
151 iunlt (pinf, ninf, 0);
152 iunlt (pinf, pinf, 0);
153 iunlt (ninf, ninf, 0);
154 iunlt (1, 4, 1);
155 iunlt (3, 3, 0);
156 iunlt (5, 2, 0);
157
158 ilt (1, 4, 1);
159 ilt (3, 3, 0);
160 ilt (5, 2, 0);
161
162 iunle (NaN, ninf, 1);
163 iunle (pinf, NaN, 1);
164 iunle (pinf, ninf, 0);
165 iunle (pinf, pinf, 1);
166 iunle (ninf, ninf, 1);
167 iunle (1, 4, 1);
168 iunle (3, 3, 1);
169 iunle (5, 2, 0);
170
171 ile (1, 4, 1);
172 ile (3, 3, 1);
173 ile (5, 2, 0);
174
175 iungt (NaN, ninf, 1);
176 iungt (pinf, NaN, 1);
177 iungt (pinf, ninf, 1);
178 iungt (pinf, pinf, 0);
179 iungt (ninf, ninf, 0);
180 iungt (1, 4, 0);
181 iungt (3, 3, 0);
182 iungt (5, 2, 1);
183
184 igt (1, 4, 0);
185 igt (3, 3, 0);
186 igt (5, 2, 1);
187
188 iunge (NaN, ninf, 1);
189 iunge (pinf, NaN, 1);
190 iunge (ninf, pinf, 0);
191 iunge (pinf, pinf, 1);
192 iunge (ninf, ninf, 1);
193 iunge (1, 4, 0);
194 iunge (3, 3, 1);
195 iunge (5, 2, 1);
196
197 ige (1, 4, 0);
198 ige (3, 3, 1);
199 ige (5, 2, 1);
200
201 if (failed) {
202 post_log ("Error in FPU math6 test\n");
203 return -1;
204 }
205 return 0;
206}
207
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200208#endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */