sp_flong.c 960 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* IEEE754 floating point arithmetic
  3. * single precision
  4. */
  5. /*
  6. * MIPS floating point support
  7. * Copyright (C) 1994-2000 Algorithmics Ltd.
  8. */
  9. #include "ieee754sp.h"
  10. union ieee754sp ieee754sp_flong(s64 x)
  11. {
  12. u64 xm; /* <--- need 64-bit mantissa temp */
  13. int xe;
  14. int xs;
  15. ieee754_clearcx();
  16. if (x == 0)
  17. return ieee754sp_zero(0);
  18. if (x == 1 || x == -1)
  19. return ieee754sp_one(x < 0);
  20. if (x == 10 || x == -10)
  21. return ieee754sp_ten(x < 0);
  22. xs = (x < 0);
  23. if (xs) {
  24. if (x == (1ULL << 63))
  25. xm = (1ULL << 63); /* max neg can't be safely negated */
  26. else
  27. xm = -x;
  28. } else {
  29. xm = x;
  30. }
  31. xe = SP_FBITS + 3;
  32. if (xm >> (SP_FBITS + 1 + 3)) {
  33. /* shunt out overflow bits
  34. */
  35. while (xm >> (SP_FBITS + 1 + 3)) {
  36. SPXSRSX1();
  37. }
  38. } else {
  39. /* normalize in grs extended single precision */
  40. while ((xm >> (SP_FBITS + 3)) == 0) {
  41. xm <<= 1;
  42. xe--;
  43. }
  44. }
  45. return ieee754sp_format(xs, xe, xm);
  46. }