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.
40 //*********************************************************************
43 // 02/02/00 (hand-optimized)
44 // 04/04/00 Unwind support added
45 // 07/30/01 Improved speed on all paths
46 // 08/20/01 Fixed bundling typo
47 // 05/13/02 Changed interface to __libm_pi_by_2_reduce
48 // 02/10/03 Reordered header: .section, .global, .proc, .align;
49 // used data8 for long double table values
51 //*********************************************************************
53 // Function: Combined sinl(x) and cosl(x), where
55 // sinl(x) = sine(x), for double-extended precision x values
56 // cosl(x) = cosine(x), for double-extended precision x values
58 //*********************************************************************
62 // Floating-Point Registers: f8 (Input and Return Value)
65 // General Purpose Registers:
67 // r44-r45 (Used to pass arguments to pi_by_2 reduce routine)
69 // Predicate Registers: p6-p13
71 //*********************************************************************
73 // IEEE Special Conditions:
75 // Denormal fault raised on denormal inputs
76 // Overflow exceptions do not occur
77 // Underflow exceptions raised when appropriate for sin
78 // (No specialized error handling for this routine)
79 // Inexact raised when appropriate by algorithm
90 //*********************************************************************
92 // Mathematical Description
93 // ========================
95 // The computation of FSIN and FCOS is best handled in one piece of
96 // code. The main reason is that given any argument Arg, computation
97 // of trigonometric functions first calculate N and an approximation
100 // Arg = N pi/2 + alpha, |alpha| <= pi/4.
104 // cosl( Arg ) = sinl( (N+1) pi/2 + alpha ),
106 // therefore, the code for computing sine will produce cosine as long
107 // as 1 is added to N immediately after the argument reduction
115 // Arg = M pi/2 + alpha, |alpha| <= pi/4,
117 // let I = M mod 4, or I be the two lsb of M when M is represented
118 // as 2's complement. I = [i_0 i_1]. Then
120 // sinl( Arg ) = (-1)^i_0 sinl( alpha ) if i_1 = 0,
121 // = (-1)^i_0 cosl( alpha ) if i_1 = 1.
125 // sin ((-pi/2 + alpha) = (-1) cos (alpha)
127 // sin (alpha) = sin (alpha)
129 // sin (pi/2 + alpha) = cos (alpha)
131 // sin (pi + alpha) = (-1) sin (alpha)
133 // sin ((3/2)pi + alpha) = (-1) cos (alpha)
135 // The value of alpha is obtained by argument reduction and
136 // represented by two working precision numbers r and c where
138 // alpha = r + c accurately.
140 // The reduction method is described in a previous write up.
141 // The argument reduction scheme identifies 4 cases. For Cases 2
142 // and 4, because |alpha| is small, sinl(r+c) and cosl(r+c) can be
143 // computed very easily by 2 or 3 terms of the Taylor series
144 // expansion as follows:
149 // sinl(r + c) = r + c - r^3/6 accurately
150 // cosl(r + c) = 1 - 2^(-67) accurately
155 // sinl(r + c) = r + c - r^3/6 + r^5/120 accurately
156 // cosl(r + c) = 1 - r^2/2 + r^4/24 accurately
158 // The only cases left are Cases 1 and 3 of the argument reduction
159 // procedure. These two cases will be merged since after the
160 // argument is reduced in either cases, we have the reduced argument
161 // represented as r + c and that the magnitude |r + c| is not small
162 // enough to allow the usage of a very short approximation.
164 // The required calculation is either
166 // sinl(r + c) = sinl(r) + correction, or
167 // cosl(r + c) = cosl(r) + correction.
171 // sinl(r + c) = sinl(r) + c sin'(r) + O(c^2)
172 // = sinl(r) + c cos (r) + O(c^2)
173 // = sinl(r) + c(1 - r^2/2) accurately.
176 // cosl(r + c) = cosl(r) - c sinl(r) + O(c^2)
177 // = cosl(r) - c(r - r^3/6) accurately.
179 // We therefore concentrate on accurately calculating sinl(r) and
180 // cosl(r) for a working-precision number r, |r| <= pi/4 to within
183 // The greatest challenge of this task is that the second terms of
186 // r - r^3/3! + r^r/5! - ...
190 // 1 - r^2/2! + r^4/4! - ...
192 // are not very small when |r| is close to pi/4 and the rounding
193 // errors will be a concern if simple polynomial accumulation is
194 // used. When |r| < 2^-3, however, the second terms will be small
195 // enough (6 bits or so of right shift) that a normal Horner
196 // recurrence suffices. Hence there are two cases that we consider
197 // in the accurate computation of sinl(r) and cosl(r), |r| <= pi/4.
199 // Case small_r: |r| < 2^(-3)
200 // --------------------------
202 // Since Arg = M pi/4 + r + c accurately, and M mod 4 is [i_0 i_1],
205 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
206 // = (-1)^i_0 * cosl(r + c) if i_1 = 1
208 // can be accurately approximated by
210 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c] if i_1 = 0
211 // = (-1)^i_0 * [cosl(r) - c*r] if i_1 = 1
213 // because |r| is small and thus the second terms in the correction
216 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
219 // sinl(r) = r + S_1 r^3 + S_2 r^5 + ... + S_5 r^11
220 // cosl(r) = 1 + C_1 r^2 + C_2 r^4 + ... + C_5 r^10
222 // We can make use of predicates to selectively calculate
223 // sinl(r) or cosl(r) based on i_1.
225 // Case normal_r: 2^(-3) <= |r| <= pi/4
226 // ------------------------------------
228 // This case is more likely than the previous one if one considers
229 // r to be uniformly distributed in [-pi/4 pi/4]. Again,
231 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
232 // = (-1)^i_0 * cosl(r + c) if i_1 = 1.
234 // Because |r| is now larger, we need one extra term in the
235 // correction. sinl(Arg) can be accurately approximated by
237 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c(1-r^2/2)] if i_1 = 0
238 // = (-1)^i_0 * [cosl(r) - c*r*(1 - r^2/6)] i_1 = 1.
240 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
243 // sinl(r) = r + PP_1_hi r^3 + PP_1_lo r^3 +
244 // PP_2 r^5 + ... + PP_8 r^17
246 // cosl(r) = 1 + QQ_1 r^2 + QQ_2 r^4 + ... + QQ_8 r^16
248 // where PP_1_hi is only about 16 bits long and QQ_1 is -1/2.
249 // The crux in accurate computation is to calculate
251 // r + PP_1_hi r^3 or 1 + QQ_1 r^2
253 // accurately as two pieces: U_hi and U_lo. The way to achieve this
254 // is to obtain r_hi as a 10 sig. bit number that approximates r to
255 // roughly 8 bits or so of accuracy. (One convenient way is
257 // r_hi := frcpa( frcpa( r ) ).)
261 // r + PP_1_hi r^3 = r + PP_1_hi r_hi^3 +
262 // PP_1_hi (r^3 - r_hi^3)
263 // = [r + PP_1_hi r_hi^3] +
264 // [PP_1_hi (r - r_hi)
265 // (r^2 + r_hi r + r_hi^2) ]
268 // Since r_hi is only 10 bit long and PP_1_hi is only 16 bit long,
269 // PP_1_hi * r_hi^3 is only at most 46 bit long and thus computed
270 // exactly. Furthermore, r and PP_1_hi r_hi^3 are of opposite sign
271 // and that there is no more than 8 bit shift off between r and
272 // PP_1_hi * r_hi^3. Hence the sum, U_hi, is representable and thus
273 // calculated without any error. Finally, the fact that
275 // |U_lo| <= 2^(-8) |U_hi|
277 // says that U_hi + U_lo is approximating r + PP_1_hi r^3 to roughly
278 // 8 extra bits of accuracy.
282 // 1 + QQ_1 r^2 = [1 + QQ_1 r_hi^2] +
283 // [QQ_1 (r - r_hi)(r + r_hi)]
286 // Summarizing, we calculate r_hi = frcpa( frcpa( r ) ).
290 // U_hi := r + PP_1_hi * r_hi^3
291 // U_lo := PP_1_hi * (r - r_hi) * (r^2 + r*r_hi + r_hi^2)
292 // poly := PP_1_lo r^3 + PP_2 r^5 + ... + PP_8 r^17
293 // correction := c * ( 1 + C_1 r^2 )
297 // U_hi := 1 + QQ_1 * r_hi * r_hi
298 // U_lo := QQ_1 * (r - r_hi) * (r + r_hi)
299 // poly := QQ_2 * r^4 + QQ_3 * r^6 + ... + QQ_8 r^16
300 // correction := -c * r * (1 + S_1 * r^2)
306 // V := poly + ( U_lo + correction )
308 // / U_hi + V if i_0 = 0
310 // \ (-U_hi) - V if i_0 = 1
312 // It is important that in the last step, negation of U_hi is
313 // performed prior to the subtraction which is to be performed in
314 // the user-set rounding mode.
317 // Algorithmic Description
318 // =======================
320 // The argument reduction algorithm is tightly integrated into FSIN
321 // and FCOS which share the same code. The following is complete and
322 // self-contained. The argument reduction description given
323 // previously is repeated below.
326 // Step 0. Initialization.
328 // If FSIN is invoked, set N_inc := 0; else if FCOS is invoked,
331 // Step 1. Check for exceptional and special cases.
333 // * If Arg is +-0, +-inf, NaN, NaT, go to Step 10 for special
335 // * If |Arg| < 2^24, go to Step 2 for reduction of moderate
336 // arguments. This is the most likely case.
337 // * If |Arg| < 2^63, go to Step 8 for pre-reduction of large
339 // * If |Arg| >= 2^63, go to Step 10 for special handling.
341 // Step 2. Reduction of moderate arguments.
343 // If |Arg| < pi/4 ...quick branch
344 // N_fix := N_inc (integer)
347 // Branch to Step 4, Case_1_complete
348 // Else ...cf. argument reduction
349 // N := Arg * two_by_PI (fp)
350 // N_fix := fcvt.fx( N ) (int)
351 // N := fcvt.xf( N_fix )
352 // N_fix := N_fix + N_inc
353 // s := Arg - N * P_1 (first piece of pi/2)
354 // w := -N * P_2 (second piece of pi/2)
357 // go to Step 3, Case_1_reduce
359 // go to Step 7, Case_2_reduce
363 // Step 3. Case_1_reduce.
366 // c := (s - r) + w ...observe order
368 // Step 4. Case_1_complete
370 // ...At this point, the reduced argument alpha is
371 // ...accurately represented as r + c.
372 // If |r| < 2^(-3), go to Step 6, small_r.
376 // Let [i_0 i_1] by the 2 lsb of N_fix.
378 // r_hi := frcpa( frcpa( r ) )
382 // poly := r*FR_rsq*(PP_1_lo + FR_rsq*(PP_2 + ... FR_rsq*PP_8))
383 // U_hi := r + PP_1_hi*r_hi*r_hi*r_hi ...any order
384 // U_lo := PP_1_hi*r_lo*(r*r + r*r_hi + r_hi*r_hi)
385 // correction := c + c*C_1*FR_rsq ...any order
387 // poly := FR_rsq*FR_rsq*(QQ_2 + FR_rsq*(QQ_3 + ... + FR_rsq*QQ_8))
388 // U_hi := 1 + QQ_1 * r_hi * r_hi ...any order
389 // U_lo := QQ_1 * r_lo * (r + r_hi)
390 // correction := -c*(r + S_1*FR_rsq*r) ...any order
393 // V := poly + (U_lo + correction) ...observe order
395 // result := (i_0 == 0? 1.0 : -1.0)
397 // Last instruction in user-set rounding mode
399 // result := (i_0 == 0? result*U_hi + V :
406 // ...Use flush to zero mode without causing exception
407 // Let [i_0 i_1] be the two lsb of N_fix.
412 // z := FR_rsq*FR_rsq; z := FR_rsq*z *r
413 // poly_lo := S_3 + FR_rsq*(S_4 + FR_rsq*S_5)
414 // poly_hi := r*FR_rsq*(S_1 + FR_rsq*S_2)
418 // z := FR_rsq*FR_rsq; z := FR_rsq*z
419 // poly_lo := C_3 + FR_rsq*(C_4 + FR_rsq*C_5)
420 // poly_hi := FR_rsq*(C_1 + FR_rsq*C_2)
421 // correction := -c*r
425 // poly := poly_hi + (z * poly_lo + correction)
427 // If i_0 = 1, result := -result
429 // Last operation. Perform in user-set rounding mode
431 // result := (i_0 == 0? result + poly :
435 // Step 7. Case_2_reduce.
437 // ...Refer to the write up for argument reduction for
438 // ...rationale. The reduction algorithm below is taken from
439 // ...argument reduction description and integrated this.
442 // U_1 := N*P_2 + w ...FMA
443 // U_2 := (N*P_2 - U_1) + w ...2 FMA
444 // ...U_1 + U_2 is N*(P_2+P_3) accurately
447 // c := ( (s - r) - U_1 ) - U_2
449 // ...The mathematical sum r + c approximates the reduced
450 // ...argument accurately. Note that although compared to
451 // ...Case 1, this case requires much more work to reduce
452 // ...the argument, the subsequent calculation needed for
453 // ...any of the trigonometric function is very little because
454 // ...|alpha| < 1.01*2^(-33) and thus two terms of the
455 // ...Taylor series expansion suffices.
458 // poly := c + S_1 * r * r * r ...any order
465 // If i_0 = 1, result := -result
467 // Last operation. Perform in user-set rounding mode
469 // result := (i_0 == 0? result + poly :
475 // Step 8. Pre-reduction of large arguments.
477 // ...Again, the following reduction procedure was described
478 // ...in the separate write up for argument reduction, which
479 // ...is tightly integrated here.
481 // N_0 := Arg * Inv_P_0
482 // N_0_fix := fcvt.fx( N_0 )
483 // N_0 := fcvt.xf( N_0_fix)
485 // Arg' := Arg - N_0 * P_0
487 // N := Arg' * two_by_PI
488 // N_fix := fcvt.fx( N )
489 // N := fcvt.xf( N_fix )
490 // N_fix := N_fix + N_inc
492 // s := Arg' - N * P_1
501 // Step 9. Case_4_reduce.
503 // ...first obtain N_0*d_1 and -N*P_2 accurately
504 // U_hi := N_0 * d_1 V_hi := -N*P_2
505 // U_lo := N_0 * d_1 - U_hi V_lo := -N*P_2 - U_hi ...FMAs
507 // ...compute the contribution from N_0*d_1 and -N*P_3
510 // t := U_lo + V_lo + w ...any order
512 // ...at this point, the mathematical value
513 // ...s + U_hi + V_hi + t approximates the true reduced argument
514 // ...accurately. Just need to compute this accurately.
516 // ...Calculate U_hi + V_hi accurately:
518 // if |U_hi| >= |V_hi| then
519 // a := (U_hi - A) + V_hi
521 // a := (V_hi - A) + U_hi
523 // ...order in computing "a" must be observed. This branch is
524 // ...best implemented by predicates.
525 // ...A + a is U_hi + V_hi accurately. Moreover, "a" is
526 // ...much smaller than A: |a| <= (1/2)ulp(A).
528 // ...Just need to calculate s + A + a + t
529 // C_hi := s + A t := t + a
530 // C_lo := (s - C_hi) + A
533 // ...Final steps for reduction
535 // c := (C_hi - r) + C_lo
537 // ...At this point, we have r and c
538 // ...And all we need is a couple of terms of the corresponding
542 // poly := c + r*FR_rsq*(S_1 + FR_rsq*S_2)
545 // poly := FR_rsq*(C_1 + FR_rsq*C_2)
549 // If i_0 = 1, result := -result
551 // Last operation. Perform in user-set rounding mode
553 // result := (i_0 == 0? result + poly :
557 // Large Arguments: For arguments above 2**63, a Payne-Hanek
558 // style argument reduction is used and pi_by_2 reduce is called.
565 LOCAL_OBJECT_START(FSINCOSL_CONSTANTS)
568 data8 0xA2F9836E4E44152A, 0x00003FFE // Inv_pi_by_2
569 data8 0xC84D32B0CE81B9F1, 0x00004016 // P_0
570 data8 0xC90FDAA22168C235, 0x00003FFF // P_1
571 data8 0xECE675D1FC8F8CBB, 0x0000BFBD // P_2
572 data8 0xB7ED8FBBACC19C60, 0x0000BF7C // P_3
573 data8 0x8D848E89DBD171A1, 0x0000BFBF // d_1
574 data8 0xD5394C3618A66F8E, 0x0000BF7C // d_2
575 LOCAL_OBJECT_END(FSINCOSL_CONSTANTS)
577 LOCAL_OBJECT_START(sincosl_table_d)
578 data8 0xC90FDAA22168C234, 0x00003FFE // pi_by_4
579 data8 0xA397E5046EC6B45A, 0x00003FE7 // Inv_P_0
580 data4 0x3E000000, 0xBE000000 // 2^-3 and -2^-3
581 data4 0x2F000000, 0xAF000000 // 2^-33 and -2^-33
582 data4 0x9E000000, 0x00000000 // -2^-67
583 data4 0x00000000, 0x00000000 // pad
584 LOCAL_OBJECT_END(sincosl_table_d)
586 LOCAL_OBJECT_START(sincosl_table_pp)
587 data8 0xCC8ABEBCA21C0BC9, 0x00003FCE // PP_8
588 data8 0xD7468A05720221DA, 0x0000BFD6 // PP_7
589 data8 0xB092382F640AD517, 0x00003FDE // PP_6
590 data8 0xD7322B47D1EB75A4, 0x0000BFE5 // PP_5
591 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
592 data8 0xAAAA000000000000, 0x0000BFFC // PP_1_hi
593 data8 0xB8EF1D2ABAF69EEA, 0x00003FEC // PP_4
594 data8 0xD00D00D00D03BB69, 0x0000BFF2 // PP_3
595 data8 0x8888888888888962, 0x00003FF8 // PP_2
596 data8 0xAAAAAAAAAAAB0000, 0x0000BFEC // PP_1_lo
597 LOCAL_OBJECT_END(sincosl_table_pp)
599 LOCAL_OBJECT_START(sincosl_table_qq)
600 data8 0xD56232EFC2B0FE52, 0x00003FD2 // QQ_8
601 data8 0xC9C99ABA2B48DCA6, 0x0000BFDA // QQ_7
602 data8 0x8F76C6509C716658, 0x00003FE2 // QQ_6
603 data8 0x93F27DBAFDA8D0FC, 0x0000BFE9 // QQ_5
604 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
605 data8 0x8000000000000000, 0x0000BFFE // QQ_1
606 data8 0xD00D00D00C6E5041, 0x00003FEF // QQ_4
607 data8 0xB60B60B60B607F60, 0x0000BFF5 // QQ_3
608 data8 0xAAAAAAAAAAAAAA9B, 0x00003FFA // QQ_2
609 LOCAL_OBJECT_END(sincosl_table_qq)
611 LOCAL_OBJECT_START(sincosl_table_c)
612 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
613 data8 0xAAAAAAAAAAAA719F, 0x00003FFA // C_2
614 data8 0xB60B60B60356F994, 0x0000BFF5 // C_3
615 data8 0xD00CFFD5B2385EA9, 0x00003FEF // C_4
616 data8 0x93E4BD18292A14CD, 0x0000BFE9 // C_5
617 LOCAL_OBJECT_END(sincosl_table_c)
619 LOCAL_OBJECT_START(sincosl_table_s)
620 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
621 data8 0x88888888888868DB, 0x00003FF8 // S_2
622 data8 0xD00D00D0055EFD4B, 0x0000BFF2 // S_3
623 data8 0xB8EF1C5D839730B9, 0x00003FEC // S_4
624 data8 0xD71EA3A4E5B3F492, 0x0000BFE5 // S_5
625 data4 0x38800000, 0xB8800000 // two**-14 and -two**-14
626 LOCAL_OBJECT_END(sincosl_table_s)
635 FR_inv_pi_2to63 = f10
639 FR_N_float_signif = f14
643 FR_Neg_Two_to_M14 = f36
645 FR_Neg_Two_to_M33 = f38
646 FR_Neg_Two_to_M67 = f39
709 FR_Neg_Two_to_M3 = f93
742 // Added for unwind support
751 GLOBAL_IEEE754_ENTRY(sinl)
753 alloc r32 = ar.pfs,0,12,2,0
754 movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
757 mov GR_Sin_or_Cos = 0x0
758 movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
763 addl GR_ad_p = @ltoff(FSINCOSL_CONSTANTS#), gp
764 fclass.m p6, p0 = FR_Input_X, 0x1E3 // Test x natval, nan, inf
765 mov GR_exp_2_to_m3 = 0xffff - 3 // Exponent of 2^-3
769 fnorm.s1 FR_norm_x = FR_Input_X // Normalize x
770 br.cond.sptk SINCOSL_CONTINUE
774 GLOBAL_IEEE754_END(sinl)
775 GLOBAL_IEEE754_ENTRY(cosl)
777 alloc r32 = ar.pfs,0,12,2,0
778 movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
781 mov GR_Sin_or_Cos = 0x1
782 movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
787 addl GR_ad_p = @ltoff(FSINCOSL_CONSTANTS#), gp
788 fclass.m p6, p0 = FR_Input_X, 0x1E3 // Test x natval, nan, inf
789 mov GR_exp_2_to_m3 = 0xffff - 3 // Exponent of 2^-3
793 fnorm.s1 FR_norm_x = FR_Input_X // Normalize x
800 setf.sig FR_inv_pi_2to63 = GR_sig_inv_pi // Form 1/pi * 2^63
802 mov GR_exp_2tom64 = 0xffff - 64 // Scaling constant to compute N
805 setf.d FR_rshf_2to64 = GR_rshf_2to64 // Form const 1.1000 * 2^(63+64)
806 movl GR_rshf = 0x43e8000000000000 // Form const 1.1000 * 2^63
811 ld8 GR_ad_p = [GR_ad_p] // Point to Inv_pi_by_2
812 fclass.m p7, p0 = FR_Input_X, 0x0b // Test x denormal
818 getf.exp GR_signexp_x = FR_Input_X // Get sign and exponent of x
819 fclass.m p10, p0 = FR_Input_X, 0x007 // Test x zero
823 mov GR_exp_mask = 0x1ffff // Exponent mask
825 (p6) br.cond.spnt SINCOSL_SPECIAL // Branch if x natval, nan, inf
830 setf.exp FR_2tom64 = GR_exp_2tom64 // Form 2^-64 for scaling N_float
832 add GR_ad_d = 0x70, GR_ad_p // Point to constant table d
835 setf.d FR_rshf = GR_rshf // Form right shift const 1.1000 * 2^63
836 mov GR_exp_m2_to_m3 = 0x2fffc // Form -(2^-3)
837 (p7) br.cond.spnt SINCOSL_DENORMAL // Branch if x denormal
843 and GR_exp_x = GR_exp_mask, GR_signexp_x // Get exponent of x
844 fclass.nm p8, p0 = FR_Input_X, 0x1FF // Test x unsupported type
845 mov GR_exp_2_to_63 = 0xffff + 63 // Exponent of 2^63
848 add GR_ad_pp = 0x40, GR_ad_d // Point to constant table pp
849 mov GR_exp_2_to_24 = 0xffff + 24 // Exponent of 2^24
850 (p10) br.cond.spnt SINCOSL_ZERO // Branch if x zero
855 ldfe FR_Inv_pi_by_2 = [GR_ad_p], 16 // Load 2/pi
856 fcmp.eq.s0 p15, p0 = FR_Input_X, f0 // Dummy to set denormal
857 add GR_ad_qq = 0xa0, GR_ad_pp // Point to constant table qq
860 ldfe FR_Pi_by_4 = [GR_ad_d], 16 // Load pi/4 for range test
862 cmp.ge p10,p0 = GR_exp_x, GR_exp_2_to_63 // Is |x| >= 2^63
867 ldfe FR_P_0 = [GR_ad_p], 16 // Load P_0 for pi/4 <= |x| < 2^63
868 fmerge.s FR_abs_x = f1, FR_norm_x // |x|
869 add GR_ad_c = 0x90, GR_ad_qq // Point to constant table c
872 ldfe FR_Inv_P_0 = [GR_ad_d], 16 // Load 1/P_0 for pi/4 <= |x| < 2^63
874 cmp.ge p7,p0 = GR_exp_x, GR_exp_2_to_24 // Is |x| >= 2^24
879 ldfe FR_P_1 = [GR_ad_p], 16 // Load P_1 for pi/4 <= |x| < 2^63
881 add GR_ad_s = 0x50, GR_ad_c // Point to constant table s
884 ldfe FR_PP_8 = [GR_ad_pp], 16 // Load PP_8 for 2^-3 < |r| < pi/4
891 ldfe FR_P_2 = [GR_ad_p], 16 // Load P_2 for pi/4 <= |x| < 2^63
893 add GR_ad_ce = 0x40, GR_ad_c // Point to end of constant table c
896 ldfe FR_QQ_8 = [GR_ad_qq], 16 // Load QQ_8 for 2^-3 < |r| < pi/4
903 ldfe FR_QQ_7 = [GR_ad_qq], 16 // Load QQ_7 for 2^-3 < |r| < pi/4
904 fma.s1 FR_N_float_signif = FR_Input_X, FR_inv_pi_2to63, FR_rshf_2to64
905 add GR_ad_se = 0x40, GR_ad_s // Point to end of constant table s
908 ldfe FR_PP_7 = [GR_ad_pp], 16 // Load PP_7 for 2^-3 < |r| < pi/4
909 mov GR_ad_s1 = GR_ad_s // Save pointer to S_1
910 (p10) br.cond.spnt SINCOSL_ARG_TOO_LARGE // Branch if |x| >= 2^63
911 // Use Payne-Hanek Reduction
916 ldfe FR_P_3 = [GR_ad_p], 16 // Load P_3 for pi/4 <= |x| < 2^63
917 fmerge.se FR_r = FR_norm_x, FR_norm_x // r = x, in case |x| < pi/4
918 add GR_ad_m14 = 0x50, GR_ad_s // Point to constant table m14
921 ldfps FR_Two_to_M3, FR_Neg_Two_to_M3 = [GR_ad_d], 8
922 fma.s1 FR_rsq = FR_norm_x, FR_norm_x, f0 // rsq = x*x, in case |x| < pi/4
923 (p7) br.cond.spnt SINCOSL_LARGER_ARG // Branch if 2^24 <= |x| < 2^63
929 ldfe FR_PP_6 = [GR_ad_pp], 16 // Load PP_6 for normal path
930 ldfe FR_QQ_6 = [GR_ad_qq], 16 // Load QQ_6 for normal path
931 fmerge.se FR_c = f0, f0 // c = 0 in case |x| < pi/4
936 ldfe FR_PP_5 = [GR_ad_pp], 16 // Load PP_5 for normal path
937 ldfe FR_QQ_5 = [GR_ad_qq], 16 // Load QQ_5 for normal path
942 // Here if 0 < |x| < 2^24
944 ldfe FR_S_5 = [GR_ad_se], -16 // Load S_5 if i_1=0
945 fcmp.lt.s1 p6, p7 = FR_abs_x, FR_Pi_by_4 // Test |x| < pi/4
949 ldfe FR_C_5 = [GR_ad_ce], -16 // Load C_5 if i_1=1
950 fms.s1 FR_N_float = FR_N_float_signif, FR_2tom64, FR_rshf
956 ldfe FR_S_4 = [GR_ad_se], -16 // Load S_4 if i_1=0
957 ldfe FR_C_4 = [GR_ad_ce], -16 // Load C_4 if i_1=1
964 // Check if Arg < pi/4
967 // Case 2: Convert integer N_fix back to normalized floating-point value.
968 // Case 1: p8 is only affected when p6 is set
971 // Grab the integer part of N and call it N_fix
974 (p7) ldfps FR_Two_to_M33, FR_Neg_Two_to_M33 = [GR_ad_d], 8
975 (p6) fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // r^3 if |x| < pi/4
976 (p6) mov GR_N_Inc = GR_Sin_or_Cos // N_Inc if |x| < pi/4
980 // If |x| < pi/4, r = x and c = 0
981 // lf |x| < pi/4, is x < 2**(-3).
985 (p7) getf.sig GR_N_Inc = FR_N_float_signif
986 (p6) cmp.lt.unc p8,p0 = GR_exp_x, GR_exp_2_to_m3 // Is |x| < 2^-3
987 (p6) tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
988 // p10 if i_1=1, N mod 4 = 2,3
993 // lf |x| < pi/4, is -2**(-3)< x < 2**(-3) - set p8.
995 // Create the right N for |x| < pi/4 and otherwise
996 // Case 2: Place integer part of N in GP register
1002 (p8) br.cond.spnt SINCOSL_SMALL_R_0 // Branch if 0 < |x| < 2^-3
1003 (p6) br.cond.spnt SINCOSL_NORMAL_R_0 // Branch if 2^-3 <= |x| < pi/4
1007 // Here if pi/4 <= |x| < 2^24
1009 ldfs FR_Neg_Two_to_M67 = [GR_ad_d], 8 // Load -2^-67
1010 fnma.s1 FR_s = FR_N_float, FR_P_1, FR_Input_X // s = -N * P_1 + Arg
1011 add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos // Adjust N_Inc for sin/cos
1015 fma.s1 FR_w = FR_N_float, FR_P_2, f0 // w = N * P_2
1022 fms.s1 FR_r = FR_s, f1, FR_w // r = s - w, assume |s| >= 2^-33
1023 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1024 // p10 if i_1=1, N mod 4 = 2,3
1030 fcmp.lt.s1 p7, p6 = FR_s, FR_Two_to_M33
1037 (p7) fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33 // p6 if |s| >= 2^-33, else p7
1044 fms.s1 FR_c = FR_s, f1, FR_r // c = s - r, for |s| >= 2^-33
1049 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r, for |s| >= 2^-33
1056 (p7) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1062 (p9) ldfe FR_C_1 = [GR_ad_pp], 16 // Load C_1 if i_1=0
1063 (p10) ldfe FR_S_1 = [GR_ad_qq], 16 // Load S_1 if i_1=1
1064 frcpa.s1 FR_r_hi, p15 = f1, FR_r // r_hi = frcpa(r)
1070 (p6) fcmp.lt.unc.s1 p8, p13 = FR_r, FR_Two_to_M3 // If big s, test r with 2^-3
1077 (p7) fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1083 // For big s: r = s - w: No futher reduction is necessary
1084 // For small s: w = N * P_3 (change sign) More reduction
1088 (p8) fcmp.gt.s1 p8, p13 = FR_r, FR_Neg_Two_to_M3 // If big s, p8 if |r| < 2^-3
1094 (p9) fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7 if i_1=0
1099 (p10) fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7 if i_1=1
1106 (p7) fms.s1 FR_r = FR_s, f1, FR_U_1
1113 (p6) fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // rcubed = r * rsq
1120 // For big s: Is |r| < 2**(-3)?
1121 // For big s: c = S - r
1122 // For small s: U_1 = N * P_2 + w
1124 // If p8 is set, prepare to branch to Small_R.
1125 // If p9 is set, prepare to branch to Normal_R.
1126 // For big s, r is complete here.
1129 // For big s: c = c + w (w has not been negated.)
1130 // For small s: r = S - U_1
1133 (p6) fms.s1 FR_c = FR_c, f1, FR_w
1138 (p8) br.cond.spnt SINCOSL_SMALL_R_1 // Branch if |s|>=2^-33, |r| < 2^-3,
1139 // and pi/4 <= |x| < 2^24
1140 (p13) br.cond.sptk SINCOSL_NORMAL_R_1 // Branch if |s|>=2^-33, |r| >= 2^-3,
1141 // and pi/4 <= |x| < 2^24
1147 // Here if |s| < 2^-33, and pi/4 <= |x| < 2^24
1150 fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1162 // Get [i_0,i_1] - two lsb of N_fix_gr.
1163 // Do dummy fmpy so inexact is always set.
1165 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1166 // p10 if i_1=1, N mod 4 = 2,3
1171 // For small s: U_2 = N * P_2 - U_1
1172 // S_1 stored constant - grab the one stored with the
1176 ldfe FR_S_1 = [GR_ad_s1], 16
1178 // Check if i_1 and i_0 != 0
1180 (p10) fma.s1 FR_poly = f0, f1, FR_Neg_Two_to_M67
1181 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
1182 // p12 if i_0=1, N mod 4 = 1,3
1188 fms.s1 FR_s = FR_s, f1, FR_r
1198 fma.s1 FR_rsq = FR_r, FR_r, f0
1203 fma.s1 FR_U_2 = FR_U_2, f1, FR_w
1208 fmerge.se FR_tmp_result = FR_r, FR_r
1213 (p10) fma.s1 FR_tmp_result = f0, f1, f1
1220 // Save r as the result.
1222 fms.s1 FR_c = FR_s, f1, FR_U_1
1228 // if ( i_1 ==0) poly = c + S_1*r*r*r
1231 (p12) fnma.s1 FR_tmp_result = FR_tmp_result, f1, f0
1236 fma.s1 FR_r = FR_S_1, FR_r, f0
1241 fma.s0 FR_S_1 = FR_S_1, FR_S_1, f0
1247 // If i_1 != 0, poly = 2**(-67)
1249 fms.s1 FR_c = FR_c, f1, FR_U_2
1257 (p9) fma.s1 FR_poly = FR_r, FR_rsq, FR_c
1263 // i_0 != 0, so Result = -Result
1265 (p11) fma.s0 FR_Result = FR_tmp_result, f1, FR_poly
1270 (p12) fms.s0 FR_Result = FR_tmp_result, f1, FR_poly
1272 // if (i_0 == 0), Result = Result + poly
1273 // else Result = Result - poly
1275 br.ret.sptk b0 // Exit if |s| < 2^-33, and pi/4 <= |x| < 2^24
1281 // Here if 2^24 <= |x| < 2^63
1284 ldfe FR_d_1 = [GR_ad_p], 16 // Load d_1 for |x| >= 2^24 path
1285 fma.s1 FR_N_0 = FR_Input_X, FR_Inv_P_0, f0
1291 // N_0 = Arg * Inv_P_0
1293 // Load values 2**(-14) and -2**(-14)
1295 ldfps FR_Two_to_M14, FR_Neg_Two_to_M14 = [GR_ad_m14]
1299 ldfe FR_d_2 = [GR_ad_p], 16 // Load d_2 for |x| >= 2^24 path
1307 fcvt.fx.s1 FR_N_0_fix = FR_N_0
1313 // N_0_fix = integer part of N_0
1315 fcvt.xf FR_N_0 = FR_N_0_fix
1321 // Make N_0 the integer part
1323 fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X
1328 fma.s1 FR_w = FR_N_0, FR_d_1, f0
1334 // Arg' = -N_0 * P_0 + Arg
1337 fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0
1345 fcvt.fx.s1 FR_N_fix = FR_N_float
1351 // N_fix is the integer part
1353 fcvt.xf FR_N_float = FR_N_fix
1357 getf.sig GR_N_Inc = FR_N_fix
1364 add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos ;;
1369 // N is the integer part of the reduced-reduced argument.
1370 // Put the integer in a GP register
1372 fnma.s1 FR_s = FR_N_float, FR_P_1, FR_ArgPrime
1377 fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w
1383 // s = -N*P_1 + Arg'
1385 // N_fix_gr = N_fix_gr + N_inc
1387 fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1392 (p9) fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14 // p9 if |s| < 2^-14
1399 // For |s| > 2**(-14) r = S + w (r complete)
1400 // Else U_hi = N_0 * d_1
1402 (p9) fma.s1 FR_V_hi = FR_N_float, FR_P_2, f0
1407 (p9) fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1413 // Either S <= -2**(-14) or S >= 2**(-14)
1414 // or -2**(-14) < s < 2**(-14)
1416 (p8) fma.s1 FR_r = FR_s, f1, FR_w
1421 (p9) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1427 // We need abs of both U_hi and V_hi - don't
1428 // worry about switched sign of V_hi.
1430 (p9) fms.s1 FR_A = FR_U_hi, f1, FR_V_hi
1436 // Big s: finish up c = (S - r) + w (c complete)
1437 // Case 4: A = U_hi + V_hi
1438 // Note: Worry about switched sign of V_hi, so subtract instead of add.
1440 (p9) fnma.s1 FR_V_lo = FR_N_float, FR_P_2, FR_V_hi
1446 (p9) fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi
1450 (p9) fmerge.s FR_V_hiabs = f0, FR_V_hi
1454 //(p9) fmerge.s f8= FR_V_lo,FR_V_lo
1455 //(p9) br.ret.sptk b0
1460 // For big s: c = S - r
1461 // For small s do more work: U_lo = N_0 * d_1 - U_hi
1463 (p9) fmerge.s FR_U_hiabs = f0, FR_U_hi
1469 // For big s: Is |r| < 2**(-3)
1470 // For big s: if p12 set, prepare to branch to Small_R.
1471 // For big s: If p13 set, prepare to branch to Normal_R.
1473 (p8) fms.s1 FR_c = FR_s, f1, FR_r
1479 // For small S: V_hi = N * P_2
1481 // Note the product does not include the (-) as in the writeup
1482 // so (-) missing for V_hi and w.
1484 (p8) fcmp.lt.unc.s1 p12, p13 = FR_r, FR_Two_to_M3
1489 (p12) fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1494 (p8) fma.s1 FR_c = FR_c, f1, FR_w
1499 (p9) fms.s1 FR_w = FR_N_0, FR_d_2, FR_w
1500 (p12) br.cond.spnt SINCOSL_SMALL_R // Branch if |r| < 2^-3
1501 // and 2^24 <= |x| < 2^63
1508 (p13) br.cond.sptk SINCOSL_NORMAL_R // Branch if |r| >= 2^-3
1509 // and 2^24 <= |x| < 2^63
1513 SINCOSL_LARGER_S_TINY:
1515 // Here if |s| < 2^-14, and 2^24 <= |x| < 2^63
1520 // Big s: Vector off when |r| < 2**(-3). Recall that p8 will be true.
1521 // The remaining stuff is for Case 4.
1522 // Small s: V_lo = N * P_2 + U_hi (U_hi is in place of V_hi in writeup)
1523 // Note: the (-) is still missing for V_lo.
1524 // Small s: w = w + N_0 * d_2
1525 // Note: the (-) is now incorporated in w.
1527 fcmp.ge.unc.s1 p7, p8 = FR_U_hiabs, FR_V_hiabs
1534 fma.s1 FR_t = FR_U_lo, f1, FR_V_lo
1544 (p7) fms.s1 FR_a = FR_U_hi, f1, FR_A
1549 (p8) fma.s1 FR_a = FR_V_hi, f1, FR_A
1556 // Is U_hiabs >= V_hiabs?
1559 fma.s1 FR_C_hi = FR_s, f1, FR_A
1563 ldfe FR_C_1 = [GR_ad_c], 16 ;;
1564 ldfe FR_C_2 = [GR_ad_c], 64
1568 // c = c + C_lo finished.
1572 ldfe FR_S_1 = [GR_ad_s], 16
1576 fma.s1 FR_t = FR_t, f1, FR_w
1580 // r and c have been computed.
1581 // Make sure ftz mode is set - should be automatic when using wre
1583 // Get [i_0,i_1] - two lsb of N_fix.
1587 ldfe FR_S_2 = [GR_ad_s], 64
1591 (p7) fms.s1 FR_a = FR_a, f1, FR_V_hi
1592 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1593 // p10 if i_1=1, N mod 4 = 2,3
1599 // For larger u than v: a = U_hi - A
1600 // Else a = V_hi - A (do an add to account for missing (-) on V_hi
1602 fms.s1 FR_C_lo = FR_s, f1, FR_C_hi
1607 (p8) fms.s1 FR_a = FR_U_hi, f1, FR_a
1608 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
1609 // p12 if i_0=1, N mod 4 = 1,3
1616 // If u > v: a = (U_hi - A) + V_hi
1617 // Else a = (V_hi - A) + U_hi
1618 // In each case account for negative missing from V_hi.
1620 fma.s1 FR_C_lo = FR_C_lo, f1, FR_A
1626 // C_lo = (S - C_hi) + A
1628 fma.s1 FR_t = FR_t, f1, FR_a
1636 fma.s1 FR_C_lo = FR_C_lo, f1, FR_t
1644 fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1652 fma.s1 FR_rsq = FR_r, FR_r, f0
1660 fms.s1 FR_c = FR_C_hi, f1, FR_r
1666 // if i_1 ==0: poly = S_2 * FR_rsq + S_1
1667 // else poly = C_2 * FR_rsq + C_1
1669 (p9) fma.s1 FR_tmp_result = f0, f1, FR_r
1674 (p10) fma.s1 FR_tmp_result = f0, f1, f1
1680 // Compute r_cube = FR_rsq * r
1682 (p9) fma.s1 FR_poly = FR_rsq, FR_S_2, FR_S_1
1687 (p10) fma.s1 FR_poly = FR_rsq, FR_C_2, FR_C_1
1693 // Compute FR_rsq = r * r
1696 fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1705 fma.s1 FR_c = FR_c, f1, FR_C_lo
1711 // if i_1 ==0: poly = r_cube * poly + c
1712 // else poly = FR_rsq * poly
1714 (p12) fms.s1 FR_tmp_result = f0, f1, FR_tmp_result
1720 // if i_1 ==0: Result = r
1721 // else Result = 1.0
1723 (p9) fma.s1 FR_poly = FR_r_cubed, FR_poly, FR_c
1728 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0
1734 // if i_0 !=0: Result = -Result
1736 (p11) fma.s0 FR_Result = FR_tmp_result, f1, FR_poly
1741 (p12) fms.s0 FR_Result = FR_tmp_result, f1, FR_poly
1743 // if i_0 == 0: Result = Result + poly
1744 // else Result = Result - poly
1746 br.ret.sptk b0 // Exit for |s| < 2^-14, and 2^24 <= |x| < 2^63
1753 // Here if |r| < 2^-3
1755 // Enter with r, c, and N_Inc computed
1757 // Compare both i_1 and i_0 with 0.
1758 // if i_1 == 0, set p9.
1759 // if i_0 == 0, set p11.
1764 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r
1765 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1766 // p10 if i_1=1, N mod 4 = 2,3
1771 (p9) ldfe FR_S_5 = [GR_ad_se], -16 // Load S_5 if i_1=0
1772 (p10) ldfe FR_C_5 = [GR_ad_ce], -16 // Load C_5 if i_1=1
1778 (p9) ldfe FR_S_4 = [GR_ad_se], -16 // Load S_4 if i_1=0
1779 (p10) ldfe FR_C_4 = [GR_ad_ce], -16 // Load C_4 if i_1=1
1785 // Entry point for 2^-3 < |x| < pi/4
1786 .pred.rel "mutex",p9,p10
1788 // Entry point for pi/4 < |x| < 2^24 and |r| < 2^-3
1789 .pred.rel "mutex",p9,p10
1791 (p9) ldfe FR_S_3 = [GR_ad_se], -16 // Load S_3 if i_1=0
1792 fma.s1 FR_Z = FR_rsq, FR_rsq, f0 // Z = rsq * rsq
1796 (p10) ldfe FR_C_3 = [GR_ad_ce], -16 // Load C_3 if i_1=1
1797 (p10) fnma.s1 FR_c = FR_c, FR_r, f0 // c = -c * r if i_1=0
1803 (p9) ldfe FR_S_2 = [GR_ad_se], -16 // Load S_2 if i_1=0
1804 (p10) ldfe FR_C_2 = [GR_ad_ce], -16 // Load C_2 if i_1=1
1805 (p10) fmerge.s FR_r = f1, f1
1810 (p9) ldfe FR_S_1 = [GR_ad_se], -16 // Load S_1 if i_1=0
1811 (p10) ldfe FR_C_1 = [GR_ad_ce], -16 // Load C_1 if i_1=1
1818 (p9) fma.s1 FR_Z = FR_Z, FR_r, f0 // Z = Z * r if i_1=0
1825 (p9) fma.s1 FR_poly_lo = FR_rsq, FR_S_5, FR_S_4 // poly_lo=rsq*S_5+S_4 if i_1=0
1830 (p10) fma.s1 FR_poly_lo = FR_rsq, FR_C_5, FR_C_4 // poly_lo=rsq*C_5+C_4 if i_1=1
1837 (p9) fma.s1 FR_poly_hi = FR_rsq, FR_S_2, FR_S_1 // poly_hi=rsq*S_2+S_1 if i_1=0
1842 (p10) fma.s1 FR_poly_hi = FR_rsq, FR_C_2, FR_C_1 // poly_hi=rsq*C_2+C_1 if i_1=1
1849 fma.s1 FR_Z = FR_Z, FR_rsq, f0 // Z = Z * rsq
1856 (p9) fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_S_3 // p_lo=p_lo*rsq+S_3, i_1=0
1861 (p10) fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_C_3 // p_lo=p_lo*rsq+C_3, i_1=1
1868 (p9) fma.s0 FR_inexact = FR_S_4, FR_S_4, f0 // Dummy op to set inexact
1869 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
1870 // p12 if i_0=1, N mod 4 = 1,3
1874 (p10) fma.s0 FR_inexact = FR_C_1, FR_C_1, f0 // Dummy op to set inexact
1881 (p9) fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0 // p_hi=p_hi*rsq if i_1=0
1886 (p10) fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0 // p_hi=p_hi*rsq if i_1=1
1893 fma.s1 FR_poly = FR_Z, FR_poly_lo, FR_c // poly=Z*poly_lo+c
1900 (p9) fma.s1 FR_poly_hi = FR_r, FR_poly_hi, f0 // p_hi=r*p_hi if i_1=0
1907 (p12) fms.s1 FR_r = f0, f1, FR_r // r = -r if i_0=1
1914 fma.s1 FR_poly = FR_poly, f1, FR_poly_hi // poly=poly+poly_hi
1920 // if (i_0 == 0) Result = r + poly
1921 // if (i_0 != 0) Result = r - poly
1925 (p11) fma.s0 FR_Result = FR_r, f1, FR_poly
1930 (p12) fms.s0 FR_Result = FR_r, f1, FR_poly
1931 br.ret.sptk b0 // Exit for |r| < 2^-3
1938 // Here if 2^-3 <= |r| < pi/4
1939 // THIS IS THE MAIN PATH
1941 // Enter with r, c, and N_Inc having been computed
1944 ldfe FR_PP_6 = [GR_ad_pp], 16 // Load PP_6
1945 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r
1946 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1947 // p10 if i_1=1, N mod 4 = 2,3
1950 ldfe FR_QQ_6 = [GR_ad_qq], 16 // Load QQ_6
1957 (p9) ldfe FR_PP_5 = [GR_ad_pp], 16 // Load PP_5 if i_1=0
1958 (p10) ldfe FR_QQ_5 = [GR_ad_qq], 16 // Load QQ_5 if i_1=1
1964 // Entry for 2^-3 < |x| < pi/4
1965 .pred.rel "mutex",p9,p10
1967 (p9) ldfe FR_C_1 = [GR_ad_pp], 16 // Load C_1 if i_1=0
1968 (p10) ldfe FR_S_1 = [GR_ad_qq], 16 // Load S_1 if i_1=1
1969 frcpa.s1 FR_r_hi, p6 = f1, FR_r // r_hi = frcpa(r)
1975 (p9) fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7 if i_1=0
1980 (p10) fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7 if i_1=1
1987 fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // rcubed = r * rsq
1994 // Entry for pi/4 <= |x| < 2^24
1995 .pred.rel "mutex",p9,p10
1997 (p9) ldfe FR_PP_1 = [GR_ad_pp], 16 // Load PP_1_hi if i_1=0
1998 (p10) ldfe FR_QQ_1 = [GR_ad_qq], 16 // Load QQ_1 if i_1=1
1999 frcpa.s1 FR_r_hi, p6 = f1, FR_r_hi // r_hi = frpca(frcpa(r))
2004 (p9) ldfe FR_PP_4 = [GR_ad_pp], 16 // Load PP_4 if i_1=0
2005 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_6 // poly = rsq*poly+PP_6 if i_1=0
2009 (p10) ldfe FR_QQ_4 = [GR_ad_qq], 16 // Load QQ_4 if i_1=1
2010 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_6 // poly = rsq*poly+QQ_6 if i_1=1
2017 (p9) fma.s1 FR_corr = FR_C_1, FR_rsq, f0 // corr = C_1 * rsq if i_1=0
2022 (p10) fma.s1 FR_corr = FR_S_1, FR_r_cubed, FR_r // corr = S_1 * r^3 + r if i_1=1
2028 (p9) ldfe FR_PP_3 = [GR_ad_pp], 16 // Load PP_3 if i_1=0
2029 fma.s1 FR_r_hi_sq = FR_r_hi, FR_r_hi, f0 // r_hi_sq = r_hi * r_hi
2033 (p10) ldfe FR_QQ_3 = [GR_ad_qq], 16 // Load QQ_3 if i_1=1
2034 fms.s1 FR_r_lo = FR_r, f1, FR_r_hi // r_lo = r - r_hi
2040 (p9) ldfe FR_PP_2 = [GR_ad_pp], 16 // Load PP_2 if i_1=0
2041 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_5 // poly = rsq*poly+PP_5 if i_1=0
2045 (p10) ldfe FR_QQ_2 = [GR_ad_qq], 16 // Load QQ_2 if i_1=1
2046 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_5 // poly = rsq*poly+QQ_5 if i_1=1
2052 (p9) ldfe FR_PP_1_lo = [GR_ad_pp], 16 // Load PP_1_lo if i_1=0
2053 (p9) fma.s1 FR_corr = FR_corr, FR_c, FR_c // corr = corr * c + c if i_1=0
2058 (p10) fnma.s1 FR_corr = FR_corr, FR_c, f0 // corr = -corr * c if i_1=1
2065 (p9) fma.s1 FR_U_lo = FR_r, FR_r_hi, FR_r_hi_sq // U_lo = r*r_hi+r_hi_sq, i_1=0
2070 (p10) fma.s1 FR_U_lo = FR_r_hi, f1, FR_r // U_lo = r_hi + r if i_1=1
2077 (p9) fma.s1 FR_U_hi = FR_r_hi, FR_r_hi_sq, f0 // U_hi = r_hi*r_hi_sq if i_1=0
2082 (p10) fma.s1 FR_U_hi = FR_QQ_1, FR_r_hi_sq, f1 // U_hi = QQ_1*r_hi_sq+1, i_1=1
2089 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_4 // poly = poly*rsq+PP_4 if i_1=0
2094 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_4 // poly = poly*rsq+QQ_4 if i_1=1
2101 (p9) fma.s1 FR_U_lo = FR_r, FR_r, FR_U_lo // U_lo = r * r + U_lo if i_1=0
2106 (p10) fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0 // U_lo = r_lo * U_lo if i_1=1
2113 (p9) fma.s1 FR_U_hi = FR_PP_1, FR_U_hi, f0 // U_hi = PP_1 * U_hi if i_1=0
2120 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_3 // poly = poly*rsq+PP_3 if i_1=0
2125 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_3 // poly = poly*rsq+QQ_3 if i_1=1
2132 (p9) fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0 // U_lo = r_lo * U_lo if i_1=0
2137 (p10) fma.s1 FR_U_lo = FR_QQ_1,FR_U_lo, f0 // U_lo = QQ_1 * U_lo if i_1=1
2144 (p9) fma.s1 FR_U_hi = FR_r, f1, FR_U_hi // U_hi = r + U_hi if i_1=0
2151 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_2 // poly = poly*rsq+PP_2 if i_1=0
2156 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_2 // poly = poly*rsq+QQ_2 if i_1=1
2163 (p9) fma.s1 FR_U_lo = FR_PP_1, FR_U_lo, f0 // U_lo = PP_1 * U_lo if i_1=0
2170 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_1_lo // poly =poly*rsq+PP1lo i_1=0
2175 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0 // poly = poly*rsq if i_1=1
2182 fma.s1 FR_V = FR_U_lo, f1, FR_corr // V = U_lo + corr
2183 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
2184 // p12 if i_0=1, N mod 4 = 1,3
2190 (p9) fma.s0 FR_inexact = FR_PP_5, FR_PP_4, f0 // Dummy op to set inexact
2195 (p10) fma.s0 FR_inexact = FR_QQ_5, FR_QQ_5, f0 // Dummy op to set inexact
2202 (p9) fma.s1 FR_poly = FR_r_cubed, FR_poly, f0 // poly = poly*r^3 if i_1=0
2207 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0 // poly = poly*rsq if i_1=1
2214 (p11) fma.s1 FR_tmp_result = f0, f1, f1// tmp_result=+1.0 if i_0=0
2219 (p12) fms.s1 FR_tmp_result = f0, f1, f1// tmp_result=-1.0 if i_0=1
2226 fma.s1 FR_V = FR_poly, f1, FR_V // V = poly + V
2231 // If i_0 = 0 Result = U_hi + V
2232 // If i_0 = 1 Result = -U_hi - V
2235 (p11) fma.s0 FR_Result = FR_tmp_result, FR_U_hi, FR_V
2240 (p12) fms.s0 FR_Result = FR_tmp_result, FR_U_hi, FR_V
2241 br.ret.sptk b0 // Exit for 2^-3 <= |r| < pi/4
2248 cmp.eq.unc p6, p7 = 0x1, GR_Sin_or_Cos
2256 (p7) fmerge.s FR_Result = FR_Input_X, FR_Input_X // If sin, result = input
2261 (p6) fma.s0 FR_Result = f1, f1, f0 // If cos, result=1.0
2262 br.ret.sptk b0 // Exit for x=0
2269 getf.exp GR_signexp_x = FR_norm_x // Get sign and exponent of x
2271 br.cond.sptk SINCOSL_COMMON // Return to common code
2279 // Path for Arg = +/- QNaN, SNaN, Inf
2280 // Invalid can be raised. SNaNs
2283 fmpy.s0 FR_Result = FR_Input_X, f0
2287 GLOBAL_IEEE754_END(cosl)
2288 // *******************************************************************
2289 // *******************************************************************
2290 // *******************************************************************
2292 // Special Code to handle very large argument case.
2293 // Call int __libm_pi_by_2_reduce(x,r,c) for |arguments| >= 2**63
2294 // The interface is custom:
2296 // (Arg or x) is in f8
2301 // Be sure to allocate at least 2 GP registers as output registers for
2302 // __libm_pi_by_2_reduce. This routine uses r49-50. These are used as
2303 // scratch registers within the __libm_pi_by_2_reduce routine (for speed).
2305 // We know also that __libm_pi_by_2_reduce preserves f10-15, f71-127. We
2306 // use this to eliminate save/restore of key fp registers in this calling
2309 // *******************************************************************
2310 // *******************************************************************
2311 // *******************************************************************
2313 LOCAL_LIBM_ENTRY(__libm_callout)
2314 SINCOSL_ARG_TOO_LARGE:
2318 .save ar.pfs,GR_SAVE_PFS
2319 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
2323 setf.exp FR_Two_to_M3 = GR_exp_2_to_m3 // Form 2^-3
2324 mov GR_SAVE_GP=gp // Save gp
2325 .save b0, GR_SAVE_B0
2326 mov GR_SAVE_B0=b0 // Save b0
2331 // Call argument reduction with x in f8
2332 // Returns with N in r8, r in f8, c in f9
2333 // Assumes f71-127 are preserved across the call
2336 setf.exp FR_Neg_Two_to_M3 = GR_exp_m2_to_m3 // Form -(2^-3)
2338 br.call.sptk b0=__libm_pi_by_2_reduce#
2342 add GR_N_Inc = GR_Sin_or_Cos,r8
2343 fcmp.lt.unc.s1 p6, p0 = FR_r, FR_Two_to_M3
2344 mov b0 = GR_SAVE_B0 // Restore return address
2348 mov gp = GR_SAVE_GP // Restore gp
2349 (p6) fcmp.gt.unc.s1 p6, p0 = FR_r, FR_Neg_Two_to_M3
2350 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
2355 (p6) br.cond.spnt SINCOSL_SMALL_R // Branch if |r|< 2^-3 for |x| >= 2^63
2356 br.cond.sptk SINCOSL_NORMAL_R // Branch if |r|>=2^-3 for |x| >= 2^63
2360 .type __libm_pi_by_2_reduce#,@function
2361 .global __libm_pi_by_2_reduce#