ieee754int.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. static inline int ieee754_class_nan(int xc)
  41. {
  42. return xc >= IEEE754_CLASS_SNAN;
  43. }
  44. #define COMPXSP \
  45. unsigned xm; int xe; int xs __maybe_unused; int xc
  46. #define COMPYSP \
  47. unsigned ym; int ye; int ys; int yc
  48. #define EXPLODESP(v, vc, vs, ve, vm) \
  49. { \
  50. vs = SPSIGN(v); \
  51. ve = SPBEXP(v); \
  52. vm = SPMANT(v); \
  53. if (ve == SP_EMAX+1+SP_EBIAS) { \
  54. if (vm == 0) \
  55. vc = IEEE754_CLASS_INF; \
  56. else if (vm & SP_MBIT(SP_FBITS-1)) \
  57. vc = IEEE754_CLASS_SNAN; \
  58. else \
  59. vc = IEEE754_CLASS_QNAN; \
  60. } else if (ve == SP_EMIN-1+SP_EBIAS) { \
  61. if (vm) { \
  62. ve = SP_EMIN; \
  63. vc = IEEE754_CLASS_DNORM; \
  64. } else \
  65. vc = IEEE754_CLASS_ZERO; \
  66. } else { \
  67. ve -= SP_EBIAS; \
  68. vm |= SP_HIDDEN_BIT; \
  69. vc = IEEE754_CLASS_NORM; \
  70. } \
  71. }
  72. #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
  73. #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
  74. #define COMPXDP \
  75. u64 xm; int xe; int xs __maybe_unused; int xc
  76. #define COMPYDP \
  77. u64 ym; int ye; int ys; int yc
  78. #define EXPLODEDP(v, vc, vs, ve, vm) \
  79. { \
  80. vm = DPMANT(v); \
  81. vs = DPSIGN(v); \
  82. ve = DPBEXP(v); \
  83. if (ve == DP_EMAX+1+DP_EBIAS) { \
  84. if (vm == 0) \
  85. vc = IEEE754_CLASS_INF; \
  86. else if (vm & DP_MBIT(DP_FBITS-1)) \
  87. vc = IEEE754_CLASS_SNAN; \
  88. else \
  89. vc = IEEE754_CLASS_QNAN; \
  90. } else if (ve == DP_EMIN-1+DP_EBIAS) { \
  91. if (vm) { \
  92. ve = DP_EMIN; \
  93. vc = IEEE754_CLASS_DNORM; \
  94. } else \
  95. vc = IEEE754_CLASS_ZERO; \
  96. } else { \
  97. ve -= DP_EBIAS; \
  98. vm |= DP_HIDDEN_BIT; \
  99. vc = IEEE754_CLASS_NORM; \
  100. } \
  101. }
  102. #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
  103. #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
  104. #define FLUSHDP(v, vc, vs, ve, vm) \
  105. if (vc==IEEE754_CLASS_DNORM) { \
  106. if (ieee754_csr.nod) { \
  107. ieee754_setcx(IEEE754_INEXACT); \
  108. vc = IEEE754_CLASS_ZERO; \
  109. ve = DP_EMIN-1+DP_EBIAS; \
  110. vm = 0; \
  111. v = ieee754dp_zero(vs); \
  112. } \
  113. }
  114. #define FLUSHSP(v, vc, vs, ve, vm) \
  115. if (vc==IEEE754_CLASS_DNORM) { \
  116. if (ieee754_csr.nod) { \
  117. ieee754_setcx(IEEE754_INEXACT); \
  118. vc = IEEE754_CLASS_ZERO; \
  119. ve = SP_EMIN-1+SP_EBIAS; \
  120. vm = 0; \
  121. v = ieee754sp_zero(vs); \
  122. } \
  123. }
  124. #define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
  125. #define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
  126. #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
  127. #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
  128. #endif /* __IEEE754INT_H */