op-4.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. /* Software floating-point emulation.
  2. Basic four-word fraction declaration and manipulation.
  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_OP_4_H
  29. #define SOFT_FP_OP_4_H 1
  30. #define _FP_FRAC_DECL_4(X) _FP_W_TYPE X##_f[4]
  31. #define _FP_FRAC_COPY_4(D, S) \
  32. (D##_f[0] = S##_f[0], D##_f[1] = S##_f[1], \
  33. D##_f[2] = S##_f[2], D##_f[3] = S##_f[3])
  34. #define _FP_FRAC_SET_4(X, I) __FP_FRAC_SET_4 (X, I)
  35. #define _FP_FRAC_HIGH_4(X) (X##_f[3])
  36. #define _FP_FRAC_LOW_4(X) (X##_f[0])
  37. #define _FP_FRAC_WORD_4(X, w) (X##_f[w])
  38. #define _FP_FRAC_SLL_4(X, N) \
  39. do \
  40. { \
  41. _FP_I_TYPE _FP_FRAC_SLL_4_up, _FP_FRAC_SLL_4_down; \
  42. _FP_I_TYPE _FP_FRAC_SLL_4_skip, _FP_FRAC_SLL_4_i; \
  43. _FP_FRAC_SLL_4_skip = (N) / _FP_W_TYPE_SIZE; \
  44. _FP_FRAC_SLL_4_up = (N) % _FP_W_TYPE_SIZE; \
  45. _FP_FRAC_SLL_4_down = _FP_W_TYPE_SIZE - _FP_FRAC_SLL_4_up; \
  46. if (!_FP_FRAC_SLL_4_up) \
  47. for (_FP_FRAC_SLL_4_i = 3; \
  48. _FP_FRAC_SLL_4_i >= _FP_FRAC_SLL_4_skip; \
  49. --_FP_FRAC_SLL_4_i) \
  50. X##_f[_FP_FRAC_SLL_4_i] \
  51. = X##_f[_FP_FRAC_SLL_4_i-_FP_FRAC_SLL_4_skip]; \
  52. else \
  53. { \
  54. for (_FP_FRAC_SLL_4_i = 3; \
  55. _FP_FRAC_SLL_4_i > _FP_FRAC_SLL_4_skip; \
  56. --_FP_FRAC_SLL_4_i) \
  57. X##_f[_FP_FRAC_SLL_4_i] \
  58. = ((X##_f[_FP_FRAC_SLL_4_i-_FP_FRAC_SLL_4_skip] \
  59. << _FP_FRAC_SLL_4_up) \
  60. | (X##_f[_FP_FRAC_SLL_4_i-_FP_FRAC_SLL_4_skip-1] \
  61. >> _FP_FRAC_SLL_4_down)); \
  62. X##_f[_FP_FRAC_SLL_4_i--] = X##_f[0] << _FP_FRAC_SLL_4_up; \
  63. } \
  64. for (; _FP_FRAC_SLL_4_i >= 0; --_FP_FRAC_SLL_4_i) \
  65. X##_f[_FP_FRAC_SLL_4_i] = 0; \
  66. } \
  67. while (0)
  68. /* This one was broken too. */
  69. #define _FP_FRAC_SRL_4(X, N) \
  70. do \
  71. { \
  72. _FP_I_TYPE _FP_FRAC_SRL_4_up, _FP_FRAC_SRL_4_down; \
  73. _FP_I_TYPE _FP_FRAC_SRL_4_skip, _FP_FRAC_SRL_4_i; \
  74. _FP_FRAC_SRL_4_skip = (N) / _FP_W_TYPE_SIZE; \
  75. _FP_FRAC_SRL_4_down = (N) % _FP_W_TYPE_SIZE; \
  76. _FP_FRAC_SRL_4_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRL_4_down; \
  77. if (!_FP_FRAC_SRL_4_down) \
  78. for (_FP_FRAC_SRL_4_i = 0; \
  79. _FP_FRAC_SRL_4_i <= 3-_FP_FRAC_SRL_4_skip; \
  80. ++_FP_FRAC_SRL_4_i) \
  81. X##_f[_FP_FRAC_SRL_4_i] \
  82. = X##_f[_FP_FRAC_SRL_4_i+_FP_FRAC_SRL_4_skip]; \
  83. else \
  84. { \
  85. for (_FP_FRAC_SRL_4_i = 0; \
  86. _FP_FRAC_SRL_4_i < 3-_FP_FRAC_SRL_4_skip; \
  87. ++_FP_FRAC_SRL_4_i) \
  88. X##_f[_FP_FRAC_SRL_4_i] \
  89. = ((X##_f[_FP_FRAC_SRL_4_i+_FP_FRAC_SRL_4_skip] \
  90. >> _FP_FRAC_SRL_4_down) \
  91. | (X##_f[_FP_FRAC_SRL_4_i+_FP_FRAC_SRL_4_skip+1] \
  92. << _FP_FRAC_SRL_4_up)); \
  93. X##_f[_FP_FRAC_SRL_4_i++] = X##_f[3] >> _FP_FRAC_SRL_4_down; \
  94. } \
  95. for (; _FP_FRAC_SRL_4_i < 4; ++_FP_FRAC_SRL_4_i) \
  96. X##_f[_FP_FRAC_SRL_4_i] = 0; \
  97. } \
  98. while (0)
  99. /* Right shift with sticky-lsb.
  100. What this actually means is that we do a standard right-shift,
  101. but that if any of the bits that fall off the right hand side
  102. were one then we always set the LSbit. */
  103. #define _FP_FRAC_SRST_4(X, S, N, size) \
  104. do \
  105. { \
  106. _FP_I_TYPE _FP_FRAC_SRST_4_up, _FP_FRAC_SRST_4_down; \
  107. _FP_I_TYPE _FP_FRAC_SRST_4_skip, _FP_FRAC_SRST_4_i; \
  108. _FP_W_TYPE _FP_FRAC_SRST_4_s; \
  109. _FP_FRAC_SRST_4_skip = (N) / _FP_W_TYPE_SIZE; \
  110. _FP_FRAC_SRST_4_down = (N) % _FP_W_TYPE_SIZE; \
  111. _FP_FRAC_SRST_4_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRST_4_down; \
  112. for (_FP_FRAC_SRST_4_s = _FP_FRAC_SRST_4_i = 0; \
  113. _FP_FRAC_SRST_4_i < _FP_FRAC_SRST_4_skip; \
  114. ++_FP_FRAC_SRST_4_i) \
  115. _FP_FRAC_SRST_4_s |= X##_f[_FP_FRAC_SRST_4_i]; \
  116. if (!_FP_FRAC_SRST_4_down) \
  117. for (_FP_FRAC_SRST_4_i = 0; \
  118. _FP_FRAC_SRST_4_i <= 3-_FP_FRAC_SRST_4_skip; \
  119. ++_FP_FRAC_SRST_4_i) \
  120. X##_f[_FP_FRAC_SRST_4_i] \
  121. = X##_f[_FP_FRAC_SRST_4_i+_FP_FRAC_SRST_4_skip]; \
  122. else \
  123. { \
  124. _FP_FRAC_SRST_4_s \
  125. |= X##_f[_FP_FRAC_SRST_4_i] << _FP_FRAC_SRST_4_up; \
  126. for (_FP_FRAC_SRST_4_i = 0; \
  127. _FP_FRAC_SRST_4_i < 3-_FP_FRAC_SRST_4_skip; \
  128. ++_FP_FRAC_SRST_4_i) \
  129. X##_f[_FP_FRAC_SRST_4_i] \
  130. = ((X##_f[_FP_FRAC_SRST_4_i+_FP_FRAC_SRST_4_skip] \
  131. >> _FP_FRAC_SRST_4_down) \
  132. | (X##_f[_FP_FRAC_SRST_4_i+_FP_FRAC_SRST_4_skip+1] \
  133. << _FP_FRAC_SRST_4_up)); \
  134. X##_f[_FP_FRAC_SRST_4_i++] \
  135. = X##_f[3] >> _FP_FRAC_SRST_4_down; \
  136. } \
  137. for (; _FP_FRAC_SRST_4_i < 4; ++_FP_FRAC_SRST_4_i) \
  138. X##_f[_FP_FRAC_SRST_4_i] = 0; \
  139. S = (_FP_FRAC_SRST_4_s != 0); \
  140. } \
  141. while (0)
  142. #define _FP_FRAC_SRS_4(X, N, size) \
  143. do \
  144. { \
  145. int _FP_FRAC_SRS_4_sticky; \
  146. _FP_FRAC_SRST_4 (X, _FP_FRAC_SRS_4_sticky, (N), (size)); \
  147. X##_f[0] |= _FP_FRAC_SRS_4_sticky; \
  148. } \
  149. while (0)
  150. #define _FP_FRAC_ADD_4(R, X, Y) \
  151. __FP_FRAC_ADD_4 (R##_f[3], R##_f[2], R##_f[1], R##_f[0], \
  152. X##_f[3], X##_f[2], X##_f[1], X##_f[0], \
  153. Y##_f[3], Y##_f[2], Y##_f[1], Y##_f[0])
  154. #define _FP_FRAC_SUB_4(R, X, Y) \
  155. __FP_FRAC_SUB_4 (R##_f[3], R##_f[2], R##_f[1], R##_f[0], \
  156. X##_f[3], X##_f[2], X##_f[1], X##_f[0], \
  157. Y##_f[3], Y##_f[2], Y##_f[1], Y##_f[0])
  158. #define _FP_FRAC_DEC_4(X, Y) \
  159. __FP_FRAC_DEC_4 (X##_f[3], X##_f[2], X##_f[1], X##_f[0], \
  160. Y##_f[3], Y##_f[2], Y##_f[1], Y##_f[0])
  161. #define _FP_FRAC_ADDI_4(X, I) \
  162. __FP_FRAC_ADDI_4 (X##_f[3], X##_f[2], X##_f[1], X##_f[0], I)
  163. #define _FP_ZEROFRAC_4 0, 0, 0, 0
  164. #define _FP_MINFRAC_4 0, 0, 0, 1
  165. #define _FP_MAXFRAC_4 (~(_FP_WS_TYPE) 0), (~(_FP_WS_TYPE) 0), (~(_FP_WS_TYPE) 0), (~(_FP_WS_TYPE) 0)
  166. #define _FP_FRAC_ZEROP_4(X) ((X##_f[0] | X##_f[1] | X##_f[2] | X##_f[3]) == 0)
  167. #define _FP_FRAC_NEGP_4(X) ((_FP_WS_TYPE) X##_f[3] < 0)
  168. #define _FP_FRAC_OVERP_4(fs, X) (_FP_FRAC_HIGH_##fs (X) & _FP_OVERFLOW_##fs)
  169. #define _FP_FRAC_HIGHBIT_DW_4(fs, X) \
  170. (_FP_FRAC_HIGH_DW_##fs (X) & _FP_HIGHBIT_DW_##fs)
  171. #define _FP_FRAC_CLEAR_OVERP_4(fs, X) (_FP_FRAC_HIGH_##fs (X) &= ~_FP_OVERFLOW_##fs)
  172. #define _FP_FRAC_EQ_4(X, Y) \
  173. (X##_f[0] == Y##_f[0] && X##_f[1] == Y##_f[1] \
  174. && X##_f[2] == Y##_f[2] && X##_f[3] == Y##_f[3])
  175. #define _FP_FRAC_GT_4(X, Y) \
  176. (X##_f[3] > Y##_f[3] \
  177. || (X##_f[3] == Y##_f[3] \
  178. && (X##_f[2] > Y##_f[2] \
  179. || (X##_f[2] == Y##_f[2] \
  180. && (X##_f[1] > Y##_f[1] \
  181. || (X##_f[1] == Y##_f[1] \
  182. && X##_f[0] > Y##_f[0]))))))
  183. #define _FP_FRAC_GE_4(X, Y) \
  184. (X##_f[3] > Y##_f[3] \
  185. || (X##_f[3] == Y##_f[3] \
  186. && (X##_f[2] > Y##_f[2] \
  187. || (X##_f[2] == Y##_f[2] \
  188. && (X##_f[1] > Y##_f[1] \
  189. || (X##_f[1] == Y##_f[1] \
  190. && X##_f[0] >= Y##_f[0]))))))
  191. #define _FP_FRAC_CLZ_4(R, X) \
  192. do \
  193. { \
  194. if (X##_f[3]) \
  195. __FP_CLZ ((R), X##_f[3]); \
  196. else if (X##_f[2]) \
  197. { \
  198. __FP_CLZ ((R), X##_f[2]); \
  199. (R) += _FP_W_TYPE_SIZE; \
  200. } \
  201. else if (X##_f[1]) \
  202. { \
  203. __FP_CLZ ((R), X##_f[1]); \
  204. (R) += _FP_W_TYPE_SIZE*2; \
  205. } \
  206. else \
  207. { \
  208. __FP_CLZ ((R), X##_f[0]); \
  209. (R) += _FP_W_TYPE_SIZE*3; \
  210. } \
  211. } \
  212. while (0)
  213. #define _FP_UNPACK_RAW_4(fs, X, val) \
  214. do \
  215. { \
  216. union _FP_UNION_##fs _FP_UNPACK_RAW_4_flo; \
  217. _FP_UNPACK_RAW_4_flo.flt = (val); \
  218. X##_f[0] = _FP_UNPACK_RAW_4_flo.bits.frac0; \
  219. X##_f[1] = _FP_UNPACK_RAW_4_flo.bits.frac1; \
  220. X##_f[2] = _FP_UNPACK_RAW_4_flo.bits.frac2; \
  221. X##_f[3] = _FP_UNPACK_RAW_4_flo.bits.frac3; \
  222. X##_e = _FP_UNPACK_RAW_4_flo.bits.exp; \
  223. X##_s = _FP_UNPACK_RAW_4_flo.bits.sign; \
  224. } \
  225. while (0)
  226. #define _FP_UNPACK_RAW_4_P(fs, X, val) \
  227. do \
  228. { \
  229. union _FP_UNION_##fs *_FP_UNPACK_RAW_4_P_flo \
  230. = (union _FP_UNION_##fs *) (val); \
  231. \
  232. X##_f[0] = _FP_UNPACK_RAW_4_P_flo->bits.frac0; \
  233. X##_f[1] = _FP_UNPACK_RAW_4_P_flo->bits.frac1; \
  234. X##_f[2] = _FP_UNPACK_RAW_4_P_flo->bits.frac2; \
  235. X##_f[3] = _FP_UNPACK_RAW_4_P_flo->bits.frac3; \
  236. X##_e = _FP_UNPACK_RAW_4_P_flo->bits.exp; \
  237. X##_s = _FP_UNPACK_RAW_4_P_flo->bits.sign; \
  238. } \
  239. while (0)
  240. #define _FP_PACK_RAW_4(fs, val, X) \
  241. do \
  242. { \
  243. union _FP_UNION_##fs _FP_PACK_RAW_4_flo; \
  244. _FP_PACK_RAW_4_flo.bits.frac0 = X##_f[0]; \
  245. _FP_PACK_RAW_4_flo.bits.frac1 = X##_f[1]; \
  246. _FP_PACK_RAW_4_flo.bits.frac2 = X##_f[2]; \
  247. _FP_PACK_RAW_4_flo.bits.frac3 = X##_f[3]; \
  248. _FP_PACK_RAW_4_flo.bits.exp = X##_e; \
  249. _FP_PACK_RAW_4_flo.bits.sign = X##_s; \
  250. (val) = _FP_PACK_RAW_4_flo.flt; \
  251. } \
  252. while (0)
  253. #define _FP_PACK_RAW_4_P(fs, val, X) \
  254. do \
  255. { \
  256. union _FP_UNION_##fs *_FP_PACK_RAW_4_P_flo \
  257. = (union _FP_UNION_##fs *) (val); \
  258. \
  259. _FP_PACK_RAW_4_P_flo->bits.frac0 = X##_f[0]; \
  260. _FP_PACK_RAW_4_P_flo->bits.frac1 = X##_f[1]; \
  261. _FP_PACK_RAW_4_P_flo->bits.frac2 = X##_f[2]; \
  262. _FP_PACK_RAW_4_P_flo->bits.frac3 = X##_f[3]; \
  263. _FP_PACK_RAW_4_P_flo->bits.exp = X##_e; \
  264. _FP_PACK_RAW_4_P_flo->bits.sign = X##_s; \
  265. } \
  266. while (0)
  267. /* Multiplication algorithms: */
  268. /* Given a 1W * 1W => 2W primitive, do the extended multiplication. */
  269. #define _FP_MUL_MEAT_DW_4_wide(wfracbits, R, X, Y, doit) \
  270. do \
  271. { \
  272. _FP_FRAC_DECL_2 (_FP_MUL_MEAT_DW_4_wide_b); \
  273. _FP_FRAC_DECL_2 (_FP_MUL_MEAT_DW_4_wide_c); \
  274. _FP_FRAC_DECL_2 (_FP_MUL_MEAT_DW_4_wide_d); \
  275. _FP_FRAC_DECL_2 (_FP_MUL_MEAT_DW_4_wide_e); \
  276. _FP_FRAC_DECL_2 (_FP_MUL_MEAT_DW_4_wide_f); \
  277. \
  278. doit (_FP_FRAC_WORD_8 (R, 1), _FP_FRAC_WORD_8 (R, 0), \
  279. X##_f[0], Y##_f[0]); \
  280. doit (_FP_MUL_MEAT_DW_4_wide_b_f1, _FP_MUL_MEAT_DW_4_wide_b_f0, \
  281. X##_f[0], Y##_f[1]); \
  282. doit (_FP_MUL_MEAT_DW_4_wide_c_f1, _FP_MUL_MEAT_DW_4_wide_c_f0, \
  283. X##_f[1], Y##_f[0]); \
  284. doit (_FP_MUL_MEAT_DW_4_wide_d_f1, _FP_MUL_MEAT_DW_4_wide_d_f0, \
  285. X##_f[1], Y##_f[1]); \
  286. doit (_FP_MUL_MEAT_DW_4_wide_e_f1, _FP_MUL_MEAT_DW_4_wide_e_f0, \
  287. X##_f[0], Y##_f[2]); \
  288. doit (_FP_MUL_MEAT_DW_4_wide_f_f1, _FP_MUL_MEAT_DW_4_wide_f_f0, \
  289. X##_f[2], Y##_f[0]); \
  290. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 3), _FP_FRAC_WORD_8 (R, 2), \
  291. _FP_FRAC_WORD_8 (R, 1), 0, \
  292. _FP_MUL_MEAT_DW_4_wide_b_f1, \
  293. _FP_MUL_MEAT_DW_4_wide_b_f0, \
  294. 0, 0, _FP_FRAC_WORD_8 (R, 1)); \
  295. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 3), _FP_FRAC_WORD_8 (R, 2), \
  296. _FP_FRAC_WORD_8 (R, 1), 0, \
  297. _FP_MUL_MEAT_DW_4_wide_c_f1, \
  298. _FP_MUL_MEAT_DW_4_wide_c_f0, \
  299. _FP_FRAC_WORD_8 (R, 3), _FP_FRAC_WORD_8 (R, 2), \
  300. _FP_FRAC_WORD_8 (R, 1)); \
  301. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 4), _FP_FRAC_WORD_8 (R, 3), \
  302. _FP_FRAC_WORD_8 (R, 2), 0, \
  303. _FP_MUL_MEAT_DW_4_wide_d_f1, \
  304. _FP_MUL_MEAT_DW_4_wide_d_f0, \
  305. 0, _FP_FRAC_WORD_8 (R, 3), _FP_FRAC_WORD_8 (R, 2)); \
  306. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 4), _FP_FRAC_WORD_8 (R, 3), \
  307. _FP_FRAC_WORD_8 (R, 2), 0, \
  308. _FP_MUL_MEAT_DW_4_wide_e_f1, \
  309. _FP_MUL_MEAT_DW_4_wide_e_f0, \
  310. _FP_FRAC_WORD_8 (R, 4), _FP_FRAC_WORD_8 (R, 3), \
  311. _FP_FRAC_WORD_8 (R, 2)); \
  312. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 4), _FP_FRAC_WORD_8 (R, 3), \
  313. _FP_FRAC_WORD_8 (R, 2), 0, \
  314. _FP_MUL_MEAT_DW_4_wide_f_f1, \
  315. _FP_MUL_MEAT_DW_4_wide_f_f0, \
  316. _FP_FRAC_WORD_8 (R, 4), _FP_FRAC_WORD_8 (R, 3), \
  317. _FP_FRAC_WORD_8 (R, 2)); \
  318. doit (_FP_MUL_MEAT_DW_4_wide_b_f1, \
  319. _FP_MUL_MEAT_DW_4_wide_b_f0, X##_f[0], Y##_f[3]); \
  320. doit (_FP_MUL_MEAT_DW_4_wide_c_f1, \
  321. _FP_MUL_MEAT_DW_4_wide_c_f0, X##_f[3], Y##_f[0]); \
  322. doit (_FP_MUL_MEAT_DW_4_wide_d_f1, _FP_MUL_MEAT_DW_4_wide_d_f0, \
  323. X##_f[1], Y##_f[2]); \
  324. doit (_FP_MUL_MEAT_DW_4_wide_e_f1, _FP_MUL_MEAT_DW_4_wide_e_f0, \
  325. X##_f[2], Y##_f[1]); \
  326. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4), \
  327. _FP_FRAC_WORD_8 (R, 3), 0, \
  328. _FP_MUL_MEAT_DW_4_wide_b_f1, \
  329. _FP_MUL_MEAT_DW_4_wide_b_f0, \
  330. 0, _FP_FRAC_WORD_8 (R, 4), _FP_FRAC_WORD_8 (R, 3)); \
  331. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4), \
  332. _FP_FRAC_WORD_8 (R, 3), 0, \
  333. _FP_MUL_MEAT_DW_4_wide_c_f1, \
  334. _FP_MUL_MEAT_DW_4_wide_c_f0, \
  335. _FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4), \
  336. _FP_FRAC_WORD_8 (R, 3)); \
  337. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4), \
  338. _FP_FRAC_WORD_8 (R, 3), 0, \
  339. _FP_MUL_MEAT_DW_4_wide_d_f1, \
  340. _FP_MUL_MEAT_DW_4_wide_d_f0, \
  341. _FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4), \
  342. _FP_FRAC_WORD_8 (R, 3)); \
  343. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4), \
  344. _FP_FRAC_WORD_8 (R, 3), 0, \
  345. _FP_MUL_MEAT_DW_4_wide_e_f1, \
  346. _FP_MUL_MEAT_DW_4_wide_e_f0, \
  347. _FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4), \
  348. _FP_FRAC_WORD_8 (R, 3)); \
  349. doit (_FP_MUL_MEAT_DW_4_wide_b_f1, _FP_MUL_MEAT_DW_4_wide_b_f0, \
  350. X##_f[2], Y##_f[2]); \
  351. doit (_FP_MUL_MEAT_DW_4_wide_c_f1, _FP_MUL_MEAT_DW_4_wide_c_f0, \
  352. X##_f[1], Y##_f[3]); \
  353. doit (_FP_MUL_MEAT_DW_4_wide_d_f1, _FP_MUL_MEAT_DW_4_wide_d_f0, \
  354. X##_f[3], Y##_f[1]); \
  355. doit (_FP_MUL_MEAT_DW_4_wide_e_f1, _FP_MUL_MEAT_DW_4_wide_e_f0, \
  356. X##_f[2], Y##_f[3]); \
  357. doit (_FP_MUL_MEAT_DW_4_wide_f_f1, _FP_MUL_MEAT_DW_4_wide_f_f0, \
  358. X##_f[3], Y##_f[2]); \
  359. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 6), _FP_FRAC_WORD_8 (R, 5), \
  360. _FP_FRAC_WORD_8 (R, 4), 0, \
  361. _FP_MUL_MEAT_DW_4_wide_b_f1, \
  362. _FP_MUL_MEAT_DW_4_wide_b_f0, \
  363. 0, _FP_FRAC_WORD_8 (R, 5), _FP_FRAC_WORD_8 (R, 4)); \
  364. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 6), _FP_FRAC_WORD_8 (R, 5), \
  365. _FP_FRAC_WORD_8 (R, 4), 0, \
  366. _FP_MUL_MEAT_DW_4_wide_c_f1, \
  367. _FP_MUL_MEAT_DW_4_wide_c_f0, \
  368. _FP_FRAC_WORD_8 (R, 6), _FP_FRAC_WORD_8 (R, 5), \
  369. _FP_FRAC_WORD_8 (R, 4)); \
  370. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 6), _FP_FRAC_WORD_8 (R, 5), \
  371. _FP_FRAC_WORD_8 (R, 4), 0, \
  372. _FP_MUL_MEAT_DW_4_wide_d_f1, \
  373. _FP_MUL_MEAT_DW_4_wide_d_f0, \
  374. _FP_FRAC_WORD_8 (R, 6), _FP_FRAC_WORD_8 (R, 5), \
  375. _FP_FRAC_WORD_8 (R, 4)); \
  376. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 7), _FP_FRAC_WORD_8 (R, 6), \
  377. _FP_FRAC_WORD_8 (R, 5), 0, \
  378. _FP_MUL_MEAT_DW_4_wide_e_f1, \
  379. _FP_MUL_MEAT_DW_4_wide_e_f0, \
  380. 0, _FP_FRAC_WORD_8 (R, 6), _FP_FRAC_WORD_8 (R, 5)); \
  381. __FP_FRAC_ADD_3 (_FP_FRAC_WORD_8 (R, 7), _FP_FRAC_WORD_8 (R, 6), \
  382. _FP_FRAC_WORD_8 (R, 5), 0, \
  383. _FP_MUL_MEAT_DW_4_wide_f_f1, \
  384. _FP_MUL_MEAT_DW_4_wide_f_f0, \
  385. _FP_FRAC_WORD_8 (R, 7), _FP_FRAC_WORD_8 (R, 6), \
  386. _FP_FRAC_WORD_8 (R, 5)); \
  387. doit (_FP_MUL_MEAT_DW_4_wide_b_f1, _FP_MUL_MEAT_DW_4_wide_b_f0, \
  388. X##_f[3], Y##_f[3]); \
  389. __FP_FRAC_ADD_2 (_FP_FRAC_WORD_8 (R, 7), _FP_FRAC_WORD_8 (R, 6), \
  390. _FP_MUL_MEAT_DW_4_wide_b_f1, \
  391. _FP_MUL_MEAT_DW_4_wide_b_f0, \
  392. _FP_FRAC_WORD_8 (R, 7), _FP_FRAC_WORD_8 (R, 6)); \
  393. } \
  394. while (0)
  395. #define _FP_MUL_MEAT_4_wide(wfracbits, R, X, Y, doit) \
  396. do \
  397. { \
  398. _FP_FRAC_DECL_8 (_FP_MUL_MEAT_4_wide_z); \
  399. \
  400. _FP_MUL_MEAT_DW_4_wide ((wfracbits), _FP_MUL_MEAT_4_wide_z, \
  401. X, Y, doit); \
  402. \
  403. /* Normalize since we know where the msb of the multiplicands \
  404. were (bit B), we know that the msb of the of the product is \
  405. at either 2B or 2B-1. */ \
  406. _FP_FRAC_SRS_8 (_FP_MUL_MEAT_4_wide_z, (wfracbits)-1, \
  407. 2*(wfracbits)); \
  408. __FP_FRAC_SET_4 (R, _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_wide_z, 3), \
  409. _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_wide_z, 2), \
  410. _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_wide_z, 1), \
  411. _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_wide_z, 0)); \
  412. } \
  413. while (0)
  414. #define _FP_MUL_MEAT_DW_4_gmp(wfracbits, R, X, Y) \
  415. do \
  416. { \
  417. mpn_mul_n (R##_f, _x_f, _y_f, 4); \
  418. } \
  419. while (0)
  420. #define _FP_MUL_MEAT_4_gmp(wfracbits, R, X, Y) \
  421. do \
  422. { \
  423. _FP_FRAC_DECL_8 (_FP_MUL_MEAT_4_gmp_z); \
  424. \
  425. _FP_MUL_MEAT_DW_4_gmp ((wfracbits), _FP_MUL_MEAT_4_gmp_z, X, Y); \
  426. \
  427. /* Normalize since we know where the msb of the multiplicands \
  428. were (bit B), we know that the msb of the of the product is \
  429. at either 2B or 2B-1. */ \
  430. _FP_FRAC_SRS_8 (_FP_MUL_MEAT_4_gmp_z, (wfracbits)-1, \
  431. 2*(wfracbits)); \
  432. __FP_FRAC_SET_4 (R, _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_gmp_z, 3), \
  433. _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_gmp_z, 2), \
  434. _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_gmp_z, 1), \
  435. _FP_FRAC_WORD_8 (_FP_MUL_MEAT_4_gmp_z, 0)); \
  436. } \
  437. while (0)
  438. /* Helper utility for _FP_DIV_MEAT_4_udiv:
  439. * pppp = m * nnn. */
  440. #define umul_ppppmnnn(p3, p2, p1, p0, m, n2, n1, n0) \
  441. do \
  442. { \
  443. UWtype umul_ppppmnnn_t; \
  444. umul_ppmm (p1, p0, m, n0); \
  445. umul_ppmm (p2, umul_ppppmnnn_t, m, n1); \
  446. __FP_FRAC_ADDI_2 (p2, p1, umul_ppppmnnn_t); \
  447. umul_ppmm (p3, umul_ppppmnnn_t, m, n2); \
  448. __FP_FRAC_ADDI_2 (p3, p2, umul_ppppmnnn_t); \
  449. } \
  450. while (0)
  451. /* Division algorithms: */
  452. #define _FP_DIV_MEAT_4_udiv(fs, R, X, Y) \
  453. do \
  454. { \
  455. int _FP_DIV_MEAT_4_udiv_i; \
  456. _FP_FRAC_DECL_4 (_FP_DIV_MEAT_4_udiv_n); \
  457. _FP_FRAC_DECL_4 (_FP_DIV_MEAT_4_udiv_m); \
  458. _FP_FRAC_SET_4 (_FP_DIV_MEAT_4_udiv_n, _FP_ZEROFRAC_4); \
  459. if (_FP_FRAC_GE_4 (X, Y)) \
  460. { \
  461. _FP_DIV_MEAT_4_udiv_n_f[3] \
  462. = X##_f[0] << (_FP_W_TYPE_SIZE - 1); \
  463. _FP_FRAC_SRL_4 (X, 1); \
  464. } \
  465. else \
  466. R##_e--; \
  467. \
  468. /* Normalize, i.e. make the most significant bit of the \
  469. denominator set. */ \
  470. _FP_FRAC_SLL_4 (Y, _FP_WFRACXBITS_##fs); \
  471. \
  472. for (_FP_DIV_MEAT_4_udiv_i = 3; ; _FP_DIV_MEAT_4_udiv_i--) \
  473. { \
  474. if (X##_f[3] == Y##_f[3]) \
  475. { \
  476. /* This is a special case, not an optimization \
  477. (X##_f[3]/Y##_f[3] would not fit into UWtype). \
  478. As X## is guaranteed to be < Y, \
  479. R##_f[_FP_DIV_MEAT_4_udiv_i] can be either \
  480. (UWtype)-1 or (UWtype)-2. */ \
  481. R##_f[_FP_DIV_MEAT_4_udiv_i] = -1; \
  482. if (!_FP_DIV_MEAT_4_udiv_i) \
  483. break; \
  484. __FP_FRAC_SUB_4 (X##_f[3], X##_f[2], X##_f[1], X##_f[0], \
  485. Y##_f[2], Y##_f[1], Y##_f[0], 0, \
  486. X##_f[2], X##_f[1], X##_f[0], \
  487. _FP_DIV_MEAT_4_udiv_n_f[_FP_DIV_MEAT_4_udiv_i]); \
  488. _FP_FRAC_SUB_4 (X, Y, X); \
  489. if (X##_f[3] > Y##_f[3]) \
  490. { \
  491. R##_f[_FP_DIV_MEAT_4_udiv_i] = -2; \
  492. _FP_FRAC_ADD_4 (X, Y, X); \
  493. } \
  494. } \
  495. else \
  496. { \
  497. udiv_qrnnd (R##_f[_FP_DIV_MEAT_4_udiv_i], \
  498. X##_f[3], X##_f[3], X##_f[2], Y##_f[3]); \
  499. umul_ppppmnnn (_FP_DIV_MEAT_4_udiv_m_f[3], \
  500. _FP_DIV_MEAT_4_udiv_m_f[2], \
  501. _FP_DIV_MEAT_4_udiv_m_f[1], \
  502. _FP_DIV_MEAT_4_udiv_m_f[0], \
  503. R##_f[_FP_DIV_MEAT_4_udiv_i], \
  504. Y##_f[2], Y##_f[1], Y##_f[0]); \
  505. X##_f[2] = X##_f[1]; \
  506. X##_f[1] = X##_f[0]; \
  507. X##_f[0] \
  508. = _FP_DIV_MEAT_4_udiv_n_f[_FP_DIV_MEAT_4_udiv_i]; \
  509. if (_FP_FRAC_GT_4 (_FP_DIV_MEAT_4_udiv_m, X)) \
  510. { \
  511. R##_f[_FP_DIV_MEAT_4_udiv_i]--; \
  512. _FP_FRAC_ADD_4 (X, Y, X); \
  513. if (_FP_FRAC_GE_4 (X, Y) \
  514. && _FP_FRAC_GT_4 (_FP_DIV_MEAT_4_udiv_m, X)) \
  515. { \
  516. R##_f[_FP_DIV_MEAT_4_udiv_i]--; \
  517. _FP_FRAC_ADD_4 (X, Y, X); \
  518. } \
  519. } \
  520. _FP_FRAC_DEC_4 (X, _FP_DIV_MEAT_4_udiv_m); \
  521. if (!_FP_DIV_MEAT_4_udiv_i) \
  522. { \
  523. if (!_FP_FRAC_EQ_4 (X, _FP_DIV_MEAT_4_udiv_m)) \
  524. R##_f[0] |= _FP_WORK_STICKY; \
  525. break; \
  526. } \
  527. } \
  528. } \
  529. } \
  530. while (0)
  531. /* Square root algorithms:
  532. We have just one right now, maybe Newton approximation
  533. should be added for those machines where division is fast. */
  534. #define _FP_SQRT_MEAT_4(R, S, T, X, q) \
  535. do \
  536. { \
  537. while (q) \
  538. { \
  539. T##_f[3] = S##_f[3] + (q); \
  540. if (T##_f[3] <= X##_f[3]) \
  541. { \
  542. S##_f[3] = T##_f[3] + (q); \
  543. X##_f[3] -= T##_f[3]; \
  544. R##_f[3] += (q); \
  545. } \
  546. _FP_FRAC_SLL_4 (X, 1); \
  547. (q) >>= 1; \
  548. } \
  549. (q) = (_FP_W_TYPE) 1 << (_FP_W_TYPE_SIZE - 1); \
  550. while (q) \
  551. { \
  552. T##_f[2] = S##_f[2] + (q); \
  553. T##_f[3] = S##_f[3]; \
  554. if (T##_f[3] < X##_f[3] \
  555. || (T##_f[3] == X##_f[3] && T##_f[2] <= X##_f[2])) \
  556. { \
  557. S##_f[2] = T##_f[2] + (q); \
  558. S##_f[3] += (T##_f[2] > S##_f[2]); \
  559. __FP_FRAC_DEC_2 (X##_f[3], X##_f[2], \
  560. T##_f[3], T##_f[2]); \
  561. R##_f[2] += (q); \
  562. } \
  563. _FP_FRAC_SLL_4 (X, 1); \
  564. (q) >>= 1; \
  565. } \
  566. (q) = (_FP_W_TYPE) 1 << (_FP_W_TYPE_SIZE - 1); \
  567. while (q) \
  568. { \
  569. T##_f[1] = S##_f[1] + (q); \
  570. T##_f[2] = S##_f[2]; \
  571. T##_f[3] = S##_f[3]; \
  572. if (T##_f[3] < X##_f[3] \
  573. || (T##_f[3] == X##_f[3] \
  574. && (T##_f[2] < X##_f[2] \
  575. || (T##_f[2] == X##_f[2] \
  576. && T##_f[1] <= X##_f[1])))) \
  577. { \
  578. S##_f[1] = T##_f[1] + (q); \
  579. S##_f[2] += (T##_f[1] > S##_f[1]); \
  580. S##_f[3] += (T##_f[2] > S##_f[2]); \
  581. __FP_FRAC_DEC_3 (X##_f[3], X##_f[2], X##_f[1], \
  582. T##_f[3], T##_f[2], T##_f[1]); \
  583. R##_f[1] += (q); \
  584. } \
  585. _FP_FRAC_SLL_4 (X, 1); \
  586. (q) >>= 1; \
  587. } \
  588. (q) = (_FP_W_TYPE) 1 << (_FP_W_TYPE_SIZE - 1); \
  589. while ((q) != _FP_WORK_ROUND) \
  590. { \
  591. T##_f[0] = S##_f[0] + (q); \
  592. T##_f[1] = S##_f[1]; \
  593. T##_f[2] = S##_f[2]; \
  594. T##_f[3] = S##_f[3]; \
  595. if (_FP_FRAC_GE_4 (X, T)) \
  596. { \
  597. S##_f[0] = T##_f[0] + (q); \
  598. S##_f[1] += (T##_f[0] > S##_f[0]); \
  599. S##_f[2] += (T##_f[1] > S##_f[1]); \
  600. S##_f[3] += (T##_f[2] > S##_f[2]); \
  601. _FP_FRAC_DEC_4 (X, T); \
  602. R##_f[0] += (q); \
  603. } \
  604. _FP_FRAC_SLL_4 (X, 1); \
  605. (q) >>= 1; \
  606. } \
  607. if (!_FP_FRAC_ZEROP_4 (X)) \
  608. { \
  609. if (_FP_FRAC_GT_4 (X, S)) \
  610. R##_f[0] |= _FP_WORK_ROUND; \
  611. R##_f[0] |= _FP_WORK_STICKY; \
  612. } \
  613. } \
  614. while (0)
  615. /* Internals. */
  616. #define __FP_FRAC_SET_4(X, I3, I2, I1, I0) \
  617. (X##_f[3] = I3, X##_f[2] = I2, X##_f[1] = I1, X##_f[0] = I0)
  618. #ifndef __FP_FRAC_ADD_3
  619. # define __FP_FRAC_ADD_3(r2, r1, r0, x2, x1, x0, y2, y1, y0) \
  620. do \
  621. { \
  622. _FP_W_TYPE __FP_FRAC_ADD_3_c1, __FP_FRAC_ADD_3_c2; \
  623. r0 = x0 + y0; \
  624. __FP_FRAC_ADD_3_c1 = r0 < x0; \
  625. r1 = x1 + y1; \
  626. __FP_FRAC_ADD_3_c2 = r1 < x1; \
  627. r1 += __FP_FRAC_ADD_3_c1; \
  628. __FP_FRAC_ADD_3_c2 |= r1 < __FP_FRAC_ADD_3_c1; \
  629. r2 = x2 + y2 + __FP_FRAC_ADD_3_c2; \
  630. } \
  631. while (0)
  632. #endif
  633. #ifndef __FP_FRAC_ADD_4
  634. # define __FP_FRAC_ADD_4(r3, r2, r1, r0, x3, x2, x1, x0, y3, y2, y1, y0) \
  635. do \
  636. { \
  637. _FP_W_TYPE __FP_FRAC_ADD_4_c1, __FP_FRAC_ADD_4_c2; \
  638. _FP_W_TYPE __FP_FRAC_ADD_4_c3; \
  639. r0 = x0 + y0; \
  640. __FP_FRAC_ADD_4_c1 = r0 < x0; \
  641. r1 = x1 + y1; \
  642. __FP_FRAC_ADD_4_c2 = r1 < x1; \
  643. r1 += __FP_FRAC_ADD_4_c1; \
  644. __FP_FRAC_ADD_4_c2 |= r1 < __FP_FRAC_ADD_4_c1; \
  645. r2 = x2 + y2; \
  646. __FP_FRAC_ADD_4_c3 = r2 < x2; \
  647. r2 += __FP_FRAC_ADD_4_c2; \
  648. __FP_FRAC_ADD_4_c3 |= r2 < __FP_FRAC_ADD_4_c2; \
  649. r3 = x3 + y3 + __FP_FRAC_ADD_4_c3; \
  650. } \
  651. while (0)
  652. #endif
  653. #ifndef __FP_FRAC_SUB_3
  654. # define __FP_FRAC_SUB_3(r2, r1, r0, x2, x1, x0, y2, y1, y0) \
  655. do \
  656. { \
  657. _FP_W_TYPE __FP_FRAC_SUB_3_c1, __FP_FRAC_SUB_3_c2; \
  658. r0 = x0 - y0; \
  659. __FP_FRAC_SUB_3_c1 = r0 > x0; \
  660. r1 = x1 - y1; \
  661. __FP_FRAC_SUB_3_c2 = r1 > x1; \
  662. r1 -= __FP_FRAC_SUB_3_c1; \
  663. __FP_FRAC_SUB_3_c2 |= __FP_FRAC_SUB_3_c1 && (y1 == x1); \
  664. r2 = x2 - y2 - __FP_FRAC_SUB_3_c2; \
  665. } \
  666. while (0)
  667. #endif
  668. #ifndef __FP_FRAC_SUB_4
  669. # define __FP_FRAC_SUB_4(r3, r2, r1, r0, x3, x2, x1, x0, y3, y2, y1, y0) \
  670. do \
  671. { \
  672. _FP_W_TYPE __FP_FRAC_SUB_4_c1, __FP_FRAC_SUB_4_c2; \
  673. _FP_W_TYPE __FP_FRAC_SUB_4_c3; \
  674. r0 = x0 - y0; \
  675. __FP_FRAC_SUB_4_c1 = r0 > x0; \
  676. r1 = x1 - y1; \
  677. __FP_FRAC_SUB_4_c2 = r1 > x1; \
  678. r1 -= __FP_FRAC_SUB_4_c1; \
  679. __FP_FRAC_SUB_4_c2 |= __FP_FRAC_SUB_4_c1 && (y1 == x1); \
  680. r2 = x2 - y2; \
  681. __FP_FRAC_SUB_4_c3 = r2 > x2; \
  682. r2 -= __FP_FRAC_SUB_4_c2; \
  683. __FP_FRAC_SUB_4_c3 |= __FP_FRAC_SUB_4_c2 && (y2 == x2); \
  684. r3 = x3 - y3 - __FP_FRAC_SUB_4_c3; \
  685. } \
  686. while (0)
  687. #endif
  688. #ifndef __FP_FRAC_DEC_3
  689. # define __FP_FRAC_DEC_3(x2, x1, x0, y2, y1, y0) \
  690. do \
  691. { \
  692. UWtype __FP_FRAC_DEC_3_t0, __FP_FRAC_DEC_3_t1; \
  693. UWtype __FP_FRAC_DEC_3_t2; \
  694. __FP_FRAC_DEC_3_t0 = x0; \
  695. __FP_FRAC_DEC_3_t1 = x1; \
  696. __FP_FRAC_DEC_3_t2 = x2; \
  697. __FP_FRAC_SUB_3 (x2, x1, x0, __FP_FRAC_DEC_3_t2, \
  698. __FP_FRAC_DEC_3_t1, __FP_FRAC_DEC_3_t0, \
  699. y2, y1, y0); \
  700. } \
  701. while (0)
  702. #endif
  703. #ifndef __FP_FRAC_DEC_4
  704. # define __FP_FRAC_DEC_4(x3, x2, x1, x0, y3, y2, y1, y0) \
  705. do \
  706. { \
  707. UWtype __FP_FRAC_DEC_4_t0, __FP_FRAC_DEC_4_t1; \
  708. UWtype __FP_FRAC_DEC_4_t2, __FP_FRAC_DEC_4_t3; \
  709. __FP_FRAC_DEC_4_t0 = x0; \
  710. __FP_FRAC_DEC_4_t1 = x1; \
  711. __FP_FRAC_DEC_4_t2 = x2; \
  712. __FP_FRAC_DEC_4_t3 = x3; \
  713. __FP_FRAC_SUB_4 (x3, x2, x1, x0, __FP_FRAC_DEC_4_t3, \
  714. __FP_FRAC_DEC_4_t2, __FP_FRAC_DEC_4_t1, \
  715. __FP_FRAC_DEC_4_t0, y3, y2, y1, y0); \
  716. } \
  717. while (0)
  718. #endif
  719. #ifndef __FP_FRAC_ADDI_4
  720. # define __FP_FRAC_ADDI_4(x3, x2, x1, x0, i) \
  721. do \
  722. { \
  723. UWtype __FP_FRAC_ADDI_4_t; \
  724. __FP_FRAC_ADDI_4_t = ((x0 += i) < i); \
  725. x1 += __FP_FRAC_ADDI_4_t; \
  726. __FP_FRAC_ADDI_4_t = (x1 < __FP_FRAC_ADDI_4_t); \
  727. x2 += __FP_FRAC_ADDI_4_t; \
  728. __FP_FRAC_ADDI_4_t = (x2 < __FP_FRAC_ADDI_4_t); \
  729. x3 += __FP_FRAC_ADDI_4_t; \
  730. } \
  731. while (0)
  732. #endif
  733. /* Convert FP values between word sizes. This appears to be more
  734. complicated than I'd have expected it to be, so these might be
  735. wrong... These macros are in any case somewhat bogus because they
  736. use information about what various FRAC_n variables look like
  737. internally [eg, that 2 word vars are X_f0 and x_f1]. But so do
  738. the ones in op-2.h and op-1.h. */
  739. #define _FP_FRAC_COPY_1_4(D, S) (D##_f = S##_f[0])
  740. #define _FP_FRAC_COPY_2_4(D, S) \
  741. do \
  742. { \
  743. D##_f0 = S##_f[0]; \
  744. D##_f1 = S##_f[1]; \
  745. } \
  746. while (0)
  747. /* Assembly/disassembly for converting to/from integral types.
  748. No shifting or overflow handled here. */
  749. /* Put the FP value X into r, which is an integer of size rsize. */
  750. #define _FP_FRAC_ASSEMBLE_4(r, X, rsize) \
  751. do \
  752. { \
  753. if ((rsize) <= _FP_W_TYPE_SIZE) \
  754. (r) = X##_f[0]; \
  755. else if ((rsize) <= 2*_FP_W_TYPE_SIZE) \
  756. { \
  757. (r) = X##_f[1]; \
  758. (r) = ((rsize) <= _FP_W_TYPE_SIZE \
  759. ? 0 \
  760. : (r) << _FP_W_TYPE_SIZE); \
  761. (r) += X##_f[0]; \
  762. } \
  763. else \
  764. { \
  765. /* I'm feeling lazy so we deal with int == 3words \
  766. (implausible) and int == 4words as a single case. */ \
  767. (r) = X##_f[3]; \
  768. (r) = ((rsize) <= _FP_W_TYPE_SIZE \
  769. ? 0 \
  770. : (r) << _FP_W_TYPE_SIZE); \
  771. (r) += X##_f[2]; \
  772. (r) = ((rsize) <= _FP_W_TYPE_SIZE \
  773. ? 0 \
  774. : (r) << _FP_W_TYPE_SIZE); \
  775. (r) += X##_f[1]; \
  776. (r) = ((rsize) <= _FP_W_TYPE_SIZE \
  777. ? 0 \
  778. : (r) << _FP_W_TYPE_SIZE); \
  779. (r) += X##_f[0]; \
  780. } \
  781. } \
  782. while (0)
  783. /* "No disassemble Number Five!" */
  784. /* Move an integer of size rsize into X's fractional part. We rely on
  785. the _f[] array consisting of words of size _FP_W_TYPE_SIZE to avoid
  786. having to mask the values we store into it. */
  787. #define _FP_FRAC_DISASSEMBLE_4(X, r, rsize) \
  788. do \
  789. { \
  790. X##_f[0] = (r); \
  791. X##_f[1] = ((rsize) <= _FP_W_TYPE_SIZE \
  792. ? 0 \
  793. : (r) >> _FP_W_TYPE_SIZE); \
  794. X##_f[2] = ((rsize) <= 2*_FP_W_TYPE_SIZE \
  795. ? 0 \
  796. : (r) >> 2*_FP_W_TYPE_SIZE); \
  797. X##_f[3] = ((rsize) <= 3*_FP_W_TYPE_SIZE \
  798. ? 0 \
  799. : (r) >> 3*_FP_W_TYPE_SIZE); \
  800. } \
  801. while (0)
  802. #define _FP_FRAC_COPY_4_1(D, S) \
  803. do \
  804. { \
  805. D##_f[0] = S##_f; \
  806. D##_f[1] = D##_f[2] = D##_f[3] = 0; \
  807. } \
  808. while (0)
  809. #define _FP_FRAC_COPY_4_2(D, S) \
  810. do \
  811. { \
  812. D##_f[0] = S##_f0; \
  813. D##_f[1] = S##_f1; \
  814. D##_f[2] = D##_f[3] = 0; \
  815. } \
  816. while (0)
  817. #define _FP_FRAC_COPY_4_4(D, S) _FP_FRAC_COPY_4 (D, S)
  818. #endif /* !SOFT_FP_OP_4_H */