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 // 4/04/00 Unwind support added
44 // 12/27/00 Improved speed
47 //==============================================================
48 // float tan( float x);
50 // Overview of operation
51 //==============================================================
52 // If the input value in radians is |x| >= 1.xxxxx 2^10 call the
53 // older slower version.
55 // The new algorithm is used when |x| <= 1.xxxxx 2^9.
57 // Represent the input X as Nfloat * pi/2 + r
58 // where r can be negative and |r| <= pi/4
61 // Nfloat = round_int(tan_W)
63 // tan_r = x - Nfloat * (pi/2)_hi
64 // tan_r = tan_r - Nfloat * (pi/2)_lo
66 // We have two paths: p8, when Nfloat is even and p9. when Nfloat is odd.
67 // p8: tan(X) = tan(r)
68 // p9: tan(X) = -cot(r)
70 // Each is evaluated as a series. The p9 path requires 1/r.
72 // The coefficients used in the series are stored in a table as
73 // are the pi constants.
76 //==============================================================
78 // predicate registers used:
81 // floating-point registers used:
85 // general registers used
89 #include "libm_support.h"
92 //==============================================================
93 TAN_INV_PI_BY_2_2TO64 = f10
100 tan_Inv_Pi_by_2 = f32
184 /////////////////////////////////////////////////////////////
186 tan_GR_sig_inv_pi_by_2 = r14
187 tan_GR_rshf_2to64 = r15
188 tan_GR_exp_2tom64 = r16
195 tan_GR_N_odd_even = r36
214 double_tan_constants:
215 ASM_TYPE_DIRECTIVE(double_tan_constants,@object)
216 // data8 0xA2F9836E4E44152A, 0x00003FFE // 2/pi
217 data8 0xC90FDAA22168C234, 0x00003FFF // pi/2 hi
219 data8 0xBEEA54580DDEA0E1 // P14
220 data8 0x3ED3021ACE749A59 // P15
221 data8 0xBEF312BD91DC8DA1 // P12
222 data8 0x3EFAE9AFC14C5119 // P13
223 data8 0x3F2F342BF411E769 // P8
224 data8 0x3F1A60FC9F3B0227 // P9
225 data8 0x3EFF246E78E5E45B // P10
226 data8 0x3F01D9D2E782875C // P11
227 data8 0x3F8226E34C4499B6 // P4
228 data8 0x3F6D6D3F12C236AC // P5
229 data8 0x3F57DA1146DCFD8B // P6
230 data8 0x3F43576410FE3D75 // P7
231 data8 0x3FD5555555555555 // P0
232 data8 0x3FC11111111111C2 // P1
233 data8 0x3FABA1BA1BA0E850 // P2
234 data8 0x3F9664F4886725A7 // P3
235 ASM_SIZE_DIRECTIVE(double_tan_constants)
237 double_Q_tan_constants:
238 ASM_TYPE_DIRECTIVE(double_Q_tan_constants,@object)
239 data8 0xC4C6628B80DC1CD1, 0x00003FBF // pi/2 lo
240 data8 0x3E223A73BA576E48 // Q8
241 data8 0x3DF54AD8D1F2CA43 // Q9
242 data8 0x3EF66A8EE529A6AA // Q4
243 data8 0x3EC2281050410EE6 // Q5
244 data8 0x3E8D6BB992CC3CF5 // Q6
245 data8 0x3E57F88DE34832E4 // Q7
246 data8 0x3FD5555555555555 // Q0
247 data8 0x3F96C16C16C16DB8 // Q1
248 data8 0x3F61566ABBFFB489 // Q2
249 data8 0x3F2BBD77945C1733 // Q3
250 data8 0x3D927FB33E2B0E04 // Q10
251 ASM_SIZE_DIRECTIVE(double_Q_tan_constants)
261 ////////////////////////////////////////////////////////
275 // The initial fnorm will take any unmasked faults and
276 // normalize any single/double unorms
279 alloc r32=ar.pfs,1,11,0,0
280 movl tan_GR_sig_inv_pi_by_2 = 0xA2F9836E4E44152A // significand of 2/pi
283 addl tan_AD = @ltoff(double_tan_constants), gp
284 movl tan_GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+63+1)
289 ld8 tan_AD = [tan_AD]
290 fnorm tan_NORM_f8 = f8
291 mov tan_GR_exp_2tom64 = 0xffff-64 // exponent of scaling factor 2^-64
295 movl tan_GR_rshf = 0x43e8000000000000 // 1.1000 2^63 for right shift
300 // Form two constants we need
301 // 2/pi * 2^1 * 2^63, scaled by 2^64 since we just loaded the significand
302 // 1.1000...000 * 2^(63+63+1) to right shift int(W) into the significand
304 setf.sig TAN_INV_PI_BY_2_2TO64 = tan_GR_sig_inv_pi_by_2
305 setf.d TAN_RSHF_2TO64 = tan_GR_rshf_2to64
306 mov tan_GR_17_ones = 0x1ffff ;;
310 // Form another constant
311 // 2^-64 for scaling Nfloat
312 // 1.1000...000 * 2^63, the right shift constant
314 setf.exp TAN_2TOM64 = tan_GR_exp_2tom64
315 adds tan_ADQ = double_Q_tan_constants - double_tan_constants, tan_AD
316 fclass.m.unc p6,p0 = f8, 0x07 // Test for x=0
321 // Form another constant
322 // 2^-64 for scaling Nfloat
323 // 1.1000...000 * 2^63, the right shift constant
325 setf.d TAN_RSHF = tan_GR_rshf
326 ldfe tan_Pi_by_2_hi = [tan_AD],16
327 fclass.m.unc p7,p0 = f8, 0x23 // Test for x=inf
332 ldfe tan_Pi_by_2_lo = [tan_ADQ],16
333 fclass.m.unc p8,p0 = f8, 0xc3 // Test for x=nan
334 (p6) br.ret.spnt b0 ;; // Exit for x=0
338 ldfpd tan_P14,tan_P15 = [tan_AD],16
339 (p7) frcpa.s0 f8,p9=f0,f0 // Set qnan indef if x=inf
340 mov tan_GR_10009 = 0x10009
343 ldfpd tan_Q8,tan_Q9 = [tan_ADQ],16
345 (p7) br.ret.spnt b0 ;; // Exit for x=inf
349 ldfpd tan_P12,tan_P13 = [tan_AD],16
350 (p8) fma.s f8=f8,f1,f8 // Set qnan if x=nan
354 ldfpd tan_Q4,tan_Q5 = [tan_ADQ],16
356 (p8) br.ret.spnt b0 ;; // Exit for x=nan
360 getf.exp tan_signexp = tan_NORM_f8
361 ldfpd tan_P8,tan_P9 = [tan_AD],16
365 // Multiply x by scaled 2/pi and add large const to shift integer part of W to
366 // rightmost bits of significand
368 ldfpd tan_Q6,tan_Q7 = [tan_ADQ],16
369 fma.s1 TAN_W_2TO64_RSH = tan_NORM_f8,TAN_INV_PI_BY_2_2TO64,TAN_RSHF_2TO64
374 ldfpd tan_P10,tan_P11 = [tan_AD],16
376 and tan_exp = tan_GR_17_ones, tan_signexp ;;
380 // p7 is true if we must call DBX TAN
381 // p7 is true if f8 exp is > 0x10009 (which includes all ones
384 ldfpd tan_Q0,tan_Q1 = [tan_ADQ],16
385 cmp.ge.unc p7,p0 = tan_exp,tan_GR_10009
391 ldfpd tan_P4,tan_P5 = [tan_AD],16
393 (p7) br.cond.spnt L(TAN_DBX) ;;
398 ldfpd tan_Q2,tan_Q3 = [tan_ADQ],16
405 // TAN_NFLOAT = Round_Int_Nearest(tan_W)
407 ldfpd tan_P6,tan_P7 = [tan_AD],16
408 fms.s1 TAN_NFLOAT = TAN_W_2TO64_RSH,TAN_2TOM64,TAN_RSHF
414 ldfd tan_Q10 = [tan_ADQ]
421 ldfpd tan_P0,tan_P1 = [tan_AD],16
428 getf.sig tan_GR_n = TAN_W_2TO64_RSH
433 // tan_r = -tan_Nfloat * tan_Pi_by_2_hi + x
435 ldfpd tan_P2,tan_P3 = [tan_AD]
436 fnma.s1 tan_r = TAN_NFLOAT, tan_Pi_by_2_hi, tan_NORM_f8
444 and tan_GR_N_odd_even = 0x1, tan_GR_n ;;
446 cmp.eq.unc p8,p9 = tan_GR_N_odd_even, r0 ;;
450 // tan_r = tan_r -tan_Nfloat * tan_Pi_by_2_lo
453 fnma.s1 tan_r = TAN_NFLOAT, tan_Pi_by_2_lo, tan_r
460 fma.s1 tan_rsq = tan_r, tan_r, f0
467 (p9) frcpa.s1 tan_y0, p10 = f1,tan_r
474 (p8) fma.s1 tan_v18 = tan_rsq, tan_P15, tan_P14
479 (p8) fma.s1 tan_v4 = tan_rsq, tan_P1, tan_P0
487 (p8) fma.s1 tan_v16 = tan_rsq, tan_P13, tan_P12
492 (p8) fma.s1 tan_v17 = tan_rsq, tan_rsq, f0
500 (p8) fma.s1 tan_v12 = tan_rsq, tan_P9, tan_P8
505 (p8) fma.s1 tan_v13 = tan_rsq, tan_P11, tan_P10
513 (p8) fma.s1 tan_v7 = tan_rsq, tan_P5, tan_P4
518 (p8) fma.s1 tan_v8 = tan_rsq, tan_P7, tan_P6
526 (p9) fnma.s1 tan_d = tan_r, tan_y0, f1
531 (p8) fma.s1 tan_v5 = tan_rsq, tan_P3, tan_P2
539 (p9) fma.s1 tan_z11 = tan_rsq, tan_Q9, tan_Q8
544 (p9) fma.s1 tan_z12 = tan_rsq, tan_rsq, f0
551 (p8) fma.s1 tan_v15 = tan_v17, tan_v18, tan_v16
556 (p9) fma.s1 tan_z7 = tan_rsq, tan_Q5, tan_Q4
563 (p8) fma.s1 tan_v11 = tan_v17, tan_v13, tan_v12
568 (p9) fma.s1 tan_z8 = tan_rsq, tan_Q7, tan_Q6
576 (p8) fma.s1 tan_v14 = tan_v17, tan_v17, f0
581 (p9) fma.s1 tan_z3 = tan_rsq, tan_Q1, tan_Q0
590 (p8) fma.s1 tan_v3 = tan_v17, tan_v5, tan_v4
595 (p8) fma.s1 tan_v6 = tan_v17, tan_v8, tan_v7
603 (p9) fma.s1 tan_y1 = tan_y0, tan_d, tan_y0
608 (p9) fma.s1 tan_dsq = tan_d, tan_d, f0
615 (p9) fma.s1 tan_z10 = tan_z12, tan_Q10, tan_z11
620 (p9) fma.s1 tan_z9 = tan_z12, tan_z12,f0
627 (p9) fma.s1 tan_z4 = tan_rsq, tan_Q3, tan_Q2
632 (p9) fma.s1 tan_z6 = tan_z12, tan_z8, tan_z7
640 (p8) fma.s1 tan_v10 = tan_v14, tan_v15, tan_v11
648 (p9) fma.s1 tan_y2 = tan_y1, tan_d, tan_y0
653 (p9) fma.s1 tan_d4 = tan_dsq, tan_dsq, tan_d
660 (p8) fma.s1 tan_v2 = tan_v14, tan_v6, tan_v3
665 (p8) fma.s1 tan_v9 = tan_v14, tan_v14, f0
672 (p9) fma.s1 tan_z2 = tan_z12, tan_z4, tan_z3
677 (p9) fma.s1 tan_z5 = tan_z9, tan_z10, tan_z6
684 (p9) fma.s1 tan_inv_r = tan_d4, tan_y2, tan_y0
689 (p8) fma.s1 tan_rcube = tan_rsq, tan_r, f0
697 (p8) fma.s1 tan_v1 = tan_v9, tan_v10, tan_v2
702 (p9) fma.s1 tan_z1 = tan_z9, tan_z5, tan_z2
710 (p8) fma.s.s0 f8 = tan_v1, tan_rcube, tan_r
715 (p9) fms.s.s0 f8 = tan_r, tan_z1, tan_inv_r
719 ASM_SIZE_DIRECTIVE(tanf#)
730 .save ar.pfs,GR_SAVE_PFS
731 mov GR_SAVE_PFS=ar.pfs
746 br.call.sptk.many b0=__libm_tan# ;;
760 mov ar.pfs = GR_SAVE_PFS
767 ASM_SIZE_DIRECTIVE(__libm_callout)
769 .type __libm_tan#,@function