double.h 7.8 KB

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