ieee754int.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. enum maddf_flags {
  27. MADDF_NEGATE_PRODUCT = 1 << 0,
  28. };
  29. static inline void ieee754_clearcx(void)
  30. {
  31. ieee754_csr.cx = 0;
  32. }
  33. static inline void ieee754_setcx(const unsigned int flags)
  34. {
  35. ieee754_csr.cx |= flags;
  36. ieee754_csr.sx |= flags;
  37. }
  38. static inline int ieee754_setandtestcx(const unsigned int x)
  39. {
  40. ieee754_setcx(x);
  41. return ieee754_csr.mx & x;
  42. }
  43. static inline int ieee754_class_nan(int xc)
  44. {
  45. return xc >= IEEE754_CLASS_SNAN;
  46. }
  47. #define COMPXSP \
  48. unsigned xm; int xe; int xs __maybe_unused; int xc
  49. #define COMPYSP \
  50. unsigned ym; int ye; int ys; int yc
  51. #define COMPZSP \
  52. unsigned zm; int ze; int zs; int zc
  53. #define EXPLODESP(v, vc, vs, ve, vm) \
  54. { \
  55. vs = SPSIGN(v); \
  56. ve = SPBEXP(v); \
  57. vm = SPMANT(v); \
  58. if (ve == SP_EMAX+1+SP_EBIAS) { \
  59. if (vm == 0) \
  60. vc = IEEE754_CLASS_INF; \
  61. else if (ieee754_csr.nan2008 ^ !(vm & SP_MBIT(SP_FBITS - 1))) \
  62. vc = IEEE754_CLASS_QNAN; \
  63. else \
  64. vc = IEEE754_CLASS_SNAN; \
  65. } else if (ve == SP_EMIN-1+SP_EBIAS) { \
  66. if (vm) { \
  67. ve = SP_EMIN; \
  68. vc = IEEE754_CLASS_DNORM; \
  69. } else \
  70. vc = IEEE754_CLASS_ZERO; \
  71. } else { \
  72. ve -= SP_EBIAS; \
  73. vm |= SP_HIDDEN_BIT; \
  74. vc = IEEE754_CLASS_NORM; \
  75. } \
  76. }
  77. #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
  78. #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
  79. #define EXPLODEZSP EXPLODESP(z, zc, zs, ze, zm)
  80. #define COMPXDP \
  81. u64 xm; int xe; int xs __maybe_unused; int xc
  82. #define COMPYDP \
  83. u64 ym; int ye; int ys; int yc
  84. #define COMPZDP \
  85. u64 zm; int ze; int zs; int zc
  86. #define EXPLODEDP(v, vc, vs, ve, vm) \
  87. { \
  88. vm = DPMANT(v); \
  89. vs = DPSIGN(v); \
  90. ve = DPBEXP(v); \
  91. if (ve == DP_EMAX+1+DP_EBIAS) { \
  92. if (vm == 0) \
  93. vc = IEEE754_CLASS_INF; \
  94. else if (ieee754_csr.nan2008 ^ !(vm & DP_MBIT(DP_FBITS - 1))) \
  95. vc = IEEE754_CLASS_QNAN; \
  96. else \
  97. vc = IEEE754_CLASS_SNAN; \
  98. } else if (ve == DP_EMIN-1+DP_EBIAS) { \
  99. if (vm) { \
  100. ve = DP_EMIN; \
  101. vc = IEEE754_CLASS_DNORM; \
  102. } else \
  103. vc = IEEE754_CLASS_ZERO; \
  104. } else { \
  105. ve -= DP_EBIAS; \
  106. vm |= DP_HIDDEN_BIT; \
  107. vc = IEEE754_CLASS_NORM; \
  108. } \
  109. }
  110. #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
  111. #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
  112. #define EXPLODEZDP EXPLODEDP(z, zc, zs, ze, zm)
  113. #define FLUSHDP(v, vc, vs, ve, vm) \
  114. if (vc==IEEE754_CLASS_DNORM) { \
  115. if (ieee754_csr.nod) { \
  116. ieee754_setcx(IEEE754_INEXACT); \
  117. vc = IEEE754_CLASS_ZERO; \
  118. ve = DP_EMIN-1+DP_EBIAS; \
  119. vm = 0; \
  120. v = ieee754dp_zero(vs); \
  121. } \
  122. }
  123. #define FLUSHSP(v, vc, vs, ve, vm) \
  124. if (vc==IEEE754_CLASS_DNORM) { \
  125. if (ieee754_csr.nod) { \
  126. ieee754_setcx(IEEE754_INEXACT); \
  127. vc = IEEE754_CLASS_ZERO; \
  128. ve = SP_EMIN-1+SP_EBIAS; \
  129. vm = 0; \
  130. v = ieee754sp_zero(vs); \
  131. } \
  132. }
  133. #define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
  134. #define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
  135. #define FLUSHZDP FLUSHDP(z, zc, zs, ze, zm)
  136. #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
  137. #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
  138. #define FLUSHZSP FLUSHSP(z, zc, zs, ze, zm)
  139. #endif /* __IEEE754INT_H */