double.h 9.6 KB

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