soft-fp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* Software floating-point emulation.
  2. Copyright (C) 1997,1998,1999,2000,2002,2003,2005,2006,2007
  3. Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Richard Henderson (rth@cygnus.com),
  6. Jakub Jelinek (jj@ultra.linux.cz),
  7. David S. Miller (davem@redhat.com) and
  8. Peter Maydell (pmaydell@chiark.greenend.org.uk).
  9. The GNU C Library is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU Lesser General Public
  11. License as published by the Free Software Foundation; either
  12. version 2.1 of the License, or (at your option) any later version.
  13. In addition to the permissions in the GNU Lesser General Public
  14. License, the Free Software Foundation gives you unlimited
  15. permission to link the compiled version of this file into
  16. combinations with other programs, and to distribute those
  17. combinations without any restriction coming from the use of this
  18. file. (The Lesser General Public License restrictions do apply in
  19. other respects; for example, they cover modification of the file,
  20. and distribution when not linked into a combine executable.)
  21. The GNU C Library is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Lesser General Public License for more details.
  25. You should have received a copy of the GNU Lesser General Public
  26. License along with the GNU C Library; if not, write to the Free
  27. Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  28. MA 02110-1301, USA. */
  29. #ifndef SOFT_FP_H
  30. #define SOFT_FP_H
  31. #include "sfp-machine.h"
  32. /* Allow sfp-machine to have its own byte order definitions. */
  33. #ifndef __BYTE_ORDER
  34. #ifdef _LIBC
  35. #include <endian.h>
  36. #else
  37. #error "endianness not defined by sfp-machine.h"
  38. #endif
  39. #endif
  40. #define _FP_WORKBITS 3
  41. #define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)
  42. #define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
  43. #define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1)
  44. #define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0)
  45. #ifndef FP_RND_NEAREST
  46. # define FP_RND_NEAREST 0
  47. # define FP_RND_ZERO 1
  48. # define FP_RND_PINF 2
  49. # define FP_RND_MINF 3
  50. #endif
  51. #ifndef FP_ROUNDMODE
  52. # define FP_ROUNDMODE FP_RND_NEAREST
  53. #endif
  54. /* By default don't care about exceptions. */
  55. #ifndef FP_EX_INVALID
  56. #define FP_EX_INVALID 0
  57. #endif
  58. #ifndef FP_EX_OVERFLOW
  59. #define FP_EX_OVERFLOW 0
  60. #endif
  61. #ifndef FP_EX_UNDERFLOW
  62. #define FP_EX_UNDERFLOW 0
  63. #endif
  64. #ifndef FP_EX_DIVZERO
  65. #define FP_EX_DIVZERO 0
  66. #endif
  67. #ifndef FP_EX_INEXACT
  68. #define FP_EX_INEXACT 0
  69. #endif
  70. #ifndef FP_EX_DENORM
  71. #define FP_EX_DENORM 0
  72. #endif
  73. #ifdef _FP_DECL_EX
  74. #define FP_DECL_EX \
  75. int _fex = 0; \
  76. _FP_DECL_EX
  77. #else
  78. #define FP_DECL_EX int _fex = 0
  79. #endif
  80. #ifndef FP_INIT_ROUNDMODE
  81. #define FP_INIT_ROUNDMODE do {} while (0)
  82. #endif
  83. #ifndef FP_HANDLE_EXCEPTIONS
  84. #define FP_HANDLE_EXCEPTIONS do {} while (0)
  85. #endif
  86. #ifndef FP_INHIBIT_RESULTS
  87. /* By default we write the results always.
  88. * sfp-machine may override this and e.g.
  89. * check if some exceptions are unmasked
  90. * and inhibit it in such a case.
  91. */
  92. #define FP_INHIBIT_RESULTS 0
  93. #endif
  94. #define FP_SET_EXCEPTION(ex) \
  95. _fex |= (ex)
  96. #define FP_UNSET_EXCEPTION(ex) \
  97. _fex &= ~(ex)
  98. #define FP_CLEAR_EXCEPTIONS \
  99. _fex = 0
  100. #define _FP_ROUND_NEAREST(wc, X) \
  101. do { \
  102. if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
  103. _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
  104. } while (0)
  105. #define _FP_ROUND_ZERO(wc, X) (void)0
  106. #define _FP_ROUND_PINF(wc, X) \
  107. do { \
  108. if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  109. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  110. } while (0)
  111. #define _FP_ROUND_MINF(wc, X) \
  112. do { \
  113. if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  114. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  115. } while (0)
  116. #define _FP_ROUND(wc, X) \
  117. do { \
  118. if (_FP_FRAC_LOW_##wc(X) & 7) \
  119. FP_SET_EXCEPTION(FP_EX_INEXACT); \
  120. switch (FP_ROUNDMODE) \
  121. { \
  122. case FP_RND_NEAREST: \
  123. _FP_ROUND_NEAREST(wc,X); \
  124. break; \
  125. case FP_RND_ZERO: \
  126. _FP_ROUND_ZERO(wc,X); \
  127. break; \
  128. case FP_RND_PINF: \
  129. _FP_ROUND_PINF(wc,X); \
  130. break; \
  131. case FP_RND_MINF: \
  132. _FP_ROUND_MINF(wc,X); \
  133. break; \
  134. } \
  135. } while (0)
  136. #define FP_CLS_NORMAL 0
  137. #define FP_CLS_ZERO 1
  138. #define FP_CLS_INF 2
  139. #define FP_CLS_NAN 3
  140. #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
  141. #include "op-1.h"
  142. #include "op-2.h"
  143. #include "op-4.h"
  144. #include "op-8.h"
  145. #include "op-common.h"
  146. /* Sigh. Silly things longlong.h needs. */
  147. #define UWtype _FP_W_TYPE
  148. #define W_TYPE_SIZE _FP_W_TYPE_SIZE
  149. typedef int QItype __attribute__((mode(QI)));
  150. typedef int SItype __attribute__((mode(SI)));
  151. typedef int DItype __attribute__((mode(DI)));
  152. typedef unsigned int UQItype __attribute__((mode(QI)));
  153. typedef unsigned int USItype __attribute__((mode(SI)));
  154. typedef unsigned int UDItype __attribute__((mode(DI)));
  155. #if _FP_W_TYPE_SIZE == 32
  156. typedef unsigned int UHWtype __attribute__((mode(HI)));
  157. #elif _FP_W_TYPE_SIZE == 64
  158. typedef USItype UHWtype;
  159. #endif
  160. #ifndef CMPtype
  161. #define CMPtype int
  162. #endif
  163. #define SI_BITS (__CHAR_BIT__ * (int)sizeof(SItype))
  164. #define DI_BITS (__CHAR_BIT__ * (int)sizeof(DItype))
  165. #ifndef umul_ppmm
  166. #include "longlong.h"
  167. #endif
  168. #ifdef _LIBC
  169. #include <stdlib.h>
  170. #else
  171. extern void abort (void);
  172. #endif
  173. #endif