double.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* Software floating-point emulation.
  2. Definitions for IEEE Double Precision
  3. Copyright (C) 1997,1998,1999,2006,2007 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. #if _FP_W_TYPE_SIZE < 32
  30. #error "Here's a nickel kid. Go buy yourself a real computer."
  31. #endif
  32. #if _FP_W_TYPE_SIZE < 64
  33. #define _FP_FRACTBITS_D (2 * _FP_W_TYPE_SIZE)
  34. #else
  35. #define _FP_FRACTBITS_D _FP_W_TYPE_SIZE
  36. #endif
  37. #define _FP_FRACBITS_D 53
  38. #define _FP_FRACXBITS_D (_FP_FRACTBITS_D - _FP_FRACBITS_D)
  39. #define _FP_WFRACBITS_D (_FP_WORKBITS + _FP_FRACBITS_D)
  40. #define _FP_WFRACXBITS_D (_FP_FRACTBITS_D - _FP_WFRACBITS_D)
  41. #define _FP_EXPBITS_D 11
  42. #define _FP_EXPBIAS_D 1023
  43. #define _FP_EXPMAX_D 2047
  44. #define _FP_QNANBIT_D \
  45. ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-2) % _FP_W_TYPE_SIZE)
  46. #define _FP_QNANBIT_SH_D \
  47. ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
  48. #define _FP_IMPLBIT_D \
  49. ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-1) % _FP_W_TYPE_SIZE)
  50. #define _FP_IMPLBIT_SH_D \
  51. ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
  52. #define _FP_OVERFLOW_D \
  53. ((_FP_W_TYPE)1 << _FP_WFRACBITS_D % _FP_W_TYPE_SIZE)
  54. typedef float DFtype __attribute__((mode(DF)));
  55. #if _FP_W_TYPE_SIZE < 64
  56. union _FP_UNION_D
  57. {
  58. DFtype flt;
  59. struct {
  60. #if __BYTE_ORDER == __BIG_ENDIAN
  61. unsigned sign : 1;
  62. unsigned exp : _FP_EXPBITS_D;
  63. unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
  64. unsigned frac0 : _FP_W_TYPE_SIZE;
  65. #else
  66. unsigned frac0 : _FP_W_TYPE_SIZE;
  67. unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
  68. unsigned exp : _FP_EXPBITS_D;
  69. unsigned sign : 1;
  70. #endif
  71. } bits __attribute__((packed));
  72. };
  73. #define FP_DECL_D(X) _FP_DECL(2,X)
  74. #define FP_UNPACK_RAW_D(X,val) _FP_UNPACK_RAW_2(D,X,val)
  75. #define FP_UNPACK_RAW_DP(X,val) _FP_UNPACK_RAW_2_P(D,X,val)
  76. #define FP_PACK_RAW_D(val,X) _FP_PACK_RAW_2(D,val,X)
  77. #define FP_PACK_RAW_DP(val,X) \
  78. do { \
  79. if (!FP_INHIBIT_RESULTS) \
  80. _FP_PACK_RAW_2_P(D,val,X); \
  81. } while (0)
  82. #define FP_UNPACK_D(X,val) \
  83. do { \
  84. _FP_UNPACK_RAW_2(D,X,val); \
  85. _FP_UNPACK_CANONICAL(D,2,X); \
  86. } while (0)
  87. #define FP_UNPACK_DP(X,val) \
  88. do { \
  89. _FP_UNPACK_RAW_2_P(D,X,val); \
  90. _FP_UNPACK_CANONICAL(D,2,X); \
  91. } while (0)
  92. #define FP_UNPACK_SEMIRAW_D(X,val) \
  93. do { \
  94. _FP_UNPACK_RAW_2(D,X,val); \
  95. _FP_UNPACK_SEMIRAW(D,2,X); \
  96. } while (0)
  97. #define FP_UNPACK_SEMIRAW_DP(X,val) \
  98. do { \
  99. _FP_UNPACK_RAW_2_P(D,X,val); \
  100. _FP_UNPACK_SEMIRAW(D,2,X); \
  101. } while (0)
  102. #define FP_PACK_D(val,X) \
  103. do { \
  104. _FP_PACK_CANONICAL(D,2,X); \
  105. _FP_PACK_RAW_2(D,val,X); \
  106. } while (0)
  107. #define FP_PACK_DP(val,X) \
  108. do { \
  109. _FP_PACK_CANONICAL(D,2,X); \
  110. if (!FP_INHIBIT_RESULTS) \
  111. _FP_PACK_RAW_2_P(D,val,X); \
  112. } while (0)
  113. #define FP_PACK_SEMIRAW_D(val,X) \
  114. do { \
  115. _FP_PACK_SEMIRAW(D,2,X); \
  116. _FP_PACK_RAW_2(D,val,X); \
  117. } while (0)
  118. #define FP_PACK_SEMIRAW_DP(val,X) \
  119. do { \
  120. _FP_PACK_SEMIRAW(D,2,X); \
  121. if (!FP_INHIBIT_RESULTS) \
  122. _FP_PACK_RAW_2_P(D,val,X); \
  123. } while (0)
  124. #define FP_ISSIGNAN_D(X) _FP_ISSIGNAN(D,2,X)
  125. #define FP_NEG_D(R,X) _FP_NEG(D,2,R,X)
  126. #define FP_ADD_D(R,X,Y) _FP_ADD(D,2,R,X,Y)
  127. #define FP_SUB_D(R,X,Y) _FP_SUB(D,2,R,X,Y)
  128. #define FP_MUL_D(R,X,Y) _FP_MUL(D,2,R,X,Y)
  129. #define FP_DIV_D(R,X,Y) _FP_DIV(D,2,R,X,Y)
  130. #define FP_SQRT_D(R,X) _FP_SQRT(D,2,R,X)
  131. #define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
  132. #define FP_CMP_D(r,X,Y,un) _FP_CMP(D,2,r,X,Y,un)
  133. #define FP_CMP_EQ_D(r,X,Y) _FP_CMP_EQ(D,2,r,X,Y)
  134. #define FP_CMP_UNORD_D(r,X,Y) _FP_CMP_UNORD(D,2,r,X,Y)
  135. #define FP_TO_INT_D(r,X,rsz,rsg) _FP_TO_INT(D,2,r,X,rsz,rsg)
  136. #define FP_FROM_INT_D(X,r,rs,rt) _FP_FROM_INT(D,2,X,r,rs,rt)
  137. #define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_2(X)
  138. #define _FP_FRAC_HIGH_RAW_D(X) _FP_FRAC_HIGH_2(X)
  139. #else
  140. union _FP_UNION_D
  141. {
  142. DFtype flt;
  143. struct {
  144. #if __BYTE_ORDER == __BIG_ENDIAN
  145. unsigned sign : 1;
  146. unsigned exp : _FP_EXPBITS_D;
  147. _FP_W_TYPE frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
  148. #else
  149. _FP_W_TYPE frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
  150. unsigned exp : _FP_EXPBITS_D;
  151. unsigned sign : 1;
  152. #endif
  153. } bits __attribute__((packed));
  154. };
  155. #define FP_DECL_D(X) _FP_DECL(1,X)
  156. #define FP_UNPACK_RAW_D(X,val) _FP_UNPACK_RAW_1(D,X,val)
  157. #define FP_UNPACK_RAW_DP(X,val) _FP_UNPACK_RAW_1_P(D,X,val)
  158. #define FP_PACK_RAW_D(val,X) _FP_PACK_RAW_1(D,val,X)
  159. #define FP_PACK_RAW_DP(val,X) \
  160. do { \
  161. if (!FP_INHIBIT_RESULTS) \
  162. _FP_PACK_RAW_1_P(D,val,X); \
  163. } while (0)
  164. #define FP_UNPACK_D(X,val) \
  165. do { \
  166. _FP_UNPACK_RAW_1(D,X,val); \
  167. _FP_UNPACK_CANONICAL(D,1,X); \
  168. } while (0)
  169. #define FP_UNPACK_DP(X,val) \
  170. do { \
  171. _FP_UNPACK_RAW_1_P(D,X,val); \
  172. _FP_UNPACK_CANONICAL(D,1,X); \
  173. } while (0)
  174. #define FP_UNPACK_SEMIRAW_D(X,val) \
  175. do { \
  176. _FP_UNPACK_RAW_2(1,X,val); \
  177. _FP_UNPACK_SEMIRAW(D,1,X); \
  178. } while (0)
  179. #define FP_UNPACK_SEMIRAW_DP(X,val) \
  180. do { \
  181. _FP_UNPACK_RAW_2_P(1,X,val); \
  182. _FP_UNPACK_SEMIRAW(D,1,X); \
  183. } while (0)
  184. #define FP_PACK_D(val,X) \
  185. do { \
  186. _FP_PACK_CANONICAL(D,1,X); \
  187. _FP_PACK_RAW_1(D,val,X); \
  188. } while (0)
  189. #define FP_PACK_DP(val,X) \
  190. do { \
  191. _FP_PACK_CANONICAL(D,1,X); \
  192. if (!FP_INHIBIT_RESULTS) \
  193. _FP_PACK_RAW_1_P(D,val,X); \
  194. } while (0)
  195. #define FP_PACK_SEMIRAW_D(val,X) \
  196. do { \
  197. _FP_PACK_SEMIRAW(D,1,X); \
  198. _FP_PACK_RAW_1(D,val,X); \
  199. } while (0)
  200. #define FP_PACK_SEMIRAW_DP(val,X) \
  201. do { \
  202. _FP_PACK_SEMIRAW(D,1,X); \
  203. if (!FP_INHIBIT_RESULTS) \
  204. _FP_PACK_RAW_1_P(D,val,X); \
  205. } while (0)
  206. #define FP_ISSIGNAN_D(X) _FP_ISSIGNAN(D,1,X)
  207. #define FP_NEG_D(R,X) _FP_NEG(D,1,R,X)
  208. #define FP_ADD_D(R,X,Y) _FP_ADD(D,1,R,X,Y)
  209. #define FP_SUB_D(R,X,Y) _FP_SUB(D,1,R,X,Y)
  210. #define FP_MUL_D(R,X,Y) _FP_MUL(D,1,R,X,Y)
  211. #define FP_DIV_D(R,X,Y) _FP_DIV(D,1,R,X,Y)
  212. #define FP_SQRT_D(R,X) _FP_SQRT(D,1,R,X)
  213. #define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_1(R,S,T,X,Q)
  214. /* The implementation of _FP_MUL_D and _FP_DIV_D should be chosen by
  215. the target machine. */
  216. #define FP_CMP_D(r,X,Y,un) _FP_CMP(D,1,r,X,Y,un)
  217. #define FP_CMP_EQ_D(r,X,Y) _FP_CMP_EQ(D,1,r,X,Y)
  218. #define FP_CMP_UNORD_D(r,X,Y) _FP_CMP_UNORD(D,1,r,X,Y)
  219. #define FP_TO_INT_D(r,X,rsz,rsg) _FP_TO_INT(D,1,r,X,rsz,rsg)
  220. #define FP_FROM_INT_D(X,r,rs,rt) _FP_FROM_INT(D,1,X,r,rs,rt)
  221. #define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_1(X)
  222. #define _FP_FRAC_HIGH_RAW_D(X) _FP_FRAC_HIGH_1(X)
  223. #endif /* W_TYPE_SIZE < 64 */