mul-subnormal-single-1.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2007
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. /*
  7. * This file is originally a part of the GCC testsuite.
  8. * Check that certain subnormal numbers (formerly known as denormalized
  9. * numbers) are rounded to within 0.5 ulp. PR other/14354.
  10. */
  11. #include <common.h>
  12. #include <post.h>
  13. GNU_FPOST_ATTR
  14. #if CONFIG_POST & CONFIG_SYS_POST_FPU
  15. union uf
  16. {
  17. unsigned int u;
  18. float f;
  19. };
  20. static float
  21. u2f (unsigned int v)
  22. {
  23. union uf u;
  24. u.u = v;
  25. return u.f;
  26. }
  27. static unsigned int
  28. f2u (float v)
  29. {
  30. union uf u;
  31. u.f = v;
  32. return u.u;
  33. }
  34. static int ok = 1;
  35. static void
  36. tstmul (unsigned int ux, unsigned int uy, unsigned int ur)
  37. {
  38. float x = u2f (ux);
  39. float y = u2f (uy);
  40. if (f2u (x * y) != ur)
  41. /* Set a variable rather than aborting here, to simplify tracing when
  42. several computations are wrong. */
  43. ok = 0;
  44. }
  45. /* We don't want to make this const and static, or else we risk inlining
  46. causing the test to fold as constants at compile-time. */
  47. struct
  48. {
  49. unsigned int p1, p2, res;
  50. } static volatile expected[] =
  51. {
  52. {0xfff, 0x3f800400, 0xfff},
  53. {0xf, 0x3fc88888, 0x17},
  54. {0xf, 0x3f844444, 0xf}
  55. };
  56. int fpu_post_test_math7 (void)
  57. {
  58. unsigned int i;
  59. for (i = 0; i < ARRAY_SIZE(expected); i++)
  60. {
  61. tstmul (expected[i].p1, expected[i].p2, expected[i].res);
  62. tstmul (expected[i].p2, expected[i].p1, expected[i].res);
  63. }
  64. if (!ok) {
  65. post_log ("Error in FPU math7 test\n");
  66. return -1;
  67. }
  68. return 0;
  69. }
  70. #endif /* CONFIG_POST & CONFIG_SYS_POST_FPU */