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.

665 lines
19 KiB

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