mul-subnormal-single-1.c 1.5 KB

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