3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
6 // Contributed 2/02/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
7 // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at
38 // http://developer.intel.com/opensource.
41 //==============================================================
42 // 2/02/00 Initial revision
43 // 6/28/00 Improved speed
44 // 6/31/00 Changed register allocation because of some duplicate macros
45 // moved nan exit bundle up to gain a cycle.
46 // 8/08/00 Improved speed by avoiding SIR flush.
47 // 8/15/00 Bundle added after call to __libm_error_support to properly
48 // set [the previously overwritten] GR_Parameter_RESULT.
49 // 8/17/00 Changed predicate register macro-usage to direct predicate
50 // names due to an assembler bug.
51 // 10/17/00 Improved speed of x=0 and x=1 paths, set D flag if x denormal.
54 //=========================================
55 // The asinf function computes the arc sine of x in the range [-pi,+pi].
56 // A doman error occurs for arguments not in the range [-1,+1].
57 // asinf(+-0) returns +-0
58 // asinf(x) returns a Nan and raises the invalid exception for |x| >1
60 // The acosf function returns the arc cosine in the range [0, +pi] radians.
61 // A doman error occurs for arguments not in the range [-1,+1].
62 // acosf(1) returns +0
63 // acosf(x) returns a Nan and raises the invalid exception for |x| >1
66 // |x| <= sqrt(2)/2. get Ax and Bx
69 // poly_p3 = x2 p4 + p3
70 // poly_p1 = x2 (poly_p1) + x = x2(x p1) + x
71 // poly_p2 = x2( poly_p3) + p2 = x2(x2 p4 + p3) + p2
73 // poly_Ax = x5(x2( poly_p3) + p2) + x2(x p1) + x
74 // = x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
76 // poly_p7 = x2 p8 + p7
77 // poly_p5 = x2 p6 + p5
79 // poly_p7 = x4 p9 + (poly_p7)
80 // poly_p7 = x4 p9 + (x2 p8 + p7)
81 // poly_Bx = x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5
83 // answer1 = x11(x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5) + x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
84 // = x19 p9 + x17 p8 + x15 p7 x13 p6 + x11 p5 + x9 p4 + x7 p3 + x5 p2 + x3 p1 + x
92 // Get polynomial in t = 1-x2
97 // poly_p4 = t p5 + p4
100 // poly_p6 = t p7 + p6
101 // poly_p2 = t p3 + p2
103 // poly_p8 = t p9 + p8
105 // poly_p4 = t2 poly_p6 + poly_p4
106 // = t2 (t p7 + p6) + (t p5 + p4)
108 // poly_p2 = t2 poly_p2 + poly_p1
109 // = t2 (t p3 + p2) + (t p1 + 1)
111 // poly_p4 = t4 poly_p8 + poly_p4
112 // = t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4))
114 // P(t) = poly_p2 + t4 poly_p8
115 // = t2 (t p3 + p2) + (t p1 + 1) + t4 (t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4)))
116 // = t3 p3 + t2 p2 + t p1 + 1 + t9 p9 + t8 p8 + t7 p7 + t6 p6 + t5 p5 + t4 p4
119 // answer2 = - sign(x) z P(t) + (sign(x) pi/2)
122 #include "libm_support.h"
125 //=========================================
127 // predicate registers
128 //asinf_pred_LEsqrt2by2 = p7
129 //asinf_pred_GTsqrt2by2 = p8
145 GR_Parameter_RESULT = r43
146 GR_Parameter_TAG = r44
148 // floating point registers
175 asinf_const_piby2 = f53
176 asinf_const_sqrt2by2 = f54
212 asinf_sgnx_2poly_p2 = f84
213 asinf_sgn_x_piby2 = f85
216 asinf_2poly_p4a = f87
217 asinf_2poly_p4b = f88
218 asinf_2poly_p2a = f89
226 //==============================================================
237 ASM_TYPE_DIRECTIVE(asinf_coeff_1_table,@object)
238 data8 0x3FC5555607DCF816 // P1
239 data8 0x3F9CF81AD9BAB2C6 // P4
240 data8 0x3FC59E0975074DF3 // P7
241 data8 0xBFA6F4CC2780AA1D // P6
242 data8 0x3FC2DD45292E93CB // P9
243 data8 0x3fe6a09e667f3bcd // sqrt(2)/2
244 ASM_SIZE_DIRECTIVE(asinf_coeff_1_table)
247 ASM_TYPE_DIRECTIVE(asinf_coeff_2_table,@object)
248 data8 0x3FA6F108E31EFBA6 // P3
249 data8 0xBFCA31BF175D82A0 // P8
250 data8 0x3FA30C0337F6418B // P5
251 data8 0x3FB332C9266CB1F9 // P2
252 data8 0x3ff921fb54442d18 // pi_by_2
253 ASM_SIZE_DIRECTIVE(asinf_coeff_2_table)
265 // Load the addresses of the two tables.
266 // Then, load the coefficients and other constants.
269 alloc r32 = ar.pfs,1,8,4,0
270 fnma.s1 asinf_t = f8,f8,f1
271 dep.z ASINF_GR_1by2 = 0x3f,24,8 // 0x3f000000
274 addl ASINF_Addr1 = @ltoff(asinf_coeff_1_table),gp
275 fma.s1 asinf_x2 = f8,f8,f0
276 addl ASINF_Addr2 = @ltoff(asinf_coeff_2_table),gp ;;
281 ld8 ASINF_Addr1 = [ASINF_Addr1]
282 fmerge.s asinf_abs_x = f1,f8
283 dep ASINF_GR_3by2 = -1,r0,22,8 // 0x3fc00000
287 movl ASINF_GR_5by2 = 0x40200000;;
293 setf.s asinf_1by2 = ASINF_GR_1by2
294 fmerge.s asinf_sgn_x = f8,f1
298 ld8 ASINF_Addr2 = [ASINF_Addr2]
305 setf.s asinf_5by2 = ASINF_GR_5by2
306 fcmp.lt.s1 p11,p12 = f8,f0
311 ldfpd asinf_coeff_P1,asinf_coeff_P4 = [ASINF_Addr1],16
312 setf.s asinf_3by2 = ASINF_GR_3by2
313 fclass.m.unc p8,p0 = f8, 0xc3 ;; //@qnan | @snan
318 ldfpd asinf_coeff_P7,asinf_coeff_P6 = [ASINF_Addr1],16
319 fma.s1 asinf_t2 = asinf_t,asinf_t,f0
323 ldfpd asinf_coeff_P3,asinf_coeff_P8 = [ASINF_Addr2],16
324 fma.s1 asinf_x4 = asinf_x2,asinf_x2,f0
330 ldfpd asinf_coeff_P9,asinf_const_sqrt2by2 = [ASINF_Addr1]
331 fclass.m.unc p10,p0 = f8, 0x07 //@zero
335 ldfpd asinf_coeff_P5,asinf_coeff_P2 = [ASINF_Addr2],16
336 fma.s1 asinf_x3 = f8,asinf_x2,f0
342 ldfd asinf_const_piby2 = [ASINF_Addr2]
343 frsqrta.s1 asinf_B,p0 = asinf_t
348 (p8) fma.s f8 = f8,f1,f0
349 (p8) br.ret.spnt b0 ;; // Exit if x=nan
355 fcmp.eq.s1 p6,p0 = asinf_abs_x,f1
356 (p10) br.ret.spnt b0 ;; // Exit if x=0
361 fcmp.gt.s1 p9,p0 = asinf_abs_x,f1
367 fma.s1 asinf_x8 = asinf_x4,asinf_x4,f0
372 fma.s1 asinf_t4 = asinf_t2,asinf_t2,f0
373 (p6) br.cond.spnt L(ASINF_ABS_ONE) ;; // Branch if |x|=1
378 fma.s1 asinf_x5 = asinf_x2,asinf_x3,f0
382 (p9) mov GR_Parameter_TAG = 62
383 fma.s1 asinf_yby2 = asinf_t,asinf_1by2,f0
384 (p9) br.cond.spnt __libm_error_region ;; // Branch if |x|>1
390 fma.s1 asinf_Az = asinf_t,asinf_B,f0
395 fma.s1 asinf_B2 = asinf_B,asinf_B,f0
401 fma.s1 asinf_poly_p1 = f8,asinf_coeff_P1,f0
406 fma.s1 asinf_2poly_p1 = asinf_coeff_P1,asinf_t,f1
412 fma.s1 asinf_poly_p3 = asinf_coeff_P4,asinf_x2,asinf_coeff_P3
417 fma.s1 asinf_2poly_p6 = asinf_coeff_P7,asinf_t,asinf_coeff_P6
423 fma.s1 asinf_poly_p7 = asinf_x2,asinf_coeff_P8,asinf_coeff_P7
428 fma.s1 asinf_2poly_p2 = asinf_coeff_P3,asinf_t,asinf_coeff_P2
435 fma.s1 asinf_poly_p5 = asinf_x2,asinf_coeff_P6,asinf_coeff_P5
440 fma.s1 asinf_2poly_p4 = asinf_coeff_P5,asinf_t,asinf_coeff_P4
447 fma.d.s1 asinf_x11 = asinf_x8,asinf_x3,f0
452 fnma.s1 asinf_dz = asinf_B2,asinf_yby2,asinf_1by2
459 fma.s1 asinf_poly_p1a = asinf_x2,asinf_poly_p1,f8
464 fma.s1 asinf_2poly_p8 = asinf_coeff_P9,asinf_t,asinf_coeff_P8
469 // Get the absolute value of x and determine the region in which x lies
473 fcmp.le.s1 p7,p8 = asinf_abs_x,asinf_const_sqrt2by2
478 fma.s1 asinf_poly_p2 = asinf_x2,asinf_poly_p3,asinf_coeff_P2
485 fma.s1 asinf_poly_p7a = asinf_x4,asinf_coeff_P9,asinf_poly_p7
490 fma.s1 asinf_2poly_p2a = asinf_2poly_p2,asinf_t2,asinf_2poly_p1
497 (p8) fma.s1 asinf_sgnx_t4 = asinf_sgn_x,asinf_t4,f0
502 (p8) fma.s1 asinf_2poly_p4a = asinf_2poly_p6,asinf_t2,asinf_2poly_p4
509 (p8) fma.s1 asinf_Sz = asinf_5by2,asinf_dz,asinf_3by2
514 (p8) fma.s1 asinf_d2z = asinf_dz,asinf_dz,f0
521 (p8) fma.s1 asinf_sgn_x_piby2 = asinf_sgn_x,asinf_const_piby2,f0
526 (p7) fma.d.s1 asinf_poly_Ax = asinf_x5,asinf_poly_p2,asinf_poly_p1a
532 (p7) fma.d.s1 asinf_poly_Bx = asinf_x4,asinf_poly_p7a,asinf_poly_p5
537 (p8) fma.s1 asinf_sgnx_2poly_p2 = asinf_sgn_x,asinf_2poly_p2a,f0
543 fcmp.eq.s0 p6,p0 = f8,f0 // Only purpose is to set D if x denormal
548 (p8) fma.s1 asinf_2poly_p4b = asinf_2poly_p8,asinf_t4,asinf_2poly_p4a
555 (p8) fma.s1 asinf_Fz = asinf_d2z,asinf_Sz,asinf_dz
562 (p8) fma.d.s1 asinf_Pt = asinf_2poly_p4b,asinf_sgnx_t4,asinf_sgnx_2poly_p2
568 (p8) fma.d.s1 asinf_z = asinf_Az,asinf_Fz,asinf_Az
572 .pred.rel "mutex",p8,p7 //asinf_pred_GTsqrt2by2,asinf_pred_LEsqrt2by2
575 (p8) fnma.s f8 = asinf_z,asinf_Pt,asinf_sgn_x_piby2
581 (p7) fma.s f8 = asinf_x11,asinf_poly_Bx,asinf_poly_Ax
586 // Here for short exit if |x|=1
589 fma.s f8 = asinf_sgn_x,asinf_const_piby2,f0
595 ASM_SIZE_DIRECTIVE(asinf)
597 // Stack operations when calling error support.
607 // sp-64 -> + sp -> +
608 // save ar.pfs save b0
612 // Stack operations when calling error support.
616 // R3 ->| <- GR_RESULT | -> f8
626 .proc __libm_error_region
630 add GR_Parameter_Y=-32,sp // Parameter 2 value
632 .save ar.pfs,GR_SAVE_PFS
633 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
637 add sp=-64,sp // Create new stack
639 mov GR_SAVE_GP=gp // Save gp
642 stfs [GR_Parameter_Y] = f1,16 // Store Parameter 2 on stack
643 add GR_Parameter_X = 16,sp // Parameter 1 address
645 mov GR_SAVE_B0=b0 // Save b0
651 frcpa.s0 f9,p0 = f0,f0
656 stfs [GR_Parameter_X] = f8 // Store Parameter 1 on stack
657 add GR_Parameter_RESULT = 0,GR_Parameter_Y
658 nop.b 0 // Parameter 3 address
661 stfs [GR_Parameter_Y] = f9 // Store Parameter 3 on stack
662 add GR_Parameter_Y = -16,GR_Parameter_Y
663 br.call.sptk b0=__libm_error_support# // Call error handling function
668 add GR_Parameter_RESULT = 48,sp
672 ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
674 add sp = 64,sp // Restore stack pointer
675 mov b0 = GR_SAVE_B0 // Restore return address
678 mov gp = GR_SAVE_GP // Restore gp
679 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
680 br.ret.sptk b0 // Return
683 .endp __libm_error_region
684 ASM_SIZE_DIRECTIVE(__libm_error_region)
686 .type __libm_error_support#,@function
687 .global __libm_error_support#