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.

631 lines
18 KiB

  1. .file "tanh.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. //
  26. // History
  27. //==============================================================
  28. // 05/30/01 Initial version
  29. //
  30. // API
  31. //==============================================================
  32. // double tanh(double)
  33. //
  34. // Overview of operation
  35. //==============================================================
  36. //
  37. // There are 8 paths:
  38. // 1. x = +/-0.0
  39. // Return tanh(x) = +/-0.0
  40. //
  41. // 2. MAX_DENORMAL_ABS < |x| < 1/16
  42. // Return tanh(x) = P13(x), where
  43. // P13(x) = (((C13*x^2 + C11)*x^4 + (C9*x^2 + C7))*x^4 +
  44. // (C5*x^2 + C3))*x^3 + x
  45. //
  46. // 3. 1/16 <= |x| < 32
  47. // Return tanh(x) = sign(x)*(1 - 2 / (1 + exp(2*|x|))
  48. // Algorithm description for exp function see below
  49. //
  50. // 4. 32 <= |x| < +INF
  51. // Return tanh(x) = sign(x)*(1.0 - 2^(63))
  52. //
  53. // 5. x = +/-INF
  54. // Return tanh(x) = sign(x)
  55. //
  56. // 6. x = [S,Q]NaN
  57. // Return tanh(x) = QNaN
  58. //
  59. // 7. x is positive denormal
  60. // Return tanhf(x) = x - x^2
  61. //
  62. // 8. x is negative denormal
  63. // Return tanhf(x) = x + x^2
  64. //
  65. //==============================================================
  66. // Algorithm Description for exp(x) function
  67. //
  68. // Take the input x. w is "how many log2/128 in x?"
  69. // w = x * 128/log2
  70. // n = int(w)
  71. // x = n log2/128 + r + delta
  72. // n = 128M + index_1 + 2^4 index_2
  73. // x = M log2 + (log2/128) index_1 + (log2/8) index_2 + r + delta
  74. // exp(x) = 2^M 2^(index_1/128) 2^(index_2/8) exp(r) exp(delta)
  75. // Construct 2^M
  76. // Get 2^(index_1/128) from table_1;
  77. // Get 2^(index_2/8) from table_2;
  78. // Calculate exp(r) by series
  79. // r = x - n (log2/128)_high
  80. // delta = - n (log2/128)_low
  81. // Calculate exp(delta) as 1 + delta
  82. // Registers used
  83. //==============================================================
  84. // Floating Point registers used:
  85. // f8, input
  86. // f32 -> f75
  87. // General registers used:
  88. // r32 -> r57
  89. // Predicate registers used:
  90. // p6 -> p15
  91. // Assembly macros
  92. //==============================================================
  93. exp_GR_rshf = r33
  94. EXP_AD_TB1 = r34
  95. EXP_AD_TB2 = r35
  96. EXP_AD_P = r36
  97. exp_GR_N = r37
  98. exp_GR_index_1 = r38
  99. exp_GR_index_2_16 = r39
  100. exp_GR_biased_M = r40
  101. exp_GR_index_1_16 = r41
  102. EXP_AD_T1 = r42
  103. EXP_AD_T2 = r43
  104. exp_GR_sig_inv_ln2 = r44
  105. exp_GR_17ones = r45
  106. exp_GR_rshf_2to56 = r46
  107. exp_GR_exp_2tom56 = r47
  108. exp_Expb = r48
  109. exp_ExpbOf2to4 = r49
  110. exp_NearZeroBound = r50
  111. TANH_NZ_CF = r51
  112. ALMOST_ONE = r52
  113. DATA_PTR = r53
  114. reg_RcMask = r54
  115. reg_ArFsr = r55
  116. reg_RcDown = r56
  117. reg_RcUp = r57
  118. //==============================================================
  119. EXP_RSHF_2TO56 = f33
  120. EXP_INV_LN2_2TO63 = f34
  121. EXP_W_2TO56_RSH = f35
  122. EXP_2TOM56 = f36
  123. exp_P4 = f37
  124. exp_P3 = f38
  125. exp_P2 = f39
  126. exp_P1 = f40
  127. exp_ln2_by_128_hi = f41
  128. exp_ln2_by_128_lo = f42
  129. EXP_RSHF = f43
  130. EXP_Nfloat = f44
  131. exp_r = f45
  132. exp_f = f46
  133. exp_rsq = f47
  134. exp_rcube = f48
  135. EXP_2M = f49
  136. exp_S1 = f50
  137. exp_T1 = f51
  138. exp_rP4pP3 = f52
  139. exp_P_lo = f53
  140. exp_P_hi = f54
  141. exp_P = f55
  142. exp_S = f56
  143. exp_ExppOne = f57
  144. EXP_NORM_f8 = f58
  145. exp_S2 = f59
  146. exp_T2 = f60
  147. tanh_rcp0 = f61
  148. tanh_rcp1 = f62
  149. tanh_rcp2 = f63
  150. tanh_rcp3 = f64
  151. tanh_Two = f65
  152. tanh_C13 = f66
  153. tanh_C11 = f67
  154. tanh_C9 = f68
  155. tanh_C7 = f69
  156. tanh_C5 = f70
  157. tanh_C3 = f71
  158. tanh_X4 = f72
  159. tanh_X3 = f73
  160. tanh_X2 = f74
  161. tanh_AlmostOne = f75
  162. // Data tables
  163. //==============================================================
  164. .data
  165. .align 16
  166. // ************* DO NOT CHANGE ORDER OF THESE TABLES ********************
  167. // double-extended 1/ln(2)
  168. // 3fff b8aa 3b29 5c17 f0bb be87fed0691d3e88
  169. // 3fff b8aa 3b29 5c17 f0bc
  170. // For speed the significand will be loaded directly with a movl and setf.sig
  171. // and the exponent will be bias+63 instead of bias+0. Thus subsequent
  172. // computations need to scale appropriately.
  173. // The constant 128/ln(2) is needed for the computation of w. This is also
  174. // obtained by scaling the computations.
  175. //
  176. // Two shifting constants are loaded directly with movl and setf.d.
  177. // 1. EXP_RSHF_2TO56 = 1.1000..00 * 2^(63-7)
  178. // This constant is added to x*1/ln2 to shift the integer part of
  179. // x*128/ln2 into the rightmost bits of the significand.
  180. // The result of this fma is EXP_W_2TO56_RSH.
  181. // 2. EXP_RSHF = 1.1000..00 * 2^(63)
  182. // This constant is subtracted from EXP_W_2TO56_RSH * 2^(-56) to give
  183. // the integer part of w, n, as a floating-point number.
  184. // The result of this fms is EXP_Nfloat.
  185. tanh_data:
  186. data8 0xeb69e870abeefdb0, 0x00003ff6 // C13
  187. data8 0x91371aaf3611e47b, 0x0000bff8 // C11
  188. data8 0xb327a4416087cf99, 0x00003ff9 // C9
  189. data8 0xb17217f7d1cf79ab , 0x00003ff7 // ln2/128 hi
  190. data8 0xffffffffffffffff, 0x00003ffe // almost one
  191. data8 0xc9e3b39803f2f6af , 0x00003fb7 // ln2/128 lo
  192. data8 0xdd0dd0dd0dd0dd0e, 0x0000bffa // C7
  193. data8 0x8888888888888889, 0x00003ffc // C5
  194. data8 0xaaaaaaaaaaaaaaab, 0x0000bffd // C3
  195. data8 0x8000000000000001, 0x00004000 // almost two
  196. // Table 1 is 2^(index_1/128) where
  197. // index_1 goes from 0 to 15
  198. data8 0x8000000000000000 , 0x00003FFF
  199. data8 0x80B1ED4FD999AB6C , 0x00003FFF
  200. data8 0x8164D1F3BC030773 , 0x00003FFF
  201. data8 0x8218AF4373FC25EC , 0x00003FFF
  202. data8 0x82CD8698AC2BA1D7 , 0x00003FFF
  203. data8 0x8383594EEFB6EE37 , 0x00003FFF
  204. data8 0x843A28C3ACDE4046 , 0x00003FFF
  205. data8 0x84F1F656379C1A29 , 0x00003FFF
  206. data8 0x85AAC367CC487B15 , 0x00003FFF
  207. data8 0x8664915B923FBA04 , 0x00003FFF
  208. data8 0x871F61969E8D1010 , 0x00003FFF
  209. data8 0x87DB357FF698D792 , 0x00003FFF
  210. data8 0x88980E8092DA8527 , 0x00003FFF
  211. data8 0x8955EE03618E5FDD , 0x00003FFF
  212. data8 0x8A14D575496EFD9A , 0x00003FFF
  213. data8 0x8AD4C6452C728924 , 0x00003FFF
  214. // Table 2 is 2^(index_1/8) where
  215. // index_2 goes from 0 to 7
  216. data8 0x8000000000000000 , 0x00003FFF
  217. data8 0x8B95C1E3EA8BD6E7 , 0x00003FFF
  218. data8 0x9837F0518DB8A96F , 0x00003FFF
  219. data8 0xA5FED6A9B15138EA , 0x00003FFF
  220. data8 0xB504F333F9DE6484 , 0x00003FFF
  221. data8 0xC5672A115506DADD , 0x00003FFF
  222. data8 0xD744FCCAD69D6AF4 , 0x00003FFF
  223. data8 0xEAC0C6E7DD24392F , 0x00003FFF
  224. data8 0x3f8111116da21757 //P_4
  225. data8 0x3fa55555d787761c //P_3
  226. data8 0x3fc5555555555414 //P_2
  227. data8 0x3fdffffffffffd6a //P_1
  228. .align 32
  229. .global tanh#
  230. .section .text
  231. .proc tanh#
  232. .align 32
  233. tanh:
  234. { .mlx
  235. alloc r32=ar.pfs,1,25,0,0
  236. // significand of 1/ln2
  237. movl exp_GR_sig_inv_ln2 = 0xb8aa3b295c17f0bc
  238. }
  239. { .mlx
  240. addl DATA_PTR = @ltoff(tanh_data), gp
  241. movl exp_GR_rshf_2to56 = 0x4768000000000000 // 1.1 * 2^(63+56)
  242. };;
  243. // We do this fnorm right at the beginning to take any enabled
  244. // faults and to normalize any input unnormals so that SWA is not taken.
  245. { .mfi
  246. ld8 EXP_AD_TB1 = [DATA_PTR]
  247. fclass.m p6,p0 = f8, 0xC7 // is arg NaN or +/-0 ?
  248. mov exp_GR_17ones = 0x1FFFF
  249. }
  250. { .mfi
  251. ld8 ALMOST_ONE = [DATA_PTR]
  252. fma.s1 EXP_NORM_f8 = f8, f1, f8 // 2*x
  253. mov exp_GR_exp_2tom56 = 0xFFFF-56
  254. };;
  255. // Form two constants we need
  256. // 1/ln2 * 2^63 to compute w = x * 1/ln2 * 128
  257. // 1.1000..000 * 2^(63+63-7) to right shift int(w) into the significand
  258. { .mmf
  259. // form 1/ln2 * 2^63
  260. setf.sig EXP_INV_LN2_2TO63 = exp_GR_sig_inv_ln2
  261. // form const 1.1 * 2^(63+56)
  262. setf.d EXP_RSHF_2TO56 = exp_GR_rshf_2to56
  263. fclass.m p7,p0 = f8, 0x0A // is arg -denormal ?
  264. };;
  265. { .mlx
  266. // form 2^-56 for scaling Nfloat
  267. setf.exp EXP_2TOM56 = exp_GR_exp_2tom56
  268. // 1.10000 2^63 for right shift
  269. movl exp_GR_rshf = 0x43e8000000000000
  270. }
  271. { .mfb
  272. nop.m 0
  273. (p6) fma.d.s0 f8 = f8, f1, f8 // NaN or +/-0
  274. (p6) br.ret.spnt b0
  275. };;
  276. { .mfi
  277. getf.exp exp_Expb = f8
  278. fclass.m p8,p0 = f8, 0x09 // is arg +denormal ?
  279. adds ALMOST_ONE = 0x40, ALMOST_ONE
  280. }
  281. { .mfb
  282. ldfe tanh_C13 = [EXP_AD_TB1], 16
  283. (p7) fma.d.s0 f8 = f8, f8, f8 // -denormal
  284. (p7) br.ret.spnt b0
  285. };;
  286. { .mfi
  287. // Form right shift const 1.100 * 2^63
  288. setf.d EXP_RSHF = exp_GR_rshf
  289. fma.s1 tanh_X2 = f8, f8, f0
  290. mov exp_ExpbOf2to4 = 0x10003 // biased exp of 16
  291. }
  292. { .mfi
  293. ldfe tanh_C11 = [EXP_AD_TB1], 16
  294. nop.f 0
  295. mov exp_NearZeroBound = 0xFFFB
  296. };;
  297. { .mfi
  298. ldfe tanh_C9 = [EXP_AD_TB1], 16
  299. fcmp.lt p10, p11 = f8, f0 // is x < 0 ?
  300. and exp_Expb = exp_Expb, exp_GR_17ones
  301. };;
  302. { .mfi
  303. ldfe exp_ln2_by_128_hi = [EXP_AD_TB1], 32
  304. fma.s1 tanh_Two = f1, f1, f1
  305. cmp.gtu p13, p0 = exp_Expb, exp_ExpbOf2to4
  306. }
  307. { .mfi
  308. ldfe tanh_AlmostOne = [ALMOST_ONE], 80
  309. nop.f 0
  310. cmp.eq p9, p0 = exp_Expb, exp_GR_17ones
  311. };;
  312. { .mfi
  313. ldfe exp_ln2_by_128_lo = [EXP_AD_TB1], 16
  314. (p8) fnma.d.s0 f8 = f8, f8, f8 // +denormal
  315. mov reg_RcDown = 0x400
  316. }
  317. { .mfb
  318. cmp.ltu p12, p0 = exp_Expb, exp_NearZeroBound
  319. nop.f 0
  320. (p8) br.ret.spnt b0
  321. };;
  322. { .mfi
  323. mov reg_ArFsr = ar.fpsr
  324. (p9) fmerge.s f8 = f8,f1 // +/- inf
  325. adds TANH_NZ_CF = -32, ALMOST_ONE
  326. }
  327. { .mfb
  328. ldfe tanh_C7 = [EXP_AD_TB1], 16
  329. nop.f 0
  330. (p9) br.ret.spnt b0
  331. };;
  332. { .mfi
  333. nop.m 0
  334. fma.s1 tanh_X4 = tanh_X2, tanh_X2, f0
  335. nop.i 0
  336. }
  337. { .mfi
  338. nop.m 0
  339. fma.s1 tanh_X3 = tanh_X2, f8, f0
  340. nop.i 0
  341. }
  342. ;;
  343. // After that last load, EXP_AD_TB1 points to the beginning of table 1
  344. // W = X * Inv_log2_by_128
  345. // By adding 1.10...0*2^63 we shift and get round_int(W) in significand.
  346. // We actually add 1.10...0*2^56 to X * Inv_log2 to do the same thing.
  347. .pred.rel "mutex",p11,p10
  348. { .mfi
  349. adds EXP_AD_TB1 = 0x30, EXP_AD_TB1
  350. (p11) fma.s1 EXP_W_2TO56_RSH = EXP_NORM_f8, EXP_INV_LN2_2TO63, EXP_RSHF_2TO56
  351. mov reg_RcMask = 0xC00
  352. }
  353. { .mfi
  354. ldfe tanh_C5 = [TANH_NZ_CF], 16
  355. (p10) fnma.s1 EXP_W_2TO56_RSH = EXP_NORM_f8, EXP_INV_LN2_2TO63, EXP_RSHF_2TO56
  356. nop.i 0
  357. };;
  358. { .mfi
  359. ldfe tanh_C3 = [TANH_NZ_CF], 16
  360. (p10) fnma.s1 EXP_NORM_f8 = EXP_NORM_f8, f1, f0
  361. adds EXP_AD_TB2 = 0x100, EXP_AD_TB1
  362. }
  363. { .mfb
  364. adds EXP_AD_P = 0x180, EXP_AD_TB1
  365. nop.f 0
  366. (p12) br.cond.spnt tanh_near_zero
  367. };;
  368. { .mfi
  369. ldfpd exp_P4, exp_P3 = [EXP_AD_P] ,16
  370. nop.f 0
  371. mov reg_RcUp = 0x800
  372. };;
  373. // Nfloat = round_int(W)
  374. // The signficand of EXP_W_2TO56_RSH contains the rounded integer part of W,
  375. // as a twos complement number in the lower bits (that is, it may be negative).
  376. // That twos complement number (called N) is put into exp_GR_N.
  377. // Since EXP_W_2TO56_RSH is scaled by 2^56, it must be multiplied by 2^-56
  378. // before the shift constant 1.10000 * 2^63 is subtracted to yield EXP_Nfloat.
  379. // Thus, EXP_Nfloat contains the floating point version of N
  380. { .mfi
  381. ldfpd exp_P2, exp_P1 = [EXP_AD_P]
  382. fms.s1 EXP_Nfloat = EXP_W_2TO56_RSH, EXP_2TOM56, EXP_RSHF
  383. nop.i 0
  384. };;
  385. .pred.rel "mutex",p11,p10
  386. tanh_gt32:
  387. { .mfi
  388. // for x > 32 result is +1.0
  389. nop.m 0
  390. (p11) fma.d.s0 f8 = tanh_AlmostOne, tanh_AlmostOne, f0
  391. nop.i 0
  392. }
  393. { .mfb
  394. nop.m 0
  395. // for x < -32 result is -1.0
  396. (p10) fnma.d.s0 f8 = tanh_AlmostOne, tanh_AlmostOne, f0
  397. (p13) br.ret.spnt b0
  398. };;
  399. { .mfi
  400. getf.sig exp_GR_N = EXP_W_2TO56_RSH
  401. nop.f 0
  402. nop.i 0
  403. };;
  404. // exp_GR_index_1 has index_1
  405. // exp_GR_index_2_16 has index_2 * 16
  406. // exp_GR_biased_M has M
  407. // exp_GR_index_1_16 has index_1 * 16
  408. // r2 has true M
  409. { .mfi
  410. and exp_GR_index_1 = 0x0f, exp_GR_N
  411. fnma.s1 exp_r = EXP_Nfloat, exp_ln2_by_128_hi, EXP_NORM_f8
  412. shr r2 = exp_GR_N, 0x7
  413. }
  414. { .mfi
  415. and exp_GR_index_2_16 = 0x70, exp_GR_N
  416. fnma.s1 exp_f = EXP_Nfloat, exp_ln2_by_128_lo, f1
  417. nop.i 0
  418. };;
  419. // EXP_AD_T1 has address of T1
  420. // EXP_AD_T2 has address if T2
  421. { .mmi
  422. addl exp_GR_biased_M = 0xffff, r2
  423. add EXP_AD_T2 = EXP_AD_TB2, exp_GR_index_2_16
  424. shladd EXP_AD_T1 = exp_GR_index_1, 4, EXP_AD_TB1
  425. };;
  426. // Create Scale = 2^M
  427. // r = x - Nfloat * ln2_by_128_hi
  428. // f = 1 - Nfloat * ln2_by_128_lo
  429. { .mmi
  430. setf.exp EXP_2M = exp_GR_biased_M
  431. ldfe exp_T2 = [EXP_AD_T2]
  432. nop.i 0
  433. };;
  434. // Load T1 and T2
  435. { .mfi
  436. ldfe exp_T1 = [EXP_AD_T1]
  437. nop.f 0
  438. and reg_ArFsr = reg_ArFsr, reg_RcMask
  439. }
  440. ;;
  441. { .mfi
  442. nop.m 0
  443. fma.s1 exp_rsq = exp_r, exp_r, f0
  444. cmp.eq p14, p0 = reg_ArFsr, reg_RcUp
  445. }
  446. { .mfi
  447. nop.m 0
  448. fma.s1 exp_rP4pP3 = exp_r, exp_P4, exp_P3
  449. nop.i 0
  450. };;
  451. { .mfi
  452. nop.m 0
  453. fma.s1 exp_rcube = exp_r, exp_rsq, f0
  454. cmp.eq p15, p0 = reg_ArFsr, reg_RcDown
  455. }
  456. { .mfi
  457. nop.m 0
  458. fma.s1 exp_P_lo = exp_r, exp_rP4pP3, exp_P2
  459. nop.i 0
  460. };;
  461. { .mfi
  462. (p14) ldfe tanh_Two = [ALMOST_ONE], 16
  463. fma.s1 exp_P_hi = exp_rsq, exp_P1, exp_r
  464. nop.i 0
  465. }
  466. { .mfi
  467. nop.m 0
  468. fma.s1 exp_S2 = exp_f,exp_T2,f0
  469. nop.i 0
  470. };;
  471. { .mfi
  472. nop.m 0
  473. fma.s1 exp_S1 = EXP_2M,exp_T1,f0
  474. nop.i 0
  475. };;
  476. { .mfi
  477. nop.m 0
  478. fma.s1 exp_P = exp_rcube, exp_P_lo, exp_P_hi
  479. nop.i 0
  480. };;
  481. { .mfi
  482. nop.m 0
  483. fma.s1 exp_S = exp_S1,exp_S2,f0
  484. nop.i 0
  485. }
  486. { .mfi
  487. nop.m 0
  488. fma.s1 exp_ExppOne = exp_S1,exp_S2,f1
  489. nop.i 0
  490. }
  491. ;;
  492. { .mfi
  493. (p15) ldfe tanh_Two = [ALMOST_ONE], 16
  494. fma.s1 exp_ExppOne = exp_S, exp_P, exp_ExppOne
  495. nop.i 0
  496. };;
  497. { .mfi
  498. nop.m 0
  499. frcpa.s1 tanh_rcp0, p6 = f1, exp_ExppOne
  500. nop.i 0
  501. }
  502. ;;
  503. // NR method: ineration #1
  504. { .mfi
  505. nop.m 0
  506. fnma.s1 tanh_rcp1 = tanh_rcp0, exp_ExppOne, f1 // t = 1 - r0*x
  507. nop.i 0
  508. };;
  509. { .mfi
  510. nop.m 0
  511. // r1 = r0 + r0*t = r0 + r0*(1 - r0*x)
  512. fma.s1 tanh_rcp1 = tanh_rcp0, tanh_rcp1, tanh_rcp0
  513. nop.i 0
  514. };;
  515. // NR method: ineration #2
  516. { .mfi
  517. nop.m 0
  518. fnma.s1 tanh_rcp2 = tanh_rcp1, exp_ExppOne, f1 // t = 1 - r1*x
  519. nop.i 0
  520. };;
  521. { .mfi
  522. nop.m 0
  523. // r2 = r1 + r1*t = r1 + r1*(1 - r1*x)
  524. fma.s1 tanh_rcp2 = tanh_rcp1, tanh_rcp2, tanh_rcp1
  525. nop.i 0
  526. };;
  527. // NR method: ineration #3
  528. { .mfi
  529. nop.m 0
  530. fnma.s1 tanh_rcp3 = tanh_rcp2, exp_ExppOne, f1 // t = 1 - r2*x
  531. nop.i 0
  532. };;
  533. { .mfi
  534. nop.m 0
  535. // y = r2 + r2*t = r2 + r2*(1 - r2*x)
  536. fma.s1 exp_ExppOne = tanh_rcp2, tanh_rcp3, tanh_rcp2
  537. nop.i 0
  538. };;
  539. .pred.rel "mutex",p11,p10
  540. { .mfi
  541. nop.m 0
  542. // tanh(x) = 1 - 2 / (1 + e^(2*x))
  543. (p11) fnma.d.s0 f8 = exp_ExppOne, tanh_Two, f1
  544. nop.i 0
  545. }
  546. { .mfb
  547. nop.m 0
  548. // tanh(x) = 2 / (1 + e^(2*x)) - 1
  549. (p10) fms.d.s0 f8 = exp_ExppOne, tanh_Two, f1
  550. br.ret.sptk b0 // Normal path exit
  551. };;
  552. // Here if |x| < 1/16
  553. tanh_near_zero:
  554. { .mfi
  555. nop.m 0
  556. fma.s1 tanh_C13 = tanh_C13, tanh_X2, tanh_C11
  557. nop.i 0
  558. }
  559. { .mfi
  560. nop.m 0
  561. fma.s1 tanh_C9 = tanh_C9, tanh_X2, tanh_C7
  562. nop.i 0
  563. };;
  564. { .mfi
  565. nop.m 0
  566. fma.s1 tanh_C5 = tanh_C5, tanh_X2, tanh_C3
  567. nop.i 0
  568. };;
  569. { .mfi
  570. nop.m 0
  571. fma.s1 tanh_C13 = tanh_C13, tanh_X4, tanh_C9
  572. nop.i 0
  573. };;
  574. { .mfi
  575. nop.m 0
  576. fma.s1 tanh_C13 = tanh_C13, tanh_X4, tanh_C5
  577. nop.i 0
  578. };;
  579. { .mfb
  580. nop.m 0
  581. fma.d.s0 f8 = tanh_C13, tanh_X3, f8
  582. br.ret.sptk b0
  583. };;
  584. .endp tanh