4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
7 // Contributed 2000 by the Intel Numerics Group, 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://www.intel.com/software/products/opensource/libraries/num.htm.
41 //==============================================================
42 // 02/02/00 Initial version
43 // 06/28/00 Improved speed
44 // 06/31/00 Changed register allocation because of some duplicate macros
45 // moved nan exit bundle up to gain a cycle.
46 // 08/08/00 Improved speed by avoiding SIR flush.
47 // 08/15/00 Bundle added after call to __libm_error_support to properly
48 // set [the previously overwritten] GR_Parameter_RESULT.
49 // 08/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.
52 // 03/13/01 Corrected sign of imm1 value in dep instruction.
53 // 05/20/02 Cleaned up namespace and sf0 syntax
54 // 02/06/03 Reordered header: .section, .global, .proc, .align
58 //=========================================
59 // The asinf function computes the arc sine of x in the range [-pi,+pi].
60 // A doman error occurs for arguments not in the range [-1,+1].
61 // asinf(+-0) returns +-0
62 // asinf(x) returns a Nan and raises the invalid exception for |x| >1
64 // The acosf function returns the arc cosine in the range [0, +pi] radians.
65 // A doman error occurs for arguments not in the range [-1,+1].
66 // acosf(1) returns +0
67 // acosf(x) returns a Nan and raises the invalid exception for |x| >1
70 // |x| <= sqrt(2)/2. get Ax and Bx
73 // poly_p3 = x2 p4 + p3
74 // poly_p1 = x2 (poly_p1) + x = x2(x p1) + x
75 // poly_p2 = x2( poly_p3) + p2 = x2(x2 p4 + p3) + p2
77 // poly_Ax = x5(x2( poly_p3) + p2) + x2(x p1) + x
78 // = x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
80 // poly_p7 = x2 p8 + p7
81 // poly_p5 = x2 p6 + p5
83 // poly_p7 = x4 p9 + (poly_p7)
84 // poly_p7 = x4 p9 + (x2 p8 + p7)
85 // poly_Bx = x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5
87 // answer1 = x11(x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5) + x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
88 // = x19 p9 + x17 p8 + x15 p7 x13 p6 + x11 p5 + x9 p4 + x7 p3 + x5 p2 + x3 p1 + x
96 // Get polynomial in t = 1-x2
101 // poly_p4 = t p5 + p4
102 // poly_p1 = t p1 + 1
104 // poly_p6 = t p7 + p6
105 // poly_p2 = t p3 + p2
107 // poly_p8 = t p9 + p8
109 // poly_p4 = t2 poly_p6 + poly_p4
110 // = t2 (t p7 + p6) + (t p5 + p4)
112 // poly_p2 = t2 poly_p2 + poly_p1
113 // = t2 (t p3 + p2) + (t p1 + 1)
115 // poly_p4 = t4 poly_p8 + poly_p4
116 // = t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4))
118 // P(t) = poly_p2 + t4 poly_p8
119 // = t2 (t p3 + p2) + (t p1 + 1) + t4 (t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4)))
120 // = t3 p3 + t2 p2 + t p1 + 1 + t9 p9 + t8 p8 + t7 p7 + t6 p6 + t5 p5 + t4 p4
123 // answer2 = - sign(x) z P(t) + (sign(x) pi/2)
128 //=========================================
130 // predicate registers
131 //asinf_pred_LEsqrt2by2 = p7
132 //asinf_pred_GTsqrt2by2 = p8
148 GR_Parameter_RESULT = r43
149 GR_Parameter_TAG = r44
151 // floating point registers
178 asinf_const_piby2 = f53
179 asinf_const_sqrt2by2 = f54
215 asinf_sgnx_2poly_p2 = f84
216 asinf_sgn_x_piby2 = f85
219 asinf_2poly_p4a = f87
220 asinf_2poly_p4b = f88
221 asinf_2poly_p2a = f89
229 //==============================================================
235 LOCAL_OBJECT_START(asinf_coeff_1_table)
236 data8 0x3FC5555607DCF816 // P1
237 data8 0x3F9CF81AD9BAB2C6 // P4
238 data8 0x3FC59E0975074DF3 // P7
239 data8 0xBFA6F4CC2780AA1D // P6
240 data8 0x3FC2DD45292E93CB // P9
241 data8 0x3fe6a09e667f3bcd // sqrt(2)/2
242 LOCAL_OBJECT_END(asinf_coeff_1_table)
244 LOCAL_OBJECT_START(asinf_coeff_2_table)
245 data8 0x3FA6F108E31EFBA6 // P3
246 data8 0xBFCA31BF175D82A0 // P8
247 data8 0x3FA30C0337F6418B // P5
248 data8 0x3FB332C9266CB1F9 // P2
249 data8 0x3ff921fb54442d18 // pi_by_2
250 LOCAL_OBJECT_END(asinf_coeff_2_table)
254 GLOBAL_LIBM_ENTRY(asinf)
256 // Load the addresses of the two tables.
257 // Then, load the coefficients and other constants.
260 alloc r32 = ar.pfs,1,8,4,0
261 fnma.s1 asinf_t = f8,f8,f1
262 dep.z ASINF_GR_1by2 = 0x3f,24,8 // 0x3f000000
265 addl ASINF_Addr1 = @ltoff(asinf_coeff_1_table),gp
266 fma.s1 asinf_x2 = f8,f8,f0
267 addl ASINF_Addr2 = @ltoff(asinf_coeff_2_table),gp ;;
272 ld8 ASINF_Addr1 = [ASINF_Addr1]
273 fmerge.s asinf_abs_x = f1,f8
274 dep ASINF_GR_3by2 = -1,r0,22,8 // 0x3fc00000
278 movl ASINF_GR_5by2 = 0x40200000;;
284 setf.s asinf_1by2 = ASINF_GR_1by2
285 fmerge.s asinf_sgn_x = f8,f1
289 ld8 ASINF_Addr2 = [ASINF_Addr2]
296 setf.s asinf_5by2 = ASINF_GR_5by2
297 fcmp.lt.s1 p11,p12 = f8,f0
302 ldfpd asinf_coeff_P1,asinf_coeff_P4 = [ASINF_Addr1],16
303 setf.s asinf_3by2 = ASINF_GR_3by2
304 fclass.m.unc p8,p0 = f8, 0xc3 ;; //@qnan | @snan
309 ldfpd asinf_coeff_P7,asinf_coeff_P6 = [ASINF_Addr1],16
310 fma.s1 asinf_t2 = asinf_t,asinf_t,f0
314 ldfpd asinf_coeff_P3,asinf_coeff_P8 = [ASINF_Addr2],16
315 fma.s1 asinf_x4 = asinf_x2,asinf_x2,f0
321 ldfpd asinf_coeff_P9,asinf_const_sqrt2by2 = [ASINF_Addr1]
322 fclass.m.unc p10,p0 = f8, 0x07 //@zero
326 ldfpd asinf_coeff_P5,asinf_coeff_P2 = [ASINF_Addr2],16
327 fma.s1 asinf_x3 = f8,asinf_x2,f0
333 ldfd asinf_const_piby2 = [ASINF_Addr2]
334 frsqrta.s1 asinf_B,p0 = asinf_t
339 (p8) fma.s.s0 f8 = f8,f1,f0
340 (p8) br.ret.spnt b0 ;; // Exit if x=nan
346 fcmp.eq.s1 p6,p0 = asinf_abs_x,f1
347 (p10) br.ret.spnt b0 ;; // Exit if x=0
352 fcmp.gt.s1 p9,p0 = asinf_abs_x,f1
358 fma.s1 asinf_x8 = asinf_x4,asinf_x4,f0
363 fma.s1 asinf_t4 = asinf_t2,asinf_t2,f0
364 (p6) br.cond.spnt ASINF_ABS_ONE ;; // Branch if |x|=1
369 fma.s1 asinf_x5 = asinf_x2,asinf_x3,f0
373 (p9) mov GR_Parameter_TAG = 62
374 fma.s1 asinf_yby2 = asinf_t,asinf_1by2,f0
375 (p9) br.cond.spnt __libm_error_region ;; // Branch if |x|>1
381 fma.s1 asinf_Az = asinf_t,asinf_B,f0
386 fma.s1 asinf_B2 = asinf_B,asinf_B,f0
392 fma.s1 asinf_poly_p1 = f8,asinf_coeff_P1,f0
397 fma.s1 asinf_2poly_p1 = asinf_coeff_P1,asinf_t,f1
403 fma.s1 asinf_poly_p3 = asinf_coeff_P4,asinf_x2,asinf_coeff_P3
408 fma.s1 asinf_2poly_p6 = asinf_coeff_P7,asinf_t,asinf_coeff_P6
414 fma.s1 asinf_poly_p7 = asinf_x2,asinf_coeff_P8,asinf_coeff_P7
419 fma.s1 asinf_2poly_p2 = asinf_coeff_P3,asinf_t,asinf_coeff_P2
426 fma.s1 asinf_poly_p5 = asinf_x2,asinf_coeff_P6,asinf_coeff_P5
431 fma.s1 asinf_2poly_p4 = asinf_coeff_P5,asinf_t,asinf_coeff_P4
438 fma.d.s1 asinf_x11 = asinf_x8,asinf_x3,f0
443 fnma.s1 asinf_dz = asinf_B2,asinf_yby2,asinf_1by2
450 fma.s1 asinf_poly_p1a = asinf_x2,asinf_poly_p1,f8
455 fma.s1 asinf_2poly_p8 = asinf_coeff_P9,asinf_t,asinf_coeff_P8
460 // Get the absolute value of x and determine the region in which x lies
464 fcmp.le.s1 p7,p8 = asinf_abs_x,asinf_const_sqrt2by2
469 fma.s1 asinf_poly_p2 = asinf_x2,asinf_poly_p3,asinf_coeff_P2
476 fma.s1 asinf_poly_p7a = asinf_x4,asinf_coeff_P9,asinf_poly_p7
481 fma.s1 asinf_2poly_p2a = asinf_2poly_p2,asinf_t2,asinf_2poly_p1
488 (p8) fma.s1 asinf_sgnx_t4 = asinf_sgn_x,asinf_t4,f0
493 (p8) fma.s1 asinf_2poly_p4a = asinf_2poly_p6,asinf_t2,asinf_2poly_p4
500 (p8) fma.s1 asinf_Sz = asinf_5by2,asinf_dz,asinf_3by2
505 (p8) fma.s1 asinf_d2z = asinf_dz,asinf_dz,f0
512 (p8) fma.s1 asinf_sgn_x_piby2 = asinf_sgn_x,asinf_const_piby2,f0
517 (p7) fma.d.s1 asinf_poly_Ax = asinf_x5,asinf_poly_p2,asinf_poly_p1a
523 (p7) fma.d.s1 asinf_poly_Bx = asinf_x4,asinf_poly_p7a,asinf_poly_p5
528 (p8) fma.s1 asinf_sgnx_2poly_p2 = asinf_sgn_x,asinf_2poly_p2a,f0
534 fcmp.eq.s0 p6,p0 = f8,f0 // Only purpose is to set D if x denormal
539 (p8) fma.s1 asinf_2poly_p4b = asinf_2poly_p8,asinf_t4,asinf_2poly_p4a
546 (p8) fma.s1 asinf_Fz = asinf_d2z,asinf_Sz,asinf_dz
553 (p8) fma.d.s1 asinf_Pt = asinf_2poly_p4b,asinf_sgnx_t4,asinf_sgnx_2poly_p2
559 (p8) fma.d.s1 asinf_z = asinf_Az,asinf_Fz,asinf_Az
563 .pred.rel "mutex",p8,p7 //asinf_pred_GTsqrt2by2,asinf_pred_LEsqrt2by2
566 (p8) fnma.s.s0 f8 = asinf_z,asinf_Pt,asinf_sgn_x_piby2
572 (p7) fma.s.s0 f8 = asinf_x11,asinf_poly_Bx,asinf_poly_Ax
577 // Here for short exit if |x|=1
580 fma.s.s0 f8 = asinf_sgn_x,asinf_const_piby2,f0
585 GLOBAL_LIBM_END(asinf)
587 // Stack operations when calling error support.
597 // sp-64 -> + sp -> +
598 // save ar.pfs save b0
602 // Stack operations when calling error support.
606 // R3 ->| <- GR_RESULT | -> f8
616 LOCAL_LIBM_ENTRY(__libm_error_region)
619 add GR_Parameter_Y=-32,sp // Parameter 2 value
621 .save ar.pfs,GR_SAVE_PFS
622 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
626 add sp=-64,sp // Create new stack
628 mov GR_SAVE_GP=gp // Save gp
631 stfs [GR_Parameter_Y] = f1,16 // Store Parameter 2 on stack
632 add GR_Parameter_X = 16,sp // Parameter 1 address
634 mov GR_SAVE_B0=b0 // Save b0
640 frcpa.s0 f9,p0 = f0,f0
645 stfs [GR_Parameter_X] = f8 // Store Parameter 1 on stack
646 add GR_Parameter_RESULT = 0,GR_Parameter_Y
647 nop.b 0 // Parameter 3 address
650 stfs [GR_Parameter_Y] = f9 // Store Parameter 3 on stack
651 add GR_Parameter_Y = -16,GR_Parameter_Y
652 br.call.sptk b0=__libm_error_support# // Call error handling function
657 add GR_Parameter_RESULT = 48,sp
661 ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
663 add sp = 64,sp // Restore stack pointer
664 mov b0 = GR_SAVE_B0 // Restore return address
667 mov gp = GR_SAVE_GP // Restore gp
668 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
669 br.ret.sptk b0 // Return
672 LOCAL_LIBM_END(__libm_error_region)
674 .type __libm_error_support#,@function
675 .global __libm_error_support#