dbl_float.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  3. *
  4. * Floating-point emulation code
  5. * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifdef __NO_PA_HDRS
  22. PA header file -- do not include this header file for non-PA builds.
  23. #endif
  24. /* 32-bit word grabbing functions */
  25. #define Dbl_firstword(value) Dallp1(value)
  26. #define Dbl_secondword(value) Dallp2(value)
  27. #define Dbl_thirdword(value) dummy_location
  28. #define Dbl_fourthword(value) dummy_location
  29. #define Dbl_sign(object) Dsign(object)
  30. #define Dbl_exponent(object) Dexponent(object)
  31. #define Dbl_signexponent(object) Dsignexponent(object)
  32. #define Dbl_mantissap1(object) Dmantissap1(object)
  33. #define Dbl_mantissap2(object) Dmantissap2(object)
  34. #define Dbl_exponentmantissap1(object) Dexponentmantissap1(object)
  35. #define Dbl_allp1(object) Dallp1(object)
  36. #define Dbl_allp2(object) Dallp2(object)
  37. /* dbl_and_signs ANDs the sign bits of each argument and puts the result
  38. * into the first argument. dbl_or_signs ors those same sign bits */
  39. #define Dbl_and_signs( src1dst, src2) \
  40. Dallp1(src1dst) = (Dallp1(src2)|~((unsigned int)1<<31)) & Dallp1(src1dst)
  41. #define Dbl_or_signs( src1dst, src2) \
  42. Dallp1(src1dst) = (Dallp1(src2)&((unsigned int)1<<31)) | Dallp1(src1dst)
  43. /* The hidden bit is always the low bit of the exponent */
  44. #define Dbl_clear_exponent_set_hidden(srcdst) Deposit_dexponent(srcdst,1)
  45. #define Dbl_clear_signexponent_set_hidden(srcdst) \
  46. Deposit_dsignexponent(srcdst,1)
  47. #define Dbl_clear_sign(srcdst) Dallp1(srcdst) &= ~((unsigned int)1<<31)
  48. #define Dbl_clear_signexponent(srcdst) \
  49. Dallp1(srcdst) &= Dmantissap1((unsigned int)-1)
  50. /* Exponent field for doubles has already been cleared and may be
  51. * included in the shift. Here we need to generate two double width
  52. * variable shifts. The insignificant bits can be ignored.
  53. * MTSAR f(varamount)
  54. * VSHD srcdst.high,srcdst.low => srcdst.low
  55. * VSHD 0,srcdst.high => srcdst.high
  56. * This is very difficult to model with C expressions since the shift amount
  57. * could exceed 32. */
  58. /* varamount must be less than 64 */
  59. #define Dbl_rightshift(srcdstA, srcdstB, varamount) \
  60. {if((varamount) >= 32) { \
  61. Dallp2(srcdstB) = Dallp1(srcdstA) >> (varamount-32); \
  62. Dallp1(srcdstA)=0; \
  63. } \
  64. else if(varamount > 0) { \
  65. Variable_shift_double(Dallp1(srcdstA), Dallp2(srcdstB), \
  66. (varamount), Dallp2(srcdstB)); \
  67. Dallp1(srcdstA) >>= varamount; \
  68. } }
  69. /* varamount must be less than 64 */
  70. #define Dbl_rightshift_exponentmantissa(srcdstA, srcdstB, varamount) \
  71. {if((varamount) >= 32) { \
  72. Dallp2(srcdstB) = Dexponentmantissap1(srcdstA) >> (varamount-32); \
  73. Dallp1(srcdstA) &= ((unsigned int)1<<31); /* clear expmant field */ \
  74. } \
  75. else if(varamount > 0) { \
  76. Variable_shift_double(Dexponentmantissap1(srcdstA), Dallp2(srcdstB), \
  77. (varamount), Dallp2(srcdstB)); \
  78. Deposit_dexponentmantissap1(srcdstA, \
  79. (Dexponentmantissap1(srcdstA)>>varamount)); \
  80. } }
  81. /* varamount must be less than 64 */
  82. #define Dbl_leftshift(srcdstA, srcdstB, varamount) \
  83. {if((varamount) >= 32) { \
  84. Dallp1(srcdstA) = Dallp2(srcdstB) << (varamount-32); \
  85. Dallp2(srcdstB)=0; \
  86. } \
  87. else { \
  88. if ((varamount) > 0) { \
  89. Dallp1(srcdstA) = (Dallp1(srcdstA) << (varamount)) | \
  90. (Dallp2(srcdstB) >> (32-(varamount))); \
  91. Dallp2(srcdstB) <<= varamount; \
  92. } \
  93. } }
  94. #define Dbl_leftshiftby1_withextent(lefta,leftb,right,resulta,resultb) \
  95. Shiftdouble(Dallp1(lefta), Dallp2(leftb), 31, Dallp1(resulta)); \
  96. Shiftdouble(Dallp2(leftb), Extall(right), 31, Dallp2(resultb))
  97. #define Dbl_rightshiftby1_withextent(leftb,right,dst) \
  98. Extall(dst) = (Dallp2(leftb) << 31) | ((unsigned int)Extall(right) >> 1) | \
  99. Extlow(right)
  100. #define Dbl_arithrightshiftby1(srcdstA,srcdstB) \
  101. Shiftdouble(Dallp1(srcdstA),Dallp2(srcdstB),1,Dallp2(srcdstB));\
  102. Dallp1(srcdstA) = (int)Dallp1(srcdstA) >> 1
  103. /* Sign extend the sign bit with an integer destination */
  104. #define Dbl_signextendedsign(value) Dsignedsign(value)
  105. #define Dbl_isone_hidden(dbl_value) (Is_dhidden(dbl_value)!=0)
  106. /* Singles and doubles may include the sign and exponent fields. The
  107. * hidden bit and the hidden overflow must be included. */
  108. #define Dbl_increment(dbl_valueA,dbl_valueB) \
  109. if( (Dallp2(dbl_valueB) += 1) == 0 ) Dallp1(dbl_valueA) += 1
  110. #define Dbl_increment_mantissa(dbl_valueA,dbl_valueB) \
  111. if( (Dmantissap2(dbl_valueB) += 1) == 0 ) \
  112. Deposit_dmantissap1(dbl_valueA,dbl_valueA+1)
  113. #define Dbl_decrement(dbl_valueA,dbl_valueB) \
  114. if( Dallp2(dbl_valueB) == 0 ) Dallp1(dbl_valueA) -= 1; \
  115. Dallp2(dbl_valueB) -= 1
  116. #define Dbl_isone_sign(dbl_value) (Is_dsign(dbl_value)!=0)
  117. #define Dbl_isone_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)!=0)
  118. #define Dbl_isone_lowmantissap1(dbl_valueA) (Is_dlowp1(dbl_valueA)!=0)
  119. #define Dbl_isone_lowmantissap2(dbl_valueB) (Is_dlowp2(dbl_valueB)!=0)
  120. #define Dbl_isone_signaling(dbl_value) (Is_dsignaling(dbl_value)!=0)
  121. #define Dbl_is_signalingnan(dbl_value) (Dsignalingnan(dbl_value)==0xfff)
  122. #define Dbl_isnotzero(dbl_valueA,dbl_valueB) \
  123. (Dallp1(dbl_valueA) || Dallp2(dbl_valueB))
  124. #define Dbl_isnotzero_hiddenhigh7mantissa(dbl_value) \
  125. (Dhiddenhigh7mantissa(dbl_value)!=0)
  126. #define Dbl_isnotzero_exponent(dbl_value) (Dexponent(dbl_value)!=0)
  127. #define Dbl_isnotzero_mantissa(dbl_valueA,dbl_valueB) \
  128. (Dmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))
  129. #define Dbl_isnotzero_mantissap1(dbl_valueA) (Dmantissap1(dbl_valueA)!=0)
  130. #define Dbl_isnotzero_mantissap2(dbl_valueB) (Dmantissap2(dbl_valueB)!=0)
  131. #define Dbl_isnotzero_exponentmantissa(dbl_valueA,dbl_valueB) \
  132. (Dexponentmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))
  133. #define Dbl_isnotzero_low4p2(dbl_value) (Dlow4p2(dbl_value)!=0)
  134. #define Dbl_iszero(dbl_valueA,dbl_valueB) (Dallp1(dbl_valueA)==0 && \
  135. Dallp2(dbl_valueB)==0)
  136. #define Dbl_iszero_allp1(dbl_value) (Dallp1(dbl_value)==0)
  137. #define Dbl_iszero_allp2(dbl_value) (Dallp2(dbl_value)==0)
  138. #define Dbl_iszero_hidden(dbl_value) (Is_dhidden(dbl_value)==0)
  139. #define Dbl_iszero_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)==0)
  140. #define Dbl_iszero_hiddenhigh3mantissa(dbl_value) \
  141. (Dhiddenhigh3mantissa(dbl_value)==0)
  142. #define Dbl_iszero_hiddenhigh7mantissa(dbl_value) \
  143. (Dhiddenhigh7mantissa(dbl_value)==0)
  144. #define Dbl_iszero_sign(dbl_value) (Is_dsign(dbl_value)==0)
  145. #define Dbl_iszero_exponent(dbl_value) (Dexponent(dbl_value)==0)
  146. #define Dbl_iszero_mantissa(dbl_valueA,dbl_valueB) \
  147. (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
  148. #define Dbl_iszero_exponentmantissa(dbl_valueA,dbl_valueB) \
  149. (Dexponentmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
  150. #define Dbl_isinfinity_exponent(dbl_value) \
  151. (Dexponent(dbl_value)==DBL_INFINITY_EXPONENT)
  152. #define Dbl_isnotinfinity_exponent(dbl_value) \
  153. (Dexponent(dbl_value)!=DBL_INFINITY_EXPONENT)
  154. #define Dbl_isinfinity(dbl_valueA,dbl_valueB) \
  155. (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \
  156. Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)
  157. #define Dbl_isnan(dbl_valueA,dbl_valueB) \
  158. (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \
  159. (Dmantissap1(dbl_valueA)!=0 || Dmantissap2(dbl_valueB)!=0))
  160. #define Dbl_isnotnan(dbl_valueA,dbl_valueB) \
  161. (Dexponent(dbl_valueA)!=DBL_INFINITY_EXPONENT || \
  162. (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0))
  163. #define Dbl_islessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
  164. (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \
  165. (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
  166. Dallp2(dbl_op1b) < Dallp2(dbl_op2b)))
  167. #define Dbl_isgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
  168. (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \
  169. (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
  170. Dallp2(dbl_op1b) > Dallp2(dbl_op2b)))
  171. #define Dbl_isnotlessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
  172. (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \
  173. (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
  174. Dallp2(dbl_op1b) >= Dallp2(dbl_op2b)))
  175. #define Dbl_isnotgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
  176. (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \
  177. (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \
  178. Dallp2(dbl_op1b) <= Dallp2(dbl_op2b)))
  179. #define Dbl_isequal(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \
  180. ((Dallp1(dbl_op1a) == Dallp1(dbl_op2a)) && \
  181. (Dallp2(dbl_op1b) == Dallp2(dbl_op2b)))
  182. #define Dbl_leftshiftby8(dbl_valueA,dbl_valueB) \
  183. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),24,Dallp1(dbl_valueA)); \
  184. Dallp2(dbl_valueB) <<= 8
  185. #define Dbl_leftshiftby7(dbl_valueA,dbl_valueB) \
  186. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),25,Dallp1(dbl_valueA)); \
  187. Dallp2(dbl_valueB) <<= 7
  188. #define Dbl_leftshiftby4(dbl_valueA,dbl_valueB) \
  189. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),28,Dallp1(dbl_valueA)); \
  190. Dallp2(dbl_valueB) <<= 4
  191. #define Dbl_leftshiftby3(dbl_valueA,dbl_valueB) \
  192. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),29,Dallp1(dbl_valueA)); \
  193. Dallp2(dbl_valueB) <<= 3
  194. #define Dbl_leftshiftby2(dbl_valueA,dbl_valueB) \
  195. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),30,Dallp1(dbl_valueA)); \
  196. Dallp2(dbl_valueB) <<= 2
  197. #define Dbl_leftshiftby1(dbl_valueA,dbl_valueB) \
  198. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),31,Dallp1(dbl_valueA)); \
  199. Dallp2(dbl_valueB) <<= 1
  200. #define Dbl_rightshiftby8(dbl_valueA,dbl_valueB) \
  201. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),8,Dallp2(dbl_valueB)); \
  202. Dallp1(dbl_valueA) >>= 8
  203. #define Dbl_rightshiftby4(dbl_valueA,dbl_valueB) \
  204. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),4,Dallp2(dbl_valueB)); \
  205. Dallp1(dbl_valueA) >>= 4
  206. #define Dbl_rightshiftby2(dbl_valueA,dbl_valueB) \
  207. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),2,Dallp2(dbl_valueB)); \
  208. Dallp1(dbl_valueA) >>= 2
  209. #define Dbl_rightshiftby1(dbl_valueA,dbl_valueB) \
  210. Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),1,Dallp2(dbl_valueB)); \
  211. Dallp1(dbl_valueA) >>= 1
  212. /* This magnitude comparison uses the signless first words and
  213. * the regular part2 words. The comparison is graphically:
  214. *
  215. * 1st greater? -------------
  216. * |
  217. * 1st less?-----------------+---------
  218. * | |
  219. * 2nd greater or equal----->| |
  220. * False True
  221. */
  222. #define Dbl_ismagnitudeless(leftB,rightB,signlessleft,signlessright) \
  223. ((signlessleft <= signlessright) && \
  224. ( (signlessleft < signlessright) || (Dallp2(leftB)<Dallp2(rightB)) ))
  225. #define Dbl_copytoint_exponentmantissap1(src,dest) \
  226. dest = Dexponentmantissap1(src)
  227. /* A quiet NaN has the high mantissa bit clear and at least on other (in this
  228. * case the adjacent bit) bit set. */
  229. #define Dbl_set_quiet(dbl_value) Deposit_dhigh2mantissa(dbl_value,1)
  230. #define Dbl_set_exponent(dbl_value, exp) Deposit_dexponent(dbl_value,exp)
  231. #define Dbl_set_mantissa(desta,destb,valuea,valueb) \
  232. Deposit_dmantissap1(desta,valuea); \
  233. Dmantissap2(destb) = Dmantissap2(valueb)
  234. #define Dbl_set_mantissap1(desta,valuea) \
  235. Deposit_dmantissap1(desta,valuea)
  236. #define Dbl_set_mantissap2(destb,valueb) \
  237. Dmantissap2(destb) = Dmantissap2(valueb)
  238. #define Dbl_set_exponentmantissa(desta,destb,valuea,valueb) \
  239. Deposit_dexponentmantissap1(desta,valuea); \
  240. Dmantissap2(destb) = Dmantissap2(valueb)
  241. #define Dbl_set_exponentmantissap1(dest,value) \
  242. Deposit_dexponentmantissap1(dest,value)
  243. #define Dbl_copyfromptr(src,desta,destb) \
  244. Dallp1(desta) = src->wd0; \
  245. Dallp2(destb) = src->wd1
  246. #define Dbl_copytoptr(srca,srcb,dest) \
  247. dest->wd0 = Dallp1(srca); \
  248. dest->wd1 = Dallp2(srcb)
  249. /* An infinity is represented with the max exponent and a zero mantissa */
  250. #define Dbl_setinfinity_exponent(dbl_value) \
  251. Deposit_dexponent(dbl_value,DBL_INFINITY_EXPONENT)
  252. #define Dbl_setinfinity_exponentmantissa(dbl_valueA,dbl_valueB) \
  253. Deposit_dexponentmantissap1(dbl_valueA, \
  254. (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH)))); \
  255. Dmantissap2(dbl_valueB) = 0
  256. #define Dbl_setinfinitypositive(dbl_valueA,dbl_valueB) \
  257. Dallp1(dbl_valueA) \
  258. = (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
  259. Dmantissap2(dbl_valueB) = 0
  260. #define Dbl_setinfinitynegative(dbl_valueA,dbl_valueB) \
  261. Dallp1(dbl_valueA) = ((unsigned int)1<<31) | \
  262. (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
  263. Dmantissap2(dbl_valueB) = 0
  264. #define Dbl_setinfinity(dbl_valueA,dbl_valueB,sign) \
  265. Dallp1(dbl_valueA) = ((unsigned int)sign << 31) | \
  266. (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \
  267. Dmantissap2(dbl_valueB) = 0
  268. #define Dbl_sethigh4bits(dbl_value, extsign) Deposit_dhigh4p1(dbl_value,extsign)
  269. #define Dbl_set_sign(dbl_value,sign) Deposit_dsign(dbl_value,sign)
  270. #define Dbl_invert_sign(dbl_value) Deposit_dsign(dbl_value,~Dsign(dbl_value))
  271. #define Dbl_setone_sign(dbl_value) Deposit_dsign(dbl_value,1)
  272. #define Dbl_setone_lowmantissap2(dbl_value) Deposit_dlowp2(dbl_value,1)
  273. #define Dbl_setzero_sign(dbl_value) Dallp1(dbl_value) &= 0x7fffffff
  274. #define Dbl_setzero_exponent(dbl_value) \
  275. Dallp1(dbl_value) &= 0x800fffff
  276. #define Dbl_setzero_mantissa(dbl_valueA,dbl_valueB) \
  277. Dallp1(dbl_valueA) &= 0xfff00000; \
  278. Dallp2(dbl_valueB) = 0
  279. #define Dbl_setzero_mantissap1(dbl_value) Dallp1(dbl_value) &= 0xfff00000
  280. #define Dbl_setzero_mantissap2(dbl_value) Dallp2(dbl_value) = 0
  281. #define Dbl_setzero_exponentmantissa(dbl_valueA,dbl_valueB) \
  282. Dallp1(dbl_valueA) &= 0x80000000; \
  283. Dallp2(dbl_valueB) = 0
  284. #define Dbl_setzero_exponentmantissap1(dbl_valueA) \
  285. Dallp1(dbl_valueA) &= 0x80000000
  286. #define Dbl_setzero(dbl_valueA,dbl_valueB) \
  287. Dallp1(dbl_valueA) = 0; Dallp2(dbl_valueB) = 0
  288. #define Dbl_setzerop1(dbl_value) Dallp1(dbl_value) = 0
  289. #define Dbl_setzerop2(dbl_value) Dallp2(dbl_value) = 0
  290. #define Dbl_setnegativezero(dbl_value) \
  291. Dallp1(dbl_value) = (unsigned int)1 << 31; Dallp2(dbl_value) = 0
  292. #define Dbl_setnegativezerop1(dbl_value) Dallp1(dbl_value) = (unsigned int)1<<31
  293. /* Use the following macro for both overflow & underflow conditions */
  294. #define ovfl -
  295. #define unfl +
  296. #define Dbl_setwrapped_exponent(dbl_value,exponent,op) \
  297. Deposit_dexponent(dbl_value,(exponent op DBL_WRAP))
  298. #define Dbl_setlargestpositive(dbl_valueA,dbl_valueB) \
  299. Dallp1(dbl_valueA) = ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
  300. | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ); \
  301. Dallp2(dbl_valueB) = 0xFFFFFFFF
  302. #define Dbl_setlargestnegative(dbl_valueA,dbl_valueB) \
  303. Dallp1(dbl_valueA) = ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
  304. | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ) \
  305. | ((unsigned int)1<<31); \
  306. Dallp2(dbl_valueB) = 0xFFFFFFFF
  307. #define Dbl_setlargest_exponentmantissa(dbl_valueA,dbl_valueB) \
  308. Deposit_dexponentmantissap1(dbl_valueA, \
  309. (((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) \
  310. | ((1<<(32-(1+DBL_EXP_LENGTH))) - 1 ))); \
  311. Dallp2(dbl_valueB) = 0xFFFFFFFF
  312. #define Dbl_setnegativeinfinity(dbl_valueA,dbl_valueB) \
  313. Dallp1(dbl_valueA) = ((1<<DBL_EXP_LENGTH) | DBL_INFINITY_EXPONENT) \
  314. << (32-(1+DBL_EXP_LENGTH)) ; \
  315. Dallp2(dbl_valueB) = 0
  316. #define Dbl_setlargest(dbl_valueA,dbl_valueB,sign) \
  317. Dallp1(dbl_valueA) = ((unsigned int)sign << 31) | \
  318. ((DBL_EMAX+DBL_BIAS) << (32-(1+DBL_EXP_LENGTH))) | \
  319. ((1 << (32-(1+DBL_EXP_LENGTH))) - 1 ); \
  320. Dallp2(dbl_valueB) = 0xFFFFFFFF
  321. /* The high bit is always zero so arithmetic or logical shifts will work. */
  322. #define Dbl_right_align(srcdstA,srcdstB,shift,extent) \
  323. if( shift >= 32 ) \
  324. { \
  325. /* Big shift requires examining the portion shift off \
  326. the end to properly set inexact. */ \
  327. if(shift < 64) \
  328. { \
  329. if(shift > 32) \
  330. { \
  331. Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB), \
  332. shift-32, Extall(extent)); \
  333. if(Dallp2(srcdstB) << 64 - (shift)) Ext_setone_low(extent); \
  334. } \
  335. else Extall(extent) = Dallp2(srcdstB); \
  336. Dallp2(srcdstB) = Dallp1(srcdstA) >> (shift - 32); \
  337. } \
  338. else \
  339. { \
  340. Extall(extent) = Dallp1(srcdstA); \
  341. if(Dallp2(srcdstB)) Ext_setone_low(extent); \
  342. Dallp2(srcdstB) = 0; \
  343. } \
  344. Dallp1(srcdstA) = 0; \
  345. } \
  346. else \
  347. { \
  348. /* Small alignment is simpler. Extension is easily set. */ \
  349. if (shift > 0) \
  350. { \
  351. Extall(extent) = Dallp2(srcdstB) << 32 - (shift); \
  352. Variable_shift_double(Dallp1(srcdstA),Dallp2(srcdstB),shift, \
  353. Dallp2(srcdstB)); \
  354. Dallp1(srcdstA) >>= shift; \
  355. } \
  356. else Extall(extent) = 0; \
  357. }
  358. /*
  359. * Here we need to shift the result right to correct for an overshift
  360. * (due to the exponent becoming negative) during normalization.
  361. */
  362. #define Dbl_fix_overshift(srcdstA,srcdstB,shift,extent) \
  363. Extall(extent) = Dallp2(srcdstB) << 32 - (shift); \
  364. Dallp2(srcdstB) = (Dallp1(srcdstA) << 32 - (shift)) | \
  365. (Dallp2(srcdstB) >> (shift)); \
  366. Dallp1(srcdstA) = Dallp1(srcdstA) >> shift
  367. #define Dbl_hiddenhigh3mantissa(dbl_value) Dhiddenhigh3mantissa(dbl_value)
  368. #define Dbl_hidden(dbl_value) Dhidden(dbl_value)
  369. #define Dbl_lowmantissap2(dbl_value) Dlowp2(dbl_value)
  370. /* The left argument is never smaller than the right argument */
  371. #define Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb) \
  372. if( Dallp2(rightb) > Dallp2(leftb) ) Dallp1(lefta)--; \
  373. Dallp2(resultb) = Dallp2(leftb) - Dallp2(rightb); \
  374. Dallp1(resulta) = Dallp1(lefta) - Dallp1(righta)
  375. /* Subtract right augmented with extension from left augmented with zeros and
  376. * store into result and extension. */
  377. #define Dbl_subtract_withextension(lefta,leftb,righta,rightb,extent,resulta,resultb) \
  378. Dbl_subtract(lefta,leftb,righta,rightb,resulta,resultb); \
  379. if( (Extall(extent) = 0-Extall(extent)) ) \
  380. { \
  381. if((Dallp2(resultb)--) == 0) Dallp1(resulta)--; \
  382. }
  383. #define Dbl_addition(lefta,leftb,righta,rightb,resulta,resultb) \
  384. /* If the sum of the low words is less than either source, then \
  385. * an overflow into the next word occurred. */ \
  386. Dallp1(resulta) = Dallp1(lefta) + Dallp1(righta); \
  387. if((Dallp2(resultb) = Dallp2(leftb) + Dallp2(rightb)) < Dallp2(rightb)) \
  388. Dallp1(resulta)++
  389. #define Dbl_xortointp1(left,right,result) \
  390. result = Dallp1(left) XOR Dallp1(right)
  391. #define Dbl_xorfromintp1(left,right,result) \
  392. Dallp1(result) = left XOR Dallp1(right)
  393. #define Dbl_swap_lower(left,right) \
  394. Dallp2(left) = Dallp2(left) XOR Dallp2(right); \
  395. Dallp2(right) = Dallp2(left) XOR Dallp2(right); \
  396. Dallp2(left) = Dallp2(left) XOR Dallp2(right)
  397. /* Need to Initialize */
  398. #define Dbl_makequietnan(desta,destb) \
  399. Dallp1(desta) = ((DBL_EMAX+DBL_BIAS)+1)<< (32-(1+DBL_EXP_LENGTH)) \
  400. | (1<<(32-(1+DBL_EXP_LENGTH+2))); \
  401. Dallp2(destb) = 0
  402. #define Dbl_makesignalingnan(desta,destb) \
  403. Dallp1(desta) = ((DBL_EMAX+DBL_BIAS)+1)<< (32-(1+DBL_EXP_LENGTH)) \
  404. | (1<<(32-(1+DBL_EXP_LENGTH+1))); \
  405. Dallp2(destb) = 0
  406. #define Dbl_normalize(dbl_opndA,dbl_opndB,exponent) \
  407. while(Dbl_iszero_hiddenhigh7mantissa(dbl_opndA)) { \
  408. Dbl_leftshiftby8(dbl_opndA,dbl_opndB); \
  409. exponent -= 8; \
  410. } \
  411. if(Dbl_iszero_hiddenhigh3mantissa(dbl_opndA)) { \
  412. Dbl_leftshiftby4(dbl_opndA,dbl_opndB); \
  413. exponent -= 4; \
  414. } \
  415. while(Dbl_iszero_hidden(dbl_opndA)) { \
  416. Dbl_leftshiftby1(dbl_opndA,dbl_opndB); \
  417. exponent -= 1; \
  418. }
  419. #define Twoword_add(src1dstA,src1dstB,src2A,src2B) \
  420. /* \
  421. * want this macro to generate: \
  422. * ADD src1dstB,src2B,src1dstB; \
  423. * ADDC src1dstA,src2A,src1dstA; \
  424. */ \
  425. if ((src1dstB) + (src2B) < (src1dstB)) Dallp1(src1dstA)++; \
  426. Dallp1(src1dstA) += (src2A); \
  427. Dallp2(src1dstB) += (src2B)
  428. #define Twoword_subtract(src1dstA,src1dstB,src2A,src2B) \
  429. /* \
  430. * want this macro to generate: \
  431. * SUB src1dstB,src2B,src1dstB; \
  432. * SUBB src1dstA,src2A,src1dstA; \
  433. */ \
  434. if ((src1dstB) < (src2B)) Dallp1(src1dstA)--; \
  435. Dallp1(src1dstA) -= (src2A); \
  436. Dallp2(src1dstB) -= (src2B)
  437. #define Dbl_setoverflow(resultA,resultB) \
  438. /* set result to infinity or largest number */ \
  439. switch (Rounding_mode()) { \
  440. case ROUNDPLUS: \
  441. if (Dbl_isone_sign(resultA)) { \
  442. Dbl_setlargestnegative(resultA,resultB); \
  443. } \
  444. else { \
  445. Dbl_setinfinitypositive(resultA,resultB); \
  446. } \
  447. break; \
  448. case ROUNDMINUS: \
  449. if (Dbl_iszero_sign(resultA)) { \
  450. Dbl_setlargestpositive(resultA,resultB); \
  451. } \
  452. else { \
  453. Dbl_setinfinitynegative(resultA,resultB); \
  454. } \
  455. break; \
  456. case ROUNDNEAREST: \
  457. Dbl_setinfinity_exponentmantissa(resultA,resultB); \
  458. break; \
  459. case ROUNDZERO: \
  460. Dbl_setlargest_exponentmantissa(resultA,resultB); \
  461. }
  462. #define Dbl_denormalize(opndp1,opndp2,exponent,guard,sticky,inexact) \
  463. Dbl_clear_signexponent_set_hidden(opndp1); \
  464. if (exponent >= (1-DBL_P)) { \
  465. if (exponent >= -31) { \
  466. guard = (Dallp2(opndp2) >> -exponent) & 1; \
  467. if (exponent < 0) sticky |= Dallp2(opndp2) << (32+exponent); \
  468. if (exponent > -31) { \
  469. Variable_shift_double(opndp1,opndp2,1-exponent,opndp2); \
  470. Dallp1(opndp1) >>= 1-exponent; \
  471. } \
  472. else { \
  473. Dallp2(opndp2) = Dallp1(opndp1); \
  474. Dbl_setzerop1(opndp1); \
  475. } \
  476. } \
  477. else { \
  478. guard = (Dallp1(opndp1) >> -32-exponent) & 1; \
  479. if (exponent == -32) sticky |= Dallp2(opndp2); \
  480. else sticky |= (Dallp2(opndp2) | Dallp1(opndp1) << 64+exponent); \
  481. Dallp2(opndp2) = Dallp1(opndp1) >> -31-exponent; \
  482. Dbl_setzerop1(opndp1); \
  483. } \
  484. inexact = guard | sticky; \
  485. } \
  486. else { \
  487. guard = 0; \
  488. sticky |= (Dallp1(opndp1) | Dallp2(opndp2)); \
  489. Dbl_setzero(opndp1,opndp2); \
  490. inexact = sticky; \
  491. }
  492. /*
  493. * The fused multiply add instructions requires a double extended format,
  494. * with 106 bits of mantissa.
  495. */
  496. #define DBLEXT_THRESHOLD 106
  497. #define Dblext_setzero(valA,valB,valC,valD) \
  498. Dextallp1(valA) = 0; Dextallp2(valB) = 0; \
  499. Dextallp3(valC) = 0; Dextallp4(valD) = 0
  500. #define Dblext_isnotzero_mantissap3(valC) (Dextallp3(valC)!=0)
  501. #define Dblext_isnotzero_mantissap4(valD) (Dextallp3(valD)!=0)
  502. #define Dblext_isone_lowp2(val) (Dextlowp2(val)!=0)
  503. #define Dblext_isone_highp3(val) (Dexthighp3(val)!=0)
  504. #define Dblext_isnotzero_low31p3(val) (Dextlow31p3(val)!=0)
  505. #define Dblext_iszero(valA,valB,valC,valD) (Dextallp1(valA)==0 && \
  506. Dextallp2(valB)==0 && Dextallp3(valC)==0 && Dextallp4(valD)==0)
  507. #define Dblext_copy(srca,srcb,srcc,srcd,desta,destb,destc,destd) \
  508. Dextallp1(desta) = Dextallp4(srca); \
  509. Dextallp2(destb) = Dextallp4(srcb); \
  510. Dextallp3(destc) = Dextallp4(srcc); \
  511. Dextallp4(destd) = Dextallp4(srcd)
  512. #define Dblext_swap_lower(leftp2,leftp3,leftp4,rightp2,rightp3,rightp4) \
  513. Dextallp2(leftp2) = Dextallp2(leftp2) XOR Dextallp2(rightp2); \
  514. Dextallp2(rightp2) = Dextallp2(leftp2) XOR Dextallp2(rightp2); \
  515. Dextallp2(leftp2) = Dextallp2(leftp2) XOR Dextallp2(rightp2); \
  516. Dextallp3(leftp3) = Dextallp3(leftp3) XOR Dextallp3(rightp3); \
  517. Dextallp3(rightp3) = Dextallp3(leftp3) XOR Dextallp3(rightp3); \
  518. Dextallp3(leftp3) = Dextallp3(leftp3) XOR Dextallp3(rightp3); \
  519. Dextallp4(leftp4) = Dextallp4(leftp4) XOR Dextallp4(rightp4); \
  520. Dextallp4(rightp4) = Dextallp4(leftp4) XOR Dextallp4(rightp4); \
  521. Dextallp4(leftp4) = Dextallp4(leftp4) XOR Dextallp4(rightp4)
  522. #define Dblext_setone_lowmantissap4(dbl_value) Deposit_dextlowp4(dbl_value,1)
  523. /* The high bit is always zero so arithmetic or logical shifts will work. */
  524. #define Dblext_right_align(srcdstA,srcdstB,srcdstC,srcdstD,shift) \
  525. {int shiftamt, sticky; \
  526. shiftamt = shift % 32; \
  527. sticky = 0; \
  528. switch (shift/32) { \
  529. case 0: if (shiftamt > 0) { \
  530. sticky = Dextallp4(srcdstD) << 32 - (shiftamt); \
  531. Variable_shift_double(Dextallp3(srcdstC), \
  532. Dextallp4(srcdstD),shiftamt,Dextallp4(srcdstD)); \
  533. Variable_shift_double(Dextallp2(srcdstB), \
  534. Dextallp3(srcdstC),shiftamt,Dextallp3(srcdstC)); \
  535. Variable_shift_double(Dextallp1(srcdstA), \
  536. Dextallp2(srcdstB),shiftamt,Dextallp2(srcdstB)); \
  537. Dextallp1(srcdstA) >>= shiftamt; \
  538. } \
  539. break; \
  540. case 1: if (shiftamt > 0) { \
  541. sticky = (Dextallp3(srcdstC) << 31 - shiftamt) | \
  542. Dextallp4(srcdstD); \
  543. Variable_shift_double(Dextallp2(srcdstB), \
  544. Dextallp3(srcdstC),shiftamt,Dextallp4(srcdstD)); \
  545. Variable_shift_double(Dextallp1(srcdstA), \
  546. Dextallp2(srcdstB),shiftamt,Dextallp3(srcdstC)); \
  547. } \
  548. else { \
  549. sticky = Dextallp4(srcdstD); \
  550. Dextallp4(srcdstD) = Dextallp3(srcdstC); \
  551. Dextallp3(srcdstC) = Dextallp2(srcdstB); \
  552. } \
  553. Dextallp2(srcdstB) = Dextallp1(srcdstA) >> shiftamt; \
  554. Dextallp1(srcdstA) = 0; \
  555. break; \
  556. case 2: if (shiftamt > 0) { \
  557. sticky = (Dextallp2(srcdstB) << 31 - shiftamt) | \
  558. Dextallp3(srcdstC) | Dextallp4(srcdstD); \
  559. Variable_shift_double(Dextallp1(srcdstA), \
  560. Dextallp2(srcdstB),shiftamt,Dextallp4(srcdstD)); \
  561. } \
  562. else { \
  563. sticky = Dextallp3(srcdstC) | Dextallp4(srcdstD); \
  564. Dextallp4(srcdstD) = Dextallp2(srcdstB); \
  565. } \
  566. Dextallp3(srcdstC) = Dextallp1(srcdstA) >> shiftamt; \
  567. Dextallp1(srcdstA) = Dextallp2(srcdstB) = 0; \
  568. break; \
  569. case 3: if (shiftamt > 0) { \
  570. sticky = (Dextallp1(srcdstA) << 31 - shiftamt) | \
  571. Dextallp2(srcdstB) | Dextallp3(srcdstC) | \
  572. Dextallp4(srcdstD); \
  573. } \
  574. else { \
  575. sticky = Dextallp2(srcdstB) | Dextallp3(srcdstC) | \
  576. Dextallp4(srcdstD); \
  577. } \
  578. Dextallp4(srcdstD) = Dextallp1(srcdstA) >> shiftamt; \
  579. Dextallp1(srcdstA) = Dextallp2(srcdstB) = 0; \
  580. Dextallp3(srcdstC) = 0; \
  581. break; \
  582. } \
  583. if (sticky) Dblext_setone_lowmantissap4(srcdstD); \
  584. }
  585. /* The left argument is never smaller than the right argument */
  586. #define Dblext_subtract(lefta,leftb,leftc,leftd,righta,rightb,rightc,rightd,resulta,resultb,resultc,resultd) \
  587. if( Dextallp4(rightd) > Dextallp4(leftd) ) \
  588. if( (Dextallp3(leftc)--) == 0) \
  589. if( (Dextallp2(leftb)--) == 0) Dextallp1(lefta)--; \
  590. Dextallp4(resultd) = Dextallp4(leftd) - Dextallp4(rightd); \
  591. if( Dextallp3(rightc) > Dextallp3(leftc) ) \
  592. if( (Dextallp2(leftb)--) == 0) Dextallp1(lefta)--; \
  593. Dextallp3(resultc) = Dextallp3(leftc) - Dextallp3(rightc); \
  594. if( Dextallp2(rightb) > Dextallp2(leftb) ) Dextallp1(lefta)--; \
  595. Dextallp2(resultb) = Dextallp2(leftb) - Dextallp2(rightb); \
  596. Dextallp1(resulta) = Dextallp1(lefta) - Dextallp1(righta)
  597. #define Dblext_addition(lefta,leftb,leftc,leftd,righta,rightb,rightc,rightd,resulta,resultb,resultc,resultd) \
  598. /* If the sum of the low words is less than either source, then \
  599. * an overflow into the next word occurred. */ \
  600. if ((Dextallp4(resultd) = Dextallp4(leftd)+Dextallp4(rightd)) < \
  601. Dextallp4(rightd)) \
  602. if((Dextallp3(resultc) = Dextallp3(leftc)+Dextallp3(rightc)+1) <= \
  603. Dextallp3(rightc)) \
  604. if((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)+1) \
  605. <= Dextallp2(rightb)) \
  606. Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
  607. else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta); \
  608. else \
  609. if ((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)) < \
  610. Dextallp2(rightb)) \
  611. Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
  612. else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta); \
  613. else \
  614. if ((Dextallp3(resultc) = Dextallp3(leftc)+Dextallp3(rightc)) < \
  615. Dextallp3(rightc)) \
  616. if ((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)+1) \
  617. <= Dextallp2(rightb)) \
  618. Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
  619. else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta); \
  620. else \
  621. if ((Dextallp2(resultb) = Dextallp2(leftb)+Dextallp2(rightb)) < \
  622. Dextallp2(rightb)) \
  623. Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)+1; \
  624. else Dextallp1(resulta) = Dextallp1(lefta)+Dextallp1(righta)
  625. #define Dblext_arithrightshiftby1(srcdstA,srcdstB,srcdstC,srcdstD) \
  626. Shiftdouble(Dextallp3(srcdstC),Dextallp4(srcdstD),1,Dextallp4(srcdstD)); \
  627. Shiftdouble(Dextallp2(srcdstB),Dextallp3(srcdstC),1,Dextallp3(srcdstC)); \
  628. Shiftdouble(Dextallp1(srcdstA),Dextallp2(srcdstB),1,Dextallp2(srcdstB)); \
  629. Dextallp1(srcdstA) = (int)Dextallp1(srcdstA) >> 1
  630. #define Dblext_leftshiftby8(valA,valB,valC,valD) \
  631. Shiftdouble(Dextallp1(valA),Dextallp2(valB),24,Dextallp1(valA)); \
  632. Shiftdouble(Dextallp2(valB),Dextallp3(valC),24,Dextallp2(valB)); \
  633. Shiftdouble(Dextallp3(valC),Dextallp4(valD),24,Dextallp3(valC)); \
  634. Dextallp4(valD) <<= 8
  635. #define Dblext_leftshiftby4(valA,valB,valC,valD) \
  636. Shiftdouble(Dextallp1(valA),Dextallp2(valB),28,Dextallp1(valA)); \
  637. Shiftdouble(Dextallp2(valB),Dextallp3(valC),28,Dextallp2(valB)); \
  638. Shiftdouble(Dextallp3(valC),Dextallp4(valD),28,Dextallp3(valC)); \
  639. Dextallp4(valD) <<= 4
  640. #define Dblext_leftshiftby3(valA,valB,valC,valD) \
  641. Shiftdouble(Dextallp1(valA),Dextallp2(valB),29,Dextallp1(valA)); \
  642. Shiftdouble(Dextallp2(valB),Dextallp3(valC),29,Dextallp2(valB)); \
  643. Shiftdouble(Dextallp3(valC),Dextallp4(valD),29,Dextallp3(valC)); \
  644. Dextallp4(valD) <<= 3
  645. #define Dblext_leftshiftby2(valA,valB,valC,valD) \
  646. Shiftdouble(Dextallp1(valA),Dextallp2(valB),30,Dextallp1(valA)); \
  647. Shiftdouble(Dextallp2(valB),Dextallp3(valC),30,Dextallp2(valB)); \
  648. Shiftdouble(Dextallp3(valC),Dextallp4(valD),30,Dextallp3(valC)); \
  649. Dextallp4(valD) <<= 2
  650. #define Dblext_leftshiftby1(valA,valB,valC,valD) \
  651. Shiftdouble(Dextallp1(valA),Dextallp2(valB),31,Dextallp1(valA)); \
  652. Shiftdouble(Dextallp2(valB),Dextallp3(valC),31,Dextallp2(valB)); \
  653. Shiftdouble(Dextallp3(valC),Dextallp4(valD),31,Dextallp3(valC)); \
  654. Dextallp4(valD) <<= 1
  655. #define Dblext_rightshiftby4(valueA,valueB,valueC,valueD) \
  656. Shiftdouble(Dextallp3(valueC),Dextallp4(valueD),4,Dextallp4(valueD)); \
  657. Shiftdouble(Dextallp2(valueB),Dextallp3(valueC),4,Dextallp3(valueC)); \
  658. Shiftdouble(Dextallp1(valueA),Dextallp2(valueB),4,Dextallp2(valueB)); \
  659. Dextallp1(valueA) >>= 4
  660. #define Dblext_rightshiftby1(valueA,valueB,valueC,valueD) \
  661. Shiftdouble(Dextallp3(valueC),Dextallp4(valueD),1,Dextallp4(valueD)); \
  662. Shiftdouble(Dextallp2(valueB),Dextallp3(valueC),1,Dextallp3(valueC)); \
  663. Shiftdouble(Dextallp1(valueA),Dextallp2(valueB),1,Dextallp2(valueB)); \
  664. Dextallp1(valueA) >>= 1
  665. #define Dblext_xortointp1(left,right,result) Dbl_xortointp1(left,right,result)
  666. #define Dblext_xorfromintp1(left,right,result) \
  667. Dbl_xorfromintp1(left,right,result)
  668. #define Dblext_copytoint_exponentmantissap1(src,dest) \
  669. Dbl_copytoint_exponentmantissap1(src,dest)
  670. #define Dblext_ismagnitudeless(leftB,rightB,signlessleft,signlessright) \
  671. Dbl_ismagnitudeless(leftB,rightB,signlessleft,signlessright)
  672. #define Dbl_copyto_dblext(src1,src2,dest1,dest2,dest3,dest4) \
  673. Dextallp1(dest1) = Dallp1(src1); Dextallp2(dest2) = Dallp2(src2); \
  674. Dextallp3(dest3) = 0; Dextallp4(dest4) = 0
  675. #define Dblext_set_sign(dbl_value,sign) Dbl_set_sign(dbl_value,sign)
  676. #define Dblext_clear_signexponent_set_hidden(srcdst) \
  677. Dbl_clear_signexponent_set_hidden(srcdst)
  678. #define Dblext_clear_signexponent(srcdst) Dbl_clear_signexponent(srcdst)
  679. #define Dblext_clear_sign(srcdst) Dbl_clear_sign(srcdst)
  680. #define Dblext_isone_hidden(dbl_value) Dbl_isone_hidden(dbl_value)
  681. /*
  682. * The Fourword_add() macro assumes that integers are 4 bytes in size.
  683. * It will break if this is not the case.
  684. */
  685. #define Fourword_add(src1dstA,src1dstB,src1dstC,src1dstD,src2A,src2B,src2C,src2D) \
  686. /* \
  687. * want this macro to generate: \
  688. * ADD src1dstD,src2D,src1dstD; \
  689. * ADDC src1dstC,src2C,src1dstC; \
  690. * ADDC src1dstB,src2B,src1dstB; \
  691. * ADDC src1dstA,src2A,src1dstA; \
  692. */ \
  693. if ((unsigned int)(src1dstD += (src2D)) < (unsigned int)(src2D)) { \
  694. if ((unsigned int)(src1dstC += (src2C) + 1) <= \
  695. (unsigned int)(src2C)) { \
  696. if ((unsigned int)(src1dstB += (src2B) + 1) <= \
  697. (unsigned int)(src2B)) src1dstA++; \
  698. } \
  699. else if ((unsigned int)(src1dstB += (src2B)) < \
  700. (unsigned int)(src2B)) src1dstA++; \
  701. } \
  702. else { \
  703. if ((unsigned int)(src1dstC += (src2C)) < \
  704. (unsigned int)(src2C)) { \
  705. if ((unsigned int)(src1dstB += (src2B) + 1) <= \
  706. (unsigned int)(src2B)) src1dstA++; \
  707. } \
  708. else if ((unsigned int)(src1dstB += (src2B)) < \
  709. (unsigned int)(src2B)) src1dstA++; \
  710. } \
  711. src1dstA += (src2A)
  712. #define Dblext_denormalize(opndp1,opndp2,opndp3,opndp4,exponent,is_tiny) \
  713. {int shiftamt, sticky; \
  714. is_tiny = TRUE; \
  715. if (exponent == 0 && (Dextallp3(opndp3) || Dextallp4(opndp4))) { \
  716. switch (Rounding_mode()) { \
  717. case ROUNDPLUS: \
  718. if (Dbl_iszero_sign(opndp1)) { \
  719. Dbl_increment(opndp1,opndp2); \
  720. if (Dbl_isone_hiddenoverflow(opndp1)) \
  721. is_tiny = FALSE; \
  722. Dbl_decrement(opndp1,opndp2); \
  723. } \
  724. break; \
  725. case ROUNDMINUS: \
  726. if (Dbl_isone_sign(opndp1)) { \
  727. Dbl_increment(opndp1,opndp2); \
  728. if (Dbl_isone_hiddenoverflow(opndp1)) \
  729. is_tiny = FALSE; \
  730. Dbl_decrement(opndp1,opndp2); \
  731. } \
  732. break; \
  733. case ROUNDNEAREST: \
  734. if (Dblext_isone_highp3(opndp3) && \
  735. (Dblext_isone_lowp2(opndp2) || \
  736. Dblext_isnotzero_low31p3(opndp3))) { \
  737. Dbl_increment(opndp1,opndp2); \
  738. if (Dbl_isone_hiddenoverflow(opndp1)) \
  739. is_tiny = FALSE; \
  740. Dbl_decrement(opndp1,opndp2); \
  741. } \
  742. break; \
  743. } \
  744. } \
  745. Dblext_clear_signexponent_set_hidden(opndp1); \
  746. if (exponent >= (1-QUAD_P)) { \
  747. shiftamt = (1-exponent) % 32; \
  748. switch((1-exponent)/32) { \
  749. case 0: sticky = Dextallp4(opndp4) << 32-(shiftamt); \
  750. Variableshiftdouble(opndp3,opndp4,shiftamt,opndp4); \
  751. Variableshiftdouble(opndp2,opndp3,shiftamt,opndp3); \
  752. Variableshiftdouble(opndp1,opndp2,shiftamt,opndp2); \
  753. Dextallp1(opndp1) >>= shiftamt; \
  754. break; \
  755. case 1: sticky = (Dextallp3(opndp3) << 32-(shiftamt)) | \
  756. Dextallp4(opndp4); \
  757. Variableshiftdouble(opndp2,opndp3,shiftamt,opndp4); \
  758. Variableshiftdouble(opndp1,opndp2,shiftamt,opndp3); \
  759. Dextallp2(opndp2) = Dextallp1(opndp1) >> shiftamt; \
  760. Dextallp1(opndp1) = 0; \
  761. break; \
  762. case 2: sticky = (Dextallp2(opndp2) << 32-(shiftamt)) | \
  763. Dextallp3(opndp3) | Dextallp4(opndp4); \
  764. Variableshiftdouble(opndp1,opndp2,shiftamt,opndp4); \
  765. Dextallp3(opndp3) = Dextallp1(opndp1) >> shiftamt; \
  766. Dextallp1(opndp1) = Dextallp2(opndp2) = 0; \
  767. break; \
  768. case 3: sticky = (Dextallp1(opndp1) << 32-(shiftamt)) | \
  769. Dextallp2(opndp2) | Dextallp3(opndp3) | \
  770. Dextallp4(opndp4); \
  771. Dextallp4(opndp4) = Dextallp1(opndp1) >> shiftamt; \
  772. Dextallp1(opndp1) = Dextallp2(opndp2) = 0; \
  773. Dextallp3(opndp3) = 0; \
  774. break; \
  775. } \
  776. } \
  777. else { \
  778. sticky = Dextallp1(opndp1) | Dextallp2(opndp2) | \
  779. Dextallp3(opndp3) | Dextallp4(opndp4); \
  780. Dblext_setzero(opndp1,opndp2,opndp3,opndp4); \
  781. } \
  782. if (sticky) Dblext_setone_lowmantissap4(opndp4); \
  783. exponent = 0; \
  784. }