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.

663 lines
19 KiB

  1. .file "asinf.s"
  2. // Copyright (c) 2000, Intel Corporation
  3. // All rights reserved.
  4. //
  5. // Contributed 2/02/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. // 2/02/00 Initial revision
  28. // 6/28/00 Improved speed
  29. // 6/31/00 Changed register allocation because of some duplicate macros
  30. // moved nan exit bundle up to gain a cycle.
  31. // 8/08/00 Improved speed by avoiding SIR flush.
  32. // 8/15/00 Bundle added after call to __libm_error_support to properly
  33. // set [the previously overwritten] GR_Parameter_RESULT.
  34. // 8/17/00 Changed predicate register macro-usage to direct predicate
  35. // names due to an assembler bug.
  36. // 10/17/00 Improved speed of x=0 and x=1 paths, set D flag if x denormal.
  37. // Description
  38. //=========================================
  39. // The asinf function computes the arc sine of x in the range [-pi,+pi].
  40. // A doman error occurs for arguments not in the range [-1,+1].
  41. // asinf(+-0) returns +-0
  42. // asinf(x) returns a Nan and raises the invalid exception for |x| >1
  43. // The acosf function returns the arc cosine in the range [0, +pi] radians.
  44. // A doman error occurs for arguments not in the range [-1,+1].
  45. // acosf(1) returns +0
  46. // acosf(x) returns a Nan and raises the invalid exception for |x| >1
  47. // |x| <= sqrt(2)/2. get Ax and Bx
  48. // poly_p1 = x p1
  49. // poly_p3 = x2 p4 + p3
  50. // poly_p1 = x2 (poly_p1) + x = x2(x p1) + x
  51. // poly_p2 = x2( poly_p3) + p2 = x2(x2 p4 + p3) + p2
  52. // poly_Ax = x5(x2( poly_p3) + p2) + x2(x p1) + x
  53. // = x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
  54. // poly_p7 = x2 p8 + p7
  55. // poly_p5 = x2 p6 + p5
  56. // poly_p7 = x4 p9 + (poly_p7)
  57. // poly_p7 = x4 p9 + (x2 p8 + p7)
  58. // poly_Bx = x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5
  59. // answer1 = x11(x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5) + x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
  60. // = x19 p9 + x17 p8 + x15 p7 x13 p6 + x11 p5 + x9 p4 + x7 p3 + x5 p2 + x3 p1 + x
  61. // |x| > sqrt(2)/2
  62. // Get z = sqrt(1-x2)
  63. // Get polynomial in t = 1-x2
  64. // t2 = t t
  65. // t4 = t2 t2
  66. // poly_p4 = t p5 + p4
  67. // poly_p1 = t p1 + 1
  68. // poly_p6 = t p7 + p6
  69. // poly_p2 = t p3 + p2
  70. // poly_p8 = t p9 + p8
  71. // poly_p4 = t2 poly_p6 + poly_p4
  72. // = t2 (t p7 + p6) + (t p5 + p4)
  73. // poly_p2 = t2 poly_p2 + poly_p1
  74. // = t2 (t p3 + p2) + (t p1 + 1)
  75. // poly_p4 = t4 poly_p8 + poly_p4
  76. // = t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4))
  77. // P(t) = poly_p2 + t4 poly_p8
  78. // = t2 (t p3 + p2) + (t p1 + 1) + t4 (t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4)))
  79. // = t3 p3 + t2 p2 + t p1 + 1 + t9 p9 + t8 p8 + t7 p7 + t6 p6 + t5 p5 + t4 p4
  80. // answer2 = - sign(x) z P(t) + (sign(x) pi/2)
  81. //
  82. // Assembly macros
  83. //=========================================
  84. // predicate registers
  85. //asinf_pred_LEsqrt2by2 = p7
  86. //asinf_pred_GTsqrt2by2 = p8
  87. // integer registers
  88. ASINF_Addr1 = r33
  89. ASINF_Addr2 = r34
  90. ASINF_GR_1by2 = r35
  91. ASINF_GR_3by2 = r36
  92. ASINF_GR_5by2 = r37
  93. GR_SAVE_B0 = r38
  94. GR_SAVE_PFS = r39
  95. GR_SAVE_GP = r40
  96. GR_Parameter_X = r41
  97. GR_Parameter_Y = r42
  98. GR_Parameter_RESULT = r43
  99. GR_Parameter_TAG = r44
  100. // floating point registers
  101. asinf_y = f32
  102. asinf_abs_x = f33
  103. asinf_x2 = f34
  104. asinf_sgn_x = f35
  105. asinf_1by2 = f36
  106. asinf_3by2 = f37
  107. asinf_5by2 = f38
  108. asinf_coeff_P3 = f39
  109. asinf_coeff_P8 = f40
  110. asinf_coeff_P1 = f41
  111. asinf_coeff_P4 = f42
  112. asinf_coeff_P5 = f43
  113. asinf_coeff_P2 = f44
  114. asinf_coeff_P7 = f45
  115. asinf_coeff_P6 = f46
  116. asinf_coeff_P9 = f47
  117. asinf_x2 = f48
  118. asinf_x3 = f49
  119. asinf_x4 = f50
  120. asinf_x8 = f51
  121. asinf_x5 = f52
  122. asinf_const_piby2 = f53
  123. asinf_const_sqrt2by2 = f54
  124. asinf_x11 = f55
  125. asinf_poly_p1 = f56
  126. asinf_poly_p3 = f57
  127. asinf_sinf1 = f58
  128. asinf_poly_p2 = f59
  129. asinf_poly_Ax = f60
  130. asinf_poly_p7 = f61
  131. asinf_poly_p5 = f62
  132. asinf_sgnx_t4 = f63
  133. asinf_poly_Bx = f64
  134. asinf_t = f65
  135. asinf_yby2 = f66
  136. asinf_B = f67
  137. asinf_B2 = f68
  138. asinf_Az = f69
  139. asinf_dz = f70
  140. asinf_Sz = f71
  141. asinf_d2z = f72
  142. asinf_Fz = f73
  143. asinf_z = f74
  144. asinf_sgnx_z = f75
  145. asinf_t2 = f76
  146. asinf_2poly_p4 = f77
  147. asinf_2poly_p6 = f78
  148. asinf_2poly_p1 = f79
  149. asinf_2poly_p2 = f80
  150. asinf_2poly_p8 = f81
  151. asinf_t4 = f82
  152. asinf_Pt = f83
  153. asinf_sgnx_2poly_p2 = f84
  154. asinf_sgn_x_piby2 = f85
  155. asinf_poly_p7a = f86
  156. asinf_2poly_p4a = f87
  157. asinf_2poly_p4b = f88
  158. asinf_2poly_p2a = f89
  159. asinf_poly_p1a = f90
  160. // Data tables
  161. //==============================================================
  162. .data
  163. .align 16
  164. asinf_coeff_1_table:
  165. data8 0x3FC5555607DCF816 // P1
  166. data8 0x3F9CF81AD9BAB2C6 // P4
  167. data8 0x3FC59E0975074DF3 // P7
  168. data8 0xBFA6F4CC2780AA1D // P6
  169. data8 0x3FC2DD45292E93CB // P9
  170. data8 0x3fe6a09e667f3bcd // sqrt(2)/2
  171. asinf_coeff_2_table:
  172. data8 0x3FA6F108E31EFBA6 // P3
  173. data8 0xBFCA31BF175D82A0 // P8
  174. data8 0x3FA30C0337F6418B // P5
  175. data8 0x3FB332C9266CB1F9 // P2
  176. data8 0x3ff921fb54442d18 // pi_by_2
  177. .align 32
  178. .global asinf
  179. .section .text
  180. .proc asinf
  181. .align 32
  182. asinf:
  183. // Load the addresses of the two tables.
  184. // Then, load the coefficients and other constants.
  185. { .mfi
  186. alloc r32 = ar.pfs,1,8,4,0
  187. fnma.s1 asinf_t = f8,f8,f1
  188. dep.z ASINF_GR_1by2 = 0x3f,24,8 // 0x3f000000
  189. }
  190. { .mfi
  191. addl ASINF_Addr1 = @ltoff(asinf_coeff_1_table),gp
  192. fma.s1 asinf_x2 = f8,f8,f0
  193. addl ASINF_Addr2 = @ltoff(asinf_coeff_2_table),gp ;;
  194. }
  195. { .mfi
  196. ld8 ASINF_Addr1 = [ASINF_Addr1]
  197. fmerge.s asinf_abs_x = f1,f8
  198. dep ASINF_GR_3by2 = 1,r0,22,8 // 0x3fc00000
  199. }
  200. { .mlx
  201. nop.m 999
  202. movl ASINF_GR_5by2 = 0x40200000;;
  203. }
  204. { .mfi
  205. setf.s asinf_1by2 = ASINF_GR_1by2
  206. fmerge.s asinf_sgn_x = f8,f1
  207. nop.i 999
  208. }
  209. { .mfi
  210. ld8 ASINF_Addr2 = [ASINF_Addr2]
  211. nop.f 0
  212. nop.i 999;;
  213. }
  214. { .mfi
  215. setf.s asinf_5by2 = ASINF_GR_5by2
  216. fcmp.lt.s1 p11,p12 = f8,f0
  217. nop.i 999;;
  218. }
  219. { .mmf
  220. ldfpd asinf_coeff_P1,asinf_coeff_P4 = [ASINF_Addr1],16
  221. setf.s asinf_3by2 = ASINF_GR_3by2
  222. fclass.m.unc p8,p0 = f8, 0xc3 ;; //@qnan | @snan
  223. }
  224. { .mfi
  225. ldfpd asinf_coeff_P7,asinf_coeff_P6 = [ASINF_Addr1],16
  226. fma.s1 asinf_t2 = asinf_t,asinf_t,f0
  227. nop.i 999
  228. }
  229. { .mfi
  230. ldfpd asinf_coeff_P3,asinf_coeff_P8 = [ASINF_Addr2],16
  231. fma.s1 asinf_x4 = asinf_x2,asinf_x2,f0
  232. nop.i 999;;
  233. }
  234. { .mfi
  235. ldfpd asinf_coeff_P9,asinf_const_sqrt2by2 = [ASINF_Addr1]
  236. fclass.m.unc p10,p0 = f8, 0x07 //@zero
  237. nop.i 999
  238. }
  239. { .mfi
  240. ldfpd asinf_coeff_P5,asinf_coeff_P2 = [ASINF_Addr2],16
  241. fma.s1 asinf_x3 = f8,asinf_x2,f0
  242. nop.i 999;;
  243. }
  244. { .mfi
  245. ldfd asinf_const_piby2 = [ASINF_Addr2]
  246. frsqrta.s1 asinf_B,p0 = asinf_t
  247. nop.i 999
  248. }
  249. { .mfb
  250. nop.m 999
  251. (p8) fma.s f8 = f8,f1,f0
  252. (p8) br.ret.spnt b0 ;; // Exit if x=nan
  253. }
  254. { .mfb
  255. nop.m 999
  256. fcmp.eq.s1 p6,p0 = asinf_abs_x,f1
  257. (p10) br.ret.spnt b0 ;; // Exit if x=0
  258. }
  259. { .mfi
  260. nop.m 999
  261. fcmp.gt.s1 p9,p0 = asinf_abs_x,f1
  262. nop.i 999;;
  263. }
  264. { .mfi
  265. nop.m 999
  266. fma.s1 asinf_x8 = asinf_x4,asinf_x4,f0
  267. nop.i 999
  268. }
  269. { .mfb
  270. nop.m 999
  271. fma.s1 asinf_t4 = asinf_t2,asinf_t2,f0
  272. (p6) br.cond.spnt ASINF_ABS_ONE ;; // Branch if |x|=1
  273. }
  274. { .mfi
  275. nop.m 999
  276. fma.s1 asinf_x5 = asinf_x2,asinf_x3,f0
  277. nop.i 999
  278. }
  279. { .mfb
  280. (p9) mov GR_Parameter_TAG = 62
  281. fma.s1 asinf_yby2 = asinf_t,asinf_1by2,f0
  282. (p9) br.cond.spnt __libm_error_region ;; // Branch if |x|>1
  283. }
  284. { .mfi
  285. nop.m 999
  286. fma.s1 asinf_Az = asinf_t,asinf_B,f0
  287. nop.i 999
  288. }
  289. { .mfi
  290. nop.m 999
  291. fma.s1 asinf_B2 = asinf_B,asinf_B,f0
  292. nop.i 999;;
  293. }
  294. { .mfi
  295. nop.m 999
  296. fma.s1 asinf_poly_p1 = f8,asinf_coeff_P1,f0
  297. nop.i 999
  298. }
  299. { .mfi
  300. nop.m 999
  301. fma.s1 asinf_2poly_p1 = asinf_coeff_P1,asinf_t,f1
  302. nop.i 999;;
  303. }
  304. { .mfi
  305. nop.m 999
  306. fma.s1 asinf_poly_p3 = asinf_coeff_P4,asinf_x2,asinf_coeff_P3
  307. nop.i 999
  308. }
  309. { .mfi
  310. nop.m 999
  311. fma.s1 asinf_2poly_p6 = asinf_coeff_P7,asinf_t,asinf_coeff_P6
  312. nop.i 999;;
  313. }
  314. { .mfi
  315. nop.m 999
  316. fma.s1 asinf_poly_p7 = asinf_x2,asinf_coeff_P8,asinf_coeff_P7
  317. nop.i 999
  318. }
  319. { .mfi
  320. nop.m 999
  321. fma.s1 asinf_2poly_p2 = asinf_coeff_P3,asinf_t,asinf_coeff_P2
  322. nop.i 999;;
  323. }
  324. { .mfi
  325. nop.m 999
  326. fma.s1 asinf_poly_p5 = asinf_x2,asinf_coeff_P6,asinf_coeff_P5
  327. nop.i 999
  328. }
  329. { .mfi
  330. nop.m 999
  331. fma.s1 asinf_2poly_p4 = asinf_coeff_P5,asinf_t,asinf_coeff_P4
  332. nop.i 999;;
  333. }
  334. { .mfi
  335. nop.m 999
  336. fma.d.s1 asinf_x11 = asinf_x8,asinf_x3,f0
  337. nop.i 999
  338. }
  339. { .mfi
  340. nop.m 999
  341. fnma.s1 asinf_dz = asinf_B2,asinf_yby2,asinf_1by2
  342. nop.i 999;;
  343. }
  344. { .mfi
  345. nop.m 999
  346. fma.s1 asinf_poly_p1a = asinf_x2,asinf_poly_p1,f8
  347. nop.i 999
  348. }
  349. { .mfi
  350. nop.m 999
  351. fma.s1 asinf_2poly_p8 = asinf_coeff_P9,asinf_t,asinf_coeff_P8
  352. nop.i 999;;
  353. }
  354. // Get the absolute value of x and determine the region in which x lies
  355. { .mfi
  356. nop.m 999
  357. fcmp.le.s1 p7,p8 = asinf_abs_x,asinf_const_sqrt2by2
  358. nop.i 999
  359. }
  360. { .mfi
  361. nop.m 999
  362. fma.s1 asinf_poly_p2 = asinf_x2,asinf_poly_p3,asinf_coeff_P2
  363. nop.i 999;;
  364. }
  365. { .mfi
  366. nop.m 999
  367. fma.s1 asinf_poly_p7a = asinf_x4,asinf_coeff_P9,asinf_poly_p7
  368. nop.i 999
  369. }
  370. { .mfi
  371. nop.m 999
  372. fma.s1 asinf_2poly_p2a = asinf_2poly_p2,asinf_t2,asinf_2poly_p1
  373. nop.i 999;;
  374. }
  375. { .mfi
  376. nop.m 999
  377. (p8) fma.s1 asinf_sgnx_t4 = asinf_sgn_x,asinf_t4,f0
  378. nop.i 999
  379. }
  380. { .mfi
  381. nop.m 999
  382. (p8) fma.s1 asinf_2poly_p4a = asinf_2poly_p6,asinf_t2,asinf_2poly_p4
  383. nop.i 999;;
  384. }
  385. { .mfi
  386. nop.m 999
  387. (p8) fma.s1 asinf_Sz = asinf_5by2,asinf_dz,asinf_3by2
  388. nop.i 999
  389. }
  390. { .mfi
  391. nop.m 999
  392. (p8) fma.s1 asinf_d2z = asinf_dz,asinf_dz,f0
  393. nop.i 999;;
  394. }
  395. { .mfi
  396. nop.m 999
  397. (p8) fma.s1 asinf_sgn_x_piby2 = asinf_sgn_x,asinf_const_piby2,f0
  398. nop.i 999
  399. }
  400. { .mfi
  401. nop.m 999
  402. (p7) fma.d.s1 asinf_poly_Ax = asinf_x5,asinf_poly_p2,asinf_poly_p1a
  403. nop.i 999;;
  404. }
  405. { .mfi
  406. nop.m 999
  407. (p7) fma.d.s1 asinf_poly_Bx = asinf_x4,asinf_poly_p7a,asinf_poly_p5
  408. nop.i 999
  409. }
  410. { .mfi
  411. nop.m 999
  412. (p8) fma.s1 asinf_sgnx_2poly_p2 = asinf_sgn_x,asinf_2poly_p2a,f0
  413. nop.i 999;;
  414. }
  415. { .mfi
  416. nop.m 999
  417. fcmp.eq.s0 p6,p0 = f8,f0 // Only purpose is to set D if x denormal
  418. nop.i 999
  419. }
  420. { .mfi
  421. nop.m 999
  422. (p8) fma.s1 asinf_2poly_p4b = asinf_2poly_p8,asinf_t4,asinf_2poly_p4a
  423. nop.i 999;;
  424. }
  425. { .mfi
  426. nop.m 999
  427. (p8) fma.s1 asinf_Fz = asinf_d2z,asinf_Sz,asinf_dz
  428. nop.i 999;;
  429. }
  430. { .mfi
  431. nop.m 999
  432. (p8) fma.d.s1 asinf_Pt = asinf_2poly_p4b,asinf_sgnx_t4,asinf_sgnx_2poly_p2
  433. nop.i 999;;
  434. }
  435. { .mfi
  436. nop.m 999
  437. (p8) fma.d.s1 asinf_z = asinf_Az,asinf_Fz,asinf_Az
  438. nop.i 999;;
  439. }
  440. .pred.rel "mutex",p8,p7 //asinf_pred_GTsqrt2by2,asinf_pred_LEsqrt2by2
  441. { .mfi
  442. nop.m 999
  443. (p8) fnma.s f8 = asinf_z,asinf_Pt,asinf_sgn_x_piby2
  444. nop.i 999
  445. }
  446. { .mfb
  447. nop.m 999
  448. (p7) fma.s f8 = asinf_x11,asinf_poly_Bx,asinf_poly_Ax
  449. br.ret.sptk b0 ;;
  450. }
  451. ASINF_ABS_ONE:
  452. // Here for short exit if |x|=1
  453. { .mfb
  454. nop.m 999
  455. fma.s f8 = asinf_sgn_x,asinf_const_piby2,f0
  456. br.ret.sptk b0
  457. }
  458. ;;
  459. .endp asinf
  460. // Stack operations when calling error support.
  461. // (1) (2)
  462. // sp -> + psp -> +
  463. // | |
  464. // | | <- GR_Y
  465. // | |
  466. // | <-GR_Y Y2->|
  467. // | |
  468. // | | <- GR_X
  469. // | |
  470. // sp-64 -> + sp -> +
  471. // save ar.pfs save b0
  472. // save gp
  473. // Stack operations when calling error support.
  474. // (3) (call) (4)
  475. // psp -> + sp -> +
  476. // | |
  477. // R3 ->| <- GR_RESULT | -> f8
  478. // | |
  479. // Y2 ->| <- GR_Y |
  480. // | |
  481. // X1 ->| |
  482. // | |
  483. // sp -> + +
  484. // restore gp
  485. // restore ar.pfs
  486. .proc __libm_error_region
  487. __libm_error_region:
  488. .prologue
  489. { .mfi
  490. add GR_Parameter_Y=-32,sp // Parameter 2 value
  491. nop.f 999
  492. .save ar.pfs,GR_SAVE_PFS
  493. mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
  494. }
  495. { .mfi
  496. .fframe 64
  497. add sp=-64,sp // Create new stack
  498. nop.f 0
  499. mov GR_SAVE_GP=gp // Save gp
  500. };;
  501. { .mmi
  502. stfs [GR_Parameter_Y] = f1,16 // Store Parameter 2 on stack
  503. add GR_Parameter_X = 16,sp // Parameter 1 address
  504. .save b0, GR_SAVE_B0
  505. mov GR_SAVE_B0=b0 // Save b0
  506. };;
  507. .body
  508. { .mfi
  509. nop.m 0
  510. frcpa.s0 f9,p0 = f0,f0
  511. nop.i 0
  512. };;
  513. { .mib
  514. stfs [GR_Parameter_X] = f8 // Store Parameter 1 on stack
  515. add GR_Parameter_RESULT = 0,GR_Parameter_Y
  516. nop.b 0 // Parameter 3 address
  517. }
  518. { .mib
  519. stfs [GR_Parameter_Y] = f9 // Store Parameter 3 on stack
  520. add GR_Parameter_Y = -16,GR_Parameter_Y
  521. br.call.sptk b0=__libm_error_support# // Call error handling function
  522. };;
  523. { .mmi
  524. nop.m 0
  525. nop.m 0
  526. add GR_Parameter_RESULT = 48,sp
  527. };;
  528. { .mmi
  529. ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
  530. .restore
  531. add sp = 64,sp // Restore stack pointer
  532. mov b0 = GR_SAVE_B0 // Restore return address
  533. };;
  534. { .mib
  535. mov gp = GR_SAVE_GP // Restore gp
  536. mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
  537. br.ret.sptk b0 // Return
  538. };;
  539. .endp __libm_error_region
  540. .type __libm_error_support#,@function
  541. .global __libm_error_support#