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.

797 lines
21 KiB

  1. .file "exp.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. //
  26. // History
  27. //==============================================================
  28. // 2/02/00 Initial version
  29. // 3/07/00 exp(inf) = inf but now does NOT call error support
  30. // exp(-inf) = 0 but now does NOT call error support
  31. // 4/04/00 Unwind support added
  32. // 8/15/00 Bundle added after call to __libm_error_support to properly
  33. // set [the previously overwritten] GR_Parameter_RESULT.
  34. // 11/30/00 Reworked to shorten main path, widen main path to include all
  35. // args in normal range, and add quick exit for 0, nan, inf.
  36. // 12/05/00 Loaded constants earlier with setf to save 2 cycles.
  37. // API
  38. //==============================================================
  39. // double exp(double)
  40. // Overview of operation
  41. //==============================================================
  42. // Take the input x. w is "how many log2/128 in x?"
  43. // w = x * 128/log2
  44. // n = int(w)
  45. // x = n log2/128 + r + delta
  46. // n = 128M + index_1 + 2^4 index_2
  47. // x = M log2 + (log2/128) index_1 + (log2/8) index_2 + r + delta
  48. // exp(x) = 2^M 2^(index_1/128) 2^(index_2/8) exp(r) exp(delta)
  49. // Construct 2^M
  50. // Get 2^(index_1/128) from table_1;
  51. // Get 2^(index_2/8) from table_2;
  52. // Calculate exp(r) by series
  53. // r = x - n (log2/128)_high
  54. // delta = - n (log2/128)_low
  55. // Calculate exp(delta) as 1 + delta
  56. // Special values
  57. //==============================================================
  58. // exp(+0) = 1.0
  59. // exp(-0) = 1.0
  60. // exp(+qnan) = +qnan
  61. // exp(-qnan) = -qnan
  62. // exp(+snan) = +qnan
  63. // exp(-snan) = -qnan
  64. // exp(-inf) = +0
  65. // exp(+inf) = +inf
  66. // Overfow and Underfow
  67. //=======================
  68. // exp(-x) = smallest double normal when
  69. // x = -708.396 = c086232bdd7abcd2
  70. // exp(x) = largest double normal when
  71. // x = 709.7827 = 40862e42fefa39ef
  72. // Registers used
  73. //==============================================================
  74. // Floating Point registers used:
  75. // f8, input
  76. // f9 -> f15, f32 -> f60
  77. // General registers used:
  78. // r32 -> r60
  79. // Predicate registers used:
  80. // p6 -> p15
  81. // Assembly macros
  82. //==============================================================
  83. exp_GR_rshf = r33
  84. EXP_AD_TB1 = r34
  85. EXP_AD_TB2 = r35
  86. EXP_AD_P = r36
  87. exp_GR_N = r37
  88. exp_GR_index_1 = r38
  89. exp_GR_index_2_16 = r39
  90. exp_GR_biased_M = r40
  91. exp_GR_index_1_16 = r41
  92. EXP_AD_T1 = r42
  93. EXP_AD_T2 = r43
  94. exp_GR_sig_inv_ln2 = r44
  95. exp_GR_17ones = r45
  96. exp_GR_one = r46
  97. exp_TB1_size = r47
  98. exp_TB2_size = r48
  99. exp_GR_rshf_2to56 = r49
  100. exp_GR_gt_ln = r50
  101. exp_GR_exp_2tom56 = r51
  102. exp_GR_17ones_m1 = r52
  103. GR_SAVE_B0 = r53
  104. GR_SAVE_PFS = r54
  105. GR_SAVE_GP = r55
  106. GR_SAVE_SP = r56
  107. GR_Parameter_X = r57
  108. GR_Parameter_Y = r58
  109. GR_Parameter_RESULT = r59
  110. GR_Parameter_TAG = r60
  111. FR_X = f10
  112. FR_Y = f1
  113. FR_RESULT = f8
  114. EXP_RSHF_2TO56 = f6
  115. EXP_INV_LN2_2TO63 = f7
  116. EXP_W_2TO56_RSH = f9
  117. EXP_2TOM56 = f11
  118. exp_P4 = f12
  119. exp_P3 = f13
  120. exp_P2 = f14
  121. exp_P1 = f15
  122. exp_ln2_by_128_hi = f33
  123. exp_ln2_by_128_lo = f34
  124. EXP_RSHF = f35
  125. EXP_Nfloat = f36
  126. exp_W = f37
  127. exp_r = f38
  128. exp_f = f39
  129. exp_rsq = f40
  130. exp_rcube = f41
  131. EXP_2M = f42
  132. exp_S1 = f43
  133. exp_T1 = f44
  134. EXP_MIN_DBL_OFLOW_ARG = f45
  135. EXP_MAX_DBL_ZERO_ARG = f46
  136. EXP_MAX_DBL_NORM_ARG = f47
  137. EXP_MAX_DBL_UFLOW_ARG = f48
  138. EXP_MIN_DBL_NORM_ARG = f49
  139. exp_rP4pP3 = f50
  140. exp_P_lo = f51
  141. exp_P_hi = f52
  142. exp_P = f53
  143. exp_S = f54
  144. EXP_NORM_f8 = f56
  145. exp_wre_urm_f8 = f57
  146. exp_ftz_urm_f8 = f57
  147. exp_gt_pln = f58
  148. exp_S2 = f59
  149. exp_T2 = f60
  150. // Data tables
  151. //==============================================================
  152. .data
  153. .align 16
  154. // ************* DO NOT CHANGE ORDER OF THESE TABLES ********************
  155. // double-extended 1/ln(2)
  156. // 3fff b8aa 3b29 5c17 f0bb be87fed0691d3e88
  157. // 3fff b8aa 3b29 5c17 f0bc
  158. // For speed the significand will be loaded directly with a movl and setf.sig
  159. // and the exponent will be bias+63 instead of bias+0. Thus subsequent
  160. // computations need to scale appropriately.
  161. // The constant 128/ln(2) is needed for the computation of w. This is also
  162. // obtained by scaling the computations.
  163. //
  164. // Two shifting constants are loaded directly with movl and setf.d.
  165. // 1. EXP_RSHF_2TO56 = 1.1000..00 * 2^(63-7)
  166. // This constant is added to x*1/ln2 to shift the integer part of
  167. // x*128/ln2 into the rightmost bits of the significand.
  168. // The result of this fma is EXP_W_2TO56_RSH.
  169. // 2. EXP_RSHF = 1.1000..00 * 2^(63)
  170. // This constant is subtracted from EXP_W_2TO56_RSH * 2^(-56) to give
  171. // the integer part of w, n, as a floating-point number.
  172. // The result of this fms is EXP_Nfloat.
  173. exp_table_1:
  174. data8 0x40862e42fefa39f0 // smallest dbl overflow arg
  175. data8 0xc0874c0000000000 // approx largest arg for zero result
  176. data8 0x40862e42fefa39ef // largest dbl arg to give normal dbl result
  177. data8 0xc086232bdd7abcd3 // largest dbl underflow arg
  178. data8 0xc086232bdd7abcd2 // smallest dbl arg to give normal dbl result
  179. data8 0x0 // pad
  180. data8 0xb17217f7d1cf79ab , 0x00003ff7 // ln2/128 hi
  181. data8 0xc9e3b39803f2f6af , 0x00003fb7 // ln2/128 lo
  182. // Table 1 is 2^(index_1/128) where
  183. // index_1 goes from 0 to 15
  184. data8 0x8000000000000000 , 0x00003FFF
  185. data8 0x80B1ED4FD999AB6C , 0x00003FFF
  186. data8 0x8164D1F3BC030773 , 0x00003FFF
  187. data8 0x8218AF4373FC25EC , 0x00003FFF
  188. data8 0x82CD8698AC2BA1D7 , 0x00003FFF
  189. data8 0x8383594EEFB6EE37 , 0x00003FFF
  190. data8 0x843A28C3ACDE4046 , 0x00003FFF
  191. data8 0x84F1F656379C1A29 , 0x00003FFF
  192. data8 0x85AAC367CC487B15 , 0x00003FFF
  193. data8 0x8664915B923FBA04 , 0x00003FFF
  194. data8 0x871F61969E8D1010 , 0x00003FFF
  195. data8 0x87DB357FF698D792 , 0x00003FFF
  196. data8 0x88980E8092DA8527 , 0x00003FFF
  197. data8 0x8955EE03618E5FDD , 0x00003FFF
  198. data8 0x8A14D575496EFD9A , 0x00003FFF
  199. data8 0x8AD4C6452C728924 , 0x00003FFF
  200. // Table 2 is 2^(index_1/8) where
  201. // index_2 goes from 0 to 7
  202. exp_table_2:
  203. data8 0x8000000000000000 , 0x00003FFF
  204. data8 0x8B95C1E3EA8BD6E7 , 0x00003FFF
  205. data8 0x9837F0518DB8A96F , 0x00003FFF
  206. data8 0xA5FED6A9B15138EA , 0x00003FFF
  207. data8 0xB504F333F9DE6484 , 0x00003FFF
  208. data8 0xC5672A115506DADD , 0x00003FFF
  209. data8 0xD744FCCAD69D6AF4 , 0x00003FFF
  210. data8 0xEAC0C6E7DD24392F , 0x00003FFF
  211. exp_p_table:
  212. data8 0x3f8111116da21757 //P_4
  213. data8 0x3fa55555d787761c //P_3
  214. data8 0x3fc5555555555414 //P_2
  215. data8 0x3fdffffffffffd6a //P_1
  216. .align 32
  217. .global exp#
  218. .section .text
  219. .proc exp#
  220. .align 32
  221. exp:
  222. { .mlx
  223. alloc r32=ar.pfs,1,24,4,0
  224. movl exp_GR_sig_inv_ln2 = 0xb8aa3b295c17f0bc // significand of 1/ln2
  225. }
  226. { .mlx
  227. addl EXP_AD_TB1 = @ltoff(exp_table_1), gp
  228. movl exp_GR_rshf_2to56 = 0x4768000000000000 ;; // 1.10000 2^(63+56)
  229. }
  230. ;;
  231. // We do this fnorm right at the beginning to take any enabled
  232. // faults and to normalize any input unnormals so that SWA is not taken.
  233. { .mfi
  234. ld8 EXP_AD_TB1 = [EXP_AD_TB1]
  235. fclass.m p8,p0 = f8,0x07 // Test for x=0
  236. mov exp_GR_17ones = 0x1FFFF
  237. }
  238. { .mfi
  239. mov exp_TB1_size = 0x100
  240. fnorm EXP_NORM_f8 = f8
  241. mov exp_GR_exp_2tom56 = 0xffff-56
  242. }
  243. ;;
  244. // Form two constants we need
  245. // 1/ln2 * 2^63 to compute w = x * 1/ln2 * 128
  246. // 1.1000..000 * 2^(63+63-7) to right shift int(w) into the significand
  247. { .mmf
  248. setf.sig EXP_INV_LN2_2TO63 = exp_GR_sig_inv_ln2 // form 1/ln2 * 2^63
  249. setf.d EXP_RSHF_2TO56 = exp_GR_rshf_2to56 // Form const 1.100 * 2^(63+56)
  250. fclass.m p9,p0 = f8,0x22 // Test for x=-inf
  251. }
  252. ;;
  253. { .mlx
  254. setf.exp EXP_2TOM56 = exp_GR_exp_2tom56 // form 2^-56 for scaling Nfloat
  255. movl exp_GR_rshf = 0x43e8000000000000 // 1.10000 2^63 for right shift
  256. }
  257. { .mfb
  258. mov exp_TB2_size = 0x80
  259. (p8) fma.d f8 = f1,f1,f0 // quick exit for x=0
  260. (p8) br.ret.spnt b0
  261. ;;
  262. }
  263. { .mfi
  264. ldfpd EXP_MIN_DBL_OFLOW_ARG, EXP_MAX_DBL_ZERO_ARG = [EXP_AD_TB1],16
  265. fclass.m p10,p0 = f8,0x21 // Test for x=+inf
  266. nop.i 999
  267. }
  268. { .mfb
  269. nop.m 999
  270. (p9) fma.d f8 = f0,f0,f0 // quick exit for x=-inf
  271. (p9) br.ret.spnt b0
  272. ;;
  273. }
  274. { .mmf
  275. ldfpd EXP_MAX_DBL_NORM_ARG, EXP_MAX_DBL_UFLOW_ARG = [EXP_AD_TB1],16
  276. setf.d EXP_RSHF = exp_GR_rshf // Form right shift const 1.100 * 2^63
  277. fclass.m p11,p0 = f8,0xc3 // Test for x=nan
  278. ;;
  279. }
  280. { .mfb
  281. ldfd EXP_MIN_DBL_NORM_ARG = [EXP_AD_TB1],16
  282. nop.f 999
  283. (p10) br.ret.spnt b0 // quick exit for x=+inf
  284. ;;
  285. }
  286. { .mfi
  287. ldfe exp_ln2_by_128_hi = [EXP_AD_TB1],16
  288. nop.f 999
  289. nop.i 999
  290. ;;
  291. }
  292. { .mfb
  293. ldfe exp_ln2_by_128_lo = [EXP_AD_TB1],16
  294. (p11) fmerge.s f8 = EXP_NORM_f8, EXP_NORM_f8
  295. (p11) br.ret.spnt b0 // quick exit for x=nan
  296. ;;
  297. }
  298. // After that last load, EXP_AD_TB1 points to the beginning of table 1
  299. // W = X * Inv_log2_by_128
  300. // By adding 1.10...0*2^63 we shift and get round_int(W) in significand.
  301. // We actually add 1.10...0*2^56 to X * Inv_log2 to do the same thing.
  302. { .mfi
  303. nop.m 999
  304. fma.s1 EXP_W_2TO56_RSH = EXP_NORM_f8, EXP_INV_LN2_2TO63, EXP_RSHF_2TO56
  305. nop.i 999
  306. ;;
  307. }
  308. // Divide arguments into the following categories:
  309. // Certain Underflow/zero p11 - -inf < x <= MAX_DBL_ZERO_ARG
  310. // Certain Underflow p12 - MAX_DBL_ZERO_ARG < x <= MAX_DBL_UFLOW_ARG
  311. // Possible Underflow p13 - MAX_DBL_UFLOW_ARG < x < MIN_DBL_NORM_ARG
  312. // Certain Safe - MIN_DBL_NORM_ARG <= x <= MAX_DBL_NORM_ARG
  313. // Possible Overflow p14 - MAX_DBL_NORM_ARG < x < MIN_DBL_OFLOW_ARG
  314. // Certain Overflow p15 - MIN_DBL_OFLOW_ARG <= x < +inf
  315. //
  316. // If the input is really a double arg, then there will never be "Possible
  317. // Underflow" or "Possible Overflow" arguments.
  318. //
  319. { .mfi
  320. add EXP_AD_TB2 = exp_TB1_size, EXP_AD_TB1
  321. fcmp.ge.s1 p15,p14 = EXP_NORM_f8,EXP_MIN_DBL_OFLOW_ARG
  322. nop.i 999
  323. ;;
  324. }
  325. { .mfi
  326. add EXP_AD_P = exp_TB2_size, EXP_AD_TB2
  327. fcmp.le.s1 p11,p12 = EXP_NORM_f8,EXP_MAX_DBL_ZERO_ARG
  328. nop.i 999
  329. ;;
  330. }
  331. { .mfb
  332. ldfpd exp_P4, exp_P3 = [EXP_AD_P] ,16
  333. (p14) fcmp.gt.unc.s1 p14,p0 = EXP_NORM_f8,EXP_MAX_DBL_NORM_ARG
  334. (p15) br.cond.spnt EXP_CERTAIN_OVERFLOW
  335. ;;
  336. }
  337. // Nfloat = round_int(W)
  338. // The signficand of EXP_W_2TO56_RSH contains the rounded integer part of W,
  339. // as a twos complement number in the lower bits (that is, it may be negative).
  340. // That twos complement number (called N) is put into exp_GR_N.
  341. // Since EXP_W_2TO56_RSH is scaled by 2^56, it must be multiplied by 2^-56
  342. // before the shift constant 1.10000 * 2^63 is subtracted to yield EXP_Nfloat.
  343. // Thus, EXP_Nfloat contains the floating point version of N
  344. { .mfi
  345. nop.m 999
  346. (p12) fcmp.le.unc p12,p0 = EXP_NORM_f8,EXP_MAX_DBL_UFLOW_ARG
  347. nop.i 999
  348. }
  349. { .mfb
  350. ldfpd exp_P2, exp_P1 = [EXP_AD_P]
  351. fms.s1 EXP_Nfloat = EXP_W_2TO56_RSH, EXP_2TOM56, EXP_RSHF
  352. (p11) br.cond.spnt EXP_CERTAIN_UNDERFLOW_ZERO
  353. ;;
  354. }
  355. { .mfi
  356. getf.sig exp_GR_N = EXP_W_2TO56_RSH
  357. (p13) fcmp.lt.unc p13,p0 = EXP_NORM_f8,EXP_MIN_DBL_NORM_ARG
  358. nop.i 999
  359. ;;
  360. }
  361. // exp_GR_index_1 has index_1
  362. // exp_GR_index_2_16 has index_2 * 16
  363. // exp_GR_biased_M has M
  364. // exp_GR_index_1_16 has index_1 * 16
  365. // r2 has true M
  366. { .mfi
  367. and exp_GR_index_1 = 0x0f, exp_GR_N
  368. fnma.s1 exp_r = EXP_Nfloat, exp_ln2_by_128_hi, EXP_NORM_f8
  369. shr r2 = exp_GR_N, 0x7
  370. }
  371. { .mfi
  372. and exp_GR_index_2_16 = 0x70, exp_GR_N
  373. fnma.s1 exp_f = EXP_Nfloat, exp_ln2_by_128_lo, f1
  374. nop.i 999
  375. ;;
  376. }
  377. // EXP_AD_T1 has address of T1
  378. // EXP_AD_T2 has address if T2
  379. { .mmi
  380. addl exp_GR_biased_M = 0xffff, r2
  381. add EXP_AD_T2 = EXP_AD_TB2, exp_GR_index_2_16
  382. shladd EXP_AD_T1 = exp_GR_index_1, 4, EXP_AD_TB1
  383. ;;
  384. }
  385. // Create Scale = 2^M
  386. // r = x - Nfloat * ln2_by_128_hi
  387. // f = 1 - Nfloat * ln2_by_128_lo
  388. { .mmi
  389. setf.exp EXP_2M = exp_GR_biased_M
  390. ldfe exp_T2 = [EXP_AD_T2]
  391. nop.i 999
  392. ;;
  393. }
  394. // Load T1 and T2
  395. { .mfi
  396. ldfe exp_T1 = [EXP_AD_T1]
  397. nop.f 999
  398. nop.i 999
  399. ;;
  400. }
  401. { .mfi
  402. nop.m 999
  403. fma.s1 exp_rsq = exp_r, exp_r, f0
  404. nop.i 999
  405. }
  406. { .mfi
  407. nop.m 999
  408. fma.s1 exp_rP4pP3 = exp_r, exp_P4, exp_P3
  409. nop.i 999
  410. ;;
  411. }
  412. { .mfi
  413. nop.m 999
  414. fma.s1 exp_rcube = exp_r, exp_rsq, f0
  415. nop.i 999
  416. }
  417. { .mfi
  418. nop.m 999
  419. fma.s1 exp_P_lo = exp_r, exp_rP4pP3, exp_P2
  420. nop.i 999
  421. ;;
  422. }
  423. { .mfi
  424. nop.m 999
  425. fma.s1 exp_P_hi = exp_rsq, exp_P1, exp_r
  426. nop.i 999
  427. }
  428. { .mfi
  429. nop.m 999
  430. fma.s1 exp_S2 = exp_f,exp_T2,f0
  431. nop.i 999
  432. ;;
  433. }
  434. { .mfi
  435. nop.m 999
  436. fma.s1 exp_S1 = EXP_2M,exp_T1,f0
  437. nop.i 999
  438. ;;
  439. }
  440. { .mfi
  441. nop.m 999
  442. fma.s1 exp_P = exp_rcube, exp_P_lo, exp_P_hi
  443. nop.i 999
  444. ;;
  445. }
  446. { .mfi
  447. nop.m 999
  448. fma.s1 exp_S = exp_S1,exp_S2,f0
  449. nop.i 999
  450. ;;
  451. }
  452. { .bbb
  453. (p12) br.cond.spnt EXP_CERTAIN_UNDERFLOW
  454. (p13) br.cond.spnt EXP_POSSIBLE_UNDERFLOW
  455. (p14) br.cond.spnt EXP_POSSIBLE_OVERFLOW
  456. ;;
  457. }
  458. { .mfb
  459. nop.m 999
  460. fma.d f8 = exp_S, exp_P, exp_S
  461. br.ret.sptk b0 ;; // Normal path exit
  462. }
  463. EXP_POSSIBLE_OVERFLOW:
  464. // We got an answer. EXP_MAX_DBL_NORM_ARG < x < EXP_MIN_DBL_OFLOW_ARG
  465. // overflow is a possibility, not a certainty
  466. { .mfi
  467. nop.m 999
  468. fsetc.s2 0x7F,0x42
  469. nop.i 999 ;;
  470. }
  471. { .mfi
  472. nop.m 999
  473. fma.d.s2 exp_wre_urm_f8 = exp_S, exp_P, exp_S
  474. nop.i 999 ;;
  475. }
  476. // We define an overflow when the answer with
  477. // WRE set
  478. // user-defined rounding mode
  479. // is ldn +1
  480. // Is the exponent 1 more than the largest double?
  481. // If so, go to ERROR RETURN, else get the answer and
  482. // leave.
  483. // Largest double is 7FE (biased double)
  484. // 7FE - 3FF + FFFF = 103FE
  485. // Create + largest_double_plus_ulp
  486. // Create - largest_double_plus_ulp
  487. // Calculate answer with WRE set.
  488. // Cases when answer is ldn+1 are as follows:
  489. // ldn ldn+1
  490. // --+----------|----------+------------
  491. // |
  492. // +inf +inf -inf
  493. // RN RN
  494. // RZ
  495. { .mfi
  496. nop.m 999
  497. fsetc.s2 0x7F,0x40
  498. mov exp_GR_gt_ln = 0x103ff ;;
  499. }
  500. { .mfi
  501. setf.exp exp_gt_pln = exp_GR_gt_ln
  502. nop.f 999
  503. nop.i 999 ;;
  504. }
  505. { .mfi
  506. nop.m 999
  507. fcmp.ge.unc.s1 p6, p0 = exp_wre_urm_f8, exp_gt_pln
  508. nop.i 999 ;;
  509. }
  510. { .mfb
  511. nop.m 999
  512. nop.f 999
  513. (p6) br.cond.spnt EXP_CERTAIN_OVERFLOW ;; // Branch if really overflow
  514. }
  515. { .mfb
  516. nop.m 999
  517. fma.d f8 = exp_S, exp_P, exp_S
  518. br.ret.sptk b0 ;; // Exit if really no overflow
  519. }
  520. EXP_CERTAIN_OVERFLOW:
  521. { .mmi
  522. sub exp_GR_17ones_m1 = exp_GR_17ones, r0, 1 ;;
  523. setf.exp f9 = exp_GR_17ones_m1
  524. nop.i 999 ;;
  525. }
  526. { .mfi
  527. nop.m 999
  528. fmerge.s FR_X = f8,f8
  529. nop.i 999
  530. }
  531. { .mfb
  532. mov GR_Parameter_TAG = 14
  533. fma.d FR_RESULT = f9, f9, f0 // Set I,O and +INF result
  534. br.cond.sptk __libm_error_region ;;
  535. }
  536. EXP_POSSIBLE_UNDERFLOW:
  537. // We got an answer. EXP_MAX_DBL_UFLOW_ARG < x < EXP_MIN_DBL_NORM_ARG
  538. // underflow is a possibility, not a certainty
  539. // We define an underflow when the answer with
  540. // ftz set
  541. // is zero (tiny numbers become zero)
  542. // Notice (from below) that if we have an unlimited exponent range,
  543. // then there is an extra machine number E between the largest denormal and
  544. // the smallest normal.
  545. // So if with unbounded exponent we round to E or below, then we are
  546. // tiny and underflow has occurred.
  547. // But notice that you can be in a situation where we are tiny, namely
  548. // rounded to E, but when the exponent is bounded we round to smallest
  549. // normal. So the answer can be the smallest normal with underflow.
  550. // E
  551. // -----+--------------------+--------------------+-----
  552. // | | |
  553. // 1.1...10 2^-3fff 1.1...11 2^-3fff 1.0...00 2^-3ffe
  554. // 0.1...11 2^-3ffe (biased, 1)
  555. // largest dn smallest normal
  556. { .mfi
  557. nop.m 999
  558. fsetc.s2 0x7F,0x41
  559. nop.i 999 ;;
  560. }
  561. { .mfi
  562. nop.m 999
  563. fma.d.s2 exp_ftz_urm_f8 = exp_S, exp_P, exp_S
  564. nop.i 999 ;;
  565. }
  566. { .mfi
  567. nop.m 999
  568. fsetc.s2 0x7F,0x40
  569. nop.i 999 ;;
  570. }
  571. { .mfi
  572. nop.m 999
  573. fcmp.eq.unc.s1 p6, p0 = exp_ftz_urm_f8, f0
  574. nop.i 999 ;;
  575. }
  576. { .mfb
  577. nop.m 999
  578. nop.f 999
  579. (p6) br.cond.spnt EXP_CERTAIN_UNDERFLOW ;; // Branch if really underflow
  580. }
  581. { .mfb
  582. nop.m 999
  583. fma.d f8 = exp_S, exp_P, exp_S
  584. br.ret.sptk b0 ;; // Exit if really no underflow
  585. }
  586. EXP_CERTAIN_UNDERFLOW:
  587. { .mfi
  588. nop.m 999
  589. fmerge.s FR_X = f8,f8
  590. nop.i 999
  591. }
  592. { .mfb
  593. mov GR_Parameter_TAG = 15
  594. fma.d FR_RESULT = exp_S, exp_P, exp_S // Set I,U and tiny result
  595. br.cond.sptk __libm_error_region ;;
  596. }
  597. EXP_CERTAIN_UNDERFLOW_ZERO:
  598. { .mmi
  599. mov exp_GR_one = 1 ;;
  600. setf.exp f9 = exp_GR_one
  601. nop.i 999 ;;
  602. }
  603. { .mfi
  604. nop.m 999
  605. fmerge.s FR_X = f8,f8
  606. nop.i 999
  607. }
  608. { .mfb
  609. mov GR_Parameter_TAG = 15
  610. fma.d FR_RESULT = f9, f9, f0 // Set I,U and tiny (+0.0) result
  611. br.cond.sptk __libm_error_region ;;
  612. }
  613. .endp exp
  614. .proc __libm_error_region
  615. __libm_error_region:
  616. .prologue
  617. { .mfi
  618. add GR_Parameter_Y=-32,sp // Parameter 2 value
  619. nop.f 0
  620. .save ar.pfs,GR_SAVE_PFS
  621. mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
  622. }
  623. { .mfi
  624. .fframe 64
  625. add sp=-64,sp // Create new stack
  626. nop.f 0
  627. mov GR_SAVE_GP=gp // Save gp
  628. };;
  629. { .mmi
  630. stfd [GR_Parameter_Y] = FR_Y,16 // STORE Parameter 2 on stack
  631. add GR_Parameter_X = 16,sp // Parameter 1 address
  632. .save b0, GR_SAVE_B0
  633. mov GR_SAVE_B0=b0 // Save b0
  634. };;
  635. .body
  636. { .mib
  637. stfd [GR_Parameter_X] = FR_X // STORE Parameter 1 on stack
  638. add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
  639. nop.b 0
  640. }
  641. { .mib
  642. stfd [GR_Parameter_Y] = FR_RESULT // STORE Parameter 3 on stack
  643. add GR_Parameter_Y = -16,GR_Parameter_Y
  644. br.call.sptk b0=__libm_error_support# // Call error handling function
  645. };;
  646. { .mmi
  647. nop.m 0
  648. nop.m 0
  649. add GR_Parameter_RESULT = 48,sp
  650. };;
  651. { .mmi
  652. ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack
  653. .restore
  654. add sp = 64,sp // Restore stack pointer
  655. mov b0 = GR_SAVE_B0 // Restore return address
  656. };;
  657. { .mib
  658. mov gp = GR_SAVE_GP // Restore gp
  659. mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
  660. br.ret.sptk b0 // Return
  661. };;
  662. .endp __libm_error_region
  663. .type __libm_error_support#,@function
  664. .global __libm_error_support#