mul-subnormal-single-1.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * This file is originally a part of the GCC testsuite.
  25. * Check that certain subnormal numbers (formerly known as denormalized
  26. * numbers) are rounded to within 0.5 ulp. PR other/14354.
  27. */
  28. #include <common.h>
  29. #include <post.h>
  30. #if CONFIG_POST & CONFIG_SYS_POST_FPU
  31. GNU_FPOST_ATTR
  32. union uf
  33. {
  34. unsigned int u;
  35. float f;
  36. };
  37. static float
  38. u2f (unsigned int v)
  39. {
  40. union uf u;
  41. u.u = v;
  42. return u.f;
  43. }
  44. static unsigned int
  45. f2u (float v)
  46. {
  47. union uf u;
  48. u.f = v;
  49. return u.u;
  50. }
  51. static int ok = 1;
  52. static void
  53. tstmul (unsigned int ux, unsigned int uy, unsigned int ur)
  54. {
  55. float x = u2f (ux);
  56. float y = u2f (uy);
  57. if (f2u (x * y) != ur)
  58. /* Set a variable rather than aborting here, to simplify tracing when
  59. several computations are wrong. */
  60. ok = 0;
  61. }
  62. /* We don't want to make this const and static, or else we risk inlining
  63. causing the test to fold as constants at compile-time. */
  64. struct
  65. {
  66. unsigned int p1, p2, res;
  67. } static volatile expected[] =
  68. {
  69. {0xfff, 0x3f800400, 0xfff},
  70. {0xf, 0x3fc88888, 0x17},
  71. {0xf, 0x3f844444, 0xf}
  72. };
  73. int fpu_post_test_math7 (void)
  74. {
  75. unsigned int i;
  76. for (i = 0; i < sizeof (expected) / sizeof (expected[0]); i++)
  77. {
  78. tstmul (expected[i].p1, expected[i].p2, expected[i].res);
  79. tstmul (expected[i].p2, expected[i].p1, expected[i].res);
  80. }
  81. if (!ok) {
  82. post_log ("Error in FPU math7 test\n");
  83. return -1;
  84. }
  85. return 0;
  86. }
  87. #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */