Source code of Windows XP (NT5)
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.

747 lines
20 KiB

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