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 version
43 // 8/17/00 New and much faster algorithm.
44 // 8/31/00 Avoided bank conflicts on loads, shortened |x|=1 path,
45 // fixed mfb split issue stalls.
46 // 12/19/00 Fixed small arg cases to force inexact, or inexact and underflow.
49 //=========================================
50 // The asin function computes the principle value of the arc sine of x.
51 // asin(0) returns 0, asin(1) returns pi/2, asin(-1) returns -pi/2.
52 // A doman error occurs for arguments not in the range [-1,+1].
54 // The asin function returns the arc sine in the range [-pi/2, +pi/2] radians.
56 #include "libm_support.h"
60 //=========================================
63 // predicate registers
64 //asin_pred_LEsqrt2by2 = p7
65 //asin_pred_GTsqrt2by2 = p8
80 GR_Parameter_RESULT = r41
81 GR_Parameter_Tag = r42
83 // floating point registers
109 asin_const_sqrt2by2 = f53
110 asin_const_piby2 = f54
193 //==============================================================
204 ASM_TYPE_DIRECTIVE(asin_coeff_1_table,@object)
205 data8 0xE4E7E0A423A21249 , 0x00003FF8 //P7
206 data8 0xC2F7EE0200FCE2A5 , 0x0000C003 //P18
207 data8 0xB745D7F6C65C20E0 , 0x00003FF9 //P5
208 data8 0xF75E381A323D4D94 , 0x0000C002 //P16
209 data8 0x8959C2629C1024C0 , 0x0000C002 //P20
210 data8 0xAFF68E7D241292C5 , 0x00003FF8 //P9
211 data8 0xB6DB6DB7260AC30D , 0x00003FFA //P3
212 data8 0xD0417CE2B41CB7BF , 0x0000C000 //P14
213 data8 0x81D570FEA724E3E4 , 0x0000BFFD //P12
214 data8 0xAAAAAAAAAAAAC277 , 0x00003FFC //P1
215 data8 0xF534912FF3E7B76F , 0x00003FFF //P21
216 data8 0xc90fdaa22168c235 , 0x00003fff // pi/2
217 data8 0x0000000000000000 , 0x00000000 // pad to avoid data bank conflict
218 ASM_SIZE_DIRECTIVE(asin_coeff_1_table)
222 ASM_TYPE_DIRECTIVE(asin_coeff_2_table,@object)
223 data8 0x8E26AF5F29B39A2A , 0x00003FF9 //P6
224 data8 0xB4F118A4B1015470 , 0x00004003 //P17
225 data8 0xF8E38E10C25990E0 , 0x00003FF9 //P4
226 data8 0x80F50489AEF1CAC6 , 0x00004002 //P15
227 data8 0x92728015172CFE1C , 0x00004003 //P19
228 data8 0xBBC3D831D4595971 , 0x00003FF8 //P8
229 data8 0x999999999952A5C3 , 0x00003FFB //P2
230 data8 0x855576BE6F0975EC , 0x00003FFF //P13
231 data8 0xF12420E778077D89 , 0x00003FFA //P11
232 data8 0xB6590FF4D23DE003 , 0x00003FF3 //P10
233 data8 0xb504f333f9de6484 , 0x00003ffe // sqrt(2)/2
234 ASM_SIZE_DIRECTIVE(asin_coeff_2_table)
249 alloc r32 = ar.pfs,1,6,4,0
250 fma.s1 asin_tx = f8,f8,f0
251 addl ASIN_Addr2 = @ltoff(asin_coeff_2_table),gp
254 mov ASIN_FFFE = 0xFFFE
255 fnma.s1 asin_t = f8,f8,f1
256 addl ASIN_Addr1 = @ltoff(asin_coeff_1_table),gp
262 setf.exp asin_1by2 = ASIN_FFFE
263 fmerge.s asin_abs_x = f1,f8
268 ld8 ASIN_Addr1 = [ASIN_Addr1]
269 ld8 ASIN_Addr2 = [ASIN_Addr2]
270 fmerge.s asin_sgn_x = f8,f1 ;;
275 ldfe asin_coeff_P7 = [ASIN_Addr1],16
276 fma.s1 asin_tx2 = asin_tx,asin_tx,f0
280 ldfe asin_coeff_P6 = [ASIN_Addr2],16
281 fma.s1 asin_t2 = asin_t,asin_t,f0
287 ldfe asin_coeff_P18 = [ASIN_Addr1],16
288 ldfe asin_coeff_P17 = [ASIN_Addr2],16
289 fclass.m.unc p8,p0 = f8, 0xc3 //@qnan |@snan
294 ldfe asin_coeff_P5 = [ASIN_Addr1],16
295 ldfe asin_coeff_P4 = [ASIN_Addr2],16
296 frsqrta.s1 asin_y0,p0 = asin_t
301 ldfe asin_coeff_P16 = [ASIN_Addr1],16
302 fcmp.gt.s1 p9,p0 = asin_abs_x,f1
306 ldfe asin_coeff_P15 = [ASIN_Addr2],16
307 (p8) fma.d f8 = f8,f1,f0
314 ldfe asin_coeff_P20 = [ASIN_Addr1],16
315 ldfe asin_coeff_P19 = [ASIN_Addr2],16
316 fclass.m.unc p8,p0 = f8, 0x07 //@zero
322 ldfe asin_coeff_P9 = [ASIN_Addr1],16
323 fma.s1 asin_t4 = asin_t2,asin_t2,f0
324 (p9) mov GR_Parameter_Tag = 61
327 ldfe asin_coeff_P8 = [ASIN_Addr2],16
328 fma.s1 asin_3by2 = asin_1by2,f1,f1
334 ldfe asin_coeff_P2 = [ASIN_Addr2],16
335 fma.s1 asin_tx4 = asin_tx2,asin_tx2,f0
339 ldfe asin_coeff_P3 = [ASIN_Addr1],16
340 fma.s1 asin_t3 = asin_t,asin_t2,f0
347 ldfe asin_coeff_P13 = [ASIN_Addr2],16
348 fma.s1 asin_H0 = asin_y0,asin_1by2,f0
352 ldfe asin_coeff_P14 = [ASIN_Addr1],16
353 fma.s1 asin_S0 = asin_y0,asin_t,f0
354 (p9) br.cond.spnt __libm_error_region
360 ldfe asin_coeff_P11 = [ASIN_Addr2],16
361 fcmp.eq.s1 p6,p0 = asin_abs_x,f1
365 ldfe asin_coeff_P12 = [ASIN_Addr1],16
366 fma.s1 asin_tx3 = asin_tx,asin_tx2,f0
372 ldfe asin_coeff_P10 = [ASIN_Addr2],16
373 fma.s1 asin_1poly_p6 = asin_tx,asin_coeff_P7,asin_coeff_P6
377 ldfe asin_coeff_P1 = [ASIN_Addr1],16
378 fma.s1 asin_poly_p6 = asin_t,asin_coeff_P7,asin_coeff_P6
384 ldfe asin_const_sqrt2by2 = [ASIN_Addr2],16
385 fma.s1 asin_5by2 = asin_3by2,f1,f1
389 ldfe asin_coeff_P21 = [ASIN_Addr1],16
390 fma.s1 asin_11by4 = asin_3by2,asin_3by2,asin_1by2
396 ldfe asin_const_piby2 = [ASIN_Addr1],16
397 fma.s1 asin_poly_p17 = asin_t,asin_coeff_P18,asin_coeff_P17
402 fma.s1 asin_3by4 = asin_3by2,asin_1by2,f0
403 (p6) br.cond.spnt L(ASIN_ABS_1) // Branch to short exit if |x|=1
409 addl ASIN_lnorm_sig = -0x1,r0 // Form significand 0xffffffffffffffff
410 fma.s1 asin_poly_p15 = asin_t,asin_coeff_P16,asin_coeff_P15
414 addl ASIN_snorm_exp = 0x0c001,r0 // Form small exponent
415 fnma.s1 asin_d = asin_S0,asin_H0,asin_1by2
420 // Form the exponent and significand of a small number
422 setf.sig asin_eps_sig = ASIN_lnorm_sig
423 fma.s1 asin_poly_p19 = asin_t,asin_coeff_P20,asin_coeff_P19
427 setf.exp asin_eps_exp = ASIN_snorm_exp
428 fma.s1 asin_poly_p4 = asin_t,asin_coeff_P5,asin_coeff_P4
435 fma.s1 asin_1poly_p17 = asin_tx,asin_coeff_P18,asin_coeff_P17
440 fma.s1 asin_poly_p8 = asin_t,asin_coeff_P9,asin_coeff_P8
447 fms.s1 asin_35by8 = asin_5by2,asin_11by4,asin_5by2
452 fma.s1 asin_63by8 = asin_5by2,asin_11by4,f1
459 fma.s1 asin_poly_p13 = asin_t,asin_coeff_P14,asin_coeff_P13
464 fma.s1 asin_18by4 = asin_3by2,asin_5by2,asin_3by4
471 fma.s1 asin_l1 = asin_5by2,asin_d,asin_3by2
476 fma.s1 asin_d2 = asin_d,asin_d,f0
483 fma.s1 asin_poly_p15 = asin_t2,asin_poly_p17,asin_poly_p15
488 fma.s1 asin_T0 = asin_d,asin_S0,f0
495 fma.s1 asin_poly_p19 = asin_t2,asin_coeff_P21,asin_poly_p19
500 fma.s1 asin_poly_p4 = asin_t2,asin_poly_p6,asin_poly_p4
507 fma.s1 asin_d1 = asin_35by8,asin_d,f0
512 fma.s1 asin_231by16 = asin_3by2,asin_35by8,asin_63by8
519 fma.s1 asin_poly_p2 = asin_t,asin_coeff_P3,asin_coeff_P2
524 fma.s1 asin_poly_p8 = asin_t2,asin_coeff_P10,asin_poly_p8
531 fma.s1 asin_poly_p11 = asin_t,asin_coeff_P12,asin_coeff_P11
536 fma.s1 asin_e0 = asin_d2,asin_l1,asin_d
543 fma.s1 asin_1poly_p15 = asin_tx,asin_coeff_P16,asin_coeff_P15
548 fma.s1 asin_poly_p0 = asin_t,asin_coeff_P1,f1
555 fma.s1 asin_1poly_p19 = asin_tx,asin_coeff_P20,asin_coeff_P19
560 fma.s1 asin_1poly_p4 = asin_tx,asin_coeff_P5,asin_coeff_P4
567 fma.s1 asin_1poly_p8 = asin_tx,asin_coeff_P9,asin_coeff_P8
572 fma.s1 asin_l2 = asin_231by16,asin_d,asin_63by8
579 fma.s1 asin_d3 = asin_d2,asin_d,f0
584 fma.s1 asin_T3 = asin_d2,asin_T0,f0
591 fma.s1 asin_429by16 = asin_18by4,asin_11by4,asin_231by16
596 fma.s1 asin_S1 = asin_e0,asin_S0,asin_S0
603 fma.s1 asin_poly_p4 = asin_t4,asin_poly_p8,asin_poly_p4
608 fma.s1 asin_poly_p15 = asin_t4,asin_poly_p19,asin_poly_p15
615 fma.s1 asin_poly_p0 = asin_t2,asin_poly_p2,asin_poly_p0
620 fma.s1 asin_poly_p11 = asin_t2,asin_poly_p13,asin_poly_p11
627 fma.s1 asin_t8 = asin_t4,asin_t4,f0
632 fma.s1 asin_e1 = asin_d2,asin_l2,asin_d1
639 fma.s1 asin_1poly_p4 = asin_tx2,asin_1poly_p6,asin_1poly_p4
644 fma.s1 asin_1poly_p15 = asin_tx2,asin_1poly_p17,asin_1poly_p15
651 fma.s1 asin_1poly_p8 = asin_tx2,asin_coeff_P10,asin_1poly_p8
656 fma.s1 asin_1poly_p19 = asin_tx2,asin_coeff_P21,asin_1poly_p19
663 fma.s1 asin_1poly_p2 = asin_tx,asin_coeff_P3,asin_coeff_P2
668 fma.s1 asin_1poly_p13 = asin_tx,asin_coeff_P14,asin_coeff_P13
675 fma.s1 asin_1poly_p0 = asin_tx,asin_coeff_P1,f1
680 fma.s1 asin_1poly_p11 = asin_tx,asin_coeff_P12,asin_coeff_P11
687 fma.s1 asin_l3 = asin_429by16,asin_d,f0
692 fma.s1 asin_z = asin_e1,asin_T3,asin_S1
699 fma.s1 asin_poly_p11 = asin_t4,asin_poly_p15,asin_poly_p11
704 fma.s1 asin_T6 = asin_T3,asin_d3,f0
711 fma.s1 asin_t11 = asin_t8,asin_t3,f0
716 fma.s1 asin_poly_p0 = asin_t4,asin_poly_p4,asin_poly_p0
723 fma.s1 asin_1poly_p4 = asin_tx4,asin_1poly_p8,asin_1poly_p4
728 fma.s1 asin_1poly_p15 = asin_tx4,asin_1poly_p19,asin_1poly_p15
735 fma.s1 asin_1poly_p0 = asin_tx2,asin_1poly_p2,asin_1poly_p0
740 fma.s1 asin_1poly_p11 = asin_tx2,asin_1poly_p13,asin_1poly_p11
747 // fcmp.le.s1 asin_pred_LEsqrt2by2,asin_pred_GTsqrt2by2 = asin_abs_x,asin_const_sqrt2by2
748 fcmp.le.s1 p7,p8 = asin_abs_x,asin_const_sqrt2by2
753 fma.s1 asin_tx8 = asin_tx4,asin_tx4,f0
758 // Form a small number to force inexact flag for small args
761 fmerge.se asin_eps = asin_eps_exp,asin_eps_sig
766 fma.s1 asin_z = asin_l3,asin_T6,asin_z
772 fma.s1 asin_series_t = asin_t11,asin_poly_p11,asin_poly_p0
778 fma.s1 asin_1poly_p0 = asin_tx4,asin_1poly_p4,asin_1poly_p0
783 fma.s1 asin_1poly_p11 = asin_tx4,asin_1poly_p15,asin_1poly_p11
790 fma.s1 asin_tx11 = asin_tx8,asin_tx3,f0
796 //(asin_pred_GTsqrt2by2) fnma.s1 answer2 = asin_z,asin_series_t,asin_const_piby2
797 (p8) fnma.s1 answer2 = asin_z,asin_series_t,asin_const_piby2
803 fma.s1 asin_series_tx = asin_tx11,asin_1poly_p11,asin_1poly_p0
809 //(asin_pred_GTsqrt2by2) fma.d f8 = asin_sgn_x,answer2,f0
810 (p8) fma.d f8 = asin_sgn_x,answer2,f0
814 // asin_eps is added only to force inexact and possibly underflow flag
815 // in case asin_series_tx is zero
819 (p7) fma.d asin_eps = f8,asin_series_tx,asin_eps
824 //(asin_pred_LEsqrt2by2) fma.d f8 = f8,asin_series_tx,f0
825 (p7) fma.d f8 = f8,asin_series_tx,f0
832 // Here for short exit if |x|=1
835 fma.d f8 = asin_sgn_x,asin_const_piby2,f0
842 ASM_SIZE_DIRECTIVE(asin)
844 .proc __libm_error_region
848 add GR_Parameter_Y=-32,sp // Parameter 2 value
850 .save ar.pfs,GR_SAVE_PFS
851 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
855 add sp=-64,sp // Create new stack
857 mov GR_SAVE_GP=gp // Save gp
860 stfs [GR_Parameter_Y] = f1,16 // Store Parameter 2 on stack
861 add GR_Parameter_X = 16,sp // Parameter 1 address
863 mov GR_SAVE_B0=b0 // Save b0
867 frcpa.s0 f9,p0 = f0,f0
871 stfd [GR_Parameter_X] = f8 // Store Parameter 1 on stack
872 add GR_Parameter_RESULT = 0,GR_Parameter_Y
873 nop.b 0 // Parameter 3 address
876 stfd [GR_Parameter_Y] = f9,-16 // Store Parameter 3 on stack
878 br.call.sptk b0=__libm_error_support# // Call error handling function
881 ldfd f8 = [r32] // Get return result off stack
883 add sp = 64,sp // Restore stack pointer
884 mov b0 = GR_SAVE_B0 // Restore return address
887 mov gp = GR_SAVE_GP // Restore gp
888 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
889 br.ret.sptk b0 // Return
893 .endp __libm_error_region
894 ASM_SIZE_DIRECTIVE(__libm_error_region)
896 .type __libm_error_support,@function
897 .global __libm_error_support