3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
6 // Contributed 2/2/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/15/00 Bundle added after call to __libm_error_support to properly
47 // set [the previously overwritten] GR_Parameter_RESULT.
48 // 8/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.
54 //=========================================
55 // The acosf function computes the principle value of the arc sine of x.
56 // A doman error occurs for arguments not in the range [-1,+1].
58 // The acosf function returns the arc cosine in the range [0, +pi] radians.
60 // acos(x) returns a Nan and raises the invalid exception for |x| >1
62 // |x| <= sqrt(2)/2. get Ax and Bx
65 // poly_p3 = x2 p4 + p3
66 // poly_p1 = x2 (poly_p1) + x = x2(x p1) + x
67 // poly_p2 = x2( poly_p3) + p2 = x2(x2 p4 + p3) + p2
69 // poly_Ax = x5(x2( poly_p3) + p2) + x2(x p1) + x
70 // = x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
72 // poly_p7 = x2 p8 + p7
73 // poly_p5 = x2 p6 + p5
75 // poly_p7 = x4 p9 + (x2 p8 + p7)
76 // poly_Bx = x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5
78 // sinf1 = x11(x4 (x4 p9 + (x2 p8 + p7)) + x2 p6 + p5) + x5(x2(x2 p4 + p3) + p2) + x2(x p1) + x
79 // = x19 p9 + x17 p8 + x15 p7 x13 p6 + x11 p5 + x9 p4 + x7 p3 + x5 p2 + x3 p1 + x
80 // answer1 = pi/2 - sinf1
88 // Get polynomial in t = 1-x2
93 // poly_p4 = t p5 + p4
96 // poly_p6 = t p7 + p6
97 // poly_p2 = t p3 + p2
99 // poly_p8 = t p9 + p8
101 // poly_p4 = t2 poly_p6 + poly_p4
102 // = t2 (t p7 + p6) + (t p5 + p4)
104 // poly_p2 = t2 poly_p2 + poly_p1
105 // = t2 (t p3 + p2) + (t p1 + 1)
107 // poly_p4 = t4 poly_p8 + poly_p4
108 // = t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4))
110 // P(t) = poly_p2 + t4 poly_p8
111 // = t2 (t p3 + p2) + (t p1 + 1) + t4 (t4 (t p9 + p8) + (t2 (t p7 + p6) + (t p5 + p4)))
112 // = t3 p3 + t2 p2 + t p1 + 1 + t9 p9 + t8 p8 + t7 p7 + t6 p6 + t5 p5 + t4 p4
115 // answer2 = sign(x) z P(t) if x>0
116 // = sign(x) z P(t) + pi if x<0
118 #include "libm_support.h"
122 //=========================================
124 // predicate registers
125 //acosf_pred_LEsqrt2by2 = p7
126 //acosf_pred_GTsqrt2by2 = p8
142 GR_Parameter_RESULT = r43
143 GR_Parameter_TAG = r44
145 // floating point registers
172 acosf_const_piby2 = f53
173 acosf_const_sqrt2by2 = f54
209 acosf_sgnx_2poly_p2 = f84
210 acosf_sgn_x_piby2 = f85
213 acosf_2poly_p4a = f87
214 acosf_2poly_p4b = f88
215 acosf_2poly_p2a = f89
223 //==============================================================
234 ASM_TYPE_DIRECTIVE(acosf_coeff_1_table,@object)
235 data8 0x3FC5555607DCF816 // P1
236 data8 0x3F9CF81AD9BAB2C6 // P4
237 data8 0x3FC59E0975074DF3 // P7
238 data8 0xBFA6F4CC2780AA1D // P6
239 data8 0x3FC2DD45292E93CB // P9
240 data8 0x3fe6a09e667f3bcd // sqrt(2)/2
241 ASM_SIZE_DIRECTIVE(acosf_coeff_1_table)
244 ASM_TYPE_DIRECTIVE(acosf_coeff_2_table,@object)
245 data8 0x3FA6F108E31EFBA6 // P3
246 data8 0xBFCA31BF175D82A0 // P8
247 data8 0x3FA30C0337F6418B // P5
248 data8 0x3FB332C9266CB1F9 // P2
249 data8 0x3ff921fb54442d18 // pi_by_2
250 ASM_SIZE_DIRECTIVE(acosf_coeff_2_table)
254 ASM_TYPE_DIRECTIVE(acosf,@function)
262 // Load the addresses of the two tables.
263 // Then, load the coefficients and other constants.
266 alloc r32 = ar.pfs,1,8,4,0
267 fnma.s1 acosf_t = f8,f8,f1
268 dep.z ACOSF_GR_1by2 = 0x3f,24,8 // 0x3f000000
271 addl ACOSF_Addr1 = @ltoff(acosf_coeff_1_table),gp
272 fma.s1 acosf_x2 = f8,f8,f0
273 addl ACOSF_Addr2 = @ltoff(acosf_coeff_2_table),gp ;;
278 ld8 ACOSF_Addr1 = [ACOSF_Addr1]
279 fmerge.s acosf_abs_x = f1,f8
280 dep ACOSF_GR_3by2 = -1,r0,22,8 // 0x3fc00000
284 movl ACOSF_GR_5by2 = 0x40200000;;
290 setf.s acosf_1by2 = ACOSF_GR_1by2
291 fmerge.s acosf_sgn_x = f8,f1
295 ld8 ACOSF_Addr2 = [ACOSF_Addr2]
302 setf.s acosf_5by2 = ACOSF_GR_5by2
303 fcmp.lt.s1 p11,p12 = f8,f0
308 ldfpd acosf_coeff_P1,acosf_coeff_P4 = [ACOSF_Addr1],16
309 setf.s acosf_3by2 = ACOSF_GR_3by2
310 fclass.m.unc p8,p0 = f8, 0xc3 ;; //@qnan | @snan
315 ldfpd acosf_coeff_P7,acosf_coeff_P6 = [ACOSF_Addr1],16
316 fma.s1 acosf_t2 = acosf_t,acosf_t,f0
320 ldfpd acosf_coeff_P3,acosf_coeff_P8 = [ACOSF_Addr2],16
321 fma.s1 acosf_x4 = acosf_x2,acosf_x2,f0
327 ldfpd acosf_coeff_P9,acosf_const_sqrt2by2 = [ACOSF_Addr1]
328 fclass.m.unc p10,p0 = f8, 0x07 //@zero
332 ldfpd acosf_coeff_P5,acosf_coeff_P2 = [ACOSF_Addr2],16
333 fma.s1 acosf_x3 = f8,acosf_x2,f0
339 ldfd acosf_const_piby2 = [ACOSF_Addr2]
340 frsqrta.s1 acosf_B,p0 = acosf_t
345 (p8) fma.s f8 = f8,f1,f0
346 (p8) br.ret.spnt b0 ;; // Exit if x=nan
352 fcmp.eq.s1 p6,p0 = acosf_abs_x,f1
353 (p10) br.cond.spnt L(ACOSF_ZERO) ;; // Branch if x=0
358 fcmp.gt.s1 p9,p0 = acosf_abs_x,f1
364 fma.s1 acosf_x8 = acosf_x4,acosf_x4,f0
369 fma.s1 acosf_t4 = acosf_t2,acosf_t2,f0
370 (p6) br.cond.spnt L(ACOSF_ABS_ONE) ;; // Branch if |x|=1
375 fma.s1 acosf_x5 = acosf_x2,acosf_x3,f0
379 (p9) mov GR_Parameter_TAG = 59
380 fma.s1 acosf_yby2 = acosf_t,acosf_1by2,f0
381 (p9) br.cond.spnt __libm_error_region ;; // Branch if |x|>1
387 fma.s1 acosf_Az = acosf_t,acosf_B,f0
392 fma.s1 acosf_B2 = acosf_B,acosf_B,f0
398 fma.s1 acosf_poly_p1 = f8,acosf_coeff_P1,f0
403 fma.s1 acosf_2poly_p1 = acosf_coeff_P1,acosf_t,f1
409 fma.s1 acosf_poly_p3 = acosf_coeff_P4,acosf_x2,acosf_coeff_P3
414 fma.s1 acosf_2poly_p6 = acosf_coeff_P7,acosf_t,acosf_coeff_P6
420 fma.s1 acosf_poly_p7 = acosf_x2,acosf_coeff_P8,acosf_coeff_P7
425 fma.s1 acosf_2poly_p2 = acosf_coeff_P3,acosf_t,acosf_coeff_P2
432 fma.s1 acosf_poly_p5 = acosf_x2,acosf_coeff_P6,acosf_coeff_P5
437 fma.s1 acosf_2poly_p4 = acosf_coeff_P5,acosf_t,acosf_coeff_P4
444 fma.s1 acosf_x11 = acosf_x8,acosf_x3,f0
449 fnma.s1 acosf_dz = acosf_B2,acosf_yby2,acosf_1by2
456 fma.s1 acosf_poly_p1a = acosf_x2,acosf_poly_p1,f8
461 fma.s1 acosf_2poly_p8 = acosf_coeff_P9,acosf_t,acosf_coeff_P8
466 // Get the absolute value of x and determine the region in which x lies
470 fcmp.le.s1 p7,p8 = acosf_abs_x,acosf_const_sqrt2by2
475 fma.s1 acosf_poly_p2 = acosf_x2,acosf_poly_p3,acosf_coeff_P2
482 fma.s1 acosf_poly_p7a = acosf_x4,acosf_coeff_P9,acosf_poly_p7
487 fma.s1 acosf_2poly_p2a = acosf_2poly_p2,acosf_t2,acosf_2poly_p1
494 (p8) fma.s1 acosf_sgnx_t4 = acosf_sgn_x,acosf_t4,f0
499 (p8) fma.s1 acosf_2poly_p4a = acosf_2poly_p6,acosf_t2,acosf_2poly_p4
506 (p8) fma.s1 acosf_Sz = acosf_5by2,acosf_dz,acosf_3by2
511 (p8) fma.s1 acosf_d2z = acosf_dz,acosf_dz,f0
518 (p8) fnma.d.s1 acosf_sgn_x_piby2 = acosf_sgn_x,acosf_const_piby2,acosf_const_piby2
523 (p7) fma.s1 acosf_poly_Ax = acosf_x5,acosf_poly_p2,acosf_poly_p1a
529 (p7) fma.s1 acosf_poly_Bx = acosf_x4,acosf_poly_p7a,acosf_poly_p5
534 (p8) fma.s1 acosf_sgnx_2poly_p2 = acosf_sgn_x,acosf_2poly_p2a,f0
540 fcmp.eq.s0 p6,p0 = f8,f0 // Only purpose is to set D if x denormal
545 (p8) fma.s1 acosf_2poly_p4b = acosf_2poly_p8,acosf_t4,acosf_2poly_p4a
552 (p8) fma.s1 acosf_Fz = acosf_d2z,acosf_Sz,acosf_dz
559 (p8) fma.d.s1 acosf_Pt = acosf_2poly_p4b,acosf_sgnx_t4,acosf_sgnx_2poly_p2
565 (p8) fma.d.s1 acosf_z = acosf_Az,acosf_Fz,acosf_Az
571 (p7) fma.d.s1 acosf_sinf1 = acosf_x11,acosf_poly_Bx,acosf_poly_Ax
575 .pred.rel "mutex",p8,p7 //acosf_pred_GTsqrt2by2,acosf_pred_LEsqrt2by2
578 (p8) fma.s f8 = acosf_z,acosf_Pt,acosf_sgn_x_piby2
584 (p7) fms.s f8 = acosf_const_piby2,f1,acosf_sinf1
592 fma.s f8 = acosf_const_piby2,f1,f0 // acosf(0)=pi/2
598 .pred.rel "mutex",p11,p12
602 (p11) fma.s f8 = acosf_const_piby2,f1,acosf_const_piby2 // acosf(-1)=pi
607 (p12) fma.s f8 = f1,f0,f0 // acosf(1)=0
612 ASM_SIZE_DIRECTIVE(acosf)
615 // Stack operations when calling error support.
625 // sp-64 -> + sp -> +
626 // save ar.pfs save b0
630 // Stack operations when calling error support.
634 // R3 ->| <- GR_RESULT | -> f8
645 .proc __libm_error_region
649 add GR_Parameter_Y=-32,sp // Parameter 2 value
651 .save ar.pfs,GR_SAVE_PFS
652 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
656 add sp=-64,sp // Create new stack
658 mov GR_SAVE_GP=gp // Save gp
661 stfs [GR_Parameter_Y] = f1,16 // Store Parameter 2 on stack
662 add GR_Parameter_X = 16,sp // Parameter 1 address
664 mov GR_SAVE_B0=b0 // Save b0
670 frcpa.s0 f9,p0 = f0,f0
675 stfs [GR_Parameter_X] = f8 // Store Parameter 1 on stack
676 add GR_Parameter_RESULT = 0,GR_Parameter_Y
677 nop.b 0 // Parameter 3 address
680 stfs [GR_Parameter_Y] = f9 // Store Parameter 3 on stack
681 add GR_Parameter_Y = -16,GR_Parameter_Y
682 br.call.sptk b0=__libm_error_support# // Call error handling function
687 add GR_Parameter_RESULT = 48,sp
691 ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
693 add sp = 64,sp // Restore stack pointer
694 mov b0 = GR_SAVE_B0 // Restore return address
697 mov gp = GR_SAVE_GP // Restore gp
698 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
699 br.ret.sptk b0 // Return
702 .endp __libm_error_region
703 ASM_SIZE_DIRECTIVE(__libm_error_region)
705 .type __libm_error_support#,@function
706 .global __libm_error_support#