soft-fp.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* Software floating-point emulation.
  2. Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson (rth@cygnus.com),
  5. Jakub Jelinek (jj@ultra.linux.cz),
  6. David S. Miller (davem@redhat.com) and
  7. Peter Maydell (pmaydell@chiark.greenend.org.uk).
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public License as
  10. published by the Free Software Foundation; either version 2 of the
  11. License, or (at your option) any later version.
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Library General Public License for more details.
  16. You should have received a copy of the GNU Library General Public
  17. License along with the GNU C Library; see the file COPYING.LIB. If
  18. not, write to the Free Software Foundation, Inc.,
  19. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  20. #ifndef __MATH_EMU_SOFT_FP_H__
  21. #define __MATH_EMU_SOFT_FP_H__
  22. #include <asm/sfp-machine.h>
  23. /* Allow sfp-machine to have its own byte order definitions. */
  24. #ifndef __BYTE_ORDER
  25. #include <endian.h>
  26. #endif
  27. #define _FP_WORKBITS 3
  28. #define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)
  29. #define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
  30. #define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1)
  31. #define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0)
  32. #ifndef FP_RND_NEAREST
  33. # define FP_RND_NEAREST 0
  34. # define FP_RND_ZERO 1
  35. # define FP_RND_PINF 2
  36. # define FP_RND_MINF 3
  37. #ifndef FP_ROUNDMODE
  38. # define FP_ROUNDMODE FP_RND_NEAREST
  39. #endif
  40. #endif
  41. /* By default don't care about exceptions. */
  42. #ifndef FP_EX_INVALID
  43. #define FP_EX_INVALID 0
  44. #endif
  45. #ifndef FP_EX_OVERFLOW
  46. #define FP_EX_OVERFLOW 0
  47. #endif
  48. #ifndef FP_EX_UNDERFLOW
  49. #define FP_EX_UNDERFLOW
  50. #endif
  51. #ifndef FP_EX_DIVZERO
  52. #define FP_EX_DIVZERO 0
  53. #endif
  54. #ifndef FP_EX_INEXACT
  55. #define FP_EX_INEXACT 0
  56. #endif
  57. #ifndef FP_EX_DENORM
  58. #define FP_EX_DENORM 0
  59. #endif
  60. #ifdef _FP_DECL_EX
  61. #define FP_DECL_EX \
  62. int _fex = 0; \
  63. _FP_DECL_EX
  64. #else
  65. #define FP_DECL_EX int _fex = 0
  66. #endif
  67. #ifndef FP_INIT_ROUNDMODE
  68. #define FP_INIT_ROUNDMODE do {} while (0)
  69. #endif
  70. #ifndef FP_HANDLE_EXCEPTIONS
  71. #define FP_HANDLE_EXCEPTIONS do {} while (0)
  72. #endif
  73. /* By default we never flush denormal input operands to signed zero. */
  74. #ifndef FP_DENORM_ZERO
  75. #define FP_DENORM_ZERO 0
  76. #endif
  77. #ifndef FP_INHIBIT_RESULTS
  78. /* By default we write the results always.
  79. * sfp-machine may override this and e.g.
  80. * check if some exceptions are unmasked
  81. * and inhibit it in such a case.
  82. */
  83. #define FP_INHIBIT_RESULTS 0
  84. #endif
  85. #define FP_SET_EXCEPTION(ex) \
  86. _fex |= (ex)
  87. #define FP_UNSET_EXCEPTION(ex) \
  88. _fex &= ~(ex)
  89. #define FP_CLEAR_EXCEPTIONS \
  90. _fex = 0
  91. #define _FP_ROUND_NEAREST(wc, X) \
  92. do { \
  93. if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
  94. _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
  95. } while (0)
  96. #define _FP_ROUND_ZERO(wc, X) 0
  97. #define _FP_ROUND_PINF(wc, X) \
  98. do { \
  99. if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  100. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  101. } while (0)
  102. #define _FP_ROUND_MINF(wc, X) \
  103. do { \
  104. if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  105. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  106. } while (0)
  107. #define _FP_ROUND(wc, X) \
  108. do { \
  109. if (_FP_FRAC_LOW_##wc(X) & 7) \
  110. FP_SET_EXCEPTION(FP_EX_INEXACT); \
  111. switch (FP_ROUNDMODE) \
  112. { \
  113. case FP_RND_NEAREST: \
  114. _FP_ROUND_NEAREST(wc,X); \
  115. break; \
  116. case FP_RND_ZERO: \
  117. _FP_ROUND_ZERO(wc,X); \
  118. break; \
  119. case FP_RND_PINF: \
  120. _FP_ROUND_PINF(wc,X); \
  121. break; \
  122. case FP_RND_MINF: \
  123. _FP_ROUND_MINF(wc,X); \
  124. break; \
  125. } \
  126. } while (0)
  127. #define FP_CLS_NORMAL 0
  128. #define FP_CLS_ZERO 1
  129. #define FP_CLS_INF 2
  130. #define FP_CLS_NAN 3
  131. #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
  132. #include <math-emu/op-1.h>
  133. #include <math-emu/op-2.h>
  134. #include <math-emu/op-4.h>
  135. #include <math-emu/op-8.h>
  136. #include <math-emu/op-common.h>
  137. /* Sigh. Silly things longlong.h needs. */
  138. #define UWtype _FP_W_TYPE
  139. #define W_TYPE_SIZE _FP_W_TYPE_SIZE
  140. typedef int SItype __attribute__((mode(SI)));
  141. typedef int DItype __attribute__((mode(DI)));
  142. typedef unsigned int USItype __attribute__((mode(SI)));
  143. typedef unsigned int UDItype __attribute__((mode(DI)));
  144. #if _FP_W_TYPE_SIZE == 32
  145. typedef unsigned int UHWtype __attribute__((mode(HI)));
  146. #elif _FP_W_TYPE_SIZE == 64
  147. typedef USItype UHWtype;
  148. #endif
  149. #ifndef umul_ppmm
  150. #include <stdlib/longlong.h>
  151. #endif
  152. #endif /* __MATH_EMU_SOFT_FP_H__ */