compare-fp-1.c 5.1 KB

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