soft-fp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #ifndef FP_TRAPPING_EXCEPTIONS
  86. #define FP_TRAPPING_EXCEPTIONS 0
  87. #endif
  88. #define FP_SET_EXCEPTION(ex) \
  89. _fex |= (ex)
  90. #define FP_UNSET_EXCEPTION(ex) \
  91. _fex &= ~(ex)
  92. #define FP_CUR_EXCEPTIONS \
  93. (_fex)
  94. #define FP_CLEAR_EXCEPTIONS \
  95. _fex = 0
  96. #define _FP_ROUND_NEAREST(wc, X) \
  97. do { \
  98. if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
  99. _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
  100. } while (0)
  101. #define _FP_ROUND_ZERO(wc, X) 0
  102. #define _FP_ROUND_PINF(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_MINF(wc, X) \
  108. do { \
  109. if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  110. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  111. } while (0)
  112. #define _FP_ROUND(wc, X) \
  113. do { \
  114. if (_FP_FRAC_LOW_##wc(X) & 7) \
  115. FP_SET_EXCEPTION(FP_EX_INEXACT); \
  116. switch (FP_ROUNDMODE) \
  117. { \
  118. case FP_RND_NEAREST: \
  119. _FP_ROUND_NEAREST(wc,X); \
  120. break; \
  121. case FP_RND_ZERO: \
  122. _FP_ROUND_ZERO(wc,X); \
  123. break; \
  124. case FP_RND_PINF: \
  125. _FP_ROUND_PINF(wc,X); \
  126. break; \
  127. case FP_RND_MINF: \
  128. _FP_ROUND_MINF(wc,X); \
  129. break; \
  130. } \
  131. } while (0)
  132. #define FP_CLS_NORMAL 0
  133. #define FP_CLS_ZERO 1
  134. #define FP_CLS_INF 2
  135. #define FP_CLS_NAN 3
  136. #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
  137. #include <math-emu/op-1.h>
  138. #include <math-emu/op-2.h>
  139. #include <math-emu/op-4.h>
  140. #include <math-emu/op-8.h>
  141. #include <math-emu/op-common.h>
  142. /* Sigh. Silly things longlong.h needs. */
  143. #define UWtype _FP_W_TYPE
  144. #define W_TYPE_SIZE _FP_W_TYPE_SIZE
  145. typedef int SItype __attribute__((mode(SI)));
  146. typedef int DItype __attribute__((mode(DI)));
  147. typedef unsigned int USItype __attribute__((mode(SI)));
  148. typedef unsigned int UDItype __attribute__((mode(DI)));
  149. #if _FP_W_TYPE_SIZE == 32
  150. typedef unsigned int UHWtype __attribute__((mode(HI)));
  151. #elif _FP_W_TYPE_SIZE == 64
  152. typedef USItype UHWtype;
  153. #endif
  154. #ifndef umul_ppmm
  155. #include <stdlib/longlong.h>
  156. #endif
  157. #endif /* __MATH_EMU_SOFT_FP_H__ */