sgl_float.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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 Sgl_firstword(value) Sall(value)
  26. #define Sgl_secondword(value) dummy_location
  27. #define Sgl_thirdword(value) dummy_location
  28. #define Sgl_fourthword(value) dummy_location
  29. #define Sgl_sign(object) Ssign(object)
  30. #define Sgl_exponent(object) Sexponent(object)
  31. #define Sgl_signexponent(object) Ssignexponent(object)
  32. #define Sgl_mantissa(object) Smantissa(object)
  33. #define Sgl_exponentmantissa(object) Sexponentmantissa(object)
  34. #define Sgl_all(object) Sall(object)
  35. /* sgl_and_signs ANDs the sign bits of each argument and puts the result
  36. * into the first argument. sgl_or_signs ors those same sign bits */
  37. #define Sgl_and_signs( src1dst, src2) \
  38. Sall(src1dst) = (Sall(src2)|~((unsigned int)1<<31)) & Sall(src1dst)
  39. #define Sgl_or_signs( src1dst, src2) \
  40. Sall(src1dst) = (Sall(src2)&((unsigned int)1<<31)) | Sall(src1dst)
  41. /* The hidden bit is always the low bit of the exponent */
  42. #define Sgl_clear_exponent_set_hidden(srcdst) Deposit_sexponent(srcdst,1)
  43. #define Sgl_clear_signexponent_set_hidden(srcdst) \
  44. Deposit_ssignexponent(srcdst,1)
  45. #define Sgl_clear_sign(srcdst) Sall(srcdst) &= ~((unsigned int)1<<31)
  46. #define Sgl_clear_signexponent(srcdst) Sall(srcdst) &= 0x007fffff
  47. /* varamount must be less than 32 for the next three functions */
  48. #define Sgl_rightshift(srcdst, varamount) \
  49. Sall(srcdst) >>= varamount
  50. #define Sgl_leftshift(srcdst, varamount) \
  51. Sall(srcdst) <<= varamount
  52. #define Sgl_rightshift_exponentmantissa(srcdst, varamount) \
  53. Sall(srcdst) = \
  54. (Sexponentmantissa(srcdst) >> varamount) | \
  55. (Sall(srcdst) & ((unsigned int)1<<31))
  56. #define Sgl_leftshiftby1_withextent(left,right,result) \
  57. Shiftdouble(Sall(left),Extall(right),31,Sall(result))
  58. #define Sgl_rightshiftby1_withextent(left,right,dst) \
  59. Shiftdouble(Sall(left),Extall(right),1,Extall(right))
  60. #define Sgl_arithrightshiftby1(srcdst) \
  61. Sall(srcdst) = (int)Sall(srcdst) >> 1
  62. /* Sign extend the sign bit with an integer destination */
  63. #define Sgl_signextendedsign(value) Ssignedsign(value)
  64. #define Sgl_isone_hidden(sgl_value) (Shidden(sgl_value))
  65. #define Sgl_increment(sgl_value) Sall(sgl_value) += 1
  66. #define Sgl_increment_mantissa(sgl_value) \
  67. Deposit_smantissa(sgl_value,sgl_value+1)
  68. #define Sgl_decrement(sgl_value) Sall(sgl_value) -= 1
  69. #define Sgl_isone_sign(sgl_value) (Is_ssign(sgl_value)!=0)
  70. #define Sgl_isone_hiddenoverflow(sgl_value) \
  71. (Is_shiddenoverflow(sgl_value)!=0)
  72. #define Sgl_isone_lowmantissa(sgl_value) (Is_slow(sgl_value)!=0)
  73. #define Sgl_isone_signaling(sgl_value) (Is_ssignaling(sgl_value)!=0)
  74. #define Sgl_is_signalingnan(sgl_value) (Ssignalingnan(sgl_value)==0x1ff)
  75. #define Sgl_isnotzero(sgl_value) (Sall(sgl_value)!=0)
  76. #define Sgl_isnotzero_hiddenhigh7mantissa(sgl_value) \
  77. (Shiddenhigh7mantissa(sgl_value)!=0)
  78. #define Sgl_isnotzero_low4(sgl_value) (Slow4(sgl_value)!=0)
  79. #define Sgl_isnotzero_exponent(sgl_value) (Sexponent(sgl_value)!=0)
  80. #define Sgl_isnotzero_mantissa(sgl_value) (Smantissa(sgl_value)!=0)
  81. #define Sgl_isnotzero_exponentmantissa(sgl_value) \
  82. (Sexponentmantissa(sgl_value)!=0)
  83. #define Sgl_iszero(sgl_value) (Sall(sgl_value)==0)
  84. #define Sgl_iszero_signaling(sgl_value) (Is_ssignaling(sgl_value)==0)
  85. #define Sgl_iszero_hidden(sgl_value) (Is_shidden(sgl_value)==0)
  86. #define Sgl_iszero_hiddenoverflow(sgl_value) \
  87. (Is_shiddenoverflow(sgl_value)==0)
  88. #define Sgl_iszero_hiddenhigh3mantissa(sgl_value) \
  89. (Shiddenhigh3mantissa(sgl_value)==0)
  90. #define Sgl_iszero_hiddenhigh7mantissa(sgl_value) \
  91. (Shiddenhigh7mantissa(sgl_value)==0)
  92. #define Sgl_iszero_sign(sgl_value) (Is_ssign(sgl_value)==0)
  93. #define Sgl_iszero_exponent(sgl_value) (Sexponent(sgl_value)==0)
  94. #define Sgl_iszero_mantissa(sgl_value) (Smantissa(sgl_value)==0)
  95. #define Sgl_iszero_exponentmantissa(sgl_value) \
  96. (Sexponentmantissa(sgl_value)==0)
  97. #define Sgl_isinfinity_exponent(sgl_value) \
  98. (Sgl_exponent(sgl_value)==SGL_INFINITY_EXPONENT)
  99. #define Sgl_isnotinfinity_exponent(sgl_value) \
  100. (Sgl_exponent(sgl_value)!=SGL_INFINITY_EXPONENT)
  101. #define Sgl_isinfinity(sgl_value) \
  102. (Sgl_exponent(sgl_value)==SGL_INFINITY_EXPONENT && \
  103. Sgl_mantissa(sgl_value)==0)
  104. #define Sgl_isnan(sgl_value) \
  105. (Sgl_exponent(sgl_value)==SGL_INFINITY_EXPONENT && \
  106. Sgl_mantissa(sgl_value)!=0)
  107. #define Sgl_isnotnan(sgl_value) \
  108. (Sgl_exponent(sgl_value)!=SGL_INFINITY_EXPONENT || \
  109. Sgl_mantissa(sgl_value)==0)
  110. #define Sgl_islessthan(sgl_op1,sgl_op2) \
  111. (Sall(sgl_op1) < Sall(sgl_op2))
  112. #define Sgl_isgreaterthan(sgl_op1,sgl_op2) \
  113. (Sall(sgl_op1) > Sall(sgl_op2))
  114. #define Sgl_isnotlessthan(sgl_op1,sgl_op2) \
  115. (Sall(sgl_op1) >= Sall(sgl_op2))
  116. #define Sgl_isequal(sgl_op1,sgl_op2) \
  117. (Sall(sgl_op1) == Sall(sgl_op2))
  118. #define Sgl_leftshiftby8(sgl_value) \
  119. Sall(sgl_value) <<= 8
  120. #define Sgl_leftshiftby4(sgl_value) \
  121. Sall(sgl_value) <<= 4
  122. #define Sgl_leftshiftby3(sgl_value) \
  123. Sall(sgl_value) <<= 3
  124. #define Sgl_leftshiftby2(sgl_value) \
  125. Sall(sgl_value) <<= 2
  126. #define Sgl_leftshiftby1(sgl_value) \
  127. Sall(sgl_value) <<= 1
  128. #define Sgl_rightshiftby1(sgl_value) \
  129. Sall(sgl_value) >>= 1
  130. #define Sgl_rightshiftby4(sgl_value) \
  131. Sall(sgl_value) >>= 4
  132. #define Sgl_rightshiftby8(sgl_value) \
  133. Sall(sgl_value) >>= 8
  134. #define Sgl_ismagnitudeless(signlessleft,signlessright) \
  135. /* unsigned int signlessleft, signlessright; */ \
  136. (signlessleft < signlessright)
  137. #define Sgl_copytoint_exponentmantissa(source,dest) \
  138. dest = Sexponentmantissa(source)
  139. /* A quiet NaN has the high mantissa bit clear and at least on other (in this
  140. * case the adjacent bit) bit set. */
  141. #define Sgl_set_quiet(sgl_value) Deposit_shigh2mantissa(sgl_value,1)
  142. #define Sgl_set_exponent(sgl_value,exp) Deposit_sexponent(sgl_value,exp)
  143. #define Sgl_set_mantissa(dest,value) Deposit_smantissa(dest,value)
  144. #define Sgl_set_exponentmantissa(dest,value) \
  145. Deposit_sexponentmantissa(dest,value)
  146. /* An infinity is represented with the max exponent and a zero mantissa */
  147. #define Sgl_setinfinity_exponent(sgl_value) \
  148. Deposit_sexponent(sgl_value,SGL_INFINITY_EXPONENT)
  149. #define Sgl_setinfinity_exponentmantissa(sgl_value) \
  150. Deposit_sexponentmantissa(sgl_value, \
  151. (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH))))
  152. #define Sgl_setinfinitypositive(sgl_value) \
  153. Sall(sgl_value) = (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH)))
  154. #define Sgl_setinfinitynegative(sgl_value) \
  155. Sall(sgl_value) = (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH))) \
  156. | ((unsigned int)1<<31)
  157. #define Sgl_setinfinity(sgl_value,sign) \
  158. Sall(sgl_value) = (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH))) | \
  159. ((unsigned int)sign << 31)
  160. #define Sgl_sethigh4bits(sgl_value, extsign) \
  161. Deposit_shigh4(sgl_value,extsign)
  162. #define Sgl_set_sign(sgl_value,sign) Deposit_ssign(sgl_value,sign)
  163. #define Sgl_invert_sign(sgl_value) \
  164. Deposit_ssign(sgl_value,~Ssign(sgl_value))
  165. #define Sgl_setone_sign(sgl_value) Deposit_ssign(sgl_value,1)
  166. #define Sgl_setone_lowmantissa(sgl_value) Deposit_slow(sgl_value,1)
  167. #define Sgl_setzero_sign(sgl_value) Sall(sgl_value) &= 0x7fffffff
  168. #define Sgl_setzero_exponent(sgl_value) Sall(sgl_value) &= 0x807fffff
  169. #define Sgl_setzero_mantissa(sgl_value) Sall(sgl_value) &= 0xff800000
  170. #define Sgl_setzero_exponentmantissa(sgl_value) Sall(sgl_value) &= 0x80000000
  171. #define Sgl_setzero(sgl_value) Sall(sgl_value) = 0
  172. #define Sgl_setnegativezero(sgl_value) Sall(sgl_value) = (unsigned int)1 << 31
  173. /* Use following macro for both overflow & underflow conditions */
  174. #define ovfl -
  175. #define unfl +
  176. #define Sgl_setwrapped_exponent(sgl_value,exponent,op) \
  177. Deposit_sexponent(sgl_value,(exponent op SGL_WRAP))
  178. #define Sgl_setlargestpositive(sgl_value) \
  179. Sall(sgl_value) = ((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \
  180. | ((1<<(32-(1+SGL_EXP_LENGTH))) - 1 )
  181. #define Sgl_setlargestnegative(sgl_value) \
  182. Sall(sgl_value) = ((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \
  183. | ((1<<(32-(1+SGL_EXP_LENGTH))) - 1 ) \
  184. | ((unsigned int)1<<31)
  185. #define Sgl_setnegativeinfinity(sgl_value) \
  186. Sall(sgl_value) = \
  187. ((1<<SGL_EXP_LENGTH) | SGL_INFINITY_EXPONENT) << (32-(1+SGL_EXP_LENGTH))
  188. #define Sgl_setlargest(sgl_value,sign) \
  189. Sall(sgl_value) = (unsigned int)sign << 31 | \
  190. (((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \
  191. | ((1 << (32-(1+SGL_EXP_LENGTH))) - 1 ))
  192. #define Sgl_setlargest_exponentmantissa(sgl_value) \
  193. Sall(sgl_value) = Sall(sgl_value) & ((unsigned int)1<<31) | \
  194. (((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \
  195. | ((1 << (32-(1+SGL_EXP_LENGTH))) - 1 ))
  196. /* The high bit is always zero so arithmetic or logical shifts will work. */
  197. #define Sgl_right_align(srcdst,shift,extent) \
  198. /* sgl_floating_point srcdst; int shift; extension extent */ \
  199. if (shift < 32) { \
  200. Extall(extent) = Sall(srcdst) << (32-(shift)); \
  201. Sall(srcdst) >>= shift; \
  202. } \
  203. else { \
  204. Extall(extent) = Sall(srcdst); \
  205. Sall(srcdst) = 0; \
  206. }
  207. #define Sgl_hiddenhigh3mantissa(sgl_value) Shiddenhigh3mantissa(sgl_value)
  208. #define Sgl_hidden(sgl_value) Shidden(sgl_value)
  209. #define Sgl_lowmantissa(sgl_value) Slow(sgl_value)
  210. /* The left argument is never smaller than the right argument */
  211. #define Sgl_subtract(sgl_left,sgl_right,sgl_result) \
  212. Sall(sgl_result) = Sall(sgl_left) - Sall(sgl_right)
  213. /* Subtract right augmented with extension from left augmented with zeros and
  214. * store into result and extension. */
  215. #define Sgl_subtract_withextension(left,right,extent,result) \
  216. /* sgl_floating_point left,right,result; extension extent */ \
  217. Sgl_subtract(left,right,result); \
  218. if((Extall(extent) = 0-Extall(extent))) \
  219. Sall(result) = Sall(result)-1
  220. #define Sgl_addition(sgl_left,sgl_right,sgl_result) \
  221. Sall(sgl_result) = Sall(sgl_left) + Sall(sgl_right)
  222. #define Sgl_xortointp1(left,right,result) \
  223. result = Sall(left) XOR Sall(right);
  224. #define Sgl_xorfromintp1(left,right,result) \
  225. Sall(result) = left XOR Sall(right)
  226. /* Need to Initialize */
  227. #define Sgl_makequietnan(dest) \
  228. Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32-(1+SGL_EXP_LENGTH)) \
  229. | (1<<(32-(1+SGL_EXP_LENGTH+2)))
  230. #define Sgl_makesignalingnan(dest) \
  231. Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32-(1+SGL_EXP_LENGTH)) \
  232. | (1<<(32-(1+SGL_EXP_LENGTH+1)))
  233. #define Sgl_normalize(sgl_opnd,exponent) \
  234. while(Sgl_iszero_hiddenhigh7mantissa(sgl_opnd)) { \
  235. Sgl_leftshiftby8(sgl_opnd); \
  236. exponent -= 8; \
  237. } \
  238. if(Sgl_iszero_hiddenhigh3mantissa(sgl_opnd)) { \
  239. Sgl_leftshiftby4(sgl_opnd); \
  240. exponent -= 4; \
  241. } \
  242. while(Sgl_iszero_hidden(sgl_opnd)) { \
  243. Sgl_leftshiftby1(sgl_opnd); \
  244. exponent -= 1; \
  245. }
  246. #define Sgl_setoverflow(sgl_opnd) \
  247. /* set result to infinity or largest number */ \
  248. switch (Rounding_mode()) { \
  249. case ROUNDPLUS: \
  250. if (Sgl_isone_sign(sgl_opnd)) { \
  251. Sgl_setlargestnegative(sgl_opnd); \
  252. } \
  253. else { \
  254. Sgl_setinfinitypositive(sgl_opnd); \
  255. } \
  256. break; \
  257. case ROUNDMINUS: \
  258. if (Sgl_iszero_sign(sgl_opnd)) { \
  259. Sgl_setlargestpositive(sgl_opnd); \
  260. } \
  261. else { \
  262. Sgl_setinfinitynegative(sgl_opnd); \
  263. } \
  264. break; \
  265. case ROUNDNEAREST: \
  266. Sgl_setinfinity_exponentmantissa(sgl_opnd); \
  267. break; \
  268. case ROUNDZERO: \
  269. Sgl_setlargest_exponentmantissa(sgl_opnd); \
  270. }
  271. #define Sgl_denormalize(opnd,exponent,guard,sticky,inexact) \
  272. Sgl_clear_signexponent_set_hidden(opnd); \
  273. if (exponent >= (1 - SGL_P)) { \
  274. guard = (Sall(opnd) >> -exponent) & 1; \
  275. if (exponent < 0) sticky |= Sall(opnd) << (32+exponent); \
  276. inexact = guard | sticky; \
  277. Sall(opnd) >>= (1-exponent); \
  278. } \
  279. else { \
  280. guard = 0; \
  281. sticky |= Sall(opnd); \
  282. inexact = sticky; \
  283. Sgl_setzero(opnd); \
  284. }
  285. /*
  286. * The fused multiply add instructions requires a single extended format,
  287. * with 48 bits of mantissa.
  288. */
  289. #define SGLEXT_THRESHOLD 48
  290. #define Sglext_setzero(valA,valB) \
  291. Sextallp1(valA) = 0; Sextallp2(valB) = 0
  292. #define Sglext_isnotzero_mantissap2(valB) (Sextallp2(valB)!=0)
  293. #define Sglext_isone_lowp1(val) (Sextlowp1(val)!=0)
  294. #define Sglext_isone_highp2(val) (Sexthighp2(val)!=0)
  295. #define Sglext_isnotzero_low31p2(val) (Sextlow31p2(val)!=0)
  296. #define Sglext_iszero(valA,valB) (Sextallp1(valA)==0 && Sextallp2(valB)==0)
  297. #define Sgl_copytoptr(src,destptr) *destptr = src
  298. #define Sgl_copyfromptr(srcptr,dest) dest = *srcptr
  299. #define Sglext_copy(srca,srcb,desta,destb) \
  300. Sextallp1(desta) = Sextallp1(srca); \
  301. Sextallp2(destb) = Sextallp2(srcb)
  302. #define Sgl_copyto_sglext(src1,dest1,dest2) \
  303. Sextallp1(dest1) = Sall(src1); Sextallp2(dest2) = 0
  304. #define Sglext_swap_lower(leftp2,rightp2) \
  305. Sextallp2(leftp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2); \
  306. Sextallp2(rightp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2); \
  307. Sextallp2(leftp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2)
  308. #define Sglext_setone_lowmantissap2(value) Deposit_dlowp2(value,1)
  309. /* The high bit is always zero so arithmetic or logical shifts will work. */
  310. #define Sglext_right_align(srcdstA,srcdstB,shift) \
  311. {int shiftamt, sticky; \
  312. shiftamt = shift % 32; \
  313. sticky = 0; \
  314. switch (shift/32) { \
  315. case 0: if (shiftamt > 0) { \
  316. sticky = Sextallp2(srcdstB) << 32 - (shiftamt); \
  317. Variable_shift_double(Sextallp1(srcdstA), \
  318. Sextallp2(srcdstB),shiftamt,Sextallp2(srcdstB)); \
  319. Sextallp1(srcdstA) >>= shiftamt; \
  320. } \
  321. break; \
  322. case 1: if (shiftamt > 0) { \
  323. sticky = (Sextallp1(srcdstA) << 32 - (shiftamt)) | \
  324. Sextallp2(srcdstB); \
  325. } \
  326. else { \
  327. sticky = Sextallp2(srcdstB); \
  328. } \
  329. Sextallp2(srcdstB) = Sextallp1(srcdstA) >> shiftamt; \
  330. Sextallp1(srcdstA) = 0; \
  331. break; \
  332. } \
  333. if (sticky) Sglext_setone_lowmantissap2(srcdstB); \
  334. }
  335. /* The left argument is never smaller than the right argument */
  336. #define Sglext_subtract(lefta,leftb,righta,rightb,resulta,resultb) \
  337. if( Sextallp2(rightb) > Sextallp2(leftb) ) Sextallp1(lefta)--; \
  338. Sextallp2(resultb) = Sextallp2(leftb) - Sextallp2(rightb); \
  339. Sextallp1(resulta) = Sextallp1(lefta) - Sextallp1(righta)
  340. #define Sglext_addition(lefta,leftb,righta,rightb,resulta,resultb) \
  341. /* If the sum of the low words is less than either source, then \
  342. * an overflow into the next word occurred. */ \
  343. if ((Sextallp2(resultb) = Sextallp2(leftb)+Sextallp2(rightb)) < \
  344. Sextallp2(rightb)) \
  345. Sextallp1(resulta) = Sextallp1(lefta)+Sextallp1(righta)+1; \
  346. else Sextallp1(resulta) = Sextallp1(lefta)+Sextallp1(righta)
  347. #define Sglext_arithrightshiftby1(srcdstA,srcdstB) \
  348. Shiftdouble(Sextallp1(srcdstA),Sextallp2(srcdstB),1,Sextallp2(srcdstB)); \
  349. Sextallp1(srcdstA) = (int)Sextallp1(srcdstA) >> 1
  350. #define Sglext_leftshiftby8(valA,valB) \
  351. Shiftdouble(Sextallp1(valA),Sextallp2(valB),24,Sextallp1(valA)); \
  352. Sextallp2(valB) <<= 8
  353. #define Sglext_leftshiftby4(valA,valB) \
  354. Shiftdouble(Sextallp1(valA),Sextallp2(valB),28,Sextallp1(valA)); \
  355. Sextallp2(valB) <<= 4
  356. #define Sglext_leftshiftby3(valA,valB) \
  357. Shiftdouble(Sextallp1(valA),Sextallp2(valB),29,Sextallp1(valA)); \
  358. Sextallp2(valB) <<= 3
  359. #define Sglext_leftshiftby2(valA,valB) \
  360. Shiftdouble(Sextallp1(valA),Sextallp2(valB),30,Sextallp1(valA)); \
  361. Sextallp2(valB) <<= 2
  362. #define Sglext_leftshiftby1(valA,valB) \
  363. Shiftdouble(Sextallp1(valA),Sextallp2(valB),31,Sextallp1(valA)); \
  364. Sextallp2(valB) <<= 1
  365. #define Sglext_rightshiftby4(valueA,valueB) \
  366. Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),4,Sextallp2(valueB)); \
  367. Sextallp1(valueA) >>= 4
  368. #define Sglext_rightshiftby3(valueA,valueB) \
  369. Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),3,Sextallp2(valueB)); \
  370. Sextallp1(valueA) >>= 3
  371. #define Sglext_rightshiftby1(valueA,valueB) \
  372. Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),1,Sextallp2(valueB)); \
  373. Sextallp1(valueA) >>= 1
  374. #define Sglext_xortointp1(left,right,result) Sgl_xortointp1(left,right,result)
  375. #define Sglext_xorfromintp1(left,right,result) \
  376. Sgl_xorfromintp1(left,right,result)
  377. #define Sglext_copytoint_exponentmantissa(src,dest) \
  378. Sgl_copytoint_exponentmantissa(src,dest)
  379. #define Sglext_ismagnitudeless(signlessleft,signlessright) \
  380. Sgl_ismagnitudeless(signlessleft,signlessright)
  381. #define Sglext_set_sign(dbl_value,sign) Sgl_set_sign(dbl_value,sign)
  382. #define Sglext_clear_signexponent_set_hidden(srcdst) \
  383. Sgl_clear_signexponent_set_hidden(srcdst)
  384. #define Sglext_clear_signexponent(srcdst) Sgl_clear_signexponent(srcdst)
  385. #define Sglext_clear_sign(srcdst) Sgl_clear_sign(srcdst)
  386. #define Sglext_isone_hidden(dbl_value) Sgl_isone_hidden(dbl_value)
  387. #define Sglext_denormalize(opndp1,opndp2,exponent,is_tiny) \
  388. {int sticky; \
  389. is_tiny = TRUE; \
  390. if (exponent == 0 && Sextallp2(opndp2)) { \
  391. switch (Rounding_mode()) { \
  392. case ROUNDPLUS: \
  393. if (Sgl_iszero_sign(opndp1)) \
  394. if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \
  395. is_tiny = FALSE; \
  396. break; \
  397. case ROUNDMINUS: \
  398. if (Sgl_isone_sign(opndp1)) { \
  399. if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \
  400. is_tiny = FALSE; \
  401. } \
  402. break; \
  403. case ROUNDNEAREST: \
  404. if (Sglext_isone_highp2(opndp2) && \
  405. (Sglext_isone_lowp1(opndp1) || \
  406. Sglext_isnotzero_low31p2(opndp2))) \
  407. if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \
  408. is_tiny = FALSE; \
  409. break; \
  410. } \
  411. } \
  412. Sglext_clear_signexponent_set_hidden(opndp1); \
  413. if (exponent >= (1-DBL_P)) { \
  414. if (exponent >= -31) { \
  415. if (exponent > -31) { \
  416. sticky = Sextallp2(opndp2) << 31+exponent; \
  417. Variable_shift_double(opndp1,opndp2,1-exponent,opndp2); \
  418. Sextallp1(opndp1) >>= 1-exponent; \
  419. } \
  420. else { \
  421. sticky = Sextallp2(opndp2); \
  422. Sextallp2(opndp2) = Sextallp1(opndp1); \
  423. Sextallp1(opndp1) = 0; \
  424. } \
  425. } \
  426. else { \
  427. sticky = (Sextallp1(opndp1) << 31+exponent) | \
  428. Sextallp2(opndp2); \
  429. Sextallp2(opndp2) = Sextallp1(opndp1) >> -31-exponent; \
  430. Sextallp1(opndp1) = 0; \
  431. } \
  432. } \
  433. else { \
  434. sticky = Sextallp1(opndp1) | Sextallp2(opndp2); \
  435. Sglext_setzero(opndp1,opndp2); \
  436. } \
  437. if (sticky) Sglext_setone_lowmantissap2(opndp2); \
  438. exponent = 0; \
  439. }