soft-fp.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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, see
  27. <http://www.gnu.org/licenses/>. */
  28. #ifndef SOFT_FP_H
  29. #define SOFT_FP_H
  30. #include "sfp-machine.h"
  31. /* Allow sfp-machine to have its own byte order definitions. */
  32. #ifndef __BYTE_ORDER
  33. #ifdef _LIBC
  34. #include <endian.h>
  35. #else
  36. #error "endianness not defined by sfp-machine.h"
  37. #endif
  38. #endif
  39. #define _FP_WORKBITS 3
  40. #define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)
  41. #define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
  42. #define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1)
  43. #define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0)
  44. #ifndef FP_RND_NEAREST
  45. # define FP_RND_NEAREST 0
  46. # define FP_RND_ZERO 1
  47. # define FP_RND_PINF 2
  48. # define FP_RND_MINF 3
  49. #endif
  50. #ifndef FP_ROUNDMODE
  51. # define FP_ROUNDMODE FP_RND_NEAREST
  52. #endif
  53. /* By default don't care about exceptions. */
  54. #ifndef FP_EX_INVALID
  55. #define FP_EX_INVALID 0
  56. #endif
  57. #ifndef FP_EX_OVERFLOW
  58. #define FP_EX_OVERFLOW 0
  59. #endif
  60. #ifndef FP_EX_UNDERFLOW
  61. #define FP_EX_UNDERFLOW 0
  62. #endif
  63. #ifndef FP_EX_DIVZERO
  64. #define FP_EX_DIVZERO 0
  65. #endif
  66. #ifndef FP_EX_INEXACT
  67. #define FP_EX_INEXACT 0
  68. #endif
  69. #ifndef FP_EX_DENORM
  70. #define FP_EX_DENORM 0
  71. #endif
  72. #ifdef _FP_DECL_EX
  73. #define FP_DECL_EX \
  74. int _fex = 0; \
  75. _FP_DECL_EX
  76. #else
  77. #define FP_DECL_EX int _fex = 0
  78. #endif
  79. #ifndef FP_INIT_ROUNDMODE
  80. #define FP_INIT_ROUNDMODE do {} while (0)
  81. #endif
  82. #ifndef FP_HANDLE_EXCEPTIONS
  83. #define FP_HANDLE_EXCEPTIONS do {} while (0)
  84. #endif
  85. #ifndef FP_INHIBIT_RESULTS
  86. /* By default we write the results always.
  87. * sfp-machine may override this and e.g.
  88. * check if some exceptions are unmasked
  89. * and inhibit it in such a case.
  90. */
  91. #define FP_INHIBIT_RESULTS 0
  92. #endif
  93. #define FP_SET_EXCEPTION(ex) \
  94. _fex |= (ex)
  95. #define FP_UNSET_EXCEPTION(ex) \
  96. _fex &= ~(ex)
  97. #define FP_CLEAR_EXCEPTIONS \
  98. _fex = 0
  99. #define _FP_ROUND_NEAREST(wc, X) \
  100. do { \
  101. if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
  102. _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
  103. } while (0)
  104. #define _FP_ROUND_ZERO(wc, X) (void)0
  105. #define _FP_ROUND_PINF(wc, X) \
  106. do { \
  107. if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  108. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  109. } while (0)
  110. #define _FP_ROUND_MINF(wc, X) \
  111. do { \
  112. if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
  113. _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
  114. } while (0)
  115. #define _FP_ROUND(wc, X) \
  116. do { \
  117. if (_FP_FRAC_LOW_##wc(X) & 7) \
  118. FP_SET_EXCEPTION(FP_EX_INEXACT); \
  119. switch (FP_ROUNDMODE) \
  120. { \
  121. case FP_RND_NEAREST: \
  122. _FP_ROUND_NEAREST(wc,X); \
  123. break; \
  124. case FP_RND_ZERO: \
  125. _FP_ROUND_ZERO(wc,X); \
  126. break; \
  127. case FP_RND_PINF: \
  128. _FP_ROUND_PINF(wc,X); \
  129. break; \
  130. case FP_RND_MINF: \
  131. _FP_ROUND_MINF(wc,X); \
  132. break; \
  133. } \
  134. } while (0)
  135. #define FP_CLS_NORMAL 0
  136. #define FP_CLS_ZERO 1
  137. #define FP_CLS_INF 2
  138. #define FP_CLS_NAN 3
  139. #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
  140. #include "op-1.h"
  141. #include "op-2.h"
  142. #include "op-4.h"
  143. #include "op-8.h"
  144. #include "op-common.h"
  145. /* Sigh. Silly things longlong.h needs. */
  146. #define UWtype _FP_W_TYPE
  147. #define W_TYPE_SIZE _FP_W_TYPE_SIZE
  148. typedef int QItype __attribute__((mode(QI)));
  149. typedef int SItype __attribute__((mode(SI)));
  150. typedef int DItype __attribute__((mode(DI)));
  151. typedef unsigned int UQItype __attribute__((mode(QI)));
  152. typedef unsigned int USItype __attribute__((mode(SI)));
  153. typedef unsigned int UDItype __attribute__((mode(DI)));
  154. #if _FP_W_TYPE_SIZE == 32
  155. typedef unsigned int UHWtype __attribute__((mode(HI)));
  156. #elif _FP_W_TYPE_SIZE == 64
  157. typedef USItype UHWtype;
  158. #endif
  159. #ifndef CMPtype
  160. #define CMPtype int
  161. #endif
  162. #define SI_BITS (__CHAR_BIT__ * (int)sizeof(SItype))
  163. #define DI_BITS (__CHAR_BIT__ * (int)sizeof(DItype))
  164. #ifndef umul_ppmm
  165. #include "longlong.h"
  166. #endif
  167. #ifdef _LIBC
  168. #include <stdlib.h>
  169. #else
  170. extern void abort (void);
  171. #endif
  172. #endif