dp_fsp.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* IEEE754 floating point arithmetic
  3. * double precision: common utilities
  4. */
  5. /*
  6. * MIPS floating point support
  7. * Copyright (C) 1994-2000 Algorithmics Ltd.
  8. */
  9. #include "ieee754sp.h"
  10. #include "ieee754dp.h"
  11. static inline union ieee754dp ieee754dp_nan_fsp(int xs, u64 xm)
  12. {
  13. return builddp(xs, DP_EMAX + 1 + DP_EBIAS,
  14. xm << (DP_FBITS - SP_FBITS));
  15. }
  16. union ieee754dp ieee754dp_fsp(union ieee754sp x)
  17. {
  18. COMPXSP;
  19. EXPLODEXSP;
  20. ieee754_clearcx();
  21. FLUSHXSP;
  22. switch (xc) {
  23. case IEEE754_CLASS_SNAN:
  24. return ieee754dp_nanxcpt(ieee754dp_nan_fsp(xs, xm));
  25. case IEEE754_CLASS_QNAN:
  26. return ieee754dp_nan_fsp(xs, xm);
  27. case IEEE754_CLASS_INF:
  28. return ieee754dp_inf(xs);
  29. case IEEE754_CLASS_ZERO:
  30. return ieee754dp_zero(xs);
  31. case IEEE754_CLASS_DNORM:
  32. /* normalize */
  33. while ((xm >> SP_FBITS) == 0) {
  34. xm <<= 1;
  35. xe--;
  36. }
  37. break;
  38. case IEEE754_CLASS_NORM:
  39. break;
  40. }
  41. /*
  42. * Can't possibly overflow,underflow, or need rounding
  43. */
  44. /* drop the hidden bit */
  45. xm &= ~SP_HIDDEN_BIT;
  46. return builddp(xs, xe + DP_EBIAS,
  47. (u64) xm << (DP_FBITS - SP_FBITS));
  48. }