ieee754dp.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * IEEE754 floating point
  3. * double precision internal header file
  4. */
  5. /*
  6. * MIPS floating point support
  7. * Copyright (C) 1994-2000 Algorithmics Ltd.
  8. *
  9. * ########################################################################
  10. *
  11. * This program is free software; you can distribute it and/or modify it
  12. * under the terms of the GNU General Public License (Version 2) as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. * for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  23. *
  24. * ########################################################################
  25. */
  26. #include "ieee754int.h"
  27. #define assert(expr) ((void)0)
  28. /* 3bit extended double precision sticky right shift */
  29. #define XDPSRS(v,rs) \
  30. ((rs > (DP_MBITS+3))?1:((v) >> (rs)) | ((v) << (64-(rs)) != 0))
  31. #define XDPSRSX1() \
  32. (xe++, (xm = (xm >> 1) | (xm & 1)))
  33. #define XDPSRS1(v) \
  34. (((v) >> 1) | ((v) & 1))
  35. /* convert denormal to normalized with extended exponent */
  36. #define DPDNORMx(m,e) \
  37. while( (m >> DP_MBITS) == 0) { m <<= 1; e--; }
  38. #define DPDNORMX DPDNORMx(xm, xe)
  39. #define DPDNORMY DPDNORMx(ym, ye)
  40. static inline ieee754dp builddp(int s, int bx, u64 m)
  41. {
  42. ieee754dp r;
  43. assert((s) == 0 || (s) == 1);
  44. assert((bx) >= DP_EMIN - 1 + DP_EBIAS
  45. && (bx) <= DP_EMAX + 1 + DP_EBIAS);
  46. assert(((m) >> DP_MBITS) == 0);
  47. r.parts.sign = s;
  48. r.parts.bexp = bx;
  49. r.parts.mant = m;
  50. return r;
  51. }
  52. extern int ieee754dp_isnan(ieee754dp);
  53. extern int ieee754dp_issnan(ieee754dp);
  54. extern int ieee754si_xcpt(int, const char *, ...);
  55. extern s64 ieee754di_xcpt(s64, const char *, ...);
  56. extern ieee754dp ieee754dp_xcpt(ieee754dp, const char *, ...);
  57. extern ieee754dp ieee754dp_nanxcpt(ieee754dp, const char *, ...);
  58. extern ieee754dp ieee754dp_bestnan(ieee754dp, ieee754dp);
  59. extern ieee754dp ieee754dp_format(int, int, u64);
  60. #define DPNORMRET2(s, e, m, name, a0, a1) \
  61. { \
  62. ieee754dp V = ieee754dp_format(s, e, m); \
  63. if(TSTX()) \
  64. return ieee754dp_xcpt(V, name, a0, a1); \
  65. else \
  66. return V; \
  67. }
  68. #define DPNORMRET1(s, e, m, name, a0) DPNORMRET2(s, e, m, name, a0, a0)