soft-fp.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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_INVALID_SNAN
  46. #define FP_EX_INVALID_SNAN 0
  47. #endif
  48. /* inf - inf */
  49. #ifndef FP_EX_INVALID_ISI
  50. #define FP_EX_INVALID_ISI 0
  51. #endif
  52. /* inf / inf */
  53. #ifndef FP_EX_INVALID_IDI
  54. #define FP_EX_INVALID_IDI 0
  55. #endif
  56. /* 0 / 0 */
  57. #ifndef FP_EX_INVALID_ZDZ
  58. #define FP_EX_INVALID_ZDZ 0
  59. #endif
  60. /* inf * 0 */
  61. #ifndef FP_EX_INVALID_IMZ
  62. #define FP_EX_INVALID_IMZ 0
  63. #endif
  64. #ifndef FP_EX_OVERFLOW
  65. #define FP_EX_OVERFLOW 0
  66. #endif
  67. #ifndef FP_EX_UNDERFLOW
  68. #define FP_EX_UNDERFLOW
  69. #endif
  70. #ifndef FP_EX_DIVZERO
  71. #define FP_EX_DIVZERO 0
  72. #endif
  73. #ifndef FP_EX_INEXACT
  74. #define FP_EX_INEXACT 0
  75. #endif
  76. #ifndef FP_EX_DENORM
  77. #define FP_EX_DENORM 0
  78. #endif
  79. #ifdef _FP_DECL_EX
  80. #define FP_DECL_EX \
  81. int _fex = 0; \
  82. _FP_DECL_EX
  83. #else
  84. #define FP_DECL_EX int _fex = 0
  85. #endif
  86. #ifndef FP_INIT_ROUNDMODE
  87. #define FP_INIT_ROUNDMODE do {} while (0)
  88. #endif
  89. #ifndef FP_HANDLE_EXCEPTIONS
  90. #define FP_HANDLE_EXCEPTIONS do {} while (0)
  91. #endif
  92. /* By default we never flush denormal input operands to signed zero. */
  93. #ifndef FP_DENORM_ZERO
  94. #define FP_DENORM_ZERO 0
  95. #endif
  96. #ifndef FP_INHIBIT_RESULTS
  97. /* By default we write the results always.
  98. * sfp-machine may override this and e.g.
  99. * check if some exceptions are unmasked
  100. * and inhibit it in such a case.
  101. */
  102. #define FP_INHIBIT_RESULTS 0
  103. #endif
  104. #ifndef FP_TRAPPING_EXCEPTIONS
  105. #define FP_TRAPPING_EXCEPTIONS 0
  106. #endif
  107. #define FP_SET_EXCEPTION(ex) \
  108. _fex |= (ex)
  109. #define FP_UNSET_EXCEPTION(ex) \
  110. _fex &= ~(ex)
  111. #define FP_CUR_EXCEPTIONS \
  112. (_fex)
  113. #define FP_CLEAR_EXCEPTIONS \
  114. _fex = 0
  115. #define _FP_ROUND_NEAREST(wc, X) \
  116. do { \
  117. if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
  118. _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
  119. } while (0)
  120. #define _FP_ROUND_ZERO(wc, X) 0
  121. #define _FP_ROUND_PINF(wc, X) \
  122. do { \
  123. if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  124. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  125. } while (0)
  126. #define _FP_ROUND_MINF(wc, X) \
  127. do { \
  128. if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  129. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  130. } while (0)
  131. #define _FP_ROUND(wc, X) \
  132. do { \
  133. if (_FP_FRAC_LOW_##wc(X) & 7) \
  134. FP_SET_EXCEPTION(FP_EX_INEXACT); \
  135. switch (FP_ROUNDMODE) \
  136. { \
  137. case FP_RND_NEAREST: \
  138. _FP_ROUND_NEAREST(wc,X); \
  139. break; \
  140. case FP_RND_ZERO: \
  141. _FP_ROUND_ZERO(wc,X); \
  142. break; \
  143. case FP_RND_PINF: \
  144. _FP_ROUND_PINF(wc,X); \
  145. break; \
  146. case FP_RND_MINF: \
  147. _FP_ROUND_MINF(wc,X); \
  148. break; \
  149. } \
  150. } while (0)
  151. #define FP_CLS_NORMAL 0
  152. #define FP_CLS_ZERO 1
  153. #define FP_CLS_INF 2
  154. #define FP_CLS_NAN 3
  155. #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
  156. #include <math-emu/op-1.h>
  157. #include <math-emu/op-2.h>
  158. #include <math-emu/op-4.h>
  159. #include <math-emu/op-8.h>
  160. #include <math-emu/op-common.h>
  161. /* Sigh. Silly things longlong.h needs. */
  162. #define UWtype _FP_W_TYPE
  163. #define W_TYPE_SIZE _FP_W_TYPE_SIZE
  164. typedef int SItype __attribute__((mode(SI)));
  165. typedef int DItype __attribute__((mode(DI)));
  166. typedef unsigned int USItype __attribute__((mode(SI)));
  167. typedef unsigned int UDItype __attribute__((mode(DI)));
  168. #if _FP_W_TYPE_SIZE == 32
  169. typedef unsigned int UHWtype __attribute__((mode(HI)));
  170. #elif _FP_W_TYPE_SIZE == 64
  171. typedef USItype UHWtype;
  172. #endif
  173. #ifndef umul_ppmm
  174. #include <stdlib/longlong.h>
  175. #endif
  176. #endif /* __MATH_EMU_SOFT_FP_H__ */