Updated to fedora-glibc-20050106T1443
[glibc.git] / sysdeps / ia64 / fpu / s_cosl.S
blob374e822256fc54a57da41f8f5ea5474d29090bfd
1 .file "sincosl.s"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
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
22 // permission.
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 //*********************************************************************
42 // History:
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 //*********************************************************************
60 // Resources Used:
62 //    Floating-Point Registers: f8 (Input and Return Value)
63 //                              f32-f99
65 //    General Purpose Registers:
66 //      r32-r43
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
81 //    sinl(SNaN) = QNaN
82 //    sinl(QNaN) = QNaN
83 //    sinl(inf) = QNaN
84 //    sinl(+/-0) = +/-0
85 //    cosl(inf) = QNaN
86 //    cosl(SNaN) = QNaN
87 //    cosl(QNaN) = QNaN
88 //    cosl(0) = 1
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
98 //  to alpha where
100 //  Arg = N pi/2 + alpha, |alpha| <= pi/4.
102 //  Since
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
108 //  process.
110 //  Let M = N if sine
111 //      N+1 if cosine.
113 //  Now, given
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.
123 //  For example:
124 //       if M = -1, I = 11
125 //         sin ((-pi/2 + alpha) = (-1) cos (alpha)
126 //       if M = 0, I = 00
127 //         sin (alpha) = sin (alpha)
128 //       if M = 1, I = 01
129 //         sin (pi/2 + alpha) = cos (alpha)
130 //       if M = 2, I = 10
131 //         sin (pi + alpha) = (-1) sin (alpha)
132 //       if M = 3, I = 11
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:
146 //  Case 2:
147 //  -------
149 //  sinl(r + c) = r + c - r^3/6        accurately
150 //  cosl(r + c) = 1 - 2^(-67)        accurately
152 //  Case 4:
153 //  -------
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.
169 //  Specifically,
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.
174 //  Similarly,
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
181 //  0.1% or so.
183 //  The greatest challenge of this task is that the second terms of
184 //  the Taylor series
186 //        r - r^3/3! + r^r/5! - ...
188 //  and
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],
203 //  we have
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
214 //  are unneccessary.
216 //  Finally, sinl(r) and cosl(r) are approximated by polynomials of
217 //  moderate lengths.
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
241 //  moderate lengths.
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 ) ).)
259 //  This way,
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) ]
266 //                        =  U_hi  +  U_lo
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.
280 //  Similarly,
282 //        1 + QQ_1 r^2  =  [1 + QQ_1 r_hi^2]  +
283 //                            [QQ_1 (r - r_hi)(r + r_hi)]
284 //                      =  U_hi  +  U_lo.
286 //  Summarizing, we calculate r_hi = frcpa( frcpa( r ) ).
288 //  If i_1 = 0, then
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 )
295 //  Else ...i_1 = 1
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)
302 //  End
304 //  Finally,
306 //        V := poly + ( U_lo + correction )
308 //                 /    U_hi  +  V         if i_0 = 0
309 //        result := |
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,
329 //   set N_inc := 1.
331 //  Step 1. Check for exceptional and special cases.
333 //   * If Arg is +-0, +-inf, NaN, NaT, go to Step 10 for special
334 //     handling.
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
338 //     arguments.
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)
345 //     r     := Arg
346 //     c     := 0.0
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)
356 //     If |s| >= 2^(-33)
357 //        go to Step 3, Case_1_reduce
358 //     Else
359 //        go to Step 7, Case_2_reduce
360 //     Endif
361 //  Endif
363 //  Step 3. Case_1_reduce.
365 //  r := s + w
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.
374 //  Step 5. Normal_r.
376 //  Let [i_0 i_1] by the 2 lsb of N_fix.
377 //  FR_rsq  := r * r
378 //  r_hi := frcpa( frcpa( r ) )
379 //  r_lo := r - r_hi
381 //  If i_1 = 0, then
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
386 //  Else
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
391 //  Endif
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 :
400 //                        result*U_hi - V)
402 //  Return
404 //  Step 6. Small_r.
406 //  ...Use flush to zero mode without causing exception
407 //    Let [i_0 i_1] be the two lsb of N_fix.
409 //  FR_rsq := r * r
411 //  If i_1 = 0 then
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)
415 //     correction := c
416 //     result := r
417 //  Else
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
422 //     result := 1
423 //  Endif
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 :
432 //                          result - poly )
433 //  Return
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.
441 //  w := N*P_3
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
446 //  r := s - U_1
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.
457 //  If i_1 = 0 then
458 //     poly := c + S_1 * r * r * r        ...any order
459 //     result := r
460 //  Else
461 //     poly := -2^(-67)
462 //     result := 1.0
463 //  Endif
465 //  If i_0 = 1, result := -result
467 //  Last operation. Perform in user-set rounding mode
469 //  result := (i_0 == 0?     result + poly :
470 //                           result - poly )
472 //  Return
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
486 //  w := N_0 * d_1
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
493 //  w := w - N * P_2
495 //  If |s| >= 2^(-14)
496 //     go to Step 3
497 //  Else
498 //     go to Step 9
499 //  Endif
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
508 //   w := -N*P_3
509 //   w := w + N_0*d_2
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:
517 //   A := U_hi + V_hi
518 //   if |U_hi| >= |V_hi| then
519 //      a := (U_hi - A) + V_hi
520 //   else
521 //      a := (V_hi - A) + U_hi
522 //   endif
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
531 //   C_lo := C_lo + t
533 //   ...Final steps for reduction
534 //   r := C_hi + C_lo
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
539 //   ...Taylor series.
541 //   If i_1 = 0
542 //      poly := c + r*FR_rsq*(S_1 + FR_rsq*S_2)
543 //      result := r
544 //   Else
545 //      poly := FR_rsq*(C_1 + FR_rsq*C_2)
546 //      result := 1
547 //   Endif
549 //   If i_0 = 1, result := -result
551 //   Last operation. Perform in user-set rounding mode
553 //   result := (i_0 == 0?     result + poly :
554 //                            result - poly )
555 //   Return
557 //   Large Arguments: For arguments above 2**63, a Payne-Hanek
558 //   style argument reduction is used and pi_by_2 reduce is called.
562 RODATA
563 .align 16
565 LOCAL_OBJECT_START(FSINCOSL_CONSTANTS)
567 sincosl_table_p:
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)
628 FR_Input_X        = f8
629 FR_Result         = f8
631 FR_r              = f8
632 FR_c              = f9
634 FR_norm_x         = f9
635 FR_inv_pi_2to63   = f10
636 FR_rshf_2to64     = f11
637 FR_2tom64         = f12
638 FR_rshf           = f13
639 FR_N_float_signif = f14
640 FR_abs_x          = f15
641 FR_Pi_by_4        = f34
642 FR_Two_to_M14     = f35
643 FR_Neg_Two_to_M14 = f36
644 FR_Two_to_M33     = f37
645 FR_Neg_Two_to_M33 = f38
646 FR_Neg_Two_to_M67 = f39
647 FR_Inv_pi_by_2    = f40
648 FR_N_float        = f41
649 FR_N_fix          = f42
650 FR_P_1            = f43
651 FR_P_2            = f44
652 FR_P_3            = f45
653 FR_s              = f46
654 FR_w              = f47
655 FR_d_2            = f48
656 FR_tmp_result     = f49
657 FR_Z              = f50
658 FR_A              = f51
659 FR_a              = f52
660 FR_t              = f53
661 FR_U_1            = f54
662 FR_U_2            = f55
663 FR_C_1            = f56
664 FR_C_2            = f57
665 FR_C_3            = f58
666 FR_C_4            = f59
667 FR_C_5            = f60
668 FR_S_1            = f61
669 FR_S_2            = f62
670 FR_S_3            = f63
671 FR_S_4            = f64
672 FR_S_5            = f65
673 FR_poly_hi        = f66
674 FR_poly_lo        = f67
675 FR_r_hi           = f68
676 FR_r_lo           = f69
677 FR_rsq            = f70
678 FR_r_cubed        = f71
679 FR_C_hi           = f72
680 FR_N_0            = f73
681 FR_d_1            = f74
682 FR_V              = f75
683 FR_V_hi           = f75
684 FR_V_lo           = f76
685 FR_U_hi           = f77
686 FR_U_lo           = f78
687 FR_U_hiabs        = f79
688 FR_V_hiabs        = f80
689 FR_PP_8           = f81
690 FR_QQ_8           = f101
691 FR_PP_7           = f82
692 FR_QQ_7           = f102
693 FR_PP_6           = f83
694 FR_QQ_6           = f103
695 FR_PP_5           = f84
696 FR_QQ_5           = f104
697 FR_PP_4           = f85
698 FR_QQ_4           = f105
699 FR_PP_3           = f86
700 FR_QQ_3           = f106
701 FR_PP_2           = f87
702 FR_QQ_2           = f107
703 FR_QQ_1           = f108
704 FR_r_hi_sq        = f88
705 FR_N_0_fix        = f89
706 FR_Inv_P_0        = f90
707 FR_corr           = f91
708 FR_poly           = f92
709 FR_Neg_Two_to_M3  = f93
710 FR_Two_to_M3      = f94
711 FR_P_0            = f95
712 FR_C_lo           = f96
713 FR_PP_1           = f97
714 FR_PP_1_lo        = f98
715 FR_ArgPrime       = f99
716 FR_inexact        = f100
718 GR_sig_inv_pi  = r14
719 GR_rshf_2to64  = r15
720 GR_exp_2tom64  = r16
721 GR_rshf        = r17
722 GR_ad_p        = r18
723 GR_ad_d        = r19
724 GR_ad_pp       = r20
725 GR_ad_qq       = r21
726 GR_ad_c        = r22
727 GR_ad_s        = r23
728 GR_ad_ce       = r24
729 GR_ad_se       = r25
730 GR_ad_m14      = r26
731 GR_ad_s1       = r27
732 GR_exp_m2_to_m3= r36
733 GR_N_Inc       = r37
734 GR_Sin_or_Cos  = r38
735 GR_signexp_x   = r40
736 GR_exp_x       = r40
737 GR_exp_mask    = r41
738 GR_exp_2_to_63 = r42
739 GR_exp_2_to_m3 = r43
740 GR_exp_2_to_24 = r44
742 // Added for unwind support
744 GR_SAVE_B0     = r39
745 GR_SAVE_GP     = r40
746 GR_SAVE_PFS    = r41
749 .section .text
751 GLOBAL_IEEE754_ENTRY(sinl)
752 { .mlx
753       alloc r32 = ar.pfs,0,12,2,0
754       movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
756 { .mlx
757       mov GR_Sin_or_Cos = 0x0
758       movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
762 { .mfi
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
767 { .mfb
768       nop.m 999
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)
776 { .mlx
777       alloc r32 = ar.pfs,0,12,2,0
778       movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
780 { .mlx
781       mov GR_Sin_or_Cos = 0x1
782       movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
786 { .mfi
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
791 { .mfi
792       nop.m 999
793       fnorm.s1 FR_norm_x = FR_Input_X      // Normalize x
794       nop.i 999
798 SINCOSL_CONTINUE:
799 { .mfi
800       setf.sig FR_inv_pi_2to63 = GR_sig_inv_pi // Form 1/pi * 2^63
801       nop.f 999
802       mov GR_exp_2tom64 = 0xffff - 64      // Scaling constant to compute N
804 { .mlx
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
810 { .mfi
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
813       nop.i 999
817 { .mfi
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
820       nop.i 999
822 { .mib
823       mov GR_exp_mask = 0x1ffff            // Exponent mask
824       nop.i 999
825 (p6)  br.cond.spnt SINCOSL_SPECIAL         // Branch if x natval, nan, inf
829 { .mfi
830       setf.exp FR_2tom64 = GR_exp_2tom64   // Form 2^-64 for scaling N_float
831       nop.f 0
832       add GR_ad_d = 0x70, GR_ad_p          // Point to constant table d
834 { .mib
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
841 SINCOSL_COMMON:
842 { .mfi
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
847 { .mib
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
854 { .mfi
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
859 { .mfi
860       ldfe FR_Pi_by_4 = [GR_ad_d], 16      // Load pi/4 for range test
861       nop.f 999
862       cmp.ge p10,p0 = GR_exp_x, GR_exp_2_to_63   // Is |x| >= 2^63
866 { .mfi
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
871 { .mfi
872       ldfe FR_Inv_P_0 = [GR_ad_d], 16      // Load 1/P_0 for pi/4 <= |x| < 2^63
873       nop.f 999
874       cmp.ge p7,p0 = GR_exp_x, GR_exp_2_to_24   // Is |x| >= 2^24
878 { .mfi
879       ldfe FR_P_1 = [GR_ad_p], 16          // Load P_1 for pi/4 <= |x| < 2^63
880       nop.f 999
881       add GR_ad_s = 0x50, GR_ad_c          // Point to constant table s
883 { .mfi
884       ldfe FR_PP_8 = [GR_ad_pp], 16        // Load PP_8 for 2^-3 < |r| < pi/4
885       nop.f 999
886       nop.i 999
890 { .mfi
891       ldfe FR_P_2 = [GR_ad_p], 16          // Load P_2 for pi/4 <= |x| < 2^63
892       nop.f 999
893       add GR_ad_ce = 0x40, GR_ad_c         // Point to end of constant table c
895 { .mfi
896       ldfe FR_QQ_8 = [GR_ad_qq], 16        // Load QQ_8 for 2^-3 < |r| < pi/4
897       nop.f 999
898       nop.i 999
902 { .mfi
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
907 { .mib
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
915 { .mfi
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
920 { .mfb
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
924                                            // Use pre-reduction
928 { .mmf
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
935 { .mmf
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
938       nop.f 999
942 // Here if 0 < |x| < 2^24
943 { .mfi
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
946       nop.i 999
948 { .mfi
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
951       nop.i 999
955 { .mmi
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
958       nop.i 999
963 //     N  = Arg * 2/pi
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
973 { .mfi
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).
982 //     r = Arg
983 //     c = 0
984 { .mmi
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.
994 //     If |x| >= pi/4,
995 //     Create the right N for |x| < pi/4 and otherwise
996 //     Case 2: Place integer part of N in GP register
1000 { .mbb
1001       nop.m 999
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
1008 { .mfi
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
1013 { .mfi
1014       nop.m 999
1015       fma.s1 FR_w = FR_N_float, FR_P_2, f0      // w = N * P_2
1016       nop.i 999
1020 { .mfi
1021       nop.m 999
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
1028 { .mfi
1029       nop.m 999
1030       fcmp.lt.s1 p7, p6 = FR_s, FR_Two_to_M33
1031       nop.i 999
1035 { .mfi
1036       nop.m 999
1037 (p7)  fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33 // p6 if |s| >= 2^-33, else p7
1038       nop.i 999
1042 { .mfi
1043       nop.m 999
1044       fms.s1 FR_c = FR_s, f1, FR_r             // c = s - r, for |s| >= 2^-33
1045       nop.i 999
1047 { .mfi
1048       nop.m 999
1049       fma.s1 FR_rsq = FR_r, FR_r, f0           // rsq = r * r, for |s| >= 2^-33
1050       nop.i 999
1054 { .mfi
1055       nop.m 999
1056 (p7)  fma.s1 FR_w = FR_N_float, FR_P_3, f0
1057       nop.i 999
1061 { .mmf
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)
1068 { .mfi
1069       nop.m 999
1070 (p6)  fcmp.lt.unc.s1 p8, p13 = FR_r, FR_Two_to_M3 // If big s, test r with 2^-3
1071       nop.i 999
1075 { .mfi
1076       nop.m 999
1077 (p7)  fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1078       nop.i 999
1083 //     For big s: r = s - w: No futher reduction is necessary
1084 //     For small s: w = N * P_3 (change sign) More reduction
1086 { .mfi
1087         nop.m 999
1088 (p8)   fcmp.gt.s1 p8, p13 = FR_r, FR_Neg_Two_to_M3 // If big s, p8 if |r| < 2^-3
1089         nop.i 999 ;;
1092 { .mfi
1093       nop.m 999
1094 (p9)  fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7 if i_1=0
1095       nop.i 999
1097 { .mfi
1098       nop.m 999
1099 (p10) fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7 if i_1=1
1100       nop.i 999
1104 { .mfi
1105         nop.m 999
1106 (p7)   fms.s1 FR_r = FR_s, f1, FR_U_1
1107         nop.i 999
1111 { .mfi
1112       nop.m 999
1113 (p6)  fma.s1 FR_r_cubed = FR_r, FR_rsq, f0  // rcubed = r * rsq
1114       nop.i 999
1118 { .mfi
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
1132       nop.m 999
1133 (p6)  fms.s1 FR_c = FR_c, f1, FR_w
1134       nop.i 999
1136 { .mbb
1137       nop.m 999
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
1145 SINCOSL_S_TINY:
1147 // Here if |s| < 2^-33, and pi/4 <= |x| < 2^24
1149 { .mfi
1150        fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1152 //     c = S - U_1
1153 //     r = S_1 * r
1159 { .mmi
1160         nop.m 999
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
1173 //     coefficients.
1175 { .mfi
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
1186 { .mfi
1187         nop.m 999
1188        fms.s1        FR_s = FR_s, f1, FR_r
1189         nop.i 999
1191 { .mfi
1192         nop.m 999
1194 //     S = S - r
1195 //     U_2 = U_2 + w
1196 //     load S_1
1198        fma.s1        FR_rsq = FR_r, FR_r, f0
1199         nop.i 999 ;;
1201 { .mfi
1202         nop.m 999
1203        fma.s1        FR_U_2 = FR_U_2, f1, FR_w
1204         nop.i 999
1206 { .mfi
1207         nop.m 999
1208        fmerge.se FR_tmp_result = FR_r, FR_r
1209         nop.i 999 ;;
1211 { .mfi
1212         nop.m 999
1213 (p10)  fma.s1 FR_tmp_result = f0, f1, f1
1214         nop.i 999 ;;
1216 { .mfi
1217         nop.m 999
1219 //     FR_rsq = r * r
1220 //     Save r as the result.
1222        fms.s1        FR_c = FR_s, f1, FR_U_1
1223         nop.i 999 ;;
1225 { .mfi
1226         nop.m 999
1228 //     if ( i_1 ==0) poly = c + S_1*r*r*r
1229 //     else Result = 1
1231 (p12)  fnma.s1 FR_tmp_result = FR_tmp_result, f1, f0
1232         nop.i 999
1234 { .mfi
1235         nop.m 999
1236        fma.s1        FR_r = FR_S_1, FR_r, f0
1237         nop.i 999 ;;
1239 { .mfi
1240         nop.m 999
1241        fma.s0        FR_S_1 = FR_S_1, FR_S_1, f0
1242         nop.i 999 ;;
1244 { .mfi
1245         nop.m 999
1247 //     If i_1 != 0, poly = 2**(-67)
1249        fms.s1 FR_c = FR_c, f1, FR_U_2
1250         nop.i 999 ;;
1252 { .mfi
1253         nop.m 999
1255 //     c = c - U_2
1257 (p9)   fma.s1 FR_poly = FR_r, FR_rsq, FR_c
1258         nop.i 999 ;;
1260 { .mfi
1261         nop.m 999
1263 //     i_0 != 0, so Result = -Result
1265 (p11)  fma.s0 FR_Result = FR_tmp_result, f1, FR_poly
1266         nop.i 999 ;;
1268 { .mfb
1269         nop.m 999
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
1279 SINCOSL_LARGER_ARG:
1281 // Here if 2^24 <= |x| < 2^63
1283 { .mfi
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
1286         nop.i 999
1291 //     N_0 = Arg * Inv_P_0
1293 //     Load values 2**(-14) and -2**(-14)
1294 { .mmi
1295        ldfps FR_Two_to_M14, FR_Neg_Two_to_M14 = [GR_ad_m14]
1296         nop.i 999 ;;
1298 { .mfi
1299       ldfe FR_d_2 = [GR_ad_p], 16          // Load d_2 for |x| >= 2^24 path
1300         nop.f 999
1301         nop.i 999 ;;
1303 { .mfi
1304         nop.m 999
1307        fcvt.fx.s1 FR_N_0_fix = FR_N_0
1308         nop.i 999 ;;
1310 { .mfi
1311         nop.m 999
1313 //     N_0_fix  = integer part of N_0
1315        fcvt.xf FR_N_0 = FR_N_0_fix
1316         nop.i 999 ;;
1318 { .mfi
1319         nop.m 999
1321 //     Make N_0 the integer part
1323        fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X
1324         nop.i 999
1326 { .mfi
1327         nop.m 999
1328        fma.s1 FR_w = FR_N_0, FR_d_1, f0
1329         nop.i 999 ;;
1331 { .mfi
1332         nop.m 999
1334 //     Arg' = -N_0 * P_0 + Arg
1335 //     w  = N_0 * d_1
1337        fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0
1338         nop.i 999 ;;
1340 { .mfi
1341         nop.m 999
1343 //     N = A' * 2/pi
1345        fcvt.fx.s1 FR_N_fix = FR_N_float
1346         nop.i 999 ;;
1348 { .mfi
1349         nop.m 999
1351 //     N_fix is the integer part
1353        fcvt.xf FR_N_float = FR_N_fix
1354         nop.i 999 ;;
1356 { .mfi
1357        getf.sig GR_N_Inc = FR_N_fix
1358         nop.f 999
1359         nop.i 999 ;;
1361 { .mii
1362         nop.m 999
1363         nop.i 999 ;;
1364        add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos ;;
1366 { .mfi
1367         nop.m 999
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
1373         nop.i 999
1375 { .mfi
1376         nop.m 999
1377        fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w
1378         nop.i 999 ;;
1380 { .mfi
1381         nop.m 999
1383 //     s = -N*P_1 + Arg'
1384 //     w = -N*P_2 + w
1385 //     N_fix_gr = N_fix_gr + N_inc
1387        fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1388         nop.i 999 ;;
1390 { .mfi
1391         nop.m 999
1392 (p9)   fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14  // p9 if |s| < 2^-14
1393         nop.i 999 ;;
1396 { .mfi
1397         nop.m 999
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
1403         nop.i 999
1405 { .mfi
1406         nop.m 999
1407 (p9)   fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1408         nop.i 999 ;;
1410 { .mfi
1411         nop.m 999
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
1417         nop.i 999
1419 { .mfi
1420         nop.m 999
1421 (p9)   fma.s1 FR_w = FR_N_float, FR_P_3, f0
1422         nop.i 999 ;;
1424 { .mfi
1425         nop.m 999
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
1431         nop.i 999
1433 { .mfi
1434         nop.m 999
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
1441         nop.i 999 ;;
1443 { .mmf
1444         nop.m 999
1445         nop.m 999
1446 (p9)   fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi
1448 { .mfi
1449         nop.m 999
1450 (p9)   fmerge.s FR_V_hiabs = f0, FR_V_hi
1451         nop.i 999 ;;
1453 //{ .mfb
1454 //(p9)   fmerge.s f8= FR_V_lo,FR_V_lo
1455 //(p9)   br.ret.sptk b0
1457 //;;
1458 { .mfi
1459         nop.m 999
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
1464         nop.i 999
1466 { .mfi
1467         nop.m 999
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
1474         nop.i 999 ;;
1476 { .mfi
1477         nop.m 999
1479 //     For small S: V_hi = N * P_2
1480 //                  w = N * P_3
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
1485         nop.i 999 ;;
1487 { .mfi
1488         nop.m 999
1489 (p12)  fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1490         nop.i 999 ;;
1492 { .mfi
1493         nop.m 999
1494 (p8)   fma.s1 FR_c = FR_c, f1, FR_w
1495         nop.i 999
1497 { .mfb
1498         nop.m 999
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
1505 { .mib
1506         nop.m 999
1507         nop.i 999
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
1517 { .mfi
1518         nop.m 999
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
1529 { .mfi
1530         nop.m 999
1532 //     C_hi = S + A
1534        fma.s1 FR_t = FR_U_lo, f1, FR_V_lo
1538 { .mfi
1539         nop.m 999
1541 //     t = U_lo + V_lo
1544 (p7)  fms.s1 FR_a = FR_U_hi, f1, FR_A
1545         nop.i 999 ;;
1547 { .mfi
1548         nop.m 999
1549 (p8)  fma.s1 FR_a = FR_V_hi, f1, FR_A
1550         nop.i 999
1554 { .mfi
1556 //     Is U_hiabs >= V_hiabs?
1558         nop.m 999
1559        fma.s1 FR_C_hi = FR_s, f1, FR_A
1560         nop.i 999 ;;
1562 { .mmi
1563        ldfe FR_C_1 = [GR_ad_c], 16 ;;
1564        ldfe FR_C_2 = [GR_ad_c], 64
1565         nop.i 999 ;;
1568 //     c = c + C_lo  finished.
1569 //     Load  C_2
1571 { .mfi
1572        ldfe        FR_S_1 = [GR_ad_s], 16
1574 //     C_lo = S - C_hi
1576        fma.s1 FR_t = FR_t, f1, FR_w
1577         nop.i 999 ;;
1580 //     r and c have been computed.
1581 //     Make sure ftz mode is set - should be automatic when using wre
1582 //     |r| < 2**(-3)
1583 //     Get [i_0,i_1] - two lsb of N_fix.
1584 //     Load S_1
1586 { .mfi
1587        ldfe FR_S_2 = [GR_ad_s], 64
1589 //     t = t + w
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
1596 { .mfi
1597         nop.m 999
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
1603         nop.i 999 ;;
1605 { .mfi
1606         nop.m 999
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
1613 { .mfi
1614         nop.m 999
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
1621         nop.i 999 ;;
1623 { .mfi
1624         nop.m 999
1626 //     C_lo = (S - C_hi) + A
1628        fma.s1 FR_t = FR_t, f1, FR_a
1629         nop.i 999 ;;
1631 { .mfi
1632         nop.m 999
1634 //     t = t + a
1636        fma.s1 FR_C_lo = FR_C_lo, f1, FR_t
1637         nop.i 999 ;;
1639 { .mfi
1640         nop.m 999
1642 //     C_lo = C_lo + t
1644        fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1645         nop.i 999 ;;
1647 { .mfi
1648         nop.m 999
1650 //     Load S_2
1652        fma.s1 FR_rsq = FR_r, FR_r, f0
1653         nop.i 999
1655 { .mfi
1656         nop.m 999
1658 //     r = C_hi + C_lo
1660        fms.s1 FR_c = FR_C_hi, f1, FR_r
1661         nop.i 999 ;;
1663 { .mfi
1664         nop.m 999
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
1670         nop.i 999 ;;
1672 { .mfi
1673         nop.m 999
1674 (p10)  fma.s1 FR_tmp_result = f0, f1, f1
1675         nop.i 999 ;;
1677 { .mfi
1678         nop.m 999
1680 //     Compute r_cube = FR_rsq * r
1682 (p9)  fma.s1 FR_poly = FR_rsq, FR_S_2, FR_S_1
1683         nop.i 999 ;;
1685 { .mfi
1686         nop.m 999
1687 (p10)  fma.s1 FR_poly = FR_rsq, FR_C_2, FR_C_1
1688         nop.i 999
1690 { .mfi
1691         nop.m 999
1693 //     Compute FR_rsq = r * r
1694 //     Is i_1 == 0 ?
1696        fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1697         nop.i 999 ;;
1699 { .mfi
1700         nop.m 999
1702 //     c = C_hi - r
1703 //     Load  C_1
1705        fma.s1 FR_c = FR_c, f1, FR_C_lo
1706         nop.i 999
1708 { .mfi
1709         nop.m 999
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
1715         nop.i 999 ;;
1717 { .mfi
1718         nop.m 999
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
1724         nop.i 999 ;;
1726 { .mfi
1727         nop.m 999
1728 (p10)  fma.s1 FR_poly = FR_rsq, FR_poly, f0
1729         nop.i 999 ;;
1731 { .mfi
1732         nop.m 999
1734 //     if i_0 !=0: Result = -Result
1736 (p11)   fma.s0 FR_Result = FR_tmp_result, f1, FR_poly
1737         nop.i 999 ;;
1739 { .mfb
1740         nop.m 999
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
1751 SINCOSL_SMALL_R:
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.
1762 { .mfi
1763       nop.m 999
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
1770 { .mmi
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
1773       nop.i 999
1777 { .mmi
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
1780       nop.i 999
1784 SINCOSL_SMALL_R_0:
1785 // Entry point for 2^-3 < |x| < pi/4
1786 .pred.rel "mutex",p9,p10
1787 SINCOSL_SMALL_R_1:
1788 // Entry point for pi/4 < |x| < 2^24 and |r| < 2^-3
1789 .pred.rel "mutex",p9,p10
1790 { .mfi
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
1793       nop.i 999
1795 { .mfi
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
1798       nop.i 999
1802 { .mmf
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
1809 { .mmi
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
1812       nop.i 999
1816 { .mfi
1817       nop.m 999
1818 (p9)  fma.s1 FR_Z = FR_Z, FR_r, f0     // Z = Z * r if i_1=0
1819       nop.i 999
1823 { .mfi
1824       nop.m 999
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
1826       nop.i 999
1828 { .mfi
1829       nop.m 999
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
1831       nop.i 999
1835 { .mfi
1836       nop.m 999
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
1838       nop.i 999
1840 { .mfi
1841       nop.m 999
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
1843       nop.i 999
1847 { .mfi
1848       nop.m 999
1849       fma.s1 FR_Z = FR_Z, FR_rsq, f0             // Z = Z * rsq
1850       nop.i 999
1854 { .mfi
1855       nop.m 999
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
1857       nop.i 999
1859 { .mfi
1860       nop.m 999
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
1862       nop.i 999
1866 { .mfi
1867       nop.m 999
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
1872 { .mfi
1873       nop.m 999
1874 (p10) fma.s0 FR_inexact = FR_C_1, FR_C_1, f0     // Dummy op to set inexact
1875       nop.i 999
1879 { .mfi
1880       nop.m 999
1881 (p9)  fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0     // p_hi=p_hi*rsq if i_1=0
1882       nop.i 999
1884 { .mfi
1885       nop.m 999
1886 (p10) fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0     // p_hi=p_hi*rsq if i_1=1
1887       nop.i 999
1891 { .mfi
1892       nop.m 999
1893       fma.s1 FR_poly = FR_Z, FR_poly_lo, FR_c        // poly=Z*poly_lo+c
1894       nop.i 999
1898 { .mfi
1899       nop.m 999
1900 (p9)  fma.s1 FR_poly_hi = FR_r, FR_poly_hi, f0       // p_hi=r*p_hi if i_1=0
1901       nop.i 999
1905 { .mfi
1906       nop.m 999
1907 (p12) fms.s1 FR_r = f0, f1, FR_r                     // r = -r if i_0=1
1908       nop.i 999
1912 { .mfi
1913       nop.m 999
1914       fma.s1 FR_poly = FR_poly, f1, FR_poly_hi       // poly=poly+poly_hi
1915       nop.i 999
1920 //      if (i_0 == 0) Result = r + poly
1921 //      if (i_0 != 0) Result = r - poly
1923 { .mfi
1924       nop.m 999
1925 (p11) fma.s0 FR_Result = FR_r, f1, FR_poly
1926       nop.i 999
1928 { .mfb
1929       nop.m 999
1930 (p12) fms.s0 FR_Result = FR_r, f1, FR_poly
1931       br.ret.sptk   b0                               // Exit for |r| < 2^-3
1936 SINCOSL_NORMAL_R:
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
1943 { .mfi
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
1949 { .mfi
1950       ldfe FR_QQ_6 = [GR_ad_qq], 16    // Load QQ_6
1951       nop.f 999
1952       nop.i 999
1956 { .mmi
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
1959       nop.i 999
1963 SINCOSL_NORMAL_R_0:
1964 // Entry for 2^-3 < |x| < pi/4
1965 .pred.rel "mutex",p9,p10
1966 { .mmf
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)
1973 { .mfi
1974       nop.m 999
1975 (p9)  fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7 if i_1=0
1976       nop.i 999
1978 { .mfi
1979       nop.m 999
1980 (p10) fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7 if i_1=1
1981       nop.i 999
1985 { .mfi
1986       nop.m 999
1987       fma.s1 FR_r_cubed = FR_r, FR_rsq, f0  // rcubed = r * rsq
1988       nop.i 999
1993 SINCOSL_NORMAL_R_1:
1994 // Entry for pi/4 <= |x| < 2^24
1995 .pred.rel "mutex",p9,p10
1996 { .mmf
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))
2003 { .mfi
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
2006       nop.i 999
2008 { .mfi
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
2011       nop.i 999
2015 { .mfi
2016       nop.m 999
2017 (p9)  fma.s1 FR_corr = FR_C_1, FR_rsq, f0       // corr = C_1 * rsq if i_1=0
2018       nop.i 999
2020 { .mfi
2021       nop.m 999
2022 (p10) fma.s1 FR_corr = FR_S_1, FR_r_cubed, FR_r // corr = S_1 * r^3 + r if i_1=1
2023       nop.i 999
2027 { .mfi
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
2030       nop.i 999
2032 { .mfi
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
2035       nop.i 999
2039 { .mfi
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
2042       nop.i 999
2044 { .mfi
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
2047       nop.i 999
2051 { .mfi
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
2054       nop.i 999
2056 { .mfi
2057       nop.m 999
2058 (p10) fnma.s1 FR_corr = FR_corr, FR_c, f0       // corr = -corr * c if i_1=1
2059       nop.i 999
2063 { .mfi
2064       nop.m 999
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
2066       nop.i 999
2068 { .mfi
2069       nop.m 999
2070 (p10) fma.s1 FR_U_lo = FR_r_hi, f1, FR_r        // U_lo = r_hi + r if i_1=1
2071       nop.i 999
2075 { .mfi
2076       nop.m 999
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
2078       nop.i 999
2080 { .mfi
2081       nop.m 999
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
2083       nop.i 999
2087 { .mfi
2088       nop.m 999
2089 (p9)  fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_4 // poly = poly*rsq+PP_4 if i_1=0
2090       nop.i 999
2092 { .mfi
2093       nop.m 999
2094 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_4 // poly = poly*rsq+QQ_4 if i_1=1
2095       nop.i 999
2099 { .mfi
2100       nop.m 999
2101 (p9)  fma.s1 FR_U_lo = FR_r, FR_r, FR_U_lo      // U_lo = r * r + U_lo if i_1=0
2102       nop.i 999
2104 { .mfi
2105       nop.m 999
2106 (p10) fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0     // U_lo = r_lo * U_lo if i_1=1
2107       nop.i 999
2111 { .mfi
2112       nop.m 999
2113 (p9)  fma.s1 FR_U_hi = FR_PP_1, FR_U_hi, f0     // U_hi = PP_1 * U_hi if i_1=0
2114       nop.i 999
2118 { .mfi
2119       nop.m 999
2120 (p9)  fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_3 // poly = poly*rsq+PP_3 if i_1=0
2121       nop.i 999
2123 { .mfi
2124       nop.m 999
2125 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_3 // poly = poly*rsq+QQ_3 if i_1=1
2126       nop.i 999
2130 { .mfi
2131       nop.m 999
2132 (p9)  fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0     // U_lo = r_lo * U_lo if i_1=0
2133       nop.i 999
2135 { .mfi
2136       nop.m 999
2137 (p10) fma.s1 FR_U_lo = FR_QQ_1,FR_U_lo, f0      // U_lo = QQ_1 * U_lo if i_1=1
2138       nop.i 999
2142 { .mfi
2143       nop.m 999
2144 (p9)  fma.s1 FR_U_hi = FR_r, f1, FR_U_hi        // U_hi = r + U_hi if i_1=0
2145       nop.i 999
2149 { .mfi
2150       nop.m 999
2151 (p9)  fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_2 // poly = poly*rsq+PP_2 if i_1=0
2152       nop.i 999
2154 { .mfi
2155       nop.m 999
2156 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_2 // poly = poly*rsq+QQ_2 if i_1=1
2157       nop.i 999
2161 { .mfi
2162       nop.m 999
2163 (p9)  fma.s1 FR_U_lo = FR_PP_1, FR_U_lo, f0     // U_lo = PP_1 * U_lo if i_1=0
2164       nop.i 999
2168 { .mfi
2169       nop.m 999
2170 (p9)  fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_1_lo // poly =poly*rsq+PP1lo i_1=0
2171       nop.i 999
2173 { .mfi
2174       nop.m 999
2175 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0      // poly = poly*rsq if i_1=1
2176       nop.i 999
2180 { .mfi
2181       nop.m 999
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
2188 { .mfi
2189       nop.m 999
2190 (p9)  fma.s0 FR_inexact = FR_PP_5, FR_PP_4, f0  // Dummy op to set inexact
2191       nop.i 999
2193 { .mfi
2194       nop.m 999
2195 (p10) fma.s0 FR_inexact = FR_QQ_5, FR_QQ_5, f0  // Dummy op to set inexact
2196       nop.i 999
2200 { .mfi
2201       nop.m 999
2202 (p9)  fma.s1 FR_poly = FR_r_cubed, FR_poly, f0  // poly = poly*r^3 if i_1=0
2203       nop.i 999
2205 { .mfi
2206       nop.m 999
2207 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0      // poly = poly*rsq if i_1=1
2208       nop.i 999
2212 { .mfi
2213       nop.m 999
2214 (p11) fma.s1 FR_tmp_result = f0, f1, f1// tmp_result=+1.0 if i_0=0
2215       nop.i 999
2217 { .mfi
2218       nop.m 999
2219 (p12) fms.s1 FR_tmp_result = f0, f1, f1// tmp_result=-1.0 if i_0=1
2220       nop.i 999
2224 { .mfi
2225       nop.m 999
2226       fma.s1 FR_V = FR_poly, f1, FR_V           // V = poly + V
2227       nop.i 999
2231 // If i_0 = 0  Result =  U_hi + V
2232 // If i_0 = 1  Result = -U_hi - V
2233 { .mfi
2234         nop.m 999
2235 (p11)        fma.s0 FR_Result = FR_tmp_result, FR_U_hi, FR_V
2236         nop.i 999
2238 { .mfb
2239         nop.m 999
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
2245 SINCOSL_ZERO:
2246 // Here if x = 0
2247 { .mfi
2248       cmp.eq.unc p6, p7 = 0x1, GR_Sin_or_Cos
2249       nop.f 999
2250       nop.i 999
2254 { .mfi
2255       nop.m 999
2256 (p7)  fmerge.s FR_Result = FR_Input_X, FR_Input_X // If sin, result = input
2257       nop.i 999
2259 { .mfb
2260       nop.m 999
2261 (p6)  fma.s0 FR_Result = f1, f1, f0    // If cos, result=1.0
2262       br.ret.sptk   b0                  // Exit for x=0
2267 SINCOSL_DENORMAL:
2268 { .mmb
2269       getf.exp GR_signexp_x = FR_norm_x   // Get sign and exponent of x
2270       nop.m 999
2271       br.cond.sptk  SINCOSL_COMMON        // Return to common code
2275 SINCOSL_SPECIAL:
2276 { .mfb
2277         nop.m 999
2279 //      Path for Arg = +/- QNaN, SNaN, Inf
2280 //      Invalid can be raised. SNaNs
2281 //      become QNaNs
2283         fmpy.s0 FR_Result = FR_Input_X, f0
2284         br.ret.sptk   b0 ;;
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:
2295 //       On input:
2296 //         (Arg or x) is in f8
2297 //       On output:
2298 //         r is in f8
2299 //         c is in f9
2300 //         N is in r8
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
2307 //     function.
2309 // *******************************************************************
2310 // *******************************************************************
2311 // *******************************************************************
2313 LOCAL_LIBM_ENTRY(__libm_callout)
2314 SINCOSL_ARG_TOO_LARGE:
2315 .prologue
2316 { .mfi
2317         nop.f 0
2318 .save   ar.pfs,GR_SAVE_PFS
2319         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
2322 { .mmi
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
2329 .body
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
2335 { .mib
2336         setf.exp FR_Neg_Two_to_M3 = GR_exp_m2_to_m3 // Form -(2^-3)
2337         nop.i 0
2338         br.call.sptk b0=__libm_pi_by_2_reduce#
2341 { .mfi
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
2347 { .mfi
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
2353 { .mbb
2354         nop.m 999
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
2359 .endp
2360 .type   __libm_pi_by_2_reduce#,@function
2361 .global __libm_pi_by_2_reduce#