1 //===-- aeabi_cfcmpeq.c - Test __aeabi_cfcmpeq ----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __aeabi_cfcmpeq for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include <stdint.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <math.h>
18 #include <pico/float.h>
19 #include "pico/stdlib.h"
20 // Include sys/types.h before inttypes.h to work around issue with
21 // certain versions of GCC and newlib which causes omission of PRIx64
22 #include <sys/types.h>
23 #include "inttypes.h"
24 
25 #define test_assert(x) ({ if (!(x)) { printf("Assertion failed: ");puts(#x);printf("  at " __FILE__ ":%d\n", __LINE__); exit(-1); } })
26 extern int __aeabi_fcmpun(float a, float b);
27 
28 #if __arm__
29 
30 #include "call_apsr.h"
31 
32 extern __attribute__((pcs("aapcs"))) void __aeabi_cfcmpeq(float a, float b);
33 
test__aeabi_cfcmpeq(float a,float b,int expected)34 int test__aeabi_cfcmpeq(float a, float b, int expected) {
35     uint32_t cpsr_value = call_apsr_f(a, b, __aeabi_cfcmpeq);
36     union cpsr cpsr = {.value = cpsr_value};
37     if (expected != cpsr.flags.z) {
38         printf("error in __aeabi_cfcmpeq(%f, %f) => Z = %08x, expected %08x\n",
39                a, b, cpsr.flags.z, expected);
40         return 1;
41     }
42     return 0;
43 }
44 
45 #endif
46 
test_cfcmpeq()47 int test_cfcmpeq() {
48 #if __arm__
49     if (test__aeabi_cfcmpeq(1.0, 1.0, 1))
50         return 1;
51     if (test__aeabi_cfcmpeq(1234.567, 765.4321, 0))
52         return 1;
53     if (test__aeabi_cfcmpeq(-123.0, -678.0, 0))
54         return 1;
55     if (test__aeabi_cfcmpeq(0.0, -0.0, 1))
56         return 1;
57     if (test__aeabi_cfcmpeq(0.0, 0.0, 1))
58         return 1;
59     if (test__aeabi_cfcmpeq(-0.0, -0.0, 1))
60         return 1;
61     if (test__aeabi_cfcmpeq(-0.0, 0.0, 1))
62         return 1;
63     if (test__aeabi_cfcmpeq(0.0, -1.0, 0))
64         return 1;
65     if (test__aeabi_cfcmpeq(-0.0, -1.0, 0))
66         return 1;
67     if (test__aeabi_cfcmpeq(-1.0, 0.0, 0))
68         return 1;
69     if (test__aeabi_cfcmpeq(-1.0, -0.0, 0))
70         return 1;
71     if (test__aeabi_cfcmpeq(1.0, NAN, 0))
72         return 1;
73     if (test__aeabi_cfcmpeq(NAN, 1.0, 0))
74         return 1;
75     if (test__aeabi_cfcmpeq(NAN, NAN, 0))
76         return 1;
77     if (test__aeabi_cfcmpeq(INFINITY, 1.0, 0))
78         return 1;
79     if (test__aeabi_cfcmpeq(0.0, INFINITY, 0))
80         return 1;
81     if (test__aeabi_cfcmpeq(-INFINITY, 0.0, 0))
82         return 1;
83     if (test__aeabi_cfcmpeq(0.0, -INFINITY, 0))
84         return 1;
85     if (test__aeabi_cfcmpeq(INFINITY, INFINITY, 1))
86         return 1;
87     if (test__aeabi_cfcmpeq(-INFINITY, -INFINITY, 1))
88         return 1;
89 #else
90     printf("skipped\n");
91 #endif
92     return 0;
93 }
94 
95 #if __arm__
96 
97 extern __attribute__((pcs("aapcs"))) void __aeabi_cfcmple(float a, float b);
98 
99 extern __attribute__((pcs("aapcs"))) void __aeabi_cfrcmple(float a, float b);
100 
test_fcmple_gt(float a,float b,int expected)101 int test_fcmple_gt(float a, float b, int expected) {
102     if ((a <= b) != expected) {
103         printf("error in fcmple(%f, %f) => %d, expected %d\n",
104                a, b, a <= b, expected);
105         return 1;
106     }
107     if ((a > b) == expected && !isnanf(a) && !isnanf(b)) {
108         printf("error in fcmpgt(%f, %f) => %d, expected %d\n",
109                a, b, a > b, !expected);
110         return 1;
111     }
112     return 0;
113 }
114 
test_fcmplt_ge(float a,float b,int expected)115 int test_fcmplt_ge(float a, float b, int expected) {
116     if ((a < b) != expected) {
117         printf("error in fcmplt(%f, %f) => %d, expected %d\n",
118                a, b, a < b, expected);
119         return 1;
120     }
121     if ((a >= b) == expected && !isnanf(a) && !isnanf(b)) {
122         printf("error in fcmpge(%f, %f) => %d, expected %d\n",
123                a, b, a >= b, !expected);
124         return 1;
125     }
126     return 0;
127 }
128 
test__aeabi_cfcmple(float a,float b,int expected)129 int test__aeabi_cfcmple(float a, float b, int expected) {
130     int32_t cpsr_value = call_apsr_f(a, b, __aeabi_cfcmple);
131     int32_t r_cpsr_value = call_apsr_f(b, a, __aeabi_cfrcmple);
132     int32_t cpsr_value2 = call_apsr_f(b, a, __aeabi_cfcmple);
133     int32_t r_cpsr_value2 = call_apsr_f(a, b, __aeabi_cfrcmple);
134 
135     if (cpsr_value != r_cpsr_value) {
136         printf("error: __aeabi_cfcmple(%f, %f) != __aeabi_cfrcmple(%f, %f)\n", a, b, b, a);
137         return 1;
138     }
139 
140     int expected_z, expected_c;
141     if (expected == -1) {
142         expected_z = 0;
143         expected_c = 0;
144     } else if (expected == 0) {
145         expected_z = 1;
146         expected_c = 1;
147     } else {
148         // a or b is NaN, or a > b
149         expected_z = 0;
150         expected_c = 1;
151     }
152 #if PICO_FLOAT_COMPILER
153     // gcc has this backwards it seems - not a good thing, but I guess it doesn't ever call them
154     expected_c ^= 1;
155 #endif
156 
157     union cpsr cpsr = {.value = cpsr_value};
158     if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
159         printf("error in __aeabi_cfcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
160                a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
161         return 1;
162     }
163 
164     cpsr.value = r_cpsr_value;
165     if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
166         printf("error in __aeabi_cfrcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
167                a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
168         return 1;
169     }
170     return 0;
171 }
172 
173 #endif
174 
test_cfcmple()175 int test_cfcmple() {
176 #if __arm__
177     if (test__aeabi_cfcmple(1.0, 1.0, 0))
178         return 1;
179     if (test__aeabi_cfcmple(1234.567, 765.4321, 1))
180         return 1;
181     if (test__aeabi_cfcmple(765.4321, 1234.567, -1))
182         return 1;
183     if (test__aeabi_cfcmple(-123.0, -678.0, 1))
184         return 1;
185     if (test__aeabi_cfcmple(-678.0, -123.0, -1))
186         return 1;
187     if (test__aeabi_cfcmple(-123.0, 678.0, -1))
188         return 1;
189     if (test__aeabi_cfcmple(678.0, -123.0, 1))
190         return 1;
191     if (test__aeabi_cfcmple(0.0, -0.0, 0))
192         return 1;
193     if (test__aeabi_cfcmple(1.0, NAN, 1))
194         return 1;
195     if (test__aeabi_cfcmple(NAN, 1.0, 1))
196         return 1;
197     if (test__aeabi_cfcmple(NAN, NAN, 1))
198         return 1;
199 #else
200     printf("skipped\n");
201 #endif
202     return 0;
203 }
204 
test_cmple_gt()205 int test_cmple_gt() {
206     if (test_fcmple_gt(1.0, 1.0, 1))
207         return 1;
208     if (test_fcmple_gt(1234.567, 765.4321, 0))
209         return 1;
210     if (test_fcmple_gt(765.4321, 1234.567, 1))
211         return 1;
212     if (test_fcmple_gt(-123.0, -678.0, 0))
213         return 1;
214     if (test_fcmple_gt(-678.0, -123.0, 1))
215         return 1;
216     if (test_fcmple_gt(-123.0, 678.0, 1))
217         return 1;
218     if (test_fcmple_gt(678.0, -123.0, 0))
219         return 1;
220     if (test_fcmple_gt(0.0, -0.0, 1))
221         return 1;
222     if (test_fcmple_gt(-0.0, 0.0, 1))
223         return 1;
224     if (test_fcmple_gt(1.0, NAN, 0))
225         return 1;
226     if (test_fcmple_gt(NAN, 1.0, 0))
227         return 1;
228     if (test_fcmple_gt(NAN, NAN, 0))
229         return 1;
230     return 0;
231 }
232 
test_cmplt_ge()233 int test_cmplt_ge() {
234     if (test_fcmplt_ge(1.0, 1.0, 0))
235         return 1;
236     if (test_fcmplt_ge(1234.567, 765.4321, 0))
237         return 1;
238     if (test_fcmplt_ge(765.4321, 1234.567, 1))
239         return 1;
240     if (test_fcmplt_ge(-123.0, -678.0, 0))
241         return 1;
242     if (test_fcmplt_ge(-678.0, -123.0, 1))
243         return 1;
244     if (test_fcmplt_ge(-123.0, 678.0, 1))
245         return 1;
246     if (test_fcmplt_ge(678.0, -123.0, 0))
247         return 1;
248     if (test_fcmplt_ge(0.0, -0.0, 0))
249         return 1;
250     if (test_fcmplt_ge(-0.0, 0.0, 0))
251         return 1;
252     if (test_fcmplt_ge(1.0, NAN, 0))
253         return 1;
254     if (test_fcmplt_ge(NAN, 1.0, 0))
255         return 1;
256     if (test_fcmplt_ge(NAN, NAN, 0))
257         return 1;
258     return 0;
259 }
260 
check_fcmpun(float a,float b,bool expected,bool expect_equal)261 int check_fcmpun(float a, float b, bool expected, bool expect_equal) {
262     if (__aeabi_fcmpun(a, b) != expected) {
263         printf("Failed fcmpun(%f, %f)\n", a, b);
264         return 1;
265     }
266     if ((a == b) != expect_equal) {
267         printf("Failed equality check %f %f\n", a, b);
268         __breakpoint();
269         if (b == a) {
270             printf("SAS\n");
271         }
272         return 1;
273     }
274     return 0;
275 }
276 
test_fcmpun()277 int test_fcmpun() {
278     if (check_fcmpun(0, 0, false, true) ||
279         check_fcmpun(-INFINITY, INFINITY, false, false) ||
280         check_fcmpun(NAN, 0, true, false) ||
281         check_fcmpun(0, NAN, true, false) ||
282         check_fcmpun(NAN, NAN, true, false) ||
283         check_fcmpun(-NAN, NAN, true, false)) {
284         return 1;
285     }
286     return 0;
287 }
288 
289 #define assert_nan(a) test_assert(isnanf(a))
290 #define check_nan(a) ({ assert_nan(a); a; })
291 
292 float __aeabi_i2f(int32_t);
293 float __aeabi_ui2f(int32_t);
294 float __aeabi_l2f(int64_t);
295 float __aeabi_ul2f(int64_t);
296 int32_t __aeabi_f2iz(float);
297 int64_t __aeabi_f2lz(float);
298 float __aeabi_fmul(float, float);
299 float __aeabi_fdiv(float, float);
300 #if LIB_PICO_FLOAT_PICO
301 #if !LIB_PICO_FLOAT_PICO_VFP
302 float __real___aeabi_i2f(int);
303 float __real___aeabi_ui2f(int);
304 float __real___aeabi_l2f(int64_t);
305 float __real___aeabi_ul2f(int64_t);
306 float __real___aeabi_fmul(float, float);
307 float __real___aeabi_fdiv(float, float);
308 int32_t __real___aeabi_f2iz(float);
309 int64_t __real___aeabi_f2lz(float);
310 float __real_sqrtf(float);
311 #endif
312 float __real_cosf(float);
313 float __real_sinf(float);
314 float __real_tanf(float);
315 float __real_expf(float);
316 float __real_logf(float);
317 float __real_atan2f(float, float);
318 float __real_powf(float, float);
319 float __real_truncf(float);
320 float __real_ldexpf(float, int);
321 float __real_fmodf(float, float);
322 #define FRAC ((float)(1u << 22))
323 #define allowed_range(a) (fabsf(a) / FRAC)
324 #ifdef LLVM_LIBC_MATH_H
325 #define isinff isinf
326 #endif
327 #define assert_close(a, b) test_assert((fabsf(a - b) <= allowed_range(a) || ({ printf("  error: %f != %f\n", a, b); 0; })) || (isinff(a) && isinff(b) && (a < 0) == (b < 0)))
328 #define check1(func,p0) ({ typeof(p0) r = func(p0), r2 = __CONCAT(__real_, func)(p0); test_assert(r == r2); r; })
329 #define check2(func,p0,p1) ({ typeof(p0) r = func(p0,p1), r2 = __CONCAT(__real_, func)(p0,p1); test_assert(r == r2); r; })
330 #define check_close1(func,p0) ({ typeof(p0) r = func(p0), r2 = __CONCAT(__real_, func)(p0); if (isnanf(p0)) assert_nan(r); else assert_close(r, r2); r; })
331 #define check_close2(func,p0,p1) ({ typeof(p0) r = func(p0,p1), r2 = __CONCAT(__real_, func)(p0,p1); if (isnanf(p0) || isnanf(p1)) assert_nan(r); else assert_close(r, r2); r; })
332 #else
333 #define check1(func,p0) func(p0)
334 #define check2(func,p0,p1) func(p0,p1)
335 #define check_close1(func,p0) func(p0)
336 #define check_close2(func,p0,p1) func(p0,p1)
337 #endif
338 
339 double aa = 0.5;
340 double bb = 1;
341 
main()342 int main() {
343     setup_default_uart();
344 
345     bool fail = false;
346 
347     printf("%d\n", aa < bb);
348     for(float a = -1; a <= 1; a++) {
349         for(float b = -1; b <= 1; b++) {
350             printf("%f < %f ? %d\n", a, b, a < b);
351         }
352     }
353     for(float a = -1; a <=1; a++) {
354         for(float b = -1; b <= 1; b++) {
355             printf("%f > %f ? %d\n", a, b, a > b);
356         }
357     }
358     printf("F\n");
359     for(float f = -1.0; f<=1.f; f+=0.25f) {
360         printf("%d\n", (int)f);
361     }
362     printf("D\n");
363     for(double d = -1.0; d<=1.0; d+=0.25) {
364         printf("%d\n", (int)d);
365     }
366     printf("LD\n");
367     for(double d = -1.0; d<=1.0; d+=0.25) {
368         printf("%lld\n", (int64_t)d);
369     }
370 
371     for(float d = -0.125; d>=-65536.0*65536.0*65536.0*65536.0*2; d*=2) {
372         printf("%g %d, %lld, %u, %llu\n", d, (int32_t)d, (int64_t)d, (uint32_t)d, (uint64_t)d);
373     }
374     for(float d = 0.125; d<=65536.0*65536.0*65536.0*65536.0*2; d*=2) {
375         printf("%g %d, %lld, %u, %llu\n", d, (int32_t)d, (int64_t)d, (uint32_t)d, (uint64_t)d);
376     }
377 
378     for(double d = -0.125; d>=-65536.0*65536.0*65536.0*65536.0*2; d*=2) {
379         printf("%g %d, %lld, %u, %llu\n", d, (int32_t)d, (int64_t)d, (uint32_t)d, (uint64_t)d);
380     }
381     for(double d = 0.125; d<=65536.0*65536.0*65536.0*65536.0*2; d*=2) {
382         printf("%g %d, %lld, %u, %llu\n", d, (int32_t)d, (int64_t)d, (uint32_t)d, (uint64_t)d);
383     }
384 
385     for(int i = (int32_t)0x80000000; i <0; i /= 2) {
386         printf("%d %f\n", i, (double)i);
387     }
388     for(int i = (1<<30); i >0; i /= 2) {
389         printf("%d %f\n", i, (double)i);
390     }
391 
392     printf("%f\n", 0.5);
393     printf("SQRT %10.18g\n", 0.5);
394     printf("SQRT %10.18g\n", 0.333333333333333333333333);
395 
396 #if 1
397     for (float x = 0; x < 3; x++) {
398         printf("\n ----- %f\n", x);
399 #if !LIB_PICO_FLOAT_PICO_VFP
400         printf("FSQRT %10.18f\n", check_close1(sqrtf, x));
401 #endif
402         printf("FCOS %10.18f\n", check_close1(cosf, x));
403         printf("FSIN %10.18f\n", check_close1(sinf, x));
404         float s, c;
405         sincosf(x, &s, &c);
406         printf("FSINCOS %10.18f %10.18f\n", s, c);
407         printf("FTAN %10.18f\n", check_close1(tanf, x));
408         printf("FATAN2 %10.18f\n", check_close2(atan2f, x, 10.f));
409         printf("FATAN2 %10.18f\n", check_close2(atan2f, 10.f, x));
410         printf("FEXP %10.18f\n", check_close1(expf, x));
411         printf("FLN %10.18f\n", check_close1(logf, x));
412         printf("POWF %10.18f\n", check_close2(powf, x, x));
413         // todo clang why does this not compile?
414 #ifndef __clang__
415         printf("TRUNCF %10.18f\n", check_close1(truncf, x));
416 #endif
417         printf("LDEXPF %10.18f\n", check_close2(ldexpf, x, x));
418         printf("FMODF %10.18f\n", check_close2(fmodf, x, 3.0f));
419         sincosf(x, &s, &c);
420         printf("SINCOS %10.18f %10.18f\n", s, c);
421         if (s != sinf(x) || c != cosf(x)) {
422             printf("SINCOS mismatch\n");
423             fail = true;
424         }
425     }
426 
427     for (double x = 0; x < 3; x++) {
428         printf("\n ----- %g\n", x);
429         printf("SQRT %10.18g\n", sqrt(x));
430         printf("COS %10.18g\n", cos(x));
431         printf("SIN %10.18g\n", sin(x));
432         printf("TAN %10.18g\n", tan(x));
433         printf("ATAN2 %10.18g\n", atan2(x, 10));
434         printf("ATAN2 %10.18g\n", atan2(10, x));
435         printf("EXP %10.18g\n", exp(x));
436         printf("LN %10.18g\n", log(x));
437     }
438 
439 #if PICO_FLOAT_PROPAGATE_NANS
440     {
441         float x = NAN;
442         printf("NANO %10.18f\n", x);
443         printf("FSQRT %10.18f\n", sqrtf(x));
444         printf("FCOS %10.18f\n", cosf(x));
445         printf("FSIN %10.18f\n", sinf(x));
446         printf("FTAN %10.18f\n", tanf(x));
447         printf("FATAN2 %10.18f\n", atan2f(x, 10));
448         printf("FATAN2 %10.18f\n", atan2f(10, x));
449         printf("FEXP %10.18f\n", expf(x));
450         printf("FLN %10.18f\n", logf(x));
451         printf("POWF %10.18f\n", powf(x, x));
452         printf("TRUNCF %10.18f\n", truncf(x));
453         printf("LDEXPF %10.18f\n", ldexpf(x, x));
454         printf("FMODF %10.18f\n", fmodf(x, 3.0f));
455         float s, c;
456 //        sincosf(x, &s, &c);
457         printf("FSINCOS %10.18f %10.18f\n", s, c);
458 
459         for(int j=0;j<2;j++) {
460             for (int i = 1; i < 4; i++) {
461                 char buf[4];
462                 sprintf(buf, "%d", i);
463                 float f0 = -nanf(buf);
464                 double d0 = -nan(buf);
465                 // hmm nanf/nan seem to ignore payload
466                 *(uint64_t *) &d0 |= i;
467                 *(uint32_t *) &f0 |= i;
468                 if (j) {
469                     // try without top bit set
470                     *(uint64_t *) &d0 &= ~0x0008000000000000ull;
471                     *(uint32_t *) &f0 &= ~0x00400000u;
472                 }
473                 float f = (float) d0;
474                 double d = (double) f0;
475                 printf("f2d %f %08"PRIx32" -> %g %016"PRIx64"\n", f0, *(uint32_t *) &f0, d, *(uint64_t *) &d);
476                 printf("d2f %f %016"PRIx64" -> %f %08"PRIx32"\n", d0, *(uint64_t *) &d0, f, *(uint32_t *) &f);
477             }
478         }
479     }
480 #endif
481 
482 #if !LIB_PICO_FLOAT_PICO_VFP
483     {
484         int32_t y;
485 //        for (int32_t x = 0; x>-512; x--) {
486 //            printf("i %d->%f\n", (int)x, (float) x);
487 //        }
488         for (int32_t x = -1; x; x <<= 1) {
489             printf("i %d->%f\n", x, (float) x);
490             check1(__aeabi_i2f, x);
491         }
492         for (int32_t x = 1; x; x <<= 1) {
493             printf("i %d->%f\n", x, (float) x);
494             check1(__aeabi_i2f, x);
495             y = x << 1;
496         }
497         for (int64_t x = 1; x; x <<= 1) {
498             printf("i %lld->%f\n", x, (float) x);
499             check1(__aeabi_l2f, x);
500             y = x << 1;
501         }
502         for (int64_t x = -1; x; x <<= 1) {
503             printf("i %lld->%f\n", x, (float) x);
504             check1(__aeabi_l2f, x);
505             y = x << 1;
506         }
507         printf("d %d->%f\n", y, (float) y);
508     }
509 
510     {
511         uint32_t y;
512         for(uint32_t x = 1; x; x <<= 1) {
513             printf("u %u->%f\n", x, (float)x);
514             check1(__aeabi_ui2f, x);
515             y = x << 1;
516         }
517         printf("u %u->%f\n", y, (float)y);
518     }
519     for(int64_t x = 1; x !=0; x <<= 1u) {
520         printf("%lld->%f\n", x, (float)x);
521         check1(__aeabi_l2f, x);
522     }
523     for(float x = -4294967296.f * 4294967296.f; x>=0.5f; x/=2.f) {
524         printf("f %f->%lld\n", x, (int64_t)x);
525         check1(__aeabi_f2lz, x);
526     }
527     for(float x = 4294967296.f * 4294967296.f * 2.f; x>=0.5f; x/=2.f) {
528         printf("f2i64 %f->%lld\n", x, (int64_t)x);
529 #if PICO_RP2040
530         if ((double)x >= (double)INT64_MAX) {
531             // seems like there is a bug in the gcc version (which returns UINT64_MAX)
532             test_assert(__aeabi_f2lz(x) == INT64_MAX);
533         } else {
534             check1(__aeabi_f2lz, x);
535         }
536 #else
537         check1(__aeabi_f2lz, x);
538 #endif
539     }
540     for(float x = -4294967296.f * 4294967296.f; x<=-0.5f; x/=2.f) {
541         printf("d2i32 %f->%d\n", x, (int32_t)x);
542         check1(__aeabi_f2iz, x);
543     }
544     for(float x = 4294967296.f * 4294967296.f; x>=0.5f; x/=2.f) {
545         printf("d2i32 %f->%d\n", x, (int32_t)x);
546 #if PICO_RP2040
547         if ((double)x >= (double)INT32_MAX) {
548             // seems like there is a bug in the clang version (which returns INT32_MIN)
549             test_assert(__aeabi_f2iz(x) == INT32_MAX);
550         } else {
551             check1(__aeabi_f2iz, x);
552         }
553 #else
554         check1(__aeabi_f2iz, x);
555 #endif
556     }
557 
558     for (float x = 1; x < 11; x += 2) {
559         float f = x * x;
560         float g = 1.0f / x;
561         printf("%g %10.18g %10.18g, %10.18g, %10.18g %10.18g\n", x, f, x + 0.37777777777777777777777777777f,
562                x - 0.377777777777777777777777777777f, g, 123456789.0f / x);
563         check2(__aeabi_fmul, x, x);
564         check2(__aeabi_fdiv, 1.0f, x);
565     }
566 #endif
567 
568     if (fail ||
569         test_cfcmpeq() ||
570         test_cfcmple() ||
571         test_fcmpun() ||
572         test_cmple_gt() ||
573         test_cmplt_ge()) {
574         printf("FAILED\n");
575         return 1;
576     } else {
577         printf("PASSED\n");
578         return 0;
579     }
580 #endif
581 }
582 
583 #if 0
584 // todo need to add tests like these
585 
586 bool __noinline check(float x, float y) {
587     return x > y;
588 }
589 
590 bool __noinline checkd(double x, double y) {
591     return x >= y;
592 }
593 
594 int main() {
595     stdio_init_all();
596 #if 0
597     printf("0 op nan %d\n", check(0, nanf("sd")));
598     printf("nan op 0 %d\n", check(nanf("sd"), 0));
599     printf("0 op -nan %d\n", check(0, -nanf("sd")));
600     printf("-nan op 0 %d\n", check(-nanf("sd"), 0));
601     printf("-nan op nan %d\n", check(-nanf("xx"), nanf("xx")));
602     printf("-nan op -nan %d\n", check(-nanf("xx"), -nanf("xx")));
603     printf("nan op -nan %d\n", check(nanf("xx"), -nanf("xx")));
604     printf("nan op nan %d\n", check(nanf("xx"), nanf("xx")));
605     printf("0 op inf %d\n", check(0, infinityf()));
606     printf("inf op 0 %d\n", check(infinityf(), 0));
607     printf("0 op -inf %d\n", check(0, -infinityf()));
608     printf("-inf op 0 %d\n", check(-infinityf(), 0));
609     printf("-inf op inf %d\n", check(-infinityf(), infinityf()));
610     printf("-inf op -inf %d\n", check(-infinityf(), -infinityf()));
611     printf("inf op -inf %d\n", check(infinityf(), -infinityf()));
612     printf("inf op inf %d\n", check(infinityf(), infinityf()));
613     printf("1 op 1 %d\n", check(1, 1));
614     printf("-1 op 1 %d\n", check(-1, 1));
615     printf("1 op -1 %d\n", check(1, -1));
616     printf("-1 op -1 %d\n", check(-1, -1));
617     printf("1 op 2 %d\n", check(1, 2));
618     printf("2 op 1 %d\n", check(2, 1));
619     printf("-1 op -2 %d\n", check(-1, -2));
620     printf("-2 op -1 %d\n", check(-2, -1));
621 #else
622     printf("0 op nan %d\n", checkd(0, nan("sd")));
623     printf("nan op 0 %d\n", checkd(nan("sd"), 0));
624     printf("0 op -nan %d\n", checkd(0, -nan("sd")));
625     printf("-nan op 0 %d\n", checkd(-nan("sd"), 0));
626     printf("-nan op nan %d\n", checkd(-nan("xx"), nan("xx")));
627     printf("-nan op -nan %d\n", checkd(-nan("xx"), -nan("xx")));
628     printf("nan op -nan %d\n", checkd(nan("xx"), -nan("xx")));
629     printf("nan op nan %d\n", checkd(nan("xx"), nan("xx")));
630     printf("0 op inf %d\n", checkd(0, infinity()));
631     printf("inf op 0 %d\n", checkd(infinity(), 0));
632     printf("0 op -inf %d\n", checkd(0, -infinity()));
633     printf("-inf op 0 %d\n", checkd(-infinity(), 0));
634     printf("-inf op inf %d\n", checkd(-infinity(), infinity()));
635     printf("-inf op -inf %d\n", checkd(-infinity(), -infinity()));
636     printf("inf op -inf %d\n", checkd(infinity(), -infinity()));
637     printf("inf op inf %d\n", checkd(infinity(), infinity()));
638     printf("1 op 1 %d\n", checkd(1, 1));
639     printf("-1 op 1 %d\n", checkd(-1, 1));
640     printf("1 op -1 %d\n", checkd(1, -1));
641     printf("-1 op -1 %d\n", checkd(-1, -1));
642     printf("1 op 2 %d\n", checkd(1, 2));
643     printf("2 op 1 %d\n", checkd(2, 1));
644     printf("-1 op -2 %d\n", checkd(-1, -2));
645     printf("-2 op -1 %d\n", checkd(-2, -1));
646 #endif
647 }
648 #endif
649