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 // WARRANTY DISCLAIMER
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
34 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 // Intel Corporation is the author of this code, and requests that all
39 // problem reports or change requests be submitted to it directly at
40 // http://developer.intel.com/opensource.
43 //==============================================================
44 // 2/02/00 Initial version
45 // 8/17/00 New and much faster algorithm.
46 // 8/30/00 Avoided bank conflicts on loads, shortened |x|=1 and x=0 paths,
47 // fixed mfb split issue stalls.
50 //=========================================
51 // The acos function computes the principle value of the arc sine of x.
52 // A doman error occurs for arguments not in the range [-1,+1].
54 // The acos function returns the arc cosine in the range [0, +pi] radians.
55 // acos(1) returns +0, acos(-1) returns pi, acos(0) returns pi/2.
56 // acos(x) returns a Nan and raises the invalid exception for |x| >1
58 // The acos function is just like asin except that pi/2 is added at the end.
62 //=========================================
64 #include "libm_support.h"
66 // predicate registers
67 //acos_pred_LEsqrt2by2 = p7
68 //acos_pred_GTsqrt2by2 = p8
81 GR_Parameter_RESULT = r41
82 GR_Parameter_Tag = r42
84 // floating point registers
110 acos_const_sqrt2by2 = f53
111 acos_const_piby2 = f54
189 acos_const_add = f119
192 //==============================================================
203 ASM_TYPE_DIRECTIVE(acos_coeff_1_table,@object)
204 data8 0xE4E7E0A423A21249 , 0x00003FF8 //P7
205 data8 0xC2F7EE0200FCE2A5 , 0x0000C003 //P18
206 data8 0xB745D7F6C65C20E0 , 0x00003FF9 //P5
207 data8 0xF75E381A323D4D94 , 0x0000C002 //P16
208 data8 0x8959C2629C1024C0 , 0x0000C002 //P20
209 data8 0xAFF68E7D241292C5 , 0x00003FF8 //P9
210 data8 0xB6DB6DB7260AC30D , 0x00003FFA //P3
211 data8 0xD0417CE2B41CB7BF , 0x0000C000 //P14
212 data8 0x81D570FEA724E3E4 , 0x0000BFFD //P12
213 data8 0xAAAAAAAAAAAAC277 , 0x00003FFC //P1
214 data8 0xF534912FF3E7B76F , 0x00003FFF //P21
215 data8 0xc90fdaa22168c235 , 0x00003fff // pi/2
216 data8 0x0000000000000000 , 0x00000000 // pad to avoid bank conflicts
217 ASM_SIZE_DIRECTIVE(acos_coeff_1_table)
221 ASM_TYPE_DIRECTIVE(acos_coeff_2_table,@object)
222 data8 0x8E26AF5F29B39A2A , 0x00003FF9 //P6
223 data8 0xB4F118A4B1015470 , 0x00004003 //P17
224 data8 0xF8E38E10C25990E0 , 0x00003FF9 //P4
225 data8 0x80F50489AEF1CAC6 , 0x00004002 //P15
226 data8 0x92728015172CFE1C , 0x00004003 //P19
227 data8 0xBBC3D831D4595971 , 0x00003FF8 //P8
228 data8 0x999999999952A5C3 , 0x00003FFB //P2
229 data8 0x855576BE6F0975EC , 0x00003FFF //P13
230 data8 0xF12420E778077D89 , 0x00003FFA //P11
231 data8 0xB6590FF4D23DE003 , 0x00003FF3 //P10
232 data8 0xb504f333f9de6484 , 0x00003ffe // sqrt(2)/2
233 ASM_SIZE_DIRECTIVE(acos_coeff_2_table)
238 ASM_TYPE_DIRECTIVE(acos,@function)
248 alloc r32 = ar.pfs,1,6,4,0
249 fma.s1 acos_tx = f8,f8,f0
250 addl ASIN_Addr2 = @ltoff(acos_coeff_2_table),gp
253 mov ASIN_FFFE = 0xFFFE
254 fnma.s1 acos_t = f8,f8,f1
255 addl ASIN_Addr1 = @ltoff(acos_coeff_1_table),gp
261 setf.exp acos_1by2 = ASIN_FFFE
262 fmerge.s acos_abs_x = f1,f8
268 ld8 ASIN_Addr1 = [ASIN_Addr1]
269 ld8 ASIN_Addr2 = [ASIN_Addr2]
270 fmerge.s acos_sgn_x = f8,f1
277 fcmp.lt.s1 p11,p12 = f8, f0
283 ldfe acos_coeff_P7 = [ASIN_Addr1],16
284 fma.s1 acos_tx2 = acos_tx,acos_tx,f0
288 ldfe acos_coeff_P6 = [ASIN_Addr2],16
289 fma.s1 acos_t2 = acos_t,acos_t,f0
295 ldfe acos_coeff_P18 = [ASIN_Addr1],16
296 ldfe acos_coeff_P17 = [ASIN_Addr2],16
297 fclass.m.unc p8,p0 = f8, 0xc3 //@qnan |@snan
303 ldfe acos_coeff_P5 = [ASIN_Addr1],16
304 ldfe acos_coeff_P4 = [ASIN_Addr2],16
305 frsqrta.s1 acos_y0,p0 = acos_t
311 ldfe acos_coeff_P16 = [ASIN_Addr1],16
312 fcmp.gt.s1 p9,p0 = acos_abs_x,f1
316 ldfe acos_coeff_P15 = [ASIN_Addr2],16
317 (p8) fma.d f8 = f8,f1,f0
324 ldfe acos_coeff_P20 = [ASIN_Addr1],16
325 ldfe acos_coeff_P19 = [ASIN_Addr2],16
326 fclass.m.unc p10,p0 = f8, 0x07 //@zero
332 ldfe acos_coeff_P9 = [ASIN_Addr1],16
333 fma.s1 acos_t4 = acos_t2,acos_t2,f0
334 (p9) mov GR_Parameter_Tag = 58
337 ldfe acos_coeff_P8 = [ASIN_Addr2],16
338 fma.s1 acos_3by2 = acos_1by2,f1,f1
344 ldfe acos_coeff_P2 = [ASIN_Addr2],16
345 fma.s1 acos_tx4 = acos_tx2,acos_tx2,f0
349 ldfe acos_coeff_P3 = [ASIN_Addr1],16
350 fma.s1 acos_t3 = acos_t,acos_t2,f0
351 (p9) br.cond.spnt __libm_error_region
357 ldfe acos_coeff_P13 = [ASIN_Addr2],16
358 fma.s1 acos_H0 = acos_y0,acos_1by2,f0
362 ldfe acos_coeff_P14 = [ASIN_Addr1],16
363 fma.s1 acos_S0 = acos_y0,acos_t,f0
369 ldfe acos_coeff_P11 = [ASIN_Addr2],16
370 fcmp.eq.s1 p6,p0 = acos_abs_x, f1
374 ldfe acos_coeff_P12 = [ASIN_Addr1],16
375 fma.s1 acos_tx3 = acos_tx,acos_tx2,f0
382 ldfe acos_coeff_P10 = [ASIN_Addr2],16
383 fma.s1 acos_1poly_p6 = acos_tx,acos_coeff_P7,acos_coeff_P6
387 ldfe acos_coeff_P1 = [ASIN_Addr1],16
388 fma.s1 acos_poly_p6 = acos_t,acos_coeff_P7,acos_coeff_P6
394 ldfe acos_const_sqrt2by2 = [ASIN_Addr2],16
395 fma.s1 acos_5by2 = acos_3by2,f1,f1
399 ldfe acos_coeff_P21 = [ASIN_Addr1],16
400 fma.s1 acos_11by4 = acos_3by2,acos_3by2,acos_1by2
406 ldfe acos_const_piby2 = [ASIN_Addr1],16
407 fma.s1 acos_poly_p17 = acos_t,acos_coeff_P18,acos_coeff_P17
412 fma.s1 acos_3by4 = acos_3by2,acos_1by2,f0
413 (p10) br.cond.spnt L(ACOS_ZERO) // Branch to short path if x=0
420 fma.s1 acos_poly_p15 = acos_t,acos_coeff_P16,acos_coeff_P15
425 fnma.s1 acos_d = acos_S0,acos_H0,acos_1by2
426 (p6) br.cond.spnt L(ACOS_ABS_ONE) // Branch to short path if |x|=1
433 fma.s1 acos_poly_p19 = acos_t,acos_coeff_P20,acos_coeff_P19
438 fma.s1 acos_poly_p4 = acos_t,acos_coeff_P5,acos_coeff_P4
445 fma.s1 acos_1poly_p17 = acos_tx,acos_coeff_P18,acos_coeff_P17
450 fma.s1 acos_poly_p8 = acos_t,acos_coeff_P9,acos_coeff_P8
457 fms.s1 acos_35by8 = acos_5by2,acos_11by4,acos_5by2
462 fma.s1 acos_63by8 = acos_5by2,acos_11by4,f1
469 fma.s1 acos_poly_p13 = acos_t,acos_coeff_P14,acos_coeff_P13
474 fma.s1 acos_18by4 = acos_3by2,acos_5by2,acos_3by4
481 fma.s1 acos_l1 = acos_5by2,acos_d,acos_3by2
486 fma.s1 acos_d2 = acos_d,acos_d,f0
493 fma.s1 acos_poly_p15 = acos_t2,acos_poly_p17,acos_poly_p15
498 fma.s1 acos_T0 = acos_d,acos_S0,f0
505 fma.s1 acos_poly_p19 = acos_t2,acos_coeff_P21,acos_poly_p19
510 fma.s1 acos_poly_p4 = acos_t2,acos_poly_p6,acos_poly_p4
517 fma.s1 acos_d1 = acos_35by8,acos_d,f0
522 fma.s1 acos_231by16 = acos_3by2,acos_35by8,acos_63by8
529 fma.s1 acos_poly_p2 = acos_t,acos_coeff_P3,acos_coeff_P2
534 fma.s1 acos_poly_p8 = acos_t2,acos_coeff_P10,acos_poly_p8
541 fma.s1 acos_poly_p11 = acos_t,acos_coeff_P12,acos_coeff_P11
546 fma.s1 acos_e0 = acos_d2,acos_l1,acos_d
553 fma.s1 acos_1poly_p15 = acos_tx,acos_coeff_P16,acos_coeff_P15
558 fma.s1 acos_poly_p0 = acos_t,acos_coeff_P1,f1
565 fma.s1 acos_1poly_p19 = acos_tx,acos_coeff_P20,acos_coeff_P19
570 fma.s1 acos_1poly_p4 = acos_tx,acos_coeff_P5,acos_coeff_P4
577 fma.s1 acos_1poly_p8 = acos_tx,acos_coeff_P9,acos_coeff_P8
582 fma.s1 acos_l2 = acos_231by16,acos_d,acos_63by8
589 fma.s1 acos_d3 = acos_d2,acos_d,f0
594 fma.s1 acos_T3 = acos_d2,acos_T0,f0
601 fma.s1 acos_429by16 = acos_18by4,acos_11by4,acos_231by16
606 fma.s1 acos_S1 = acos_e0,acos_S0,acos_S0
613 fma.s1 acos_poly_p4 = acos_t4,acos_poly_p8,acos_poly_p4
618 fma.s1 acos_poly_p15 = acos_t4,acos_poly_p19,acos_poly_p15
625 fma.s1 acos_poly_p0 = acos_t2,acos_poly_p2,acos_poly_p0
630 fma.s1 acos_poly_p11 = acos_t2,acos_poly_p13,acos_poly_p11
637 fma.s1 acos_t8 = acos_t4,acos_t4,f0
642 fma.s1 acos_e1 = acos_d2,acos_l2,acos_d1
649 fma.s1 acos_1poly_p4 = acos_tx2,acos_1poly_p6,acos_1poly_p4
654 fma.s1 acos_1poly_p15 = acos_tx2,acos_1poly_p17,acos_1poly_p15
661 fma.s1 acos_1poly_p8 = acos_tx2,acos_coeff_P10,acos_1poly_p8
666 fma.s1 acos_1poly_p19 = acos_tx2,acos_coeff_P21,acos_1poly_p19
673 fma.s1 acos_1poly_p2 = acos_tx,acos_coeff_P3,acos_coeff_P2
678 fma.s1 acos_1poly_p13 = acos_tx,acos_coeff_P14,acos_coeff_P13
685 fma.s1 acos_1poly_p0 = acos_tx,acos_coeff_P1,f1
690 fma.s1 acos_1poly_p11 = acos_tx,acos_coeff_P12,acos_coeff_P11
697 fma.s1 acos_l3 = acos_429by16,acos_d,f0
702 fma.s1 acos_z = acos_e1,acos_T3,acos_S1
709 fma.s1 acos_poly_p11 = acos_t4,acos_poly_p15,acos_poly_p11
714 fma.s1 acos_T6 = acos_T3,acos_d3,f0
721 fma.s1 acos_t11 = acos_t8,acos_t3,f0
726 fma.s1 acos_poly_p0 = acos_t4,acos_poly_p4,acos_poly_p0
733 fma.s1 acos_1poly_p4 = acos_tx4,acos_1poly_p8,acos_1poly_p4
738 fma.s1 acos_1poly_p15 = acos_tx4,acos_1poly_p19,acos_1poly_p15
745 fma.s1 acos_1poly_p0 = acos_tx2,acos_1poly_p2,acos_1poly_p0
750 fma.s1 acos_1poly_p11 = acos_tx2,acos_1poly_p13,acos_1poly_p11
757 // fcmp.le.s1 acos_pred_LEsqrt2by2,acos_pred_GTsqrt2by2 = acos_abs_x,acos_const_sqrt2by2
758 fcmp.le.s1 p7,p8 = acos_abs_x,acos_const_sqrt2by2
763 fma.s1 acos_tx8 = acos_tx4,acos_tx4,f0
770 fma.s1 acos_z = acos_l3,acos_T6,acos_z
776 fma.s1 acos_series_t = acos_t11,acos_poly_p11,acos_poly_p0
781 (p11) fma.s1 acos_const_add = acos_const_piby2, f1, acos_const_piby2
788 (p12) fma.s1 acos_const_add = f1,f0,f0
795 fma.s1 acos_1poly_p0 = acos_tx4,acos_1poly_p4,acos_1poly_p0
800 fma.s1 acos_1poly_p11 = acos_tx4,acos_1poly_p15,acos_1poly_p11
807 fma.s1 acos_tx11 = acos_tx8,acos_tx3,f0
813 //(acos_pred_GTsqrt2by2) fnma.s1 answer2 = acos_z,acos_series_t,acos_const_piby2
814 (p8) fnma.s1 answer2 = acos_z,acos_series_t,f0
820 fma.s1 acos_series_tx = acos_tx11,acos_1poly_p11,acos_1poly_p0
826 //(acos_pred_GTsqrt2by2) fnma.d f8 = acos_sgn_x,answer2,acos_const_piby2
827 (p8) fnma.d f8 = acos_sgn_x,answer2,acos_const_add
833 //(acos_pred_LEsqrt2by2) fnma.d f8 = f8,acos_series_tx,acos_const_piby2
834 (p7) fnma.d f8 = f8,acos_series_tx,acos_const_piby2
843 fma.d f8 = acos_const_piby2,f1,f0
849 .pred.rel "mutex",p11,p12
853 (p11) fma.d f8 = acos_const_piby2,f1,acos_const_piby2 // acos(-1)=pi
858 (p12) fma.d f8 = f1,f0,f0 // acos(1)=0
864 ASM_SIZE_DIRECTIVE(acos)
866 .proc __libm_error_region
870 add GR_Parameter_Y=-32,sp // Parameter 2 value
872 .save ar.pfs,GR_SAVE_PFS
873 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
877 add sp=-64,sp // Create new stack
879 mov GR_SAVE_GP=gp // Save gp
882 stfs [GR_Parameter_Y] = f1,16 // Store Parameter 2 on stack
883 add GR_Parameter_X = 16,sp // Parameter 1 address
885 mov GR_SAVE_B0=b0 // Save b0
889 frcpa.s0 f9,p0 = f0,f0
893 stfd [GR_Parameter_X] = f8 // Store Parameter 1 on stack
894 add GR_Parameter_RESULT = 0,GR_Parameter_Y
895 nop.b 0 // Parameter 3 address
898 stfd [GR_Parameter_Y] = f9,-16 // Store Parameter 3 on stack
900 br.call.sptk b0=__libm_error_support# // Call error handling function
903 ldfd f8 = [r32] // Get return result off stack
905 add sp = 64,sp // Restore stack pointer
906 mov b0 = GR_SAVE_B0 // Restore return address
909 mov gp = GR_SAVE_GP // Restore gp
910 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
911 br.ret.sptk b0 // Return
915 .endp __libm_error_region
916 ASM_SIZE_DIRECTIVE(__libm_error_region)
918 .type __libm_error_support,@function
919 .global __libm_error_support