quad.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /* Software floating-point emulation.
  2. Definitions for IEEE Quad 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_QUAD_H
  29. #define SOFT_FP_QUAD_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_Q (4*_FP_W_TYPE_SIZE)
  35. # define _FP_FRACTBITS_DW_Q (8*_FP_W_TYPE_SIZE)
  36. #else
  37. # define _FP_FRACTBITS_Q (2*_FP_W_TYPE_SIZE)
  38. # define _FP_FRACTBITS_DW_Q (4*_FP_W_TYPE_SIZE)
  39. #endif
  40. #define _FP_FRACBITS_Q 113
  41. #define _FP_FRACXBITS_Q (_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
  42. #define _FP_WFRACBITS_Q (_FP_WORKBITS + _FP_FRACBITS_Q)
  43. #define _FP_WFRACXBITS_Q (_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
  44. #define _FP_EXPBITS_Q 15
  45. #define _FP_EXPBIAS_Q 16383
  46. #define _FP_EXPMAX_Q 32767
  47. #define _FP_QNANBIT_Q \
  48. ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
  49. #define _FP_QNANBIT_SH_Q \
  50. ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
  51. #define _FP_IMPLBIT_Q \
  52. ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
  53. #define _FP_IMPLBIT_SH_Q \
  54. ((_FP_W_TYPE) 1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
  55. #define _FP_OVERFLOW_Q \
  56. ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
  57. #define _FP_WFRACBITS_DW_Q (2 * _FP_WFRACBITS_Q)
  58. #define _FP_WFRACXBITS_DW_Q (_FP_FRACTBITS_DW_Q - _FP_WFRACBITS_DW_Q)
  59. #define _FP_HIGHBIT_DW_Q \
  60. ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_Q - 1) % _FP_W_TYPE_SIZE)
  61. typedef float TFtype __attribute__ ((mode (TF)));
  62. #if _FP_W_TYPE_SIZE < 64
  63. union _FP_UNION_Q
  64. {
  65. TFtype flt;
  66. struct _FP_STRUCT_LAYOUT
  67. {
  68. # if __BYTE_ORDER == __BIG_ENDIAN
  69. unsigned sign : 1;
  70. unsigned exp : _FP_EXPBITS_Q;
  71. unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
  72. unsigned long frac2 : _FP_W_TYPE_SIZE;
  73. unsigned long frac1 : _FP_W_TYPE_SIZE;
  74. unsigned long frac0 : _FP_W_TYPE_SIZE;
  75. # else
  76. unsigned long frac0 : _FP_W_TYPE_SIZE;
  77. unsigned long frac1 : _FP_W_TYPE_SIZE;
  78. unsigned long frac2 : _FP_W_TYPE_SIZE;
  79. unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
  80. unsigned exp : _FP_EXPBITS_Q;
  81. unsigned sign : 1;
  82. # endif /* not bigendian */
  83. } bits __attribute__ ((packed));
  84. };
  85. # define FP_DECL_Q(X) _FP_DECL (4, X)
  86. # define FP_UNPACK_RAW_Q(X, val) _FP_UNPACK_RAW_4 (Q, X, (val))
  87. # define FP_UNPACK_RAW_QP(X, val) _FP_UNPACK_RAW_4_P (Q, X, (val))
  88. # define FP_PACK_RAW_Q(val, X) _FP_PACK_RAW_4 (Q, (val), X)
  89. # define FP_PACK_RAW_QP(val, X) \
  90. do \
  91. { \
  92. if (!FP_INHIBIT_RESULTS) \
  93. _FP_PACK_RAW_4_P (Q, (val), X); \
  94. } \
  95. while (0)
  96. # define FP_UNPACK_Q(X, val) \
  97. do \
  98. { \
  99. _FP_UNPACK_RAW_4 (Q, X, (val)); \
  100. _FP_UNPACK_CANONICAL (Q, 4, X); \
  101. } \
  102. while (0)
  103. # define FP_UNPACK_QP(X, val) \
  104. do \
  105. { \
  106. _FP_UNPACK_RAW_4_P (Q, X, (val)); \
  107. _FP_UNPACK_CANONICAL (Q, 4, X); \
  108. } \
  109. while (0)
  110. # define FP_UNPACK_SEMIRAW_Q(X, val) \
  111. do \
  112. { \
  113. _FP_UNPACK_RAW_4 (Q, X, (val)); \
  114. _FP_UNPACK_SEMIRAW (Q, 4, X); \
  115. } \
  116. while (0)
  117. # define FP_UNPACK_SEMIRAW_QP(X, val) \
  118. do \
  119. { \
  120. _FP_UNPACK_RAW_4_P (Q, X, (val)); \
  121. _FP_UNPACK_SEMIRAW (Q, 4, X); \
  122. } \
  123. while (0)
  124. # define FP_PACK_Q(val, X) \
  125. do \
  126. { \
  127. _FP_PACK_CANONICAL (Q, 4, X); \
  128. _FP_PACK_RAW_4 (Q, (val), X); \
  129. } \
  130. while (0)
  131. # define FP_PACK_QP(val, X) \
  132. do \
  133. { \
  134. _FP_PACK_CANONICAL (Q, 4, X); \
  135. if (!FP_INHIBIT_RESULTS) \
  136. _FP_PACK_RAW_4_P (Q, (val), X); \
  137. } \
  138. while (0)
  139. # define FP_PACK_SEMIRAW_Q(val, X) \
  140. do \
  141. { \
  142. _FP_PACK_SEMIRAW (Q, 4, X); \
  143. _FP_PACK_RAW_4 (Q, (val), X); \
  144. } \
  145. while (0)
  146. # define FP_PACK_SEMIRAW_QP(val, X) \
  147. do \
  148. { \
  149. _FP_PACK_SEMIRAW (Q, 4, X); \
  150. if (!FP_INHIBIT_RESULTS) \
  151. _FP_PACK_RAW_4_P (Q, (val), X); \
  152. } \
  153. while (0)
  154. # define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN (Q, 4, X)
  155. # define FP_NEG_Q(R, X) _FP_NEG (Q, 4, R, X)
  156. # define FP_ADD_Q(R, X, Y) _FP_ADD (Q, 4, R, X, Y)
  157. # define FP_SUB_Q(R, X, Y) _FP_SUB (Q, 4, R, X, Y)
  158. # define FP_MUL_Q(R, X, Y) _FP_MUL (Q, 4, R, X, Y)
  159. # define FP_DIV_Q(R, X, Y) _FP_DIV (Q, 4, R, X, Y)
  160. # define FP_SQRT_Q(R, X) _FP_SQRT (Q, 4, R, X)
  161. # define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_4 (R, S, T, X, (Q))
  162. # define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 4, 8, R, X, Y, Z)
  163. # define FP_CMP_Q(r, X, Y, un, ex) _FP_CMP (Q, 4, (r), X, Y, (un), (ex))
  164. # define FP_CMP_EQ_Q(r, X, Y, ex) _FP_CMP_EQ (Q, 4, (r), X, Y, (ex))
  165. # define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 4, (r), X, Y, (ex))
  166. # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 4, (r), X, (rsz), (rsg))
  167. # define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
  168. _FP_TO_INT_ROUND (Q, 4, (r), X, (rsz), (rsg))
  169. # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 4, X, (r), (rs), rt)
  170. # define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_4 (X)
  171. # define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_4 (X)
  172. # define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_8 (X)
  173. #else /* not _FP_W_TYPE_SIZE < 64 */
  174. union _FP_UNION_Q
  175. {
  176. TFtype flt /* __attribute__ ((mode (TF))) */ ;
  177. struct _FP_STRUCT_LAYOUT
  178. {
  179. _FP_W_TYPE a, b;
  180. } longs;
  181. struct _FP_STRUCT_LAYOUT
  182. {
  183. # if __BYTE_ORDER == __BIG_ENDIAN
  184. unsigned sign : 1;
  185. unsigned exp : _FP_EXPBITS_Q;
  186. _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
  187. _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
  188. # else
  189. _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
  190. _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
  191. unsigned exp : _FP_EXPBITS_Q;
  192. unsigned sign : 1;
  193. # endif
  194. } bits;
  195. };
  196. # define FP_DECL_Q(X) _FP_DECL (2, X)
  197. # define FP_UNPACK_RAW_Q(X, val) _FP_UNPACK_RAW_2 (Q, X, (val))
  198. # define FP_UNPACK_RAW_QP(X, val) _FP_UNPACK_RAW_2_P (Q, X, (val))
  199. # define FP_PACK_RAW_Q(val, X) _FP_PACK_RAW_2 (Q, (val), X)
  200. # define FP_PACK_RAW_QP(val, X) \
  201. do \
  202. { \
  203. if (!FP_INHIBIT_RESULTS) \
  204. _FP_PACK_RAW_2_P (Q, (val), X); \
  205. } \
  206. while (0)
  207. # define FP_UNPACK_Q(X, val) \
  208. do \
  209. { \
  210. _FP_UNPACK_RAW_2 (Q, X, (val)); \
  211. _FP_UNPACK_CANONICAL (Q, 2, X); \
  212. } \
  213. while (0)
  214. # define FP_UNPACK_QP(X, val) \
  215. do \
  216. { \
  217. _FP_UNPACK_RAW_2_P (Q, X, (val)); \
  218. _FP_UNPACK_CANONICAL (Q, 2, X); \
  219. } \
  220. while (0)
  221. # define FP_UNPACK_SEMIRAW_Q(X, val) \
  222. do \
  223. { \
  224. _FP_UNPACK_RAW_2 (Q, X, (val)); \
  225. _FP_UNPACK_SEMIRAW (Q, 2, X); \
  226. } \
  227. while (0)
  228. # define FP_UNPACK_SEMIRAW_QP(X, val) \
  229. do \
  230. { \
  231. _FP_UNPACK_RAW_2_P (Q, X, (val)); \
  232. _FP_UNPACK_SEMIRAW (Q, 2, X); \
  233. } \
  234. while (0)
  235. # define FP_PACK_Q(val, X) \
  236. do \
  237. { \
  238. _FP_PACK_CANONICAL (Q, 2, X); \
  239. _FP_PACK_RAW_2 (Q, (val), X); \
  240. } \
  241. while (0)
  242. # define FP_PACK_QP(val, X) \
  243. do \
  244. { \
  245. _FP_PACK_CANONICAL (Q, 2, X); \
  246. if (!FP_INHIBIT_RESULTS) \
  247. _FP_PACK_RAW_2_P (Q, (val), X); \
  248. } \
  249. while (0)
  250. # define FP_PACK_SEMIRAW_Q(val, X) \
  251. do \
  252. { \
  253. _FP_PACK_SEMIRAW (Q, 2, X); \
  254. _FP_PACK_RAW_2 (Q, (val), X); \
  255. } \
  256. while (0)
  257. # define FP_PACK_SEMIRAW_QP(val, X) \
  258. do \
  259. { \
  260. _FP_PACK_SEMIRAW (Q, 2, X); \
  261. if (!FP_INHIBIT_RESULTS) \
  262. _FP_PACK_RAW_2_P (Q, (val), X); \
  263. } \
  264. while (0)
  265. # define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN (Q, 2, X)
  266. # define FP_NEG_Q(R, X) _FP_NEG (Q, 2, R, X)
  267. # define FP_ADD_Q(R, X, Y) _FP_ADD (Q, 2, R, X, Y)
  268. # define FP_SUB_Q(R, X, Y) _FP_SUB (Q, 2, R, X, Y)
  269. # define FP_MUL_Q(R, X, Y) _FP_MUL (Q, 2, R, X, Y)
  270. # define FP_DIV_Q(R, X, Y) _FP_DIV (Q, 2, R, X, Y)
  271. # define FP_SQRT_Q(R, X) _FP_SQRT (Q, 2, R, X)
  272. # define _FP_SQRT_MEAT_Q(R, S, T, X, Q) _FP_SQRT_MEAT_2 (R, S, T, X, (Q))
  273. # define FP_FMA_Q(R, X, Y, Z) _FP_FMA (Q, 2, 4, R, X, Y, Z)
  274. # define FP_CMP_Q(r, X, Y, un, ex) _FP_CMP (Q, 2, (r), X, Y, (un), (ex))
  275. # define FP_CMP_EQ_Q(r, X, Y, ex) _FP_CMP_EQ (Q, 2, (r), X, Y, (ex))
  276. # define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 2, (r), X, Y, (ex))
  277. # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 2, (r), X, (rsz), (rsg))
  278. # define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \
  279. _FP_TO_INT_ROUND (Q, 2, (r), X, (rsz), (rsg))
  280. # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 2, X, (r), (rs), rt)
  281. # define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_2 (X)
  282. # define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_2 (X)
  283. # define _FP_FRAC_HIGH_DW_Q(X) _FP_FRAC_HIGH_4 (X)
  284. #endif /* not _FP_W_TYPE_SIZE < 64 */
  285. #endif /* !SOFT_FP_QUAD_H */