Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

762 lines
22 KiB

  1. .file "expf.s"
  2. // Copyright (c) 2000, 2001, Intel Corporation
  3. // All rights reserved.
  4. //
  5. // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
  6. // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
  7. //
  8. // WARRANTY DISCLAIMER
  9. //
  10. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  11. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  12. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  13. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
  14. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  15. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  18. // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
  19. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. //
  22. // Intel Corporation is the author of this code, and requests that all
  23. // problem reports or change requests be submitted to it directly at
  24. // http://developer.intel.com/opensource.
  25. // History
  26. //==============================================================
  27. // 4/04/00 Unwind update
  28. // 4/04/00 Unwind support added
  29. // 8/15/00 Bundle added after call to __libm_error_support to properly
  30. // set [the previously overwritten] GR_Parameter_RESULT.
  31. // 8/21/00 Improvements to save 2 cycles on main path, and shorten x=0 case
  32. // 12/07/00 Widen main path, shorten x=inf, nan paths
  33. // 3/15/01 Fix monotonicity problem around x=0 for round to +inf
  34. //
  35. // Assembly macros
  36. //==============================================================
  37. // integer registers used
  38. exp_GR_0x0f = r33
  39. exp_GR_0xf0 = r34
  40. EXP_AD_P_1 = r36
  41. EXP_AD_P_2 = r37
  42. EXP_AD_T1 = r38
  43. EXP_AD_T2 = r39
  44. exp_GR_Mint = r40
  45. exp_GR_Mint_p_128 = r41
  46. exp_GR_Ind1 = r42
  47. EXP_AD_M1 = r43
  48. exp_GR_Ind2 = r44
  49. EXP_AD_M2 = r45
  50. exp_GR_min_oflow = r46
  51. exp_GR_max_zero = r47
  52. exp_GR_max_norm = r48
  53. exp_GR_max_uflow = r49
  54. exp_GR_min_norm = r50
  55. exp_GR_17ones = r51
  56. exp_GR_gt_ln = r52
  57. exp_GR_T2_size = r53
  58. exp_GR_bias = r54
  59. exp_GR_signexp = r55
  60. exp_GR_17ones_m1 = r56
  61. exp_GR_one = r57
  62. exp_GR_exp = r58
  63. GR_SAVE_B0 = r53
  64. GR_SAVE_PFS = r55
  65. GR_SAVE_GP = r54
  66. GR_Parameter_X = r59
  67. GR_Parameter_Y = r60
  68. GR_Parameter_RESULT = r61
  69. GR_Parameter_TAG = r62
  70. FR_X = f10
  71. FR_Y = f1
  72. FR_RESULT = f8
  73. // floating point registers used
  74. EXP_MIN_SGL_OFLOW_ARG = f11
  75. EXP_MAX_SGL_ZERO_ARG = f12
  76. EXP_MAX_SGL_NORM_ARG = f13
  77. EXP_MAX_SGL_UFLOW_ARG = f14
  78. EXP_MIN_SGL_NORM_ARG = f15
  79. exp_coeff_P5 = f32
  80. exp_coeff_P6 = f33
  81. exp_coeff_P3 = f34
  82. exp_coeff_P4 = f35
  83. exp_coeff_P1 = f36
  84. exp_coeff_P2 = f37
  85. exp_Mx = f38
  86. exp_Mfloat = f39
  87. exp_R = f40
  88. exp_P1 = f41
  89. exp_P2 = f42
  90. exp_P3 = f43
  91. exp_Rsq = f44
  92. exp_R4 = f45
  93. exp_P4 = f46
  94. exp_P5 = f47
  95. exp_P6 = f48
  96. exp_P7 = f49
  97. exp_T1 = f50
  98. exp_T2 = f51
  99. exp_T = f52
  100. exp_A = f53
  101. exp_norm_f8 = f54
  102. exp_wre_urm_f8 = f55
  103. exp_ftz_urm_f8 = f56
  104. exp_gt_pln = f57
  105. .data
  106. .align 16
  107. exp_coeff_1_table:
  108. data8 0x3F56F35FDE4F8563 // p5
  109. data8 0x3F2A378BEFECCFDD // p6
  110. data8 0x3FE00000258C581D // p1
  111. data8 0x3FC555557AE7B3D4 // p2
  112. exp_coeff_2_table:
  113. data8 0x3FA5551BB6592FAE // p3
  114. data8 0x3F8110E8EBFFD485 // p4
  115. exp_T2_table:
  116. data8 0xa175cf9cd7d85844 , 0x00003f46 // exp(-128)
  117. data8 0xdb7279415a1f9eed , 0x00003f47 // exp(-127)
  118. data8 0x95213b242bd8ca5f , 0x00003f49 // exp(-126)
  119. data8 0xcab03c968c989f83 , 0x00003f4a // exp(-125)
  120. data8 0x89bdb674702961ad , 0x00003f4c // exp(-124)
  121. data8 0xbb35a2eec278be35 , 0x00003f4d // exp(-123)
  122. data8 0xfe71b17f373e7e7a , 0x00003f4e // exp(-122)
  123. data8 0xace9a6ec52a39b63 , 0x00003f50 // exp(-121)
  124. data8 0xeb03423fe393cf1c , 0x00003f51 // exp(-120)
  125. data8 0x9fb52c5bcaef1693 , 0x00003f53 // exp(-119)
  126. data8 0xd910b6377ed60bf1 , 0x00003f54 // exp(-118)
  127. data8 0x9382dad8a9fdbfe4 , 0x00003f56 // exp(-117)
  128. data8 0xc87d0a84dea869a3 , 0x00003f57 // exp(-116)
  129. data8 0x883efb4c6d1087b0 , 0x00003f59 // exp(-115)
  130. data8 0xb92d7373dce9a502 , 0x00003f5a // exp(-114)
  131. data8 0xfbaeb020577fb0cb , 0x00003f5b // exp(-113)
  132. exp_T1_table:
  133. data8 0x8000000000000000 , 0x00003fff // exp(16 * 0)
  134. data8 0x87975e8540010249 , 0x00004016 // exp(16 * 1)
  135. data8 0x8fa1fe625b3163ec , 0x0000402d // exp(16 * 2)
  136. data8 0x9826b576512a59d7 , 0x00004044 // exp(16 * 3)
  137. data8 0xa12cc167acbe6902 , 0x0000405b // exp(16 * 4)
  138. data8 0xaabbcdcc279f59e4 , 0x00004072 // exp(16 * 5)
  139. data8 0xb4dbfaadc045d16f , 0x00004089 // exp(16 * 6)
  140. data8 0xbf95e372ccdbf146 , 0x000040a0 // exp(16 * 7)
  141. data8 0xcaf2a62eea10bbfb , 0x000040b7 // exp(16 * 8)
  142. data8 0xd6fbeb62fddbd340 , 0x000040ce // exp(16 * 9)
  143. data8 0xe3bbee32e4a440ea , 0x000040e5 // exp(16 * 10)
  144. data8 0xf13d8517c34199a8 , 0x000040fc // exp(16 * 11)
  145. data8 0xff8c2b166241eedd , 0x00004113 // exp(16 * 12)
  146. data8 0x875a04c0b38d6129 , 0x0000412b // exp(16 * 13)
  147. data8 0x8f610127db6774d7 , 0x00004142 // exp(16 * 14)
  148. data8 0x97e1dd87e5c20bb6 , 0x00004159 // exp(16 * 15)
  149. // Argument Reduction
  150. // exp_Mx = (int)f8 ==> The value of f8 rounded to int is placed into the
  151. // significand of exp_Mx as a two's
  152. // complement number.
  153. // Later we want to have exp_Mx in a general register. Do this with a getf.sig
  154. // and call the general register exp_GR_Mint
  155. // exp_Mfloat = (float)(int)f8 ==> the two's complement number in
  156. // significand of exp_Mx is turned
  157. // into a floating point number.
  158. // R = 1 - exp_Mfloat ==> reduced argument
  159. // Core Approximation
  160. // Calculate a series in R
  161. // R * p6 + p5
  162. // R * p4 + p3
  163. // R * p2 + p1
  164. // R^2
  165. // R^4
  166. // R^2(R * p6 + p5) + (R * p4 + p3)
  167. // R^2(R * p2 + p1)
  168. // R^4(R^2(R * p6 + p5) + (R * p4 + p3)) + (R^2(R * p2 + p1))
  169. // R + 1
  170. // exp(R) = (1 + R) + R^4(R^2(R * p6 + p5) + (R * p4 + p3)) + (R^2(R * p2 + p1))
  171. // exp(R) = 1 + R + R^2 * p1 + R^3 * p2 + R^4 * p3 + R^5 * p4 + R^6 * p5 + R^7 * p6
  172. // Reconstruction
  173. // signficand of exp_Mx is two's complement,
  174. // -103 < x < 89
  175. // The smallest single denormal is 2^-149 = ssdn
  176. // For e^x = ssdn
  177. // x = log(ssdn) = -103.279
  178. // But with rounding result goes to ssdn until -103.972079
  179. // The largest single normal is 1.<23 1's> 2^126 ~ 2^127 = lsn
  180. // For e^x = lsn
  181. // x = log(lsn) = 88.7228
  182. //
  183. // expf overflows when x > 42b17218 = 88.7228
  184. // expf returns largest single denormal when x = c2aeac50
  185. // expf goes to zero when x < c2cff1b5
  186. // Consider range of 8-bit two's complement, -128 ---> 127
  187. // Add 128; range becomes 0 ---> 255
  188. // The number (=i) in 0 ---> 255 is used as offset into two tables.
  189. // i = abcd efgh = abcd * 16 + efgh = i1 * 16 + i2
  190. // i1 = (exp_GR_Mint + 128) & 0xf0 (show 0xf0 as -0x10 to avoid assembler error)
  191. // (The immediate in the AND is an 8-bit two's complement)
  192. // i1 = i1 + start of T1 table (EXP_AD_T1)
  193. // Note that the entries in T1 are double-extended numbers on 16-byte boundaries
  194. // and that i1 is already shifted left by 16 after the AND.
  195. // i2 must be shifted left by 4 before adding to the start of the table.
  196. // i2 = ((exp_GR_Mint + 128) & 0x0f) << 4
  197. // i2 = i2 + start of T2 table (EXP_AD_T2)
  198. // T = T1 * T2
  199. // A = T * (1 + R)
  200. // answer = T * (R^2 * p1 + R^3 * p2 + R^4 * p3 + R^5 * p4 + R^6 * p5 + R^7 * p6) +
  201. // T * (1 + R)
  202. // = T * exp(R)
  203. .global expf#
  204. .section .text
  205. .proc expf#
  206. .align 32
  207. expf:
  208. { .mfi
  209. alloc r32 = ar.pfs,1,26,4,0
  210. fcvt.fx.s1 exp_Mx = f8
  211. mov exp_GR_17ones = 0x1FFFF
  212. }
  213. { .mlx
  214. addl EXP_AD_P_1 = @ltoff(exp_coeff_1_table),gp
  215. movl exp_GR_min_oflow = 0x42b17218
  216. }
  217. ;;
  218. // Fnorm done to take any enabled faults
  219. { .mfi
  220. ld8 EXP_AD_P_1 = [EXP_AD_P_1]
  221. fclass.m p6,p0 = f8, 0x07 //@zero
  222. nop.i 999
  223. }
  224. { .mfi
  225. add exp_GR_max_norm = -1, exp_GR_min_oflow // 0x42b17217
  226. fnorm exp_norm_f8 = f8
  227. nop.i 999
  228. }
  229. ;;
  230. { .mfi
  231. setf.s EXP_MIN_SGL_OFLOW_ARG = exp_GR_min_oflow // 0x42b17218
  232. fclass.m p7,p0 = f8, 0x22 // Test for x=-inf
  233. mov exp_GR_0xf0 = 0x0f0
  234. }
  235. { .mlx
  236. setf.s EXP_MAX_SGL_NORM_ARG = exp_GR_max_norm
  237. movl exp_GR_max_zero = 0xc2cff1b5
  238. }
  239. ;;
  240. { .mlx
  241. mov exp_GR_0x0f = 0x00f
  242. movl exp_GR_max_uflow = 0xc2aeac50
  243. }
  244. { .mfb
  245. nop.m 999
  246. (p6) fma.s f8 = f1,f1,f0
  247. (p6) br.ret.spnt b0 // quick exit for x=0
  248. }
  249. ;;
  250. { .mfi
  251. setf.s EXP_MAX_SGL_ZERO_ARG = exp_GR_max_zero
  252. fclass.m p8,p0 = f8, 0x21 // Test for x=+inf
  253. adds exp_GR_min_norm = 1, exp_GR_max_uflow // 0xc2aeac51
  254. }
  255. { .mfb
  256. ldfpd exp_coeff_P5,exp_coeff_P6 = [EXP_AD_P_1],16
  257. (p7) fma.s f8 = f0,f0,f0
  258. (p7) br.ret.spnt b0 // quick exit for x=-inf
  259. }
  260. ;;
  261. { .mmf
  262. ldfpd exp_coeff_P1,exp_coeff_P2 = [EXP_AD_P_1],16
  263. setf.s EXP_MAX_SGL_UFLOW_ARG = exp_GR_max_uflow
  264. fclass.m p9,p0 = f8, 0xc3 // Test for x=nan
  265. }
  266. ;;
  267. { .mmb
  268. ldfpd exp_coeff_P3,exp_coeff_P4 = [EXP_AD_P_1],16
  269. setf.s EXP_MIN_SGL_NORM_ARG = exp_GR_min_norm
  270. (p8) br.ret.spnt b0 // quick exit for x=+inf
  271. }
  272. ;;
  273. // EXP_AD_P_1 now points to exp_T2_table
  274. { .mfi
  275. mov exp_GR_T2_size = 0x100
  276. fcvt.xf exp_Mfloat = exp_Mx
  277. nop.i 999
  278. }
  279. ;;
  280. { .mfb
  281. getf.sig exp_GR_Mint = exp_Mx
  282. (p9) fmerge.s f8 = exp_norm_f8, exp_norm_f8
  283. (p9) br.ret.spnt b0 // quick exit for x=nan
  284. }
  285. ;;
  286. { .mmi
  287. getf.exp exp_GR_signexp = exp_norm_f8
  288. mov EXP_AD_T2 = EXP_AD_P_1
  289. add EXP_AD_T1 = exp_GR_T2_size,EXP_AD_P_1 ;;
  290. }
  291. { .mmi
  292. adds exp_GR_Mint_p_128 = 0x80,exp_GR_Mint ;;
  293. and exp_GR_Ind1 = exp_GR_Mint_p_128, exp_GR_0xf0
  294. and exp_GR_Ind2 = exp_GR_Mint_p_128, exp_GR_0x0f ;;
  295. }
  296. // Divide arguments into the following categories:
  297. // Certain Underflow/zero p11 - -inf < x <= MAX_SGL_ZERO_ARG
  298. // Certain Underflow p12 - MAX_SGL_ZERO_ARG < x <= MAX_SGL_UFLOW_ARG
  299. // Possible Underflow p13 - MAX_SGL_UFLOW_ARG < x < MIN_SGL_NORM_ARG
  300. // Certain Safe - MIN_SGL_NORM_ARG <= x <= MAX_SGL_NORM_ARG
  301. // Possible Overflow p14 - MAX_SGL_NORM_ARG < x < MIN_SGL_OFLOW_ARG
  302. // Certain Overflow p15 - MIN_SGL_OFLOW_ARG <= x < +inf
  303. //
  304. // If the input is really a single arg, then there will never be "Possible
  305. // Underflow" or "Possible Overflow" arguments.
  306. //
  307. { .mfi
  308. add EXP_AD_M1 = exp_GR_Ind1,EXP_AD_T1
  309. fcmp.ge.s1 p15,p14 = exp_norm_f8,EXP_MIN_SGL_OFLOW_ARG
  310. nop.i 999
  311. }
  312. { .mfi
  313. shladd EXP_AD_M2 = exp_GR_Ind2,4,EXP_AD_T2
  314. fms.s1 exp_R = f1,f8,exp_Mfloat
  315. nop.i 999 ;;
  316. }
  317. { .mfi
  318. ldfe exp_T1 = [EXP_AD_M1]
  319. fcmp.le.s1 p11,p12 = exp_norm_f8,EXP_MAX_SGL_ZERO_ARG
  320. mov exp_GR_bias = 0xffff
  321. }
  322. ;;
  323. { .mfb
  324. ldfe exp_T2 = [EXP_AD_M2]
  325. (p14) fcmp.gt.s1 p14,p0 = exp_norm_f8,EXP_MAX_SGL_NORM_ARG
  326. (p15) br.cond.spnt EXP_CERTAIN_OVERFLOW ;;
  327. }
  328. { .mfb
  329. and exp_GR_exp = exp_GR_signexp, exp_GR_17ones
  330. (p12) fcmp.le.s1 p12,p0 = exp_norm_f8,EXP_MAX_SGL_UFLOW_ARG
  331. (p11) br.cond.spnt EXP_CERTAIN_UNDERFLOW_ZERO
  332. }
  333. ;;
  334. { .mfi
  335. sub exp_GR_exp = exp_GR_exp, exp_GR_bias
  336. (p13) fcmp.lt.s1 p13,p0 = exp_norm_f8,EXP_MIN_SGL_NORM_ARG
  337. nop.i 999
  338. }
  339. ;;
  340. { .mfi
  341. nop.m 999
  342. fma.s1 exp_Rsq = exp_R,exp_R,f0
  343. nop.i 999
  344. }
  345. { .mfi
  346. nop.m 999
  347. fma.s1 exp_P3 = exp_R,exp_coeff_P2,exp_coeff_P1
  348. nop.i 999
  349. }
  350. ;;
  351. { .mfi
  352. nop.m 999
  353. fma.s1 exp_P1 = exp_R,exp_coeff_P6,exp_coeff_P5
  354. nop.i 999
  355. }
  356. { .mfi
  357. nop.m 999
  358. fma.s1 exp_P2 = exp_R,exp_coeff_P4,exp_coeff_P3
  359. nop.i 999
  360. }
  361. ;;
  362. { .mfi
  363. nop.m 999
  364. fma.s1 exp_P7 = f1,exp_R,f1
  365. nop.i 999
  366. }
  367. ;;
  368. { .mfi
  369. nop.m 999
  370. fma.s1 exp_P5 = exp_Rsq,exp_P3,f0
  371. nop.i 999
  372. }
  373. { .mfi
  374. nop.m 999
  375. fma.s1 exp_R4 = exp_Rsq,exp_Rsq,f0
  376. nop.i 999
  377. }
  378. ;;
  379. { .mfi
  380. nop.m 999
  381. fma.s1 exp_T = exp_T1,exp_T2,f0
  382. nop.i 999
  383. }
  384. { .mfi
  385. nop.m 999
  386. fma.s1 exp_P4 = exp_Rsq,exp_P1,exp_P2
  387. nop.i 999
  388. }
  389. ;;
  390. // There is a potential monotonicity problem in round to +inf. If x is
  391. // very small and negative, exp_P7 (and exp_A) will round to 1.0,
  392. // whereas exp_P6 will be very small, but positive. This would result in the
  393. // final calculation rounding to 3f800001. To fix this, we test for |x|<=2^63.
  394. // If so, the result will be set to 1+x.
  395. { .mfi
  396. cmp.ge p6,p7 = -63, exp_GR_exp
  397. fma.s1 exp_A = exp_T,exp_P7,f0
  398. nop.i 999
  399. }
  400. { .mfi
  401. nop.m 999
  402. fma.s1 exp_P6 = exp_R4,exp_P4,exp_P5
  403. nop.i 999
  404. }
  405. ;;
  406. { .bbb
  407. (p12) br.cond.spnt EXP_CERTAIN_UNDERFLOW
  408. (p13) br.cond.spnt EXP_POSSIBLE_UNDERFLOW
  409. (p14) br.cond.spnt EXP_POSSIBLE_OVERFLOW
  410. }
  411. ;;
  412. { .mfi
  413. nop.m 999
  414. (p6) fma.s f8 = f1,f1,exp_norm_f8
  415. nop.i 999
  416. }
  417. { .mfb
  418. nop.m 999
  419. (p7) fma.s f8 = exp_T,exp_P6,exp_A
  420. br.ret.sptk b0
  421. }
  422. ;;
  423. EXP_POSSIBLE_OVERFLOW:
  424. // We got an answer. EXP_MAX_SGL_NORM_ARG < x < EXP_MIN_SGL_OFLOW_ARG
  425. // overflow is a possibility, not a certainty
  426. // Set wre in s2 and perform the last operation with s2
  427. // We define an overflow when the answer with
  428. // WRE set
  429. // user-defined rounding mode
  430. // is lsn +1
  431. // Is the exponent 1 more than the largest single?
  432. // If so, go to ERROR RETURN, else (no overflow) get the answer and
  433. // leave.
  434. // Largest single is FE (biased single)
  435. // FE - 7F + FFFF = 1007E
  436. // Create + largest_single_plus_ulp
  437. // Create - largest_single_plus_ulp
  438. // Calculate answer with WRE set.
  439. // Cases when answer is lsn+1 are as follows:
  440. // midpoint
  441. // |
  442. // lsn | lsn+1
  443. // --+----------|----------+------------
  444. // |
  445. // +inf +inf -inf
  446. // RN RN
  447. // RZ
  448. // exp_gt_pln contains the floating point number lsn+1.
  449. // The setf.exp puts 0x1007f in the exponent and 0x800... in the significand.
  450. // If the answer is >= lsn+1, we have overflowed.
  451. // Then p6 is TRUE. Set the overflow tag, save input in FR_X,
  452. // do the final calculation for IEEE result, and branch to error return.
  453. { .mfi
  454. mov exp_GR_gt_ln = 0x1007F
  455. fsetc.s2 0x7F,0x42
  456. nop.i 999
  457. }
  458. ;;
  459. { .mfi
  460. setf.exp exp_gt_pln = exp_GR_gt_ln
  461. fma.s.s2 exp_wre_urm_f8 = exp_T, exp_P6, exp_A
  462. nop.i 999
  463. }
  464. ;;
  465. { .mfi
  466. nop.m 999
  467. fsetc.s2 0x7F,0x40
  468. nop.i 999
  469. }
  470. ;;
  471. { .mfi
  472. nop.m 999
  473. fcmp.ge.unc.s1 p6, p0 = exp_wre_urm_f8, exp_gt_pln
  474. nop.i 999
  475. }
  476. ;;
  477. { .mfb
  478. nop.m 999
  479. nop.f 999
  480. (p6) br.cond.spnt EXP_CERTAIN_OVERFLOW // Branch if really overflow
  481. }
  482. ;;
  483. { .mfb
  484. nop.m 999
  485. fma.s f8 = exp_T, exp_P6, exp_A
  486. br.ret.sptk b0 // Exit if really no overflow
  487. }
  488. ;;
  489. EXP_CERTAIN_OVERFLOW:
  490. { .mmi
  491. sub exp_GR_17ones_m1 = exp_GR_17ones, r0, 1 ;;
  492. setf.exp f9 = exp_GR_17ones_m1
  493. nop.i 999 ;;
  494. }
  495. { .mfi
  496. nop.m 999
  497. fmerge.s FR_X = f8,f8
  498. nop.i 999
  499. }
  500. { .mfb
  501. mov GR_Parameter_TAG = 16
  502. fma.s FR_RESULT = f9, f9, f0 // Set I,O and +INF result
  503. br.cond.sptk __libm_error_region ;;
  504. }
  505. EXP_POSSIBLE_UNDERFLOW:
  506. // We got an answer. EXP_MAX_SGL_UFLOW_ARG < x < EXP_MIN_SGL_NORM_ARG
  507. // underflow is a possibility, not a certainty
  508. // We define an underflow when the answer with
  509. // ftz set
  510. // is zero (tiny numbers become zero)
  511. // Notice (from below) that if we have an unlimited exponent range,
  512. // then there is an extra machine number E between the largest denormal and
  513. // the smallest normal.
  514. // So if with unbounded exponent we round to E or below, then we are
  515. // tiny and underflow has occurred.
  516. // But notice that you can be in a situation where we are tiny, namely
  517. // rounded to E, but when the exponent is bounded we round to smallest
  518. // normal. So the answer can be the smallest normal with underflow.
  519. // E
  520. // -----+--------------------+--------------------+-----
  521. // | | |
  522. // 1.1...10 2^-7f 1.1...11 2^-7f 1.0...00 2^-7e
  523. // 0.1...11 2^-7e (biased, 1)
  524. // largest dn smallest normal
  525. // If the answer is = 0, we have underflowed.
  526. // Then p6 is TRUE. Set the underflow tag, save input in FR_X,
  527. // do the final calculation for IEEE result, and branch to error return.
  528. { .mfi
  529. nop.m 999
  530. fsetc.s2 0x7F,0x41
  531. nop.i 999
  532. }
  533. ;;
  534. { .mfi
  535. nop.m 999
  536. fma.s.s2 exp_ftz_urm_f8 = exp_T, exp_P6, exp_A
  537. nop.i 999
  538. }
  539. ;;
  540. { .mfi
  541. nop.m 999
  542. fsetc.s2 0x7F,0x40
  543. nop.i 999
  544. }
  545. ;;
  546. { .mfi
  547. nop.m 999
  548. fcmp.eq.unc.s1 p6, p0 = exp_ftz_urm_f8, f0
  549. nop.i 999
  550. }
  551. ;;
  552. { .mfb
  553. nop.m 999
  554. nop.f 999
  555. (p6) br.cond.spnt EXP_CERTAIN_UNDERFLOW // Branch if really underflow
  556. }
  557. ;;
  558. { .mfb
  559. nop.m 999
  560. fma.s f8 = exp_T, exp_P6, exp_A
  561. br.ret.sptk b0 // Exit if really no underflow
  562. }
  563. ;;
  564. EXP_CERTAIN_UNDERFLOW:
  565. { .mfi
  566. nop.m 999
  567. fmerge.s FR_X = f8,f8
  568. nop.i 999
  569. }
  570. { .mfb
  571. mov GR_Parameter_TAG = 17
  572. fma.s FR_RESULT = exp_T, exp_P6, exp_A // Set I,U and tiny result
  573. br.cond.sptk __libm_error_region ;;
  574. }
  575. EXP_CERTAIN_UNDERFLOW_ZERO:
  576. { .mmi
  577. mov exp_GR_one = 1 ;;
  578. setf.exp f9 = exp_GR_one
  579. nop.i 999 ;;
  580. }
  581. { .mfi
  582. nop.m 999
  583. fmerge.s FR_X = f8,f8
  584. nop.i 999
  585. }
  586. { .mfb
  587. mov GR_Parameter_TAG = 17
  588. fma.s FR_RESULT = f9, f9, f0 // Set I,U and tiny (+0.0) result
  589. br.cond.sptk __libm_error_region ;;
  590. }
  591. .endp expf
  592. .proc __libm_error_region
  593. __libm_error_region:
  594. .prologue
  595. { .mfi
  596. add GR_Parameter_Y=-32,sp // Parameter 2 value
  597. nop.f 999
  598. .save ar.pfs,GR_SAVE_PFS
  599. mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
  600. }
  601. { .mfi
  602. .fframe 64
  603. add sp=-64,sp // Create new stack
  604. nop.f 0
  605. mov GR_SAVE_GP=gp // Save gp
  606. };;
  607. { .mmi
  608. stfs [GR_Parameter_Y] = FR_Y,16 // Store Parameter 2 on stack
  609. add GR_Parameter_X = 16,sp // Parameter 1 address
  610. .save b0, GR_SAVE_B0
  611. mov GR_SAVE_B0=b0 // Save b0
  612. };;
  613. .body
  614. { .mfi
  615. stfs [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
  616. nop.f 0
  617. add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
  618. }
  619. { .mib
  620. stfs [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
  621. add GR_Parameter_Y = -16,GR_Parameter_Y
  622. br.call.sptk b0=__libm_error_support# // Call error handling function
  623. };;
  624. { .mmi
  625. nop.m 0
  626. nop.m 0
  627. add GR_Parameter_RESULT = 48,sp
  628. };;
  629. { .mmi
  630. ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
  631. .restore
  632. add sp = 64,sp // Restore stack pointer
  633. mov b0 = GR_SAVE_B0 // Restore return address
  634. };;
  635. { .mib
  636. mov gp = GR_SAVE_GP // Restore gp
  637. mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
  638. br.ret.sptk b0 // Return
  639. };;
  640. .endp __libm_error_region
  641. .type __libm_error_support#,@function
  642. .global __libm_error_support#