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/15/00 Bundle added after call to __libm_error_support to properly
47 // set [the previously overwritten] GR_Parameter_RESULT.
48 // 08/17/00 Changed predicate register macro-usage to direct predicate
49 // names due to an assembler bug.
50 // 10/17/00 Improved speed of x=0 and x=1 paths, set D flag if x denormal.
51 // 03/13/01 Corrected sign of imm1 value in dep instruction.
52 // 05/20/02 Cleaned up namespace and sf0 syntax
53 // 02/06/03 Reordered header: .section, .global, .proc, .align
54 // 04/17/03 Moved mutex after label
58 //=========================================
59 // The acosf function computes the principle value of the arc sine of x.
60 // A doman error occurs for arguments not in the range [-1,+1].
62 // The acosf function returns the arc cosine in the range [0, +pi] radians.
64 // acos(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 + (x2 p8 + p7)
80 // poly_Bx = x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5
82 // sinf1 = x11(x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5) + x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
83 // = x19 p9 + x17 p8 + x15 p7 x13 p6 + x11 p5 + x9 p4 + x7 p3 + x5 p2 + x3 p1 + x
84 // answer1 = pi/2 - sinf1
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) if x>0
120 // = sign(x) z P(t) + pi if x<0
125 //=========================================
127 // predicate registers
128 //acosf_pred_LEsqrt2by2 = p7
129 //acosf_pred_GTsqrt2by2 = p8
145 GR_Parameter_RESULT = r43
146 GR_Parameter_TAG = r44
148 // floating point registers
175 acosf_const_piby2 = f53
176 acosf_const_sqrt2by2 = f54
212 acosf_sgnx_2poly_p2 = f84
213 acosf_sgn_x_piby2 = f85
216 acosf_2poly_p4a = f87
217 acosf_2poly_p4b = f88
218 acosf_2poly_p2a = f89
226 //==============================================================
232 LOCAL_OBJECT_START(acosf_coeff_1_table)
233 data8 0x3FC5555607DCF816 // P1
234 data8 0x3F9CF81AD9BAB2C6 // P4
235 data8 0x3FC59E0975074DF3 // P7
236 data8 0xBFA6F4CC2780AA1D // P6
237 data8 0x3FC2DD45292E93CB // P9
238 data8 0x3fe6a09e667f3bcd // sqrt(2)/2
239 LOCAL_OBJECT_END(acosf_coeff_1_table)
241 LOCAL_OBJECT_START(acosf_coeff_2_table)
242 data8 0x3FA6F108E31EFBA6 // P3
243 data8 0xBFCA31BF175D82A0 // P8
244 data8 0x3FA30C0337F6418B // P5
245 data8 0x3FB332C9266CB1F9 // P2
246 data8 0x3ff921fb54442d18 // pi_by_2
247 LOCAL_OBJECT_END(acosf_coeff_2_table)
251 GLOBAL_LIBM_ENTRY(acosf)
253 // Load the addresses of the two tables.
254 // Then, load the coefficients and other constants.
257 alloc r32 = ar.pfs,1,8,4,0
258 fnma.s1 acosf_t = f8,f8,f1
259 dep.z ACOSF_GR_1by2 = 0x3f,24,8 // 0x3f000000
262 addl ACOSF_Addr1 = @ltoff(acosf_coeff_1_table),gp
263 fma.s1 acosf_x2 = f8,f8,f0
264 addl ACOSF_Addr2 = @ltoff(acosf_coeff_2_table),gp ;;
269 ld8 ACOSF_Addr1 = [ACOSF_Addr1]
270 fmerge.s acosf_abs_x = f1,f8
271 dep ACOSF_GR_3by2 = -1,r0,22,8 // 0x3fc00000
275 movl ACOSF_GR_5by2 = 0x40200000;;
281 setf.s acosf_1by2 = ACOSF_GR_1by2
282 fmerge.s acosf_sgn_x = f8,f1
286 ld8 ACOSF_Addr2 = [ACOSF_Addr2]
293 setf.s acosf_5by2 = ACOSF_GR_5by2
294 fcmp.lt.s1 p11,p12 = f8,f0
299 ldfpd acosf_coeff_P1,acosf_coeff_P4 = [ACOSF_Addr1],16
300 setf.s acosf_3by2 = ACOSF_GR_3by2
301 fclass.m.unc p8,p0 = f8, 0xc3 ;; //@qnan | @snan
306 ldfpd acosf_coeff_P7,acosf_coeff_P6 = [ACOSF_Addr1],16
307 fma.s1 acosf_t2 = acosf_t,acosf_t,f0
311 ldfpd acosf_coeff_P3,acosf_coeff_P8 = [ACOSF_Addr2],16
312 fma.s1 acosf_x4 = acosf_x2,acosf_x2,f0
318 ldfpd acosf_coeff_P9,acosf_const_sqrt2by2 = [ACOSF_Addr1]
319 fclass.m.unc p10,p0 = f8, 0x07 //@zero
323 ldfpd acosf_coeff_P5,acosf_coeff_P2 = [ACOSF_Addr2],16
324 fma.s1 acosf_x3 = f8,acosf_x2,f0
330 ldfd acosf_const_piby2 = [ACOSF_Addr2]
331 frsqrta.s1 acosf_B,p0 = acosf_t
336 (p8) fma.s.s0 f8 = f8,f1,f0
337 (p8) br.ret.spnt b0 ;; // Exit if x=nan
343 fcmp.eq.s1 p6,p0 = acosf_abs_x,f1
344 (p10) br.cond.spnt ACOSF_ZERO ;; // Branch if x=0
349 fcmp.gt.s1 p9,p0 = acosf_abs_x,f1
355 fma.s1 acosf_x8 = acosf_x4,acosf_x4,f0
360 fma.s1 acosf_t4 = acosf_t2,acosf_t2,f0
361 (p6) br.cond.spnt ACOSF_ABS_ONE ;; // Branch if |x|=1
366 fma.s1 acosf_x5 = acosf_x2,acosf_x3,f0
370 (p9) mov GR_Parameter_TAG = 59
371 fma.s1 acosf_yby2 = acosf_t,acosf_1by2,f0
372 (p9) br.cond.spnt __libm_error_region ;; // Branch if |x|>1
378 fma.s1 acosf_Az = acosf_t,acosf_B,f0
383 fma.s1 acosf_B2 = acosf_B,acosf_B,f0
389 fma.s1 acosf_poly_p1 = f8,acosf_coeff_P1,f0
394 fma.s1 acosf_2poly_p1 = acosf_coeff_P1,acosf_t,f1
400 fma.s1 acosf_poly_p3 = acosf_coeff_P4,acosf_x2,acosf_coeff_P3
405 fma.s1 acosf_2poly_p6 = acosf_coeff_P7,acosf_t,acosf_coeff_P6
411 fma.s1 acosf_poly_p7 = acosf_x2,acosf_coeff_P8,acosf_coeff_P7
416 fma.s1 acosf_2poly_p2 = acosf_coeff_P3,acosf_t,acosf_coeff_P2
423 fma.s1 acosf_poly_p5 = acosf_x2,acosf_coeff_P6,acosf_coeff_P5
428 fma.s1 acosf_2poly_p4 = acosf_coeff_P5,acosf_t,acosf_coeff_P4
435 fma.s1 acosf_x11 = acosf_x8,acosf_x3,f0
440 fnma.s1 acosf_dz = acosf_B2,acosf_yby2,acosf_1by2
447 fma.s1 acosf_poly_p1a = acosf_x2,acosf_poly_p1,f8
452 fma.s1 acosf_2poly_p8 = acosf_coeff_P9,acosf_t,acosf_coeff_P8
457 // Get the absolute value of x and determine the region in which x lies
461 fcmp.le.s1 p7,p8 = acosf_abs_x,acosf_const_sqrt2by2
466 fma.s1 acosf_poly_p2 = acosf_x2,acosf_poly_p3,acosf_coeff_P2
473 fma.s1 acosf_poly_p7a = acosf_x4,acosf_coeff_P9,acosf_poly_p7
478 fma.s1 acosf_2poly_p2a = acosf_2poly_p2,acosf_t2,acosf_2poly_p1
485 (p8) fma.s1 acosf_sgnx_t4 = acosf_sgn_x,acosf_t4,f0
490 (p8) fma.s1 acosf_2poly_p4a = acosf_2poly_p6,acosf_t2,acosf_2poly_p4
497 (p8) fma.s1 acosf_Sz = acosf_5by2,acosf_dz,acosf_3by2
502 (p8) fma.s1 acosf_d2z = acosf_dz,acosf_dz,f0
509 (p8) fnma.d.s1 acosf_sgn_x_piby2 = acosf_sgn_x,acosf_const_piby2,acosf_const_piby2
514 (p7) fma.s1 acosf_poly_Ax = acosf_x5,acosf_poly_p2,acosf_poly_p1a
520 (p7) fma.s1 acosf_poly_Bx = acosf_x4,acosf_poly_p7a,acosf_poly_p5
525 (p8) fma.s1 acosf_sgnx_2poly_p2 = acosf_sgn_x,acosf_2poly_p2a,f0
531 fcmp.eq.s0 p6,p0 = f8,f0 // Only purpose is to set D if x denormal
536 (p8) fma.s1 acosf_2poly_p4b = acosf_2poly_p8,acosf_t4,acosf_2poly_p4a
543 (p8) fma.s1 acosf_Fz = acosf_d2z,acosf_Sz,acosf_dz
550 (p8) fma.d.s1 acosf_Pt = acosf_2poly_p4b,acosf_sgnx_t4,acosf_sgnx_2poly_p2
556 (p8) fma.d.s1 acosf_z = acosf_Az,acosf_Fz,acosf_Az
562 (p7) fma.d.s1 acosf_sinf1 = acosf_x11,acosf_poly_Bx,acosf_poly_Ax
566 .pred.rel "mutex",p8,p7 //acosf_pred_GTsqrt2by2,acosf_pred_LEsqrt2by2
569 (p8) fma.s.s0 f8 = acosf_z,acosf_Pt,acosf_sgn_x_piby2
575 (p7) fms.s.s0 f8 = acosf_const_piby2,f1,acosf_sinf1
583 fma.s.s0 f8 = acosf_const_piby2,f1,f0 // acosf(0)=pi/2
589 .pred.rel "mutex",p11,p12
593 (p11) fma.s.s0 f8 = acosf_const_piby2,f1,acosf_const_piby2 // acosf(-1)=pi
598 (p12) fma.s.s0 f8 = f1,f0,f0 // acosf(1)=0
602 GLOBAL_LIBM_END(acosf)
605 // Stack operations when calling error support.
615 // sp-64 -> + sp -> +
616 // save ar.pfs save b0
620 // Stack operations when calling error support.
624 // R3 ->| <- GR_RESULT | -> f8
635 LOCAL_LIBM_ENTRY(__libm_error_region)
638 add GR_Parameter_Y=-32,sp // Parameter 2 value
640 .save ar.pfs,GR_SAVE_PFS
641 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
645 add sp=-64,sp // Create new stack
647 mov GR_SAVE_GP=gp // Save gp
650 stfs [GR_Parameter_Y] = f1,16 // Store Parameter 2 on stack
651 add GR_Parameter_X = 16,sp // Parameter 1 address
653 mov GR_SAVE_B0=b0 // Save b0
659 frcpa.s0 f9,p0 = f0,f0
664 stfs [GR_Parameter_X] = f8 // Store Parameter 1 on stack
665 add GR_Parameter_RESULT = 0,GR_Parameter_Y
666 nop.b 0 // Parameter 3 address
669 stfs [GR_Parameter_Y] = f9 // Store Parameter 3 on stack
670 add GR_Parameter_Y = -16,GR_Parameter_Y
671 br.call.sptk b0=__libm_error_support# // Call error handling function
676 add GR_Parameter_RESULT = 48,sp
680 ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
682 add sp = 64,sp // Restore stack pointer
683 mov b0 = GR_SAVE_B0 // Restore return address
686 mov gp = GR_SAVE_GP // Restore gp
687 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
688 br.ret.sptk b0 // Return
691 LOCAL_LIBM_END(__libm_error_region)
693 .type __libm_error_support#,@function
694 .global __libm_error_support#