double.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* Software floating-point emulation.
  2. Definitions for IEEE Double Precision
  3. Copyright (C) 1997,1998,1999 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 Library General Public License as
  11. published by the Free Software Foundation; either version 2 of the
  12. License, or (at your option) any later version.
  13. The GNU C Library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. Library General Public License for more details.
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB. If
  19. not, write to the Free Software Foundation, Inc.,
  20. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  21. #ifndef __MATH_EMU_DOUBLE_H__
  22. #define __MATH_EMU_DOUBLE_H__
  23. #if _FP_W_TYPE_SIZE < 32
  24. #error "Here's a nickel kid. Go buy yourself a real computer."
  25. #endif
  26. #if _FP_W_TYPE_SIZE < 64
  27. #define _FP_FRACTBITS_D (2 * _FP_W_TYPE_SIZE)
  28. #else
  29. #define _FP_FRACTBITS_D _FP_W_TYPE_SIZE
  30. #endif
  31. #define _FP_FRACBITS_D 53
  32. #define _FP_FRACXBITS_D (_FP_FRACTBITS_D - _FP_FRACBITS_D)
  33. #define _FP_WFRACBITS_D (_FP_WORKBITS + _FP_FRACBITS_D)
  34. #define _FP_WFRACXBITS_D (_FP_FRACTBITS_D - _FP_WFRACBITS_D)
  35. #define _FP_EXPBITS_D 11
  36. #define _FP_EXPBIAS_D 1023
  37. #define _FP_EXPMAX_D 2047
  38. #define _FP_QNANBIT_D \
  39. ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-2) % _FP_W_TYPE_SIZE)
  40. #define _FP_IMPLBIT_D \
  41. ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-1) % _FP_W_TYPE_SIZE)
  42. #define _FP_OVERFLOW_D \
  43. ((_FP_W_TYPE)1 << _FP_WFRACBITS_D % _FP_W_TYPE_SIZE)
  44. #if _FP_W_TYPE_SIZE < 64
  45. union _FP_UNION_D
  46. {
  47. double flt;
  48. struct {
  49. #if __BYTE_ORDER == __BIG_ENDIAN
  50. unsigned sign : 1;
  51. unsigned exp : _FP_EXPBITS_D;
  52. unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
  53. unsigned frac0 : _FP_W_TYPE_SIZE;
  54. #else
  55. unsigned frac0 : _FP_W_TYPE_SIZE;
  56. unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
  57. unsigned exp : _FP_EXPBITS_D;
  58. unsigned sign : 1;
  59. #endif
  60. } bits __attribute__((packed));
  61. };
  62. #define FP_DECL_D(X) _FP_DECL(2,X)
  63. #define FP_UNPACK_RAW_D(X,val) _FP_UNPACK_RAW_2(D,X,val)
  64. #define FP_UNPACK_RAW_DP(X,val) _FP_UNPACK_RAW_2_P(D,X,val)
  65. #define FP_PACK_RAW_D(val,X) _FP_PACK_RAW_2(D,val,X)
  66. #define FP_PACK_RAW_DP(val,X) \
  67. do { \
  68. if (!FP_INHIBIT_RESULTS) \
  69. _FP_PACK_RAW_2_P(D,val,X); \
  70. } while (0)
  71. #define FP_UNPACK_D(X,val) \
  72. do { \
  73. _FP_UNPACK_RAW_2(D,X,val); \
  74. _FP_UNPACK_CANONICAL(D,2,X); \
  75. } while (0)
  76. #define FP_UNPACK_DP(X,val) \
  77. do { \
  78. _FP_UNPACK_RAW_2_P(D,X,val); \
  79. _FP_UNPACK_CANONICAL(D,2,X); \
  80. } while (0)
  81. #define FP_PACK_D(val,X) \
  82. do { \
  83. _FP_PACK_CANONICAL(D,2,X); \
  84. _FP_PACK_RAW_2(D,val,X); \
  85. } while (0)
  86. #define FP_PACK_DP(val,X) \
  87. do { \
  88. _FP_PACK_CANONICAL(D,2,X); \
  89. if (!FP_INHIBIT_RESULTS) \
  90. _FP_PACK_RAW_2_P(D,val,X); \
  91. } while (0)
  92. #define FP_ISSIGNAN_D(X) _FP_ISSIGNAN(D,2,X)
  93. #define FP_NEG_D(R,X) _FP_NEG(D,2,R,X)
  94. #define FP_ADD_D(R,X,Y) _FP_ADD(D,2,R,X,Y)
  95. #define FP_SUB_D(R,X,Y) _FP_SUB(D,2,R,X,Y)
  96. #define FP_MUL_D(R,X,Y) _FP_MUL(D,2,R,X,Y)
  97. #define FP_DIV_D(R,X,Y) _FP_DIV(D,2,R,X,Y)
  98. #define FP_SQRT_D(R,X) _FP_SQRT(D,2,R,X)
  99. #define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
  100. #define FP_CMP_D(r,X,Y,un) _FP_CMP(D,2,r,X,Y,un)
  101. #define FP_CMP_EQ_D(r,X,Y) _FP_CMP_EQ(D,2,r,X,Y)
  102. #define FP_TO_INT_D(r,X,rsz,rsg) _FP_TO_INT(D,2,r,X,rsz,rsg)
  103. #define FP_TO_INT_ROUND_D(r,X,rsz,rsg) _FP_TO_INT_ROUND(D,2,r,X,rsz,rsg)
  104. #define FP_FROM_INT_D(X,r,rs,rt) _FP_FROM_INT(D,2,X,r,rs,rt)
  105. #define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_2(X)
  106. #define _FP_FRAC_HIGH_RAW_D(X) _FP_FRAC_HIGH_2(X)
  107. #else
  108. union _FP_UNION_D
  109. {
  110. double flt;
  111. struct {
  112. #if __BYTE_ORDER == __BIG_ENDIAN
  113. unsigned sign : 1;
  114. unsigned exp : _FP_EXPBITS_D;
  115. unsigned long frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
  116. #else
  117. unsigned long frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
  118. unsigned exp : _FP_EXPBITS_D;
  119. unsigned sign : 1;
  120. #endif
  121. } bits __attribute__((packed));
  122. };
  123. #define FP_DECL_D(X) _FP_DECL(1,X)
  124. #define FP_UNPACK_RAW_D(X,val) _FP_UNPACK_RAW_1(D,X,val)
  125. #define FP_UNPACK_RAW_DP(X,val) _FP_UNPACK_RAW_1_P(D,X,val)
  126. #define FP_PACK_RAW_D(val,X) _FP_PACK_RAW_1(D,val,X)
  127. #define FP_PACK_RAW_DP(val,X) \
  128. do { \
  129. if (!FP_INHIBIT_RESULTS) \
  130. _FP_PACK_RAW_1_P(D,val,X); \
  131. } while (0)
  132. #define FP_UNPACK_D(X,val) \
  133. do { \
  134. _FP_UNPACK_RAW_1(D,X,val); \
  135. _FP_UNPACK_CANONICAL(D,1,X); \
  136. } while (0)
  137. #define FP_UNPACK_DP(X,val) \
  138. do { \
  139. _FP_UNPACK_RAW_1_P(D,X,val); \
  140. _FP_UNPACK_CANONICAL(D,1,X); \
  141. } while (0)
  142. #define FP_PACK_D(val,X) \
  143. do { \
  144. _FP_PACK_CANONICAL(D,1,X); \
  145. _FP_PACK_RAW_1(D,val,X); \
  146. } while (0)
  147. #define FP_PACK_DP(val,X) \
  148. do { \
  149. _FP_PACK_CANONICAL(D,1,X); \
  150. if (!FP_INHIBIT_RESULTS) \
  151. _FP_PACK_RAW_1_P(D,val,X); \
  152. } while (0)
  153. #define FP_ISSIGNAN_D(X) _FP_ISSIGNAN(D,1,X)
  154. #define FP_NEG_D(R,X) _FP_NEG(D,1,R,X)
  155. #define FP_ADD_D(R,X,Y) _FP_ADD(D,1,R,X,Y)
  156. #define FP_SUB_D(R,X,Y) _FP_SUB(D,1,R,X,Y)
  157. #define FP_MUL_D(R,X,Y) _FP_MUL(D,1,R,X,Y)
  158. #define FP_DIV_D(R,X,Y) _FP_DIV(D,1,R,X,Y)
  159. #define FP_SQRT_D(R,X) _FP_SQRT(D,1,R,X)
  160. #define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_1(R,S,T,X,Q)
  161. /* The implementation of _FP_MUL_D and _FP_DIV_D should be chosen by
  162. the target machine. */
  163. #define FP_CMP_D(r,X,Y,un) _FP_CMP(D,1,r,X,Y,un)
  164. #define FP_CMP_EQ_D(r,X,Y) _FP_CMP_EQ(D,1,r,X,Y)
  165. #define FP_TO_INT_D(r,X,rsz,rsg) _FP_TO_INT(D,1,r,X,rsz,rsg)
  166. #define FP_TO_INT_ROUND_D(r,X,rsz,rsg) _FP_TO_INT_ROUND(D,1,r,X,rsz,rsg)
  167. #define FP_FROM_INT_D(X,r,rs,rt) _FP_FROM_INT(D,1,X,r,rs,rt)
  168. #define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_1(X)
  169. #define _FP_FRAC_HIGH_RAW_D(X) _FP_FRAC_HIGH_1(X)
  170. #endif /* W_TYPE_SIZE < 64 */
  171. #endif /* __MATH_EMU_DOUBLE_H__ */