compare-fp-1.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Copyright (C) 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  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.
  12. *
  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.
  17. *
  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,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  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.
  27. */
  28. #include <common.h>
  29. #include <post.h>
  30. #if CONFIG_POST & CONFIG_SYS_POST_FPU
  31. static int failed;
  32. #define TEST(c) if ((c) != ok) failed++
  33. #define ORD(a, b) (!__builtin_isunordered ((a), (b)))
  34. #define UNORD(a, b) (__builtin_isunordered ((a), (b)))
  35. #define UNEQ(a, b) (__builtin_isunordered ((a), (b)) || ((a) == (b)))
  36. #define UNLT(a, b) (__builtin_isunordered ((a), (b)) || ((a) < (b)))
  37. #define UNLE(a, b) (__builtin_isunordered ((a), (b)) || ((a) <= (b)))
  38. #define UNGT(a, b) (__builtin_isunordered ((a), (b)) || ((a) > (b)))
  39. #define UNGE(a, b) (__builtin_isunordered ((a), (b)) || ((a) >= (b)))
  40. #define LTGT(a, b) (__builtin_islessgreater ((a), (b)))
  41. static float pinf;
  42. static float ninf;
  43. static float NaN;
  44. static void iuneq (float x, float y, int ok)
  45. {
  46. TEST (UNEQ (x, y));
  47. TEST (!LTGT (x, y));
  48. TEST (UNLE (x, y) && UNGE (x,y));
  49. }
  50. static void ieq (float x, float y, int ok)
  51. {
  52. TEST (ORD (x, y) && UNEQ (x, y));
  53. }
  54. static void iltgt (float x, float y, int ok)
  55. {
  56. TEST (!UNEQ (x, y)); /* Not optimizable. */
  57. TEST (LTGT (x, y)); /* Same, __builtin_islessgreater does not trap. */
  58. TEST (ORD (x, y) && (UNLT (x, y) || UNGT (x,y)));
  59. }
  60. static void ine (float x, float y, int ok)
  61. {
  62. TEST (UNLT (x, y) || UNGT (x, y));
  63. }
  64. static void iunlt (float x, float y, int ok)
  65. {
  66. TEST (UNLT (x, y));
  67. TEST (UNORD (x, y) || (x < y));
  68. }
  69. static void ilt (float x, float y, int ok)
  70. {
  71. TEST (ORD (x, y) && UNLT (x, y)); /* Not optimized */
  72. TEST ((x <= y) && (x != y));
  73. TEST ((x <= y) && (y != x));
  74. TEST ((x != y) && (x <= y)); /* Not optimized */
  75. TEST ((y != x) && (x <= y)); /* Not optimized */
  76. }
  77. static void iunle (float x, float y, int ok)
  78. {
  79. TEST (UNLE (x, y));
  80. TEST (UNORD (x, y) || (x <= y));
  81. }
  82. static 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. static void iungt (float x, float y, int ok)
  91. {
  92. TEST (UNGT (x, y));
  93. TEST (UNORD (x, y) || (x > y));
  94. }
  95. static void igt (float x, float y, int ok)
  96. {
  97. TEST (ORD (x, y) && UNGT (x, y)); /* Not optimized */
  98. TEST ((x >= y) && (x != y));
  99. TEST ((x >= y) && (y != x));
  100. TEST ((x != y) && (x >= y)); /* Not optimized */
  101. TEST ((y != x) && (x >= y)); /* Not optimized */
  102. }
  103. static void iunge (float x, float y, int ok)
  104. {
  105. TEST (UNGE (x, y));
  106. TEST (UNORD (x, y) || (x >= y));
  107. }
  108. static void ige (float x, float y, int ok)
  109. {
  110. TEST (ORD (x, y) && UNGE (x, y)); /* Not optimized */
  111. TEST ((x > y) || (x == y));
  112. TEST ((y < x) || (x == y));
  113. TEST ((x == y) || (x > y)); /* Not optimized */
  114. TEST ((y == x) || (x > y)); /* Not optimized */
  115. }
  116. int fpu_post_test_math6 (void)
  117. {
  118. pinf = __builtin_inf ();
  119. ninf = -__builtin_inf ();
  120. NaN = __builtin_nan ("");
  121. iuneq (ninf, pinf, 0);
  122. iuneq (NaN, NaN, 1);
  123. iuneq (pinf, ninf, 0);
  124. iuneq (1, 4, 0);
  125. iuneq (3, 3, 1);
  126. iuneq (5, 2, 0);
  127. ieq (1, 4, 0);
  128. ieq (3, 3, 1);
  129. ieq (5, 2, 0);
  130. iltgt (ninf, pinf, 1);
  131. iltgt (NaN, NaN, 0);
  132. iltgt (pinf, ninf, 1);
  133. iltgt (1, 4, 1);
  134. iltgt (3, 3, 0);
  135. iltgt (5, 2, 1);
  136. ine (1, 4, 1);
  137. ine (3, 3, 0);
  138. ine (5, 2, 1);
  139. iunlt (NaN, ninf, 1);
  140. iunlt (pinf, NaN, 1);
  141. iunlt (pinf, ninf, 0);
  142. iunlt (pinf, pinf, 0);
  143. iunlt (ninf, ninf, 0);
  144. iunlt (1, 4, 1);
  145. iunlt (3, 3, 0);
  146. iunlt (5, 2, 0);
  147. ilt (1, 4, 1);
  148. ilt (3, 3, 0);
  149. ilt (5, 2, 0);
  150. iunle (NaN, ninf, 1);
  151. iunle (pinf, NaN, 1);
  152. iunle (pinf, ninf, 0);
  153. iunle (pinf, pinf, 1);
  154. iunle (ninf, ninf, 1);
  155. iunle (1, 4, 1);
  156. iunle (3, 3, 1);
  157. iunle (5, 2, 0);
  158. ile (1, 4, 1);
  159. ile (3, 3, 1);
  160. ile (5, 2, 0);
  161. iungt (NaN, ninf, 1);
  162. iungt (pinf, NaN, 1);
  163. iungt (pinf, ninf, 1);
  164. iungt (pinf, pinf, 0);
  165. iungt (ninf, ninf, 0);
  166. iungt (1, 4, 0);
  167. iungt (3, 3, 0);
  168. iungt (5, 2, 1);
  169. igt (1, 4, 0);
  170. igt (3, 3, 0);
  171. igt (5, 2, 1);
  172. iunge (NaN, ninf, 1);
  173. iunge (pinf, NaN, 1);
  174. iunge (ninf, pinf, 0);
  175. iunge (pinf, pinf, 1);
  176. iunge (ninf, ninf, 1);
  177. iunge (1, 4, 0);
  178. iunge (3, 3, 1);
  179. iunge (5, 2, 1);
  180. ige (1, 4, 0);
  181. ige (3, 3, 1);
  182. ige (5, 2, 1);
  183. if (failed) {
  184. post_log ("Error in FPU math6 test\n");
  185. return -1;
  186. }
  187. return 0;
  188. }
  189. #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */