ieee754int.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * IEEE754 floating point
  3. * common internal header file
  4. */
  5. /*
  6. * MIPS floating point support
  7. * Copyright (C) 1994-2000 Algorithmics Ltd.
  8. *
  9. * This program is free software; you can distribute it and/or modify it
  10. * under the terms of the GNU General Public License (Version 2) as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef __IEEE754INT_H
  23. #define __IEEE754INT_H
  24. #include "ieee754.h"
  25. #define CLPAIR(x, y) ((x)*6+(y))
  26. static inline void ieee754_clearcx(void)
  27. {
  28. ieee754_csr.cx = 0;
  29. }
  30. static inline void ieee754_setcx(const unsigned int flags)
  31. {
  32. ieee754_csr.cx |= flags;
  33. ieee754_csr.sx |= flags;
  34. }
  35. static inline int ieee754_setandtestcx(const unsigned int x)
  36. {
  37. ieee754_setcx(x);
  38. return ieee754_csr.mx & x;
  39. }
  40. #define COMPXSP \
  41. unsigned xm; int xe; int xs __maybe_unused; int xc
  42. #define COMPYSP \
  43. unsigned ym; int ye; int ys; int yc
  44. #define EXPLODESP(v, vc, vs, ve, vm) \
  45. { \
  46. vs = SPSIGN(v); \
  47. ve = SPBEXP(v); \
  48. vm = SPMANT(v); \
  49. if (ve == SP_EMAX+1+SP_EBIAS) { \
  50. if (vm == 0) \
  51. vc = IEEE754_CLASS_INF; \
  52. else if (vm & SP_MBIT(SP_FBITS-1)) \
  53. vc = IEEE754_CLASS_SNAN; \
  54. else \
  55. vc = IEEE754_CLASS_QNAN; \
  56. } else if (ve == SP_EMIN-1+SP_EBIAS) { \
  57. if (vm) { \
  58. ve = SP_EMIN; \
  59. vc = IEEE754_CLASS_DNORM; \
  60. } else \
  61. vc = IEEE754_CLASS_ZERO; \
  62. } else { \
  63. ve -= SP_EBIAS; \
  64. vm |= SP_HIDDEN_BIT; \
  65. vc = IEEE754_CLASS_NORM; \
  66. } \
  67. }
  68. #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
  69. #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
  70. #define COMPXDP \
  71. u64 xm; int xe; int xs __maybe_unused; int xc
  72. #define COMPYDP \
  73. u64 ym; int ye; int ys; int yc
  74. #define EXPLODEDP(v, vc, vs, ve, vm) \
  75. { \
  76. vm = DPMANT(v); \
  77. vs = DPSIGN(v); \
  78. ve = DPBEXP(v); \
  79. if (ve == DP_EMAX+1+DP_EBIAS) { \
  80. if (vm == 0) \
  81. vc = IEEE754_CLASS_INF; \
  82. else if (vm & DP_MBIT(DP_FBITS-1)) \
  83. vc = IEEE754_CLASS_SNAN; \
  84. else \
  85. vc = IEEE754_CLASS_QNAN; \
  86. } else if (ve == DP_EMIN-1+DP_EBIAS) { \
  87. if (vm) { \
  88. ve = DP_EMIN; \
  89. vc = IEEE754_CLASS_DNORM; \
  90. } else \
  91. vc = IEEE754_CLASS_ZERO; \
  92. } else { \
  93. ve -= DP_EBIAS; \
  94. vm |= DP_HIDDEN_BIT; \
  95. vc = IEEE754_CLASS_NORM; \
  96. } \
  97. }
  98. #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
  99. #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
  100. #define FLUSHDP(v, vc, vs, ve, vm) \
  101. if (vc==IEEE754_CLASS_DNORM) { \
  102. if (ieee754_csr.nod) { \
  103. ieee754_setcx(IEEE754_INEXACT); \
  104. vc = IEEE754_CLASS_ZERO; \
  105. ve = DP_EMIN-1+DP_EBIAS; \
  106. vm = 0; \
  107. v = ieee754dp_zero(vs); \
  108. } \
  109. }
  110. #define FLUSHSP(v, vc, vs, ve, vm) \
  111. if (vc==IEEE754_CLASS_DNORM) { \
  112. if (ieee754_csr.nod) { \
  113. ieee754_setcx(IEEE754_INEXACT); \
  114. vc = IEEE754_CLASS_ZERO; \
  115. ve = SP_EMIN-1+SP_EBIAS; \
  116. vm = 0; \
  117. v = ieee754sp_zero(vs); \
  118. } \
  119. }
  120. #define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
  121. #define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
  122. #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
  123. #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
  124. #endif /* __IEEE754INT_H */