test_fpu_impl.c 663 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <linux/errno.h>
  3. #include "test_fpu.h"
  4. int test_fpu(void)
  5. {
  6. /*
  7. * This sequence of operations tests that rounding mode is
  8. * to nearest and that denormal numbers are supported.
  9. * Volatile variables are used to avoid compiler optimizing
  10. * the calculations away.
  11. */
  12. volatile double a, b, c, d, e, f, g;
  13. a = 4.0;
  14. b = 1e-15;
  15. c = 1e-310;
  16. /* Sets precision flag */
  17. d = a + b;
  18. /* Result depends on rounding mode */
  19. e = a + b / 2;
  20. /* Denormal and very large values */
  21. f = b / c;
  22. /* Depends on denormal support */
  23. g = a + c * f;
  24. if (d > a && e > a && g > a)
  25. return 0;
  26. else
  27. return -EINVAL;
  28. }