pico_float_test.c 20 KB

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