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.
40 // *********************************************************************
43 // 2/02/2000 (hand-optimized)
44 // 4/04/00 Unwind support added
46 // *********************************************************************
48 // Function: Combined sinl(x) and cosl(x), where
50 // sinl(x) = sine(x), for double-extended precision x values
51 // cosl(x) = cosine(x), for double-extended precision x values
53 // *********************************************************************
57 // Floating-Point Registers: f8 (Input and Return Value)
60 // General Purpose Registers:
62 // r44-r45 (Used to pass arguments to pi_by_2 reduce routine)
64 // Predicate Registers: p6-p13
66 // *********************************************************************
68 // IEEE Special Conditions:
70 // Denormal fault raised on denormal inputs
71 // Overflow exceptions do not occur
72 // Underflow exceptions raised when appropriate for sin
73 // (No specialized error handling for this routine)
74 // Inexact raised when appropriate by algorithm
85 // *********************************************************************
87 // Mathematical Description
88 // ========================
90 // The computation of FSIN and FCOS is best handled in one piece of
91 // code. The main reason is that given any argument Arg, computation
92 // of trigonometric functions first calculate N and an approximation
95 // Arg = N pi/2 + alpha, |alpha| <= pi/4.
99 // cosl( Arg ) = sinl( (N+1) pi/2 + alpha ),
101 // therefore, the code for computing sine will produce cosine as long
102 // as 1 is added to N immediately after the argument reduction
110 // Arg = M pi/2 + alpha, |alpha| <= pi/4,
112 // let I = M mod 4, or I be the two lsb of M when M is represented
113 // as 2's complement. I = [i_0 i_1]. Then
115 // sinl( Arg ) = (-1)^i_0 sinl( alpha ) if i_1 = 0,
116 // = (-1)^i_0 cosl( alpha ) if i_1 = 1.
120 // sin ((-pi/2 + alpha) = (-1) cos (alpha)
122 // sin (alpha) = sin (alpha)
124 // sin (pi/2 + alpha) = cos (alpha)
126 // sin (pi + alpha) = (-1) sin (alpha)
128 // sin ((3/2)pi + alpha) = (-1) cos (alpha)
130 // The value of alpha is obtained by argument reduction and
131 // represented by two working precision numbers r and c where
133 // alpha = r + c accurately.
135 // The reduction method is described in a previous write up.
136 // The argument reduction scheme identifies 4 cases. For Cases 2
137 // and 4, because |alpha| is small, sinl(r+c) and cosl(r+c) can be
138 // computed very easily by 2 or 3 terms of the Taylor series
139 // expansion as follows:
144 // sinl(r + c) = r + c - r^3/6 accurately
145 // cosl(r + c) = 1 - 2^(-67) accurately
150 // sinl(r + c) = r + c - r^3/6 + r^5/120 accurately
151 // cosl(r + c) = 1 - r^2/2 + r^4/24 accurately
153 // The only cases left are Cases 1 and 3 of the argument reduction
154 // procedure. These two cases will be merged since after the
155 // argument is reduced in either cases, we have the reduced argument
156 // represented as r + c and that the magnitude |r + c| is not small
157 // enough to allow the usage of a very short approximation.
159 // The required calculation is either
161 // sinl(r + c) = sinl(r) + correction, or
162 // cosl(r + c) = cosl(r) + correction.
166 // sinl(r + c) = sinl(r) + c sin'(r) + O(c^2)
167 // = sinl(r) + c cos (r) + O(c^2)
168 // = sinl(r) + c(1 - r^2/2) accurately.
171 // cosl(r + c) = cosl(r) - c sinl(r) + O(c^2)
172 // = cosl(r) - c(r - r^3/6) accurately.
174 // We therefore concentrate on accurately calculating sinl(r) and
175 // cosl(r) for a working-precision number r, |r| <= pi/4 to within
178 // The greatest challenge of this task is that the second terms of
181 // r - r^3/3! + r^r/5! - ...
185 // 1 - r^2/2! + r^4/4! - ...
187 // are not very small when |r| is close to pi/4 and the rounding
188 // errors will be a concern if simple polynomial accumulation is
189 // used. When |r| < 2^-3, however, the second terms will be small
190 // enough (6 bits or so of right shift) that a normal Horner
191 // recurrence suffices. Hence there are two cases that we consider
192 // in the accurate computation of sinl(r) and cosl(r), |r| <= pi/4.
194 // Case small_r: |r| < 2^(-3)
195 // --------------------------
197 // Since Arg = M pi/4 + r + c accurately, and M mod 4 is [i_0 i_1],
200 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
201 // = (-1)^i_0 * cosl(r + c) if i_1 = 1
203 // can be accurately approximated by
205 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c] if i_1 = 0
206 // = (-1)^i_0 * [cosl(r) - c*r] if i_1 = 1
208 // because |r| is small and thus the second terms in the correction
211 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
214 // sinl(r) = r + S_1 r^3 + S_2 r^5 + ... + S_5 r^11
215 // cosl(r) = 1 + C_1 r^2 + C_2 r^4 + ... + C_5 r^10
217 // We can make use of predicates to selectively calculate
218 // sinl(r) or cosl(r) based on i_1.
220 // Case normal_r: 2^(-3) <= |r| <= pi/4
221 // ------------------------------------
223 // This case is more likely than the previous one if one considers
224 // r to be uniformly distributed in [-pi/4 pi/4]. Again,
226 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
227 // = (-1)^i_0 * cosl(r + c) if i_1 = 1.
229 // Because |r| is now larger, we need one extra term in the
230 // correction. sinl(Arg) can be accurately approximated by
232 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c(1-r^2/2)] if i_1 = 0
233 // = (-1)^i_0 * [cosl(r) - c*r*(1 - r^2/6)] i_1 = 1.
235 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
238 // sinl(r) = r + PP_1_hi r^3 + PP_1_lo r^3 +
239 // PP_2 r^5 + ... + PP_8 r^17
241 // cosl(r) = 1 + QQ_1 r^2 + QQ_2 r^4 + ... + QQ_8 r^16
243 // where PP_1_hi is only about 16 bits long and QQ_1 is -1/2.
244 // The crux in accurate computation is to calculate
246 // r + PP_1_hi r^3 or 1 + QQ_1 r^2
248 // accurately as two pieces: U_hi and U_lo. The way to achieve this
249 // is to obtain r_hi as a 10 sig. bit number that approximates r to
250 // roughly 8 bits or so of accuracy. (One convenient way is
252 // r_hi := frcpa( frcpa( r ) ).)
256 // r + PP_1_hi r^3 = r + PP_1_hi r_hi^3 +
257 // PP_1_hi (r^3 - r_hi^3)
258 // = [r + PP_1_hi r_hi^3] +
259 // [PP_1_hi (r - r_hi)
260 // (r^2 + r_hi r + r_hi^2) ]
263 // Since r_hi is only 10 bit long and PP_1_hi is only 16 bit long,
264 // PP_1_hi * r_hi^3 is only at most 46 bit long and thus computed
265 // exactly. Furthermore, r and PP_1_hi r_hi^3 are of opposite sign
266 // and that there is no more than 8 bit shift off between r and
267 // PP_1_hi * r_hi^3. Hence the sum, U_hi, is representable and thus
268 // calculated without any error. Finally, the fact that
270 // |U_lo| <= 2^(-8) |U_hi|
272 // says that U_hi + U_lo is approximating r + PP_1_hi r^3 to roughly
273 // 8 extra bits of accuracy.
277 // 1 + QQ_1 r^2 = [1 + QQ_1 r_hi^2] +
278 // [QQ_1 (r - r_hi)(r + r_hi)]
281 // Summarizing, we calculate r_hi = frcpa( frcpa( r ) ).
285 // U_hi := r + PP_1_hi * r_hi^3
286 // U_lo := PP_1_hi * (r - r_hi) * (r^2 + r*r_hi + r_hi^2)
287 // poly := PP_1_lo r^3 + PP_2 r^5 + ... + PP_8 r^17
288 // correction := c * ( 1 + C_1 r^2 )
292 // U_hi := 1 + QQ_1 * r_hi * r_hi
293 // U_lo := QQ_1 * (r - r_hi) * (r + r_hi)
294 // poly := QQ_2 * r^4 + QQ_3 * r^6 + ... + QQ_8 r^16
295 // correction := -c * r * (1 + S_1 * r^2)
301 // V := poly + ( U_lo + correction )
303 // / U_hi + V if i_0 = 0
305 // \ (-U_hi) - V if i_0 = 1
307 // It is important that in the last step, negation of U_hi is
308 // performed prior to the subtraction which is to be performed in
309 // the user-set rounding mode.
312 // Algorithmic Description
313 // =======================
315 // The argument reduction algorithm is tightly integrated into FSIN
316 // and FCOS which share the same code. The following is complete and
317 // self-contained. The argument reduction description given
318 // previously is repeated below.
321 // Step 0. Initialization.
323 // If FSIN is invoked, set N_inc := 0; else if FCOS is invoked,
326 // Step 1. Check for exceptional and special cases.
328 // * If Arg is +-0, +-inf, NaN, NaT, go to Step 10 for special
330 // * If |Arg| < 2^24, go to Step 2 for reduction of moderate
331 // arguments. This is the most likely case.
332 // * If |Arg| < 2^63, go to Step 8 for pre-reduction of large
334 // * If |Arg| >= 2^63, go to Step 10 for special handling.
336 // Step 2. Reduction of moderate arguments.
338 // If |Arg| < pi/4 ...quick branch
339 // N_fix := N_inc (integer)
342 // Branch to Step 4, Case_1_complete
343 // Else ...cf. argument reduction
344 // N := Arg * two_by_PI (fp)
345 // N_fix := fcvt.fx( N ) (int)
346 // N := fcvt.xf( N_fix )
347 // N_fix := N_fix + N_inc
348 // s := Arg - N * P_1 (first piece of pi/2)
349 // w := -N * P_2 (second piece of pi/2)
352 // go to Step 3, Case_1_reduce
354 // go to Step 7, Case_2_reduce
358 // Step 3. Case_1_reduce.
361 // c := (s - r) + w ...observe order
363 // Step 4. Case_1_complete
365 // ...At this point, the reduced argument alpha is
366 // ...accurately represented as r + c.
367 // If |r| < 2^(-3), go to Step 6, small_r.
371 // Let [i_0 i_1] by the 2 lsb of N_fix.
373 // r_hi := frcpa( frcpa( r ) )
377 // poly := r*FR_rsq*(PP_1_lo + FR_rsq*(PP_2 + ... FR_rsq*PP_8))
378 // U_hi := r + PP_1_hi*r_hi*r_hi*r_hi ...any order
379 // U_lo := PP_1_hi*r_lo*(r*r + r*r_hi + r_hi*r_hi)
380 // correction := c + c*C_1*FR_rsq ...any order
382 // poly := FR_rsq*FR_rsq*(QQ_2 + FR_rsq*(QQ_3 + ... + FR_rsq*QQ_8))
383 // U_hi := 1 + QQ_1 * r_hi * r_hi ...any order
384 // U_lo := QQ_1 * r_lo * (r + r_hi)
385 // correction := -c*(r + S_1*FR_rsq*r) ...any order
388 // V := poly + (U_lo + correction) ...observe order
390 // result := (i_0 == 0? 1.0 : -1.0)
392 // Last instruction in user-set rounding mode
394 // result := (i_0 == 0? result*U_hi + V :
401 // ...Use flush to zero mode without causing exception
402 // Let [i_0 i_1] be the two lsb of N_fix.
407 // z := FR_rsq*FR_rsq; z := FR_rsq*z *r
408 // poly_lo := S_3 + FR_rsq*(S_4 + FR_rsq*S_5)
409 // poly_hi := r*FR_rsq*(S_1 + FR_rsq*S_2)
413 // z := FR_rsq*FR_rsq; z := FR_rsq*z
414 // poly_lo := C_3 + FR_rsq*(C_4 + FR_rsq*C_5)
415 // poly_hi := FR_rsq*(C_1 + FR_rsq*C_2)
416 // correction := -c*r
420 // poly := poly_hi + (z * poly_lo + correction)
422 // If i_0 = 1, result := -result
424 // Last operation. Perform in user-set rounding mode
426 // result := (i_0 == 0? result + poly :
430 // Step 7. Case_2_reduce.
432 // ...Refer to the write up for argument reduction for
433 // ...rationale. The reduction algorithm below is taken from
434 // ...argument reduction description and integrated this.
437 // U_1 := N*P_2 + w ...FMA
438 // U_2 := (N*P_2 - U_1) + w ...2 FMA
439 // ...U_1 + U_2 is N*(P_2+P_3) accurately
442 // c := ( (s - r) - U_1 ) - U_2
444 // ...The mathematical sum r + c approximates the reduced
445 // ...argument accurately. Note that although compared to
446 // ...Case 1, this case requires much more work to reduce
447 // ...the argument, the subsequent calculation needed for
448 // ...any of the trigonometric function is very little because
449 // ...|alpha| < 1.01*2^(-33) and thus two terms of the
450 // ...Taylor series expansion suffices.
453 // poly := c + S_1 * r * r * r ...any order
460 // If i_0 = 1, result := -result
462 // Last operation. Perform in user-set rounding mode
464 // result := (i_0 == 0? result + poly :
470 // Step 8. Pre-reduction of large arguments.
472 // ...Again, the following reduction procedure was described
473 // ...in the separate write up for argument reduction, which
474 // ...is tightly integrated here.
476 // N_0 := Arg * Inv_P_0
477 // N_0_fix := fcvt.fx( N_0 )
478 // N_0 := fcvt.xf( N_0_fix)
480 // Arg' := Arg - N_0 * P_0
482 // N := Arg' * two_by_PI
483 // N_fix := fcvt.fx( N )
484 // N := fcvt.xf( N_fix )
485 // N_fix := N_fix + N_inc
487 // s := Arg' - N * P_1
496 // Step 9. Case_4_reduce.
498 // ...first obtain N_0*d_1 and -N*P_2 accurately
499 // U_hi := N_0 * d_1 V_hi := -N*P_2
500 // U_lo := N_0 * d_1 - U_hi V_lo := -N*P_2 - U_hi ...FMAs
502 // ...compute the contribution from N_0*d_1 and -N*P_3
505 // t := U_lo + V_lo + w ...any order
507 // ...at this point, the mathematical value
508 // ...s + U_hi + V_hi + t approximates the true reduced argument
509 // ...accurately. Just need to compute this accurately.
511 // ...Calculate U_hi + V_hi accurately:
513 // if |U_hi| >= |V_hi| then
514 // a := (U_hi - A) + V_hi
516 // a := (V_hi - A) + U_hi
518 // ...order in computing "a" must be observed. This branch is
519 // ...best implemented by predicates.
520 // ...A + a is U_hi + V_hi accurately. Moreover, "a" is
521 // ...much smaller than A: |a| <= (1/2)ulp(A).
523 // ...Just need to calculate s + A + a + t
524 // C_hi := s + A t := t + a
525 // C_lo := (s - C_hi) + A
528 // ...Final steps for reduction
530 // c := (C_hi - r) + C_lo
532 // ...At this point, we have r and c
533 // ...And all we need is a couple of terms of the corresponding
537 // poly := c + r*FR_rsq*(S_1 + FR_rsq*S_2)
540 // poly := FR_rsq*(C_1 + FR_rsq*C_2)
544 // If i_0 = 1, result := -result
546 // Last operation. Perform in user-set rounding mode
548 // result := (i_0 == 0? result + poly :
552 // Large Arguments: For arguments above 2**63, a Payne-Hanek
553 // style argument reduction is used and pi_by_2 reduce is called.
556 #include "libm_support.h"
566 ASM_TYPE_DIRECTIVE(FSINCOSL_CONSTANTS,@object)
567 data4 0x4B800000, 0xCB800000, 0x00000000,0x00000000 // two**24, -two**24
568 data4 0x4E44152A, 0xA2F9836E, 0x00003FFE,0x00000000 // Inv_pi_by_2
569 data4 0xCE81B9F1, 0xC84D32B0, 0x00004016,0x00000000 // P_0
570 data4 0x2168C235, 0xC90FDAA2, 0x00003FFF,0x00000000 // P_1
571 data4 0xFC8F8CBB, 0xECE675D1, 0x0000BFBD,0x00000000 // P_2
572 data4 0xACC19C60, 0xB7ED8FBB, 0x0000BF7C,0x00000000 // P_3
573 data4 0x5F000000, 0xDF000000, 0x00000000,0x00000000 // two_to_63, -two_to_63
574 data4 0x6EC6B45A, 0xA397E504, 0x00003FE7,0x00000000 // Inv_P_0
575 data4 0xDBD171A1, 0x8D848E89, 0x0000BFBF,0x00000000 // d_1
576 data4 0x18A66F8E, 0xD5394C36, 0x0000BF7C,0x00000000 // d_2
577 data4 0x2168C234, 0xC90FDAA2, 0x00003FFE,0x00000000 // pi_by_4
578 data4 0x2168C234, 0xC90FDAA2, 0x0000BFFE,0x00000000 // neg_pi_by_4
579 data4 0x3E000000, 0xBE000000, 0x00000000,0x00000000 // two**-3, -two**-3
580 data4 0x2F000000, 0xAF000000, 0x9E000000,0x00000000 // two**-33, -two**-33, -two**-67
581 data4 0xA21C0BC9, 0xCC8ABEBC, 0x00003FCE,0x00000000 // PP_8
582 data4 0x720221DA, 0xD7468A05, 0x0000BFD6,0x00000000 // PP_7
583 data4 0x640AD517, 0xB092382F, 0x00003FDE,0x00000000 // PP_6
584 data4 0xD1EB75A4, 0xD7322B47, 0x0000BFE5,0x00000000 // PP_5
585 data4 0xFFFFFFFE, 0xFFFFFFFF, 0x0000BFFD,0x00000000 // C_1
586 data4 0x00000000, 0xAAAA0000, 0x0000BFFC,0x00000000 // PP_1_hi
587 data4 0xBAF69EEA, 0xB8EF1D2A, 0x00003FEC,0x00000000 // PP_4
588 data4 0x0D03BB69, 0xD00D00D0, 0x0000BFF2,0x00000000 // PP_3
589 data4 0x88888962, 0x88888888, 0x00003FF8,0x00000000 // PP_2
590 data4 0xAAAB0000, 0xAAAAAAAA, 0x0000BFEC,0x00000000 // PP_1_lo
591 data4 0xC2B0FE52, 0xD56232EF, 0x00003FD2,0x00000000 // QQ_8
592 data4 0x2B48DCA6, 0xC9C99ABA, 0x0000BFDA,0x00000000 // QQ_7
593 data4 0x9C716658, 0x8F76C650, 0x00003FE2,0x00000000 // QQ_6
594 data4 0xFDA8D0FC, 0x93F27DBA, 0x0000BFE9,0x00000000 // QQ_5
595 data4 0xAAAAAAAA, 0xAAAAAAAA, 0x0000BFFC,0x00000000 // S_1
596 data4 0x00000000, 0x80000000, 0x0000BFFE,0x00000000 // QQ_1
597 data4 0x0C6E5041, 0xD00D00D0, 0x00003FEF,0x00000000 // QQ_4
598 data4 0x0B607F60, 0xB60B60B6, 0x0000BFF5,0x00000000 // QQ_3
599 data4 0xAAAAAA9B, 0xAAAAAAAA, 0x00003FFA,0x00000000 // QQ_2
600 data4 0xFFFFFFFE, 0xFFFFFFFF, 0x0000BFFD,0x00000000 // C_1
601 data4 0xAAAA719F, 0xAAAAAAAA, 0x00003FFA,0x00000000 // C_2
602 data4 0x0356F994, 0xB60B60B6, 0x0000BFF5,0x00000000 // C_3
603 data4 0xB2385EA9, 0xD00CFFD5, 0x00003FEF,0x00000000 // C_4
604 data4 0x292A14CD, 0x93E4BD18, 0x0000BFE9,0x00000000 // C_5
605 data4 0xAAAAAAAA, 0xAAAAAAAA, 0x0000BFFC,0x00000000 // S_1
606 data4 0x888868DB, 0x88888888, 0x00003FF8,0x00000000 // S_2
607 data4 0x055EFD4B, 0xD00D00D0, 0x0000BFF2,0x00000000 // S_3
608 data4 0x839730B9, 0xB8EF1C5D, 0x00003FEC,0x00000000 // S_4
609 data4 0xE5B3F492, 0xD71EA3A4, 0x0000BFE5,0x00000000 // S_5
610 data4 0x38800000, 0xB8800000, 0x00000000 // two**-14, -two**-14
611 ASM_SIZE_DIRECTIVE(FSINCOSL_CONSTANTS)
614 FR_Neg_Two_to_M3 = f32
620 FR_Neg_Two_to_24 = f36
622 FR_Neg_Two_to_M14 = f37
623 FR_Neg_Two_to_M33 = f38
624 FR_Neg_Two_to_M67 = f39
688 FR_Neg_Two_to_63 = f94
702 // Added for unwind support
727 alloc GR_Table_Base = ar.pfs,0,12,2,0
728 (p0) movl GR_Sin_or_Cos = 0x0 ;;
733 (p0) addl GR_Table_Base = @ltoff(FSINCOSL_CONSTANTS#), gp
739 ld8 GR_Table_Base = [GR_Table_Base]
741 (p0) br.cond.sptk L(SINCOSL_CONTINUE) ;;
747 ASM_SIZE_DIRECTIVE(sinl#)
757 alloc GR_Table_Base= ar.pfs,0,12,2,0
758 (p0) movl GR_Sin_or_Cos = 0x1 ;;
764 (p0) addl GR_Table_Base = @ltoff(FSINCOSL_CONSTANTS#), gp
770 ld8 GR_Table_Base = [GR_Table_Base]
779 // Load Table Address
784 (p0) add GR_Table_Base1 = 96, GR_Table_Base
785 (p0) ldfs FR_Two_to_24 = [GR_Table_Base], 4
786 // GR_Sin_or_Cos denotes
792 // Load 2**24, load 2**63.
794 (p0) ldfs FR_Neg_Two_to_24 = [GR_Table_Base], 12
798 (p0) ldfs FR_Two_to_63 = [GR_Table_Base1], 4
800 // Check for unnormals - unsupported operands. We do not want
801 // to generate denormal exception
802 // Check for NatVals, QNaNs, SNaNs, +/-Infs
803 // Check for EM unsupporteds
806 (p0) fclass.m.unc p6, p0 = FR_Input_X, 0x1E3
811 (p0) ldfs FR_Neg_Two_to_63 = [GR_Table_Base1], 12
812 (p0) fclass.nm.unc p8, p0 = FR_Input_X, 0x1FF
816 (p0) fclass.m.unc p10, p0 = FR_Input_X, 0x007
817 (p6) br.cond.spnt L(SINCOSL_SPECIAL) ;;
822 (p8) br.cond.spnt L(SINCOSL_SPECIAL) ;;
828 // Branch if +/- NaN, Inf.
829 // Load -2**24, load -2**63.
831 (p10) br.cond.spnt L(SINCOSL_ZERO) ;;
834 (p0) ldfe FR_Inv_pi_by_2 = [GR_Table_Base], 16
835 (p0) ldfe FR_Inv_P_0 = [GR_Table_Base1], 16
839 (p0) ldfe FR_d_1 = [GR_Table_Base1], 16
841 // Raise possible denormal operand flag with useful fcmp
843 // Load Inv_P_0 for pre-reduction
846 (p0) ldfe FR_P_0 = [GR_Table_Base], 16
850 (p0) ldfe FR_d_2 = [GR_Table_Base1], 16
857 (p0) ldfe FR_P_1 = [GR_Table_Base], 16
866 (p0) ldfe FR_P_2 = [GR_Table_Base], 16
867 (p0) fcmp.le.unc.s1 p7, p8 = FR_Input_X, FR_Neg_Two_to_24
871 (p0) ldfe FR_P_3 = [GR_Table_Base], 16
877 (p8) fcmp.ge.s1 p7, p0 = FR_Input_X, FR_Two_to_24
881 (p0) ldfe FR_Pi_by_4 = [GR_Table_Base1], 16
883 // Branch if +/- zero.
884 // Decide about the paths to take:
885 // If -2**24 < FR_Input_X < 2**24 - CASE 1 OR 2
886 // OTHERWISE - CASE 3 OR 4
888 (p0) fcmp.le.unc.s0 p10, p11 = FR_Input_X, FR_Neg_Two_to_63
892 (p0) ldfe FR_Neg_Pi_by_4 = [GR_Table_Base1], 16 ;;
893 (p0) ldfs FR_Two_to_M3 = [GR_Table_Base1], 4
898 (p11) fcmp.ge.s1 p10, p0 = FR_Input_X, FR_Two_to_63
902 (p0) ldfs FR_Neg_Two_to_M3 = [GR_Table_Base1], 12
912 (p10) br.cond.spnt L(SINCOSL_ARG_TOO_LARGE) ;;
918 // Branch out if x >= 2**63. Use Payne-Hanek Reduction
920 (p7) br.cond.spnt L(SINCOSL_LARGER_ARG) ;;
925 // Branch if Arg <= -2**24 or Arg >= 2**24 and use pre-reduction.
927 (p0) fma.s1 FR_N_float = FR_Input_X, FR_Inv_pi_by_2, f0
932 (p0) fcmp.lt.unc.s1 p6, p7 = FR_Input_X, FR_Pi_by_4
938 // Select the case when |Arg| < pi/4
939 // Else Select the case when |Arg| >= pi/4
941 (p0) fcvt.fx.s1 FR_N_fix = FR_N_float
948 // Check if Arg < pi/4
950 (p6) fcmp.gt.s1 p6, p7 = FR_Input_X, FR_Neg_Pi_by_4
954 // Case 2: Convert integer N_fix back to normalized floating-point value.
955 // Case 1: p8 is only affected when p6 is set
958 (p7) ldfs FR_Two_to_M33 = [GR_Table_Base1], 4
960 // Grab the integer part of N and call it N_fix
962 (p6) fmerge.se FR_r = FR_Input_X, FR_Input_X
963 // If |x| < pi/4, r = x and c = 0
964 // lf |x| < pi/4, is x < 2**(-3).
967 (p6) mov GR_N_Inc = GR_Sin_or_Cos ;;
971 (p7) ldfs FR_Neg_Two_to_M33 = [GR_Table_Base1], 4
972 (p6) fmerge.se FR_c = f0, f0
976 (p6) fcmp.lt.unc.s1 p8, p9 = FR_Input_X, FR_Two_to_M3
982 // lf |x| < pi/4, is -2**(-3)< x < 2**(-3) - set p8.
984 // Create the right N for |x| < pi/4 and otherwise
985 // Case 2: Place integer part of N in GP register
987 (p7) fcvt.xf FR_N_float = FR_N_fix
992 (p7) getf.sig GR_N_Inc = FR_N_fix
993 (p8) fcmp.gt.s1 p8, p0 = FR_Input_X, FR_Neg_Two_to_M3 ;;
999 // Load 2**(-33), -2**(-33)
1001 (p8) br.cond.spnt L(SINCOSL_SMALL_R) ;;
1006 (p6) br.cond.sptk L(SINCOSL_NORMAL_R) ;;
1009 // if |x| < pi/4, branch based on |x| < 2**(-3) or otherwise.
1012 // In this branch, |x| >= pi/4.
1015 (p0) ldfs FR_Neg_Two_to_M67 = [GR_Table_Base1], 8
1019 (p0) fnma.s1 FR_s = FR_N_float, FR_P_1, FR_Input_X
1022 // s = -N * P_1 + Arg
1024 (p0) add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos
1028 (p0) fma.s1 FR_w = FR_N_float, FR_P_2, f0
1034 // Adjust N_fix by N_inc to determine whether sine or
1035 // cosine is being calculated
1037 (p0) fcmp.lt.unc.s1 p7, p6 = FR_s, FR_Two_to_M33
1042 (p7) fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33
1047 // Remember x >= pi/4.
1048 // Is s <= -2**(-33) or s >= 2**(-33) (p6)
1049 // or -2**(-33) < s < 2**(-33) (p7)
1050 (p6) fms.s1 FR_r = FR_s, f1, FR_w
1055 (p7) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1060 (p7) fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1065 (p6) fms.s1 FR_c = FR_s, f1, FR_r
1071 // For big s: r = s - w: No futher reduction is necessary
1072 // For small s: w = N * P_3 (change sign) More reduction
1074 (p6) fcmp.lt.unc.s1 p8, p9 = FR_r, FR_Two_to_M3
1079 (p8) fcmp.gt.s1 p8, p9 = FR_r, FR_Neg_Two_to_M3
1084 (p7) fms.s1 FR_r = FR_s, f1, FR_U_1
1090 // For big s: Is |r| < 2**(-3)?
1091 // For big s: c = S - r
1092 // For small s: U_1 = N * P_2 + w
1094 // If p8 is set, prepare to branch to Small_R.
1095 // If p9 is set, prepare to branch to Normal_R.
1096 // For big s, r is complete here.
1098 (p6) fms.s1 FR_c = FR_c, f1, FR_w
1100 // For big s: c = c + w (w has not been negated.)
1101 // For small s: r = S - U_1
1103 (p8) br.cond.spnt L(SINCOSL_SMALL_R) ;;
1108 (p9) br.cond.sptk L(SINCOSL_NORMAL_R) ;;
1111 (p7) add GR_Table_Base1 = 224, GR_Table_Base1
1113 // Branch to SINCOSL_SMALL_R or SINCOSL_NORMAL_R
1115 (p7) fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1121 (p7) extr.u GR_i_1 = GR_N_Inc, 0, 1 ;;
1126 // Get [i_0,i_1] - two lsb of N_fix_gr.
1127 // Do dummy fmpy so inexact is always set.
1129 (p7) cmp.eq.unc p9, p10 = 0x0, GR_i_1
1130 (p7) extr.u GR_i_0 = GR_N_Inc, 1, 1 ;;
1133 // For small s: U_2 = N * P_2 - U_1
1134 // S_1 stored constant - grab the one stored with the
1138 (p7) ldfe FR_S_1 = [GR_Table_Base1], 16
1140 // Check if i_1 and i_0 != 0
1142 (p10) fma.s1 FR_poly = f0, f1, FR_Neg_Two_to_M67
1143 (p7) cmp.eq.unc p11, p12 = 0x0, GR_i_0 ;;
1147 (p7) fms.s1 FR_s = FR_s, f1, FR_r
1157 (p7) fma.s1 FR_rsq = FR_r, FR_r, f0
1162 (p7) fma.s1 FR_U_2 = FR_U_2, f1, FR_w
1167 (p7) fmerge.se FR_Input_X = FR_r, FR_r
1172 (p10) fma.s1 FR_Input_X = f0, f1, f1
1179 // Save r as the result.
1181 (p7) fms.s1 FR_c = FR_s, f1, FR_U_1
1187 // if ( i_1 ==0) poly = c + S_1*r*r*r
1190 (p12) fnma.s1 FR_Input_X = FR_Input_X, f1, f0
1195 (p7) fma.s1 FR_r = FR_S_1, FR_r, f0
1200 (p7) fma.s0 FR_S_1 = FR_S_1, FR_S_1, f0
1206 // If i_1 != 0, poly = 2**(-67)
1208 (p7) fms.s1 FR_c = FR_c, f1, FR_U_2
1216 (p9) fma.s1 FR_poly = FR_r, FR_rsq, FR_c
1222 // i_0 != 0, so Result = -Result
1224 (p11) fma.s0 FR_Input_X = FR_Input_X, f1, FR_poly
1229 (p12) fms.s0 FR_Input_X = FR_Input_X, f1, FR_poly
1231 // if (i_0 == 0), Result = Result + poly
1232 // else Result = Result - poly
1234 (p0) br.ret.sptk b0 ;;
1236 L(SINCOSL_LARGER_ARG):
1239 (p0) fma.s1 FR_N_0 = FR_Input_X, FR_Inv_P_0, f0
1244 // This path for argument > 2*24
1245 // Adjust table_ptr1 to beginning of table.
1250 (p0) addl GR_Table_Base = @ltoff(FSINCOSL_CONSTANTS#), gp
1256 ld8 GR_Table_Base = [GR_Table_Base]
1265 // N_0 = Arg * Inv_P_0
1268 (p0) add GR_Table_Base = 688, GR_Table_Base ;;
1269 (p0) ldfs FR_Two_to_M14 = [GR_Table_Base], 4
1273 (p0) ldfs FR_Neg_Two_to_M14 = [GR_Table_Base], 0
1280 // Load values 2**(-14) and -2**(-14)
1282 (p0) fcvt.fx.s1 FR_N_0_fix = FR_N_0
1288 // N_0_fix = integer part of N_0
1290 (p0) fcvt.xf FR_N_0 = FR_N_0_fix
1296 // Make N_0 the integer part
1298 (p0) fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X
1303 (p0) fma.s1 FR_w = FR_N_0, FR_d_1, f0
1309 // Arg' = -N_0 * P_0 + Arg
1312 (p0) fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0
1320 (p0) fcvt.fx.s1 FR_N_fix = FR_N_float
1326 // N_fix is the integer part
1328 (p0) fcvt.xf FR_N_float = FR_N_fix
1332 (p0) getf.sig GR_N_Inc = FR_N_fix
1339 (p0) add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos ;;
1344 // N is the integer part of the reduced-reduced argument.
1345 // Put the integer in a GP register
1347 (p0) fnma.s1 FR_s = FR_N_float, FR_P_1, FR_ArgPrime
1352 (p0) fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w
1358 // s = -N*P_1 + Arg'
1360 // N_fix_gr = N_fix_gr + N_inc
1362 (p0) fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1367 (p9) fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14
1373 // For |s| > 2**(-14) r = S + w (r complete)
1374 // Else U_hi = N_0 * d_1
1376 (p9) fma.s1 FR_V_hi = FR_N_float, FR_P_2, f0
1381 (p9) fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1387 // Either S <= -2**(-14) or S >= 2**(-14)
1388 // or -2**(-14) < s < 2**(-14)
1390 (p8) fma.s1 FR_r = FR_s, f1, FR_w
1395 (p9) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1401 // We need abs of both U_hi and V_hi - don't
1402 // worry about switched sign of V_hi.
1404 (p9) fms.s1 FR_A = FR_U_hi, f1, FR_V_hi
1410 // Big s: finish up c = (S - r) + w (c complete)
1411 // Case 4: A = U_hi + V_hi
1412 // Note: Worry about switched sign of V_hi, so subtract instead of add.
1414 (p9) fnma.s1 FR_V_lo = FR_N_float, FR_P_2, FR_V_hi
1420 (p9) fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi
1424 (p9) fmerge.s FR_V_hiabs = f0, FR_V_hi
1429 // For big s: c = S - r
1430 // For small s do more work: U_lo = N_0 * d_1 - U_hi
1432 (p9) fmerge.s FR_U_hiabs = f0, FR_U_hi
1438 // For big s: Is |r| < 2**(-3)
1439 // For big s: if p12 set, prepare to branch to Small_R.
1440 // For big s: If p13 set, prepare to branch to Normal_R.
1442 (p8) fms.s1 FR_c = FR_s, f1, FR_r
1448 // For small S: V_hi = N * P_2
1450 // Note the product does not include the (-) as in the writeup
1451 // so (-) missing for V_hi and w.
1453 (p8) fcmp.lt.unc.s1 p12, p13 = FR_r, FR_Two_to_M3
1458 (p12) fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1463 (p8) fma.s1 FR_c = FR_c, f1, FR_w
1468 (p9) fms.s1 FR_w = FR_N_0, FR_d_2, FR_w
1469 (p12) br.cond.spnt L(SINCOSL_SMALL_R) ;;
1474 (p13) br.cond.sptk L(SINCOSL_NORMAL_R) ;;
1479 // Big s: Vector off when |r| < 2**(-3). Recall that p8 will be true.
1480 // The remaining stuff is for Case 4.
1481 // Small s: V_lo = N * P_2 + U_hi (U_hi is in place of V_hi in writeup)
1482 // Note: the (-) is still missing for V_lo.
1483 // Small s: w = w + N_0 * d_2
1484 // Note: the (-) is now incorporated in w.
1486 (p9) fcmp.ge.unc.s1 p10, p11 = FR_U_hiabs, FR_V_hiabs
1487 (p0) extr.u GR_i_1 = GR_N_Inc, 0, 1
1494 (p9) fma.s1 FR_t = FR_U_lo, f1, FR_V_lo
1495 (p0) extr.u GR_i_0 = GR_N_Inc, 1, 1 ;;
1503 (p10) fms.s1 FR_a = FR_U_hi, f1, FR_A
1508 (p11) fma.s1 FR_a = FR_V_hi, f1, FR_A
1515 (p0) addl GR_Table_Base = @ltoff(FSINCOSL_CONSTANTS#), gp
1521 ld8 GR_Table_Base = [GR_Table_Base]
1529 (p0) add GR_Table_Base = 528, GR_Table_Base
1531 // Is U_hiabs >= V_hiabs?
1533 (p9) fma.s1 FR_C_hi = FR_s, f1, FR_A
1537 (p0) ldfe FR_C_1 = [GR_Table_Base], 16 ;;
1538 (p0) ldfe FR_C_2 = [GR_Table_Base], 64
1542 // c = c + C_lo finished.
1546 (p0) ldfe FR_S_1 = [GR_Table_Base], 16
1550 (p0) fma.s1 FR_t = FR_t, f1, FR_w
1554 // r and c have been computed.
1555 // Make sure ftz mode is set - should be automatic when using wre
1557 // Get [i_0,i_1] - two lsb of N_fix.
1561 (p0) ldfe FR_S_2 = [GR_Table_Base], 64
1565 (p10) fms.s1 FR_a = FR_a, f1, FR_V_hi
1566 (p0) cmp.eq.unc p9, p10 = 0x0, GR_i_0 ;;
1571 // For larger u than v: a = U_hi - A
1572 // Else a = V_hi - A (do an add to account for missing (-) on V_hi
1574 (p0) fms.s1 FR_C_lo = FR_s, f1, FR_C_hi
1579 (p11) fms.s1 FR_a = FR_U_hi, f1, FR_a
1580 (p0) cmp.eq.unc p11, p12 = 0x0, GR_i_1 ;;
1585 // If u > v: a = (U_hi - A) + V_hi
1586 // Else a = (V_hi - A) + U_hi
1587 // In each case account for negative missing from V_hi.
1589 (p0) fma.s1 FR_C_lo = FR_C_lo, f1, FR_A
1595 // C_lo = (S - C_hi) + A
1597 (p0) fma.s1 FR_t = FR_t, f1, FR_a
1605 (p0) fma.s1 FR_C_lo = FR_C_lo, f1, FR_t
1612 // Adjust Table_Base to beginning of table
1614 (p0) fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1622 (p0) fma.s1 FR_rsq = FR_r, FR_r, f0
1628 // Table_Base points to C_1
1631 (p0) fms.s1 FR_c = FR_C_hi, f1, FR_r
1637 // if i_1 ==0: poly = S_2 * FR_rsq + S_1
1638 // else poly = C_2 * FR_rsq + C_1
1640 (p11) fma.s1 FR_Input_X = f0, f1, FR_r
1645 (p12) fma.s1 FR_Input_X = f0, f1, f1
1651 // Compute r_cube = FR_rsq * r
1653 (p11) fma.s1 FR_poly = FR_rsq, FR_S_2, FR_S_1
1658 (p12) fma.s1 FR_poly = FR_rsq, FR_C_2, FR_C_1
1664 // Compute FR_rsq = r * r
1667 (p0) fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1676 (p0) fma.s1 FR_c = FR_c, f1, FR_C_lo
1682 // if i_1 ==0: poly = r_cube * poly + c
1683 // else poly = FR_rsq * poly
1685 (p10) fms.s1 FR_Input_X = f0, f1, FR_Input_X
1691 // if i_1 ==0: Result = r
1692 // else Result = 1.0
1694 (p11) fma.s1 FR_poly = FR_r_cubed, FR_poly, FR_c
1699 (p12) fma.s1 FR_poly = FR_rsq, FR_poly, f0
1705 // if i_0 !=0: Result = -Result
1707 (p9) fma.s0 FR_Input_X = FR_Input_X, f1, FR_poly
1712 (p10) fms.s0 FR_Input_X = FR_Input_X, f1, FR_poly
1714 // if i_0 == 0: Result = Result + poly
1715 // else Result = Result - poly
1717 (p0) br.ret.sptk b0 ;;
1722 (p0) extr.u GR_i_1 = GR_N_Inc, 0, 1 ;;
1725 // Compare both i_1 and i_0 with 0.
1726 // if i_1 == 0, set p9.
1727 // if i_0 == 0, set p11.
1729 (p0) cmp.eq.unc p9, p10 = 0x0, GR_i_1 ;;
1733 (p0) fma.s1 FR_rsq = FR_r, FR_r, f0
1734 (p0) extr.u GR_i_0 = GR_N_Inc, 1, 1 ;;
1741 (p10) fnma.s1 FR_c = FR_c, FR_r, f0
1742 (p0) cmp.eq.unc p11, p12 = 0x0, GR_i_0
1746 // ******************************************************************
1747 // ******************************************************************
1748 // ******************************************************************
1749 // r and c have been computed.
1750 // We know whether this is the sine or cosine routine.
1751 // Make sure ftz mode is set - should be automatic when using wre
1754 // Set table_ptr1 to beginning of constant table.
1755 // Get [i_0,i_1] - two lsb of N_fix_gr.
1760 (p0) addl GR_Table_Base = @ltoff(FSINCOSL_CONSTANTS#), gp
1766 ld8 GR_Table_Base = [GR_Table_Base]
1774 // Set table_ptr1 to point to S_5.
1775 // Set table_ptr1 to point to C_5.
1776 // Compute FR_rsq = r * r
1779 (p9) add GR_Table_Base = 672, GR_Table_Base
1780 (p10) fmerge.s FR_r = f1, f1
1781 (p10) add GR_Table_Base = 592, GR_Table_Base ;;
1784 // Set table_ptr1 to point to S_5.
1785 // Set table_ptr1 to point to C_5.
1788 (p9) ldfe FR_S_5 = [GR_Table_Base], -16 ;;
1790 // if (i_1 == 0) load S_5
1791 // if (i_1 != 0) load C_5
1793 (p9) ldfe FR_S_4 = [GR_Table_Base], -16
1797 (p10) ldfe FR_C_5 = [GR_Table_Base], -16
1799 // Z = FR_rsq * FR_rsq
1801 (p9) ldfe FR_S_3 = [GR_Table_Base], -16
1803 // Compute FR_rsq = r * r
1804 // if (i_1 == 0) load S_4
1805 // if (i_1 != 0) load C_4
1807 (p0) fma.s1 FR_Z = FR_rsq, FR_rsq, f0 ;;
1810 // if (i_1 == 0) load S_3
1811 // if (i_1 != 0) load C_3
1814 (p9) ldfe FR_S_2 = [GR_Table_Base], -16 ;;
1816 // if (i_1 == 0) load S_2
1817 // if (i_1 != 0) load C_2
1819 (p9) ldfe FR_S_1 = [GR_Table_Base], -16
1823 (p10) ldfe FR_C_4 = [GR_Table_Base], -16 ;;
1824 (p10) ldfe FR_C_3 = [GR_Table_Base], -16
1828 (p10) ldfe FR_C_2 = [GR_Table_Base], -16 ;;
1829 (p10) ldfe FR_C_1 = [GR_Table_Base], -16
1836 // poly_lo = FR_rsq * C_5 + C_4
1837 // poly_hi = FR_rsq * C_2 + C_1
1839 (p9) fma.s1 FR_Z = FR_Z, FR_r, f0
1845 // if (i_1 == 0) load S_1
1846 // if (i_1 != 0) load C_1
1848 (p9) fma.s1 FR_poly_lo = FR_rsq, FR_S_5, FR_S_4
1855 // dummy fmpy's to flag inexact.
1857 (p9) fma.s0 FR_S_4 = FR_S_4, FR_S_4, f0
1863 // poly_lo = FR_rsq * poly_lo + C_3
1864 // poly_hi = FR_rsq * poly_hi
1866 (p0) fma.s1 FR_Z = FR_Z, FR_rsq, f0
1871 (p9) fma.s1 FR_poly_hi = FR_rsq, FR_S_2, FR_S_1
1878 // poly_lo = FR_rsq * S_5 + S_4
1879 // poly_hi = FR_rsq * S_2 + S_1
1881 (p10) fma.s1 FR_poly_lo = FR_rsq, FR_C_5, FR_C_4
1888 // Z = Z * r for only one of the small r cases - not there
1889 // in original implementation notes.
1891 (p9) fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_S_3
1896 (p10) fma.s1 FR_poly_hi = FR_rsq, FR_C_2, FR_C_1
1901 (p10) fma.s0 FR_C_1 = FR_C_1, FR_C_1, f0
1906 (p9) fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0
1912 // poly_lo = FR_rsq * poly_lo + S_3
1913 // poly_hi = FR_rsq * poly_hi
1915 (p10) fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_C_3
1920 (p10) fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0
1926 // if (i_1 == 0): dummy fmpy's to flag inexact
1929 (p9) fma.s1 FR_poly_hi = FR_r, FR_poly_hi, f0
1935 // poly_hi = r * poly_hi
1937 (p0) fma.s1 FR_poly = FR_Z, FR_poly_lo, FR_c
1942 (p12) fms.s1 FR_r = f0, f1, FR_r
1948 // poly_hi = Z * poly_lo + c
1949 // if i_0 == 1: r = -r
1951 (p0) fma.s1 FR_poly = FR_poly, f1, FR_poly_hi
1956 (p12) fms.s0 FR_Input_X = FR_r, f1, FR_poly
1962 // poly = poly + poly_hi
1964 (p11) fma.s0 FR_Input_X = FR_r, f1, FR_poly
1966 // if (i_0 == 0) Result = r + poly
1967 // if (i_0 != 0) Result = r - poly
1969 (p0) br.ret.sptk b0 ;;
1971 L(SINCOSL_NORMAL_R):
1974 (p0) extr.u GR_i_1 = GR_N_Inc, 0, 1 ;;
1976 // Set table_ptr1 and table_ptr2 to base address of
1978 (p0) cmp.eq.unc p9, p10 = 0x0, GR_i_1 ;;
1982 (p0) fma.s1 FR_rsq = FR_r, FR_r, f0
1983 (p0) extr.u GR_i_0 = GR_N_Inc, 1, 1 ;;
1987 (p0) frcpa.s1 FR_r_hi, p6 = f1, FR_r
1988 (p0) cmp.eq.unc p11, p12 = 0x0, GR_i_0
1992 // ******************************************************************
1993 // ******************************************************************
1994 // ******************************************************************
1996 // r and c have been computed.
1997 // We known whether this is the sine or cosine routine.
1998 // Make sure ftz mode is set - should be automatic when using wre
1999 // Get [i_0,i_1] - two lsb of N_fix_gr alone.
2004 (p0) addl GR_Table_Base = @ltoff(FSINCOSL_CONSTANTS#), gp
2010 ld8 GR_Table_Base = [GR_Table_Base]
2018 (p10) add GR_Table_Base = 384, GR_Table_Base
2019 (p12) fms.s1 FR_Input_X = f0, f1, f1
2020 (p9) add GR_Table_Base = 224, GR_Table_Base ;;
2023 (p10) ldfe FR_QQ_8 = [GR_Table_Base], 16
2025 // if (i_1==0) poly = poly * FR_rsq + PP_1_lo
2026 // else poly = FR_rsq * poly
2028 (p11) fma.s1 FR_Input_X = f0, f1, f1
2032 (p10) ldfe FR_QQ_7 = [GR_Table_Base], 16
2034 // Adjust table pointers based on i_0
2035 // Compute rsq = r * r
2037 (p9) ldfe FR_PP_8 = [GR_Table_Base], 16
2042 (p0) fma.s1 FR_r_cubed = FR_r, FR_rsq, f0
2046 (p9) ldfe FR_PP_7 = [GR_Table_Base], 16
2047 (p10) ldfe FR_QQ_6 = [GR_Table_Base], 16
2049 // Load PP_8 and QQ_8; PP_7 and QQ_7
2051 (p0) frcpa.s1 FR_r_hi, p6 = f1, FR_r_hi ;;
2054 // if (i_1==0) poly = PP_7 + FR_rsq * PP_8.
2055 // else poly = QQ_7 + FR_rsq * QQ_8.
2058 (p9) ldfe FR_PP_6 = [GR_Table_Base], 16
2059 (p10) ldfe FR_QQ_5 = [GR_Table_Base], 16
2063 (p9) ldfe FR_PP_5 = [GR_Table_Base], 16
2064 (p10) ldfe FR_S_1 = [GR_Table_Base], 16
2068 (p10) ldfe FR_QQ_1 = [GR_Table_Base], 16
2069 (p9) ldfe FR_C_1 = [GR_Table_Base], 16
2073 (p10) ldfe FR_QQ_4 = [GR_Table_Base], 16
2074 (p9) ldfe FR_PP_1 = [GR_Table_Base], 16
2078 (p10) ldfe FR_QQ_3 = [GR_Table_Base], 16
2080 // if (i_1=0) corr = corr + c*c
2081 // else corr = corr * c
2083 (p9) ldfe FR_PP_4 = [GR_Table_Base], 16
2088 (p10) fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7
2092 // if (i_1=0) poly = rsq * poly + PP_5
2093 // else poly = rsq * poly + QQ_5
2094 // Load PP_4 or QQ_4
2097 (p9) ldfe FR_PP_3 = [GR_Table_Base], 16 ;;
2098 (p10) ldfe FR_QQ_2 = [GR_Table_Base], 16
2104 // r_hi = frcpa(frcpa(r)).
2105 // r_cube = r * FR_rsq.
2107 (p9) fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7
2111 // Do dummy multiplies so inexact is always set.
2114 (p9) ldfe FR_PP_2 = [GR_Table_Base], 16
2118 (p9) fma.s1 FR_U_lo = FR_r_hi, FR_r_hi, f0
2122 (p9) ldfe FR_PP_1_lo = [GR_Table_Base], 16
2128 (p10) fma.s1 FR_corr = FR_S_1, FR_r_cubed, FR_r
2133 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_6
2139 // if (i_1=0) U_lo = r_hi * r_hi
2140 // else U_lo = r_hi + r
2142 (p9) fma.s1 FR_corr = FR_C_1, FR_rsq, f0
2148 // if (i_1=0) corr = C_1 * rsq
2149 // else corr = S_1 * r_cubed + r
2151 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_6
2156 (p10) fma.s1 FR_U_lo = FR_r_hi, f1, FR_r
2162 // if (i_1=0) U_hi = r_hi + U_hi
2163 // else U_hi = QQ_1 * U_hi + 1
2165 (p9) fma.s1 FR_U_lo = FR_r, FR_r_hi, FR_U_lo
2171 // U_hi = r_hi * r_hi
2173 (p0) fms.s1 FR_r_lo = FR_r, f1, FR_r_hi
2179 // Load PP_1, PP_6, PP_5, and C_1
2180 // Load QQ_1, QQ_6, QQ_5, and S_1
2182 (p0) fma.s1 FR_U_hi = FR_r_hi, FR_r_hi, f0
2187 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_5
2192 (p10) fnma.s1 FR_corr = FR_corr, FR_c, f0
2198 // if (i_1=0) U_lo = r * r_hi + U_lo
2199 // else U_lo = r_lo * U_lo
2201 (p9) fma.s1 FR_corr = FR_corr, FR_c, FR_c
2206 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_5
2212 // if (i_1 =0) U_hi = r + U_hi
2213 // if (i_1 =0) U_lo = r_lo * U_lo
2216 (p9) fma.s0 FR_PP_5 = FR_PP_5, FR_PP_4, f0
2221 (p9) fma.s1 FR_U_lo = FR_r, FR_r, FR_U_lo
2226 (p10) fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0
2232 // if (i_1=0) poly = poly * rsq + PP_6
2233 // else poly = poly * rsq + QQ_6
2235 (p9) fma.s1 FR_U_hi = FR_r_hi, FR_U_hi, f0
2240 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_4
2245 (p10) fma.s1 FR_U_hi = FR_QQ_1, FR_U_hi, f1
2250 (p10) fma.s0 FR_QQ_5 = FR_QQ_5, FR_QQ_5, f0
2256 // if (i_1!=0) U_hi = PP_1 * U_hi
2257 // if (i_1!=0) U_lo = r * r + U_lo
2258 // Load PP_3 or QQ_3
2260 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_4
2265 (p9) fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0
2270 (p10) fma.s1 FR_U_lo = FR_QQ_1,FR_U_lo, f0
2275 (p9) fma.s1 FR_U_hi = FR_PP_1, FR_U_hi, f0
2280 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_3
2288 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_3
2294 // if (i_1==0) poly = FR_rsq * poly + PP_3
2295 // else poly = FR_rsq * poly + QQ_3
2298 (p9) fma.s1 FR_U_lo = FR_PP_1, FR_U_lo, f0
2304 // if (i_1 =0) poly = poly * rsq + pp_r4
2305 // else poly = poly * rsq + qq_r4
2307 (p9) fma.s1 FR_U_hi = FR_r, f1, FR_U_hi
2312 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_2
2318 // if (i_1==0) U_lo = PP_1_hi * U_lo
2319 // else U_lo = QQ_1 * U_lo
2321 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_2
2327 // if (i_0==0) Result = 1
2330 (p0) fma.s1 FR_V = FR_U_lo, f1, FR_corr
2335 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0
2341 // if (i_1==0) poly = FR_rsq * poly + PP_2
2342 // else poly = FR_rsq * poly + QQ_2
2344 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_1_lo
2349 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0
2357 (p9) fma.s1 FR_poly = FR_r_cubed, FR_poly, f0
2363 // if (i_1==0) poly = r_cube * poly
2364 // else poly = FR_rsq * poly
2366 (p0) fma.s1 FR_V = FR_poly, f1, FR_V
2371 (p12) fms.s0 FR_Input_X = FR_Input_X, FR_U_hi, FR_V
2379 (p11) fma.s0 FR_Input_X = FR_Input_X, FR_U_hi, FR_V
2381 // if (i_0==0) Result = Result * U_hi + V
2382 // else Result = Result * U_hi - V
2388 // If cosine, FR_Input_X = 1
2389 // If sine, FR_Input_X = +/-Zero (Input FR_Input_X)
2390 // Results are exact, no exceptions
2395 (p0) cmp.eq.unc p6, p7 = 0x1, GR_Sin_or_Cos
2401 (p7) fmerge.s FR_Input_X = FR_Input_X, FR_Input_X
2406 (p6) fmerge.s FR_Input_X = f1, f1
2407 (p0) br.ret.sptk b0 ;;
2413 // Path for Arg = +/- QNaN, SNaN, Inf
2414 // Invalid can be raised. SNaNs
2417 (p0) fmpy.s0 FR_Input_X = FR_Input_X, f0
2418 (p0) br.ret.sptk b0 ;;
2421 ASM_SIZE_DIRECTIVE(cosl#)
2423 // Call int pi_by_2_reduce(double* x, double *y)
2424 // for |arguments| >= 2**63
2425 // Address to save r and c as double
2429 // r44 -> sp -> InputX
2432 .proc __libm_callout
2434 L(SINCOSL_ARG_TOO_LARGE):
2437 add r45=-32,sp // Parameter: r address
2439 .save ar.pfs,GR_SAVE_PFS
2440 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
2444 add sp=-64,sp // Create new stack
2446 mov GR_SAVE_GP=gp // Save gp
2449 stfe [r45] = f0,16 // Clear Parameter r on stack
2450 add r44 = 16,sp // Parameter x address
2451 .save b0, GR_SAVE_B0
2452 mov GR_SAVE_B0=b0 // Save b0
2456 stfe [r45] = f0,-16 // Clear Parameter c on stack
2461 stfe [r44] = FR_Input_X // Store Parameter x on stack
2463 (p0) br.call.sptk b0=__libm_pi_by_2_reduce# ;;
2466 (p0) ldfe FR_Input_X =[r44],16
2468 // Get r and c off stack
2470 (p0) adds GR_Table_Base1 = -16, GR_Table_Base1
2472 // Get r and c off stack
2474 (p0) add GR_N_Inc = GR_Sin_or_Cos,r8 ;;
2477 (p0) ldfe FR_r =[r45],16
2479 // Get X off the stack
2480 // Readjust Table ptr
2482 (p0) ldfs FR_Two_to_M3 = [GR_Table_Base1],4
2486 (p0) ldfs FR_Neg_Two_to_M3 = [GR_Table_Base1],0
2487 (p0) ldfe FR_c =[r45]
2492 add sp = 64,sp // Restore stack pointer
2493 (p0) fcmp.lt.unc.s1 p6, p0 = FR_r, FR_Two_to_M3
2494 mov b0 = GR_SAVE_B0 // Restore return address
2497 mov gp = GR_SAVE_GP // Restore gp
2498 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
2503 (p6) fcmp.gt.unc.s1 p6, p0 = FR_r, FR_Neg_Two_to_M3
2509 (p6) br.cond.spnt L(SINCOSL_SMALL_R) ;;
2514 (p0) br.cond.sptk L(SINCOSL_NORMAL_R) ;;
2516 .endp __libm_callout
2517 ASM_SIZE_DIRECTIVE(__libm_callout)
2518 .type __libm_pi_by_2_reduce#,@function
2519 .global __libm_pi_by_2_reduce#