Fix a few typos in comments
[glibc.git] / sysdeps / ia64 / fpu / libm_sincosl.S
blobb0d027caf58e29b4c5ee08572f8a0260f99f38bb
1 .file "libm_sincosl.s"
4 // Copyright (c) 2000 - 2004, 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 // 05/13/02 Initial version of sincosl (based on libm's sinl and cosl)
44 // 02/10/03 Reordered header: .section, .global, .proc, .align;
45 //          used data8 for long double table values
46 // 10/13/03 Corrected .file name
47 // 02/11/04 cisl is moved to the separate file.
48 // 10/26/04 Avoided using r14-31 as scratch so not clobbered by dynamic loader
50 //*********************************************************************
52 // Function:   Combined sincosl routine with 3 different API's
54 // API's
55 //==============================================================
56 // 1) void sincosl(long double, long double*s, long double*c)
57 // 2) __libm_sincosl - internal LIBM function, that accepts
58 //    argument in f8 and returns cosine through f8, sine through f9
61 //*********************************************************************
63 // Resources Used:
65 //    Floating-Point Registers: f8 (Input x and cosl return value),
66 //                              f9 (sinl returned)
67 //                              f32-f121
69 //    General Purpose Registers:
70 //      r32-r61
72 //    Predicate Registers:      p6-p15
74 //*********************************************************************
76 //  IEEE Special Conditions:
78 //    Denormal  fault raised on denormal inputs
79 //    Overflow exceptions do not occur
80 //    Underflow exceptions raised when appropriate for sincosl
81 //    (No specialized error handling for this routine)
82 //    Inexact raised when appropriate by algorithm
84 //    sincosl(SNaN) = QNaN, QNaN
85 //    sincosl(QNaN) = QNaN, QNaN
86 //    sincosl(inf)  = QNaN, QNaN
87 //    sincosl(+/-0) = +/-0, 1
89 //*********************************************************************
91 //  Mathematical Description
92 //  ========================
94 //  The computation of FSIN and FCOS performed in parallel.
96 //  Arg = N pi/2 + alpha, |alpha| <= pi/4.
98 //  cosl( Arg ) = sinl( (N+1) pi/2 + alpha ),
100 //  therefore, the code for computing sine will produce cosine as long
101 //  as 1 is added to N immediately after the argument reduction
102 //  process.
104 //  Let M = N if sine
105 //      N+1 if cosine.
107 //  Now, given
109 //  Arg = M pi/2  + alpha, |alpha| <= pi/4,
111 //  let I = M mod 4, or I be the two lsb of M when M is represented
112 //  as 2's complement. I = [i_0 i_1]. Then
114 //  sinl( Arg ) = (-1)^i_0  sinl( alpha ) if i_1 = 0,
115 //             = (-1)^i_0  cosl( alpha )     if i_1 = 1.
117 //  For example:
118 //       if M = -1, I = 11
119 //         sin ((-pi/2 + alpha) = (-1) cos (alpha)
120 //       if M = 0, I = 00
121 //         sin (alpha) = sin (alpha)
122 //       if M = 1, I = 01
123 //         sin (pi/2 + alpha) = cos (alpha)
124 //       if M = 2, I = 10
125 //         sin (pi + alpha) = (-1) sin (alpha)
126 //       if M = 3, I = 11
127 //         sin ((3/2)pi + alpha) = (-1) cos (alpha)
129 //  The value of alpha is obtained by argument reduction and
130 //  represented by two working precision numbers r and c where
132 //  alpha =  r  +  c     accurately.
134 //  The reduction method is described in a previous write up.
135 //  The argument reduction scheme identifies 4 cases. For Cases 2
136 //  and 4, because |alpha| is small, sinl(r+c) and cosl(r+c) can be
137 //  computed very easily by 2 or 3 terms of the Taylor series
138 //  expansion as follows:
140 //  Case 2:
141 //  -------
143 //  sinl(r + c) = r + c - r^3/6 accurately
144 //  cosl(r + c) = 1 - 2^(-67) accurately
146 //  Case 4:
147 //  -------
149 //  sinl(r + c) = r + c - r^3/6 + r^5/120 accurately
150 //  cosl(r + c) = 1 - r^2/2 + r^4/24    accurately
152 //  The only cases left are Cases 1 and 3 of the argument reduction
153 //  procedure. These two cases will be merged since after the
154 //  argument is reduced in either cases, we have the reduced argument
155 //  represented as r + c and that the magnitude |r + c| is not small
156 //  enough to allow the usage of a very short approximation.
158 //  The required calculation is either
160 //  sinl(r + c)  =  sinl(r)  +  correction,  or
161 //  cosl(r + c)  =  cosl(r)  +  correction.
163 //  Specifically,
165 //  sinl(r + c) = sinl(r) + c sin'(r) + O(c^2)
166 //       = sinl(r) + c cos (r) + O(c^2)
167 //       = sinl(r) + c(1 - r^2/2)  accurately.
168 //  Similarly,
170 //  cosl(r + c) = cosl(r) - c sinl(r) + O(c^2)
171 //       = cosl(r) - c(r - r^3/6)  accurately.
173 //  We therefore concentrate on accurately calculating sinl(r) and
174 //  cosl(r) for a working-precision number r, |r| <= pi/4 to within
175 //  0.1% or so.
177 //  The greatest challenge of this task is that the second terms of
178 //  the Taylor series
180 //  r - r^3/3! + r^r/5! - ...
182 //  and
184 //  1 - r^2/2! + r^4/4! - ...
186 //  are not very small when |r| is close to pi/4 and the rounding
187 //  errors will be a concern if simple polynomial accumulation is
188 //  used. When |r| < 2^-3, however, the second terms will be small
189 //  enough (6 bits or so of right shift) that a normal Horner
190 //  recurrence suffices. Hence there are two cases that we consider
191 //  in the accurate computation of sinl(r) and cosl(r), |r| <= pi/4.
193 //  Case small_r: |r| < 2^(-3)
194 //  --------------------------
196 //  Since Arg = M pi/4 + r + c accurately, and M mod 4 is [i_0 i_1],
197 //  we have
199 //  sinl(Arg) = (-1)^i_0 * sinl(r + c)  if i_1 = 0
200 //     = (-1)^i_0 * cosl(r + c)   if i_1 = 1
202 //  can be accurately approximated by
204 //  sinl(Arg) = (-1)^i_0 * [sinl(r) + c]  if i_1 = 0
205 //           = (-1)^i_0 * [cosl(r) - c*r] if i_1 = 1
207 //  because |r| is small and thus the second terms in the correction
208 //  are unnecessary.
210 //  Finally, sinl(r) and cosl(r) are approximated by polynomials of
211 //  moderate lengths.
213 //  sinl(r) =  r + S_1 r^3 + S_2 r^5 + ... + S_5 r^11
214 //  cosl(r) =  1 + C_1 r^2 + C_2 r^4 + ... + C_5 r^10
216 //  We can make use of predicates to selectively calculate
217 //  sinl(r) or cosl(r) based on i_1.
219 //  Case normal_r: 2^(-3) <= |r| <= pi/4
220 //  ------------------------------------
222 //  This case is more likely than the previous one if one considers
223 //  r to be uniformly distributed in [-pi/4 pi/4]. Again,
225 //  sinl(Arg) = (-1)^i_0 * sinl(r + c)  if i_1 = 0
226 //           = (-1)^i_0 * cosl(r + c)   if i_1 = 1.
228 //  Because |r| is now larger, we need one extra term in the
229 //  correction. sinl(Arg) can be accurately approximated by
231 //  sinl(Arg) = (-1)^i_0 * [sinl(r) + c(1-r^2/2)]      if i_1 = 0
232 //           = (-1)^i_0 * [cosl(r) - c*r*(1 - r^2/6)]    i_1 = 1.
234 //  Finally, sinl(r) and cosl(r) are approximated by polynomials of
235 //  moderate lengths.
237 //  sinl(r) =  r + PP_1_hi r^3 + PP_1_lo r^3 +
238 //                PP_2 r^5 + ... + PP_8 r^17
240 //  cosl(r) =  1 + QQ_1 r^2 + QQ_2 r^4 + ... + QQ_8 r^16
242 //  where PP_1_hi is only about 16 bits long and QQ_1 is -1/2.
243 //  The crux in accurate computation is to calculate
245 //  r + PP_1_hi r^3   or  1 + QQ_1 r^2
247 //  accurately as two pieces: U_hi and U_lo. The way to achieve this
248 //  is to obtain r_hi as a 10 sig. bit number that approximates r to
249 //  roughly 8 bits or so of accuracy. (One convenient way is
251 //  r_hi := frcpa( frcpa( r ) ).)
253 //  This way,
255 //  r + PP_1_hi r^3 =  r + PP_1_hi r_hi^3 +
256 //                          PP_1_hi (r^3 - r_hi^3)
257 //            =  [r + PP_1_hi r_hi^3]  +
258 //         [PP_1_hi (r - r_hi)
259 //            (r^2 + r_hi r + r_hi^2) ]
260 //            =  U_hi  +  U_lo
262 //  Since r_hi is only 10 bit long and PP_1_hi is only 16 bit long,
263 //  PP_1_hi * r_hi^3 is only at most 46 bit long and thus computed
264 //  exactly. Furthermore, r and PP_1_hi r_hi^3 are of opposite sign
265 //  and that there is no more than 8 bit shift off between r and
266 //  PP_1_hi * r_hi^3. Hence the sum, U_hi, is representable and thus
267 //  calculated without any error. Finally, the fact that
269 //  |U_lo| <= 2^(-8) |U_hi|
271 //  says that U_hi + U_lo is approximating r + PP_1_hi r^3 to roughly
272 //  8 extra bits of accuracy.
274 //  Similarly,
276 //  1 + QQ_1 r^2  =  [1 + QQ_1 r_hi^2]  +
277 //                      [QQ_1 (r - r_hi)(r + r_hi)]
278 //          =  U_hi  +  U_lo.
280 //  Summarizing, we calculate r_hi = frcpa( frcpa( r ) ).
282 //  If i_1 = 0, then
284 //    U_hi := r + PP_1_hi * r_hi^3
285 //    U_lo := PP_1_hi * (r - r_hi) * (r^2 + r*r_hi + r_hi^2)
286 //    poly := PP_1_lo r^3 + PP_2 r^5 + ... + PP_8 r^17
287 //    correction := c * ( 1 + C_1 r^2 )
289 //  Else ...i_1 = 1
291 //    U_hi := 1 + QQ_1 * r_hi * r_hi
292 //    U_lo := QQ_1 * (r - r_hi) * (r + r_hi)
293 //    poly := QQ_2 * r^4 + QQ_3 * r^6 + ... + QQ_8 r^16
294 //    correction := -c * r * (1 + S_1 * r^2)
296 //  End
298 //  Finally,
300 //  V := poly + ( U_lo + correction )
302 //                 /    U_hi  +  V         if i_0 = 0
303 //  result := |
304 //                 \  (-U_hi) -  V         if i_0 = 1
306 //  It is important that in the last step, negation of U_hi is
307 //  performed prior to the subtraction which is to be performed in
308 //  the user-set rounding mode.
311 //  Algorithmic Description
312 //  =======================
314 //  The argument reduction algorithm shares the same code between FSIN and FCOS.
315 //  The argument reduction description given
316 //  previously is repeated below.
319 //  Step 0. Initialization.
321 //  Step 1. Check for exceptional and special cases.
323 //   * If Arg is +-0, +-inf, NaN, NaT, go to Step 10 for special
324 //     handling.
325 //   * If |Arg| < 2^24, go to Step 2 for reduction of moderate
326 //     arguments. This is the most likely case.
327 //   * If |Arg| < 2^63, go to Step 8 for pre-reduction of large
328 //     arguments.
329 //   * If |Arg| >= 2^63, go to Step 10 for special handling.
331 //  Step 2. Reduction of moderate arguments.
333 //  If |Arg| < pi/4   ...quick branch
334 //     N_fix := N_inc (integer)
335 //     r     := Arg
336 //     c     := 0.0
337 //     Branch to Step 4, Case_1_complete
338 //  Else    ...cf. argument reduction
339 //     N     := Arg * two_by_PI (fp)
340 //     N_fix := fcvt.fx( N )  (int)
341 //     N     := fcvt.xf( N_fix )
342 //     N_fix := N_fix + N_inc
343 //     s     := Arg - N * P_1 (first piece of pi/2)
344 //     w     := -N * P_2  (second piece of pi/2)
346 //     If |s| >= 2^(-33)
347 //        go to Step 3, Case_1_reduce
348 //     Else
349 //        go to Step 7, Case_2_reduce
350 //     Endif
351 //  Endif
353 //  Step 3. Case_1_reduce.
355 //  r := s + w
356 //  c := (s - r) + w  ...observe order
358 //  Step 4. Case_1_complete
360 //  ...At this point, the reduced argument alpha is
361 //  ...accurately represented as r + c.
362 //  If |r| < 2^(-3), go to Step 6, small_r.
364 //  Step 5. Normal_r.
366 //  Let [i_0 i_1] by the 2 lsb of N_fix.
367 //  FR_rsq  := r * r
368 //  r_hi := frcpa( frcpa( r ) )
369 //  r_lo := r - r_hi
371 //  If i_1 = 0, then
372 //    poly := r*FR_rsq*(PP_1_lo + FR_rsq*(PP_2 + ... FR_rsq*PP_8))
373 //    U_hi := r + PP_1_hi*r_hi*r_hi*r_hi  ...any order
374 //    U_lo := PP_1_hi*r_lo*(r*r + r*r_hi + r_hi*r_hi)
375 //    correction := c + c*C_1*FR_rsq    ...any order
376 //  Else
377 //    poly := FR_rsq*FR_rsq*(QQ_2 + FR_rsq*(QQ_3 + ... + FR_rsq*QQ_8))
378 //    U_hi := 1 + QQ_1 * r_hi * r_hi    ...any order
379 //    U_lo := QQ_1 * r_lo * (r + r_hi)
380 //    correction := -c*(r + S_1*FR_rsq*r) ...any order
381 //  Endif
383 //  V := poly + (U_lo + correction) ...observe order
385 //  result := (i_0 == 0?   1.0 : -1.0)
387 //  Last instruction in user-set rounding mode
389 //  result := (i_0 == 0?   result*U_hi + V :
390 //                        result*U_hi - V)
392 //  Return
394 //  Step 6. Small_r.
396 //  ...Use flush to zero mode without causing exception
397 //    Let [i_0 i_1] be the two lsb of N_fix.
399 //  FR_rsq := r * r
401 //  If i_1 = 0 then
402 //     z := FR_rsq*FR_rsq; z := FR_rsq*z *r
403 //     poly_lo := S_3 + FR_rsq*(S_4 + FR_rsq*S_5)
404 //     poly_hi := r*FR_rsq*(S_1 + FR_rsq*S_2)
405 //     correction := c
406 //     result := r
407 //  Else
408 //     z := FR_rsq*FR_rsq; z := FR_rsq*z
409 //     poly_lo := C_3 + FR_rsq*(C_4 + FR_rsq*C_5)
410 //     poly_hi := FR_rsq*(C_1 + FR_rsq*C_2)
411 //     correction := -c*r
412 //     result := 1
413 //  Endif
415 //  poly := poly_hi + (z * poly_lo + correction)
417 //  If i_0 = 1, result := -result
419 //  Last operation. Perform in user-set rounding mode
421 //  result := (i_0 == 0?     result + poly :
422 //                          result - poly )
423 //  Return
425 //  Step 7. Case_2_reduce.
427 //  ...Refer to the write up for argument reduction for
428 //  ...rationale. The reduction algorithm below is taken from
429 //  ...argument reduction description and integrated this.
431 //  w := N*P_3
432 //  U_1 := N*P_2 + w    ...FMA
433 //  U_2 := (N*P_2 - U_1) + w  ...2 FMA
434 //  ...U_1 + U_2 is  N*(P_2+P_3) accurately
436 //  r := s - U_1
437 //  c := ( (s - r) - U_1 ) - U_2
439 //  ...The mathematical sum r + c approximates the reduced
440 //  ...argument accurately. Note that although compared to
441 //  ...Case 1, this case requires much more work to reduce
442 //  ...the argument, the subsequent calculation needed for
443 //  ...any of the trigonometric function is very little because
444 //  ...|alpha| < 1.01*2^(-33) and thus two terms of the
445 //  ...Taylor series expansion suffices.
447 //  If i_1 = 0 then
448 //     poly := c + S_1 * r * r * r  ...any order
449 //     result := r
450 //  Else
451 //     poly := -2^(-67)
452 //     result := 1.0
453 //  Endif
455 //  If i_0 = 1, result := -result
457 //  Last operation. Perform in user-set rounding mode
459 //  result := (i_0 == 0?     result + poly :
460 //                           result - poly )
462 //  Return
465 //  Step 8. Pre-reduction of large arguments.
467 //  ...Again, the following reduction procedure was described
468 //  ...in the separate write up for argument reduction, which
469 //  ...is tightly integrated here.
471 //  N_0 := Arg * Inv_P_0
472 //  N_0_fix := fcvt.fx( N_0 )
473 //  N_0 := fcvt.xf( N_0_fix)
475 //  Arg' := Arg - N_0 * P_0
476 //  w := N_0 * d_1
477 //  N := Arg' * two_by_PI
478 //  N_fix := fcvt.fx( N )
479 //  N := fcvt.xf( N_fix )
480 //  N_fix := N_fix + N_inc
482 //  s := Arg' - N * P_1
483 //  w := w - N * P_2
485 //  If |s| >= 2^(-14)
486 //     go to Step 3
487 //  Else
488 //     go to Step 9
489 //  Endif
491 //  Step 9. Case_4_reduce.
493 //    ...first obtain N_0*d_1 and -N*P_2 accurately
494 //   U_hi := N_0 * d_1    V_hi := -N*P_2
495 //   U_lo := N_0 * d_1 - U_hi V_lo := -N*P_2 - U_hi ...FMAs
497 //   ...compute the contribution from N_0*d_1 and -N*P_3
498 //   w := -N*P_3
499 //   w := w + N_0*d_2
500 //   t := U_lo + V_lo + w   ...any order
502 //   ...at this point, the mathematical value
503 //   ...s + U_hi + V_hi  + t approximates the true reduced argument
504 //   ...accurately. Just need to compute this accurately.
506 //   ...Calculate U_hi + V_hi accurately:
507 //   A := U_hi + V_hi
508 //   if |U_hi| >= |V_hi| then
509 //      a := (U_hi - A) + V_hi
510 //   else
511 //      a := (V_hi - A) + U_hi
512 //   endif
513 //   ...order in computing "a" must be observed. This branch is
514 //   ...best implemented by predicates.
515 //   ...A + a  is U_hi + V_hi accurately. Moreover, "a" is
516 //   ...much smaller than A: |a| <= (1/2)ulp(A).
518 //   ...Just need to calculate   s + A + a + t
519 //   C_hi := s + A    t := t + a
520 //   C_lo := (s - C_hi) + A
521 //   C_lo := C_lo + t
523 //   ...Final steps for reduction
524 //   r := C_hi + C_lo
525 //   c := (C_hi - r) + C_lo
527 //   ...At this point, we have r and c
528 //   ...And all we need is a couple of terms of the corresponding
529 //   ...Taylor series.
531 //   If i_1 = 0
532 //      poly := c + r*FR_rsq*(S_1 + FR_rsq*S_2)
533 //      result := r
534 //   Else
535 //      poly := FR_rsq*(C_1 + FR_rsq*C_2)
536 //      result := 1
537 //   Endif
539 //   If i_0 = 1, result := -result
541 //   Last operation. Perform in user-set rounding mode
543 //   result := (i_0 == 0?     result + poly :
544 //                            result - poly )
545 //   Return
547 //   Large Arguments: For arguments above 2**63, a Payne-Hanek
548 //   style argument reduction is used and pi_by_2 reduce is called.
552 RODATA
553 .align 64
555 LOCAL_OBJECT_START(FSINCOSL_CONSTANTS)
557 sincosl_table_p:
558 //data4 0x4E44152A, 0xA2F9836E, 0x00003FFE,0x00000000 // Inv_pi_by_2
559 //data4 0xCE81B9F1, 0xC84D32B0, 0x00004016,0x00000000 // P_0
560 //data4 0x2168C235, 0xC90FDAA2, 0x00003FFF,0x00000000 // P_1
561 //data4 0xFC8F8CBB, 0xECE675D1, 0x0000BFBD,0x00000000 // P_2
562 //data4 0xACC19C60, 0xB7ED8FBB, 0x0000BF7C,0x00000000 // P_3
563 //data4 0xDBD171A1, 0x8D848E89, 0x0000BFBF,0x00000000 // d_1
564 //data4 0x18A66F8E, 0xD5394C36, 0x0000BF7C,0x00000000 // d_2
565 data8 0xA2F9836E4E44152A, 0x00003FFE // Inv_pi_by_2
566 data8 0xC84D32B0CE81B9F1, 0x00004016 // P_0
567 data8 0xC90FDAA22168C235, 0x00003FFF // P_1
568 data8 0xECE675D1FC8F8CBB, 0x0000BFBD // P_2
569 data8 0xB7ED8FBBACC19C60, 0x0000BF7C // P_3
570 data8 0x8D848E89DBD171A1, 0x0000BFBF // d_1
571 data8 0xD5394C3618A66F8E, 0x0000BF7C // d_2
572 LOCAL_OBJECT_END(FSINCOSL_CONSTANTS)
574 LOCAL_OBJECT_START(sincosl_table_d)
575 //data4 0x2168C234, 0xC90FDAA2, 0x00003FFE,0x00000000 // pi_by_4
576 //data4 0x6EC6B45A, 0xA397E504, 0x00003FE7,0x00000000 // Inv_P_0
577 data8 0xC90FDAA22168C234, 0x00003FFE // pi_by_4
578 data8 0xA397E5046EC6B45A, 0x00003FE7 // Inv_P_0
579 data4 0x3E000000, 0xBE000000         // 2^-3 and -2^-3
580 data4 0x2F000000, 0xAF000000         // 2^-33 and -2^-33
581 data4 0x9E000000, 0x00000000         // -2^-67
582 data4 0x00000000, 0x00000000         // pad
583 LOCAL_OBJECT_END(sincosl_table_d)
585 LOCAL_OBJECT_START(sincosl_table_pp)
586 //data4 0xA21C0BC9, 0xCC8ABEBC, 0x00003FCE,0x00000000 // PP_8
587 //data4 0x720221DA, 0xD7468A05, 0x0000BFD6,0x00000000 // PP_7
588 //data4 0x640AD517, 0xB092382F, 0x00003FDE,0x00000000 // PP_6
589 //data4 0xD1EB75A4, 0xD7322B47, 0x0000BFE5,0x00000000 // PP_5
590 //data4 0xFFFFFFFE, 0xFFFFFFFF, 0x0000BFFD,0x00000000 // C_1
591 //data4 0x00000000, 0xAAAA0000, 0x0000BFFC,0x00000000 // PP_1_hi
592 //data4 0xBAF69EEA, 0xB8EF1D2A, 0x00003FEC,0x00000000 // PP_4
593 //data4 0x0D03BB69, 0xD00D00D0, 0x0000BFF2,0x00000000 // PP_3
594 //data4 0x88888962, 0x88888888, 0x00003FF8,0x00000000 // PP_2
595 //data4 0xAAAB0000, 0xAAAAAAAA, 0x0000BFEC,0x00000000 // PP_1_lo
596 data8 0xCC8ABEBCA21C0BC9, 0x00003FCE // PP_8
597 data8 0xD7468A05720221DA, 0x0000BFD6 // PP_7
598 data8 0xB092382F640AD517, 0x00003FDE // PP_6
599 data8 0xD7322B47D1EB75A4, 0x0000BFE5 // PP_5
600 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
601 data8 0xAAAA000000000000, 0x0000BFFC // PP_1_hi
602 data8 0xB8EF1D2ABAF69EEA, 0x00003FEC // PP_4
603 data8 0xD00D00D00D03BB69, 0x0000BFF2 // PP_3
604 data8 0x8888888888888962, 0x00003FF8 // PP_2
605 data8 0xAAAAAAAAAAAB0000, 0x0000BFEC // PP_1_lo
606 LOCAL_OBJECT_END(sincosl_table_pp)
608 LOCAL_OBJECT_START(sincosl_table_qq)
609 //data4 0xC2B0FE52, 0xD56232EF, 0x00003FD2 // QQ_8
610 //data4 0x2B48DCA6, 0xC9C99ABA, 0x0000BFDA // QQ_7
611 //data4 0x9C716658, 0x8F76C650, 0x00003FE2 // QQ_6
612 //data4 0xFDA8D0FC, 0x93F27DBA, 0x0000BFE9 // QQ_5
613 //data4 0xAAAAAAAA, 0xAAAAAAAA, 0x0000BFFC // S_1
614 //data4 0x00000000, 0x80000000, 0x0000BFFE,0x00000000 // QQ_1
615 //data4 0x0C6E5041, 0xD00D00D0, 0x00003FEF,0x00000000 // QQ_4
616 //data4 0x0B607F60, 0xB60B60B6, 0x0000BFF5,0x00000000 // QQ_3
617 //data4 0xAAAAAA9B, 0xAAAAAAAA, 0x00003FFA,0x00000000 // QQ_2
618 data8 0xD56232EFC2B0FE52, 0x00003FD2 // QQ_8
619 data8 0xC9C99ABA2B48DCA6, 0x0000BFDA // QQ_7
620 data8 0x8F76C6509C716658, 0x00003FE2 // QQ_6
621 data8 0x93F27DBAFDA8D0FC, 0x0000BFE9 // QQ_5
622 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
623 data8 0x8000000000000000, 0x0000BFFE // QQ_1
624 data8 0xD00D00D00C6E5041, 0x00003FEF // QQ_4
625 data8 0xB60B60B60B607F60, 0x0000BFF5 // QQ_3
626 data8 0xAAAAAAAAAAAAAA9B, 0x00003FFA // QQ_2
627 LOCAL_OBJECT_END(sincosl_table_qq)
629 LOCAL_OBJECT_START(sincosl_table_c)
630 //data4 0xFFFFFFFE, 0xFFFFFFFF, 0x0000BFFD,0x00000000 // C_1
631 //data4 0xAAAA719F, 0xAAAAAAAA, 0x00003FFA,0x00000000 // C_2
632 //data4 0x0356F994, 0xB60B60B6, 0x0000BFF5,0x00000000 // C_3
633 //data4 0xB2385EA9, 0xD00CFFD5, 0x00003FEF,0x00000000 // C_4
634 //data4 0x292A14CD, 0x93E4BD18, 0x0000BFE9,0x00000000 // C_5
635 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
636 data8 0xAAAAAAAAAAAA719F, 0x00003FFA // C_2
637 data8 0xB60B60B60356F994, 0x0000BFF5 // C_3
638 data8 0xD00CFFD5B2385EA9, 0x00003FEF // C_4
639 data8 0x93E4BD18292A14CD, 0x0000BFE9 // C_5
640 LOCAL_OBJECT_END(sincosl_table_c)
642 LOCAL_OBJECT_START(sincosl_table_s)
643 //data4 0xAAAAAAAA, 0xAAAAAAAA, 0x0000BFFC,0x00000000 // S_1
644 //data4 0x888868DB, 0x88888888, 0x00003FF8,0x00000000 // S_2
645 //data4 0x055EFD4B, 0xD00D00D0, 0x0000BFF2,0x00000000 // S_3
646 //data4 0x839730B9, 0xB8EF1C5D, 0x00003FEC,0x00000000 // S_4
647 //data4 0xE5B3F492, 0xD71EA3A4, 0x0000BFE5,0x00000000 // S_5
648 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
649 data8 0x88888888888868DB, 0x00003FF8 // S_2
650 data8 0xD00D00D0055EFD4B, 0x0000BFF2 // S_3
651 data8 0xB8EF1C5D839730B9, 0x00003FEC // S_4
652 data8 0xD71EA3A4E5B3F492, 0x0000BFE5 // S_5
653 data4 0x38800000, 0xB8800000         // two**-14 and -two**-14
654 LOCAL_OBJECT_END(sincosl_table_s)
656 FR_Input_X        = f8
657 FR_Result         = f8
658 FR_ResultS        = f9
659 FR_ResultC        = f8
660 FR_r              = f8
661 FR_c              = f9
663 FR_norm_x         = f9
664 FR_inv_pi_2to63   = f10
665 FR_rshf_2to64     = f11
666 FR_2tom64         = f12
667 FR_rshf           = f13
668 FR_N_float_signif = f14
669 FR_abs_x          = f15
671 FR_r6             = f32
672 FR_r7             = f33
673 FR_Pi_by_4        = f34
674 FR_Two_to_M14     = f35
675 FR_Neg_Two_to_M14 = f36
676 FR_Two_to_M33     = f37
677 FR_Neg_Two_to_M33 = f38
678 FR_Neg_Two_to_M67 = f39
679 FR_Inv_pi_by_2    = f40
680 FR_N_float        = f41
681 FR_N_fix          = f42
682 FR_P_1            = f43
683 FR_P_2            = f44
684 FR_P_3            = f45
685 FR_s              = f46
686 FR_w              = f47
687 FR_Z              = f50
688 FR_A              = f51
689 FR_a              = f52
690 FR_t              = f53
691 FR_U_1            = f54
692 FR_U_2            = f55
693 FR_C_1            = f56
694 FR_C_2            = f57
695 FR_C_3            = f58
696 FR_C_4            = f59
697 FR_C_5            = f60
698 FR_S_1            = f61
699 FR_S_2            = f62
700 FR_S_3            = f63
701 FR_S_4            = f64
702 FR_S_5            = f65
703 FR_r_hi           = f68
704 FR_r_lo           = f69
705 FR_rsq            = f70
706 FR_r_cubed        = f71
707 FR_C_hi           = f72
708 FR_N_0            = f73
709 FR_d_1            = f74
710 FR_V_hi           = f75
711 FR_V_lo           = f76
712 FR_U_hi           = f77
713 FR_U_lo           = f78
714 FR_U_hiabs        = f79
715 FR_V_hiabs        = f80
716 FR_PP_8           = f81
717 FR_QQ_8           = f101
718 FR_PP_7           = f82
719 FR_QQ_7           = f102
720 FR_PP_6           = f83
721 FR_QQ_6           = f103
722 FR_PP_5           = f84
723 FR_QQ_5           = f104
724 FR_PP_4           = f85
725 FR_QQ_4           = f105
726 FR_PP_3           = f86
727 FR_QQ_3           = f106
728 FR_PP_2           = f87
729 FR_QQ_2           = f107
730 FR_QQ_1           = f108
731 FR_r_hi_sq        = f88
732 FR_N_0_fix        = f89
733 FR_Inv_P_0        = f90
734 FR_d_2            = f93
735 FR_P_0            = f95
736 FR_C_lo           = f96
737 FR_PP_1           = f97
738 FR_PP_1_lo        = f98
739 FR_ArgPrime       = f99
740 FR_inexact        = f100
742 FR_Neg_Two_to_M3  = f109
743 FR_Two_to_M3      = f110
745 FR_poly_hiS       = f66
746 FR_poly_hiC       = f112
748 FR_poly_loS       = f67
749 FR_poly_loC       = f113
751 FR_polyS          = f92
752 FR_polyC          = f114
754 FR_cS             = FR_c
755 FR_cC             = f115
757 FR_corrS          = f91
758 FR_corrC          = f116
760 FR_U_hiC          = f117
761 FR_U_loC          = f118
763 FR_VS             = f75
764 FR_VC             = f119
766 FR_FirstS         = f120
767 FR_FirstC         = f121
769 FR_U_hiS          = FR_U_hi
770 FR_U_loS          = FR_U_lo
772 FR_Tmp            = f94
777 sincos_pResSin = r34
778 sincos_pResCos = r35
780 GR_exp_m2_to_m3= r36
781 GR_N_Inc       = r37
782 GR_Cis         = r38
783 GR_signexp_x   = r40
784 GR_exp_x       = r40
785 GR_exp_mask    = r41
786 GR_exp_2_to_63 = r42
787 GR_exp_2_to_m3 = r43
788 GR_exp_2_to_24 = r44
790 GR_N_SignS     = r45
791 GR_N_SignC     = r46
792 GR_N_SinCos    = r47
794 GR_sig_inv_pi  = r48
795 GR_rshf_2to64  = r49
796 GR_exp_2tom64  = r50
797 GR_rshf        = r51
798 GR_ad_p        = r52
799 GR_ad_d        = r53
800 GR_ad_pp       = r54
801 GR_ad_qq       = r55
802 GR_ad_c        = r56
803 GR_ad_s        = r57
804 GR_ad_ce       = r58
805 GR_ad_se       = r59
806 GR_ad_m14      = r60
807 GR_ad_s1       = r61
809 // For unwind support
810 GR_SAVE_B0     = r39
811 GR_SAVE_GP     = r40
812 GR_SAVE_PFS    = r41
815 .section .text
817 GLOBAL_IEEE754_ENTRY(sincosl)
818 { .mlx  ///////////////////////////// 1 /////////////////
819       alloc r32 = ar.pfs,3,27,2,0
820       movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
822 { .mlx
823       mov GR_N_Inc = 0x0
824       movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
827 { .mfi ///////////////////////////// 2 /////////////////
828       addl           GR_ad_p   = @ltoff(FSINCOSL_CONSTANTS#), gp
829       fclass.m p6, p0 =  FR_Input_X, 0x1E3 // Test x natval, nan, inf
830       mov GR_exp_2_to_m3 = 0xffff - 3      // Exponent of 2^-3
832 { .mfb
833       mov GR_Cis = 0x0
834       fnorm.s1 FR_norm_x = FR_Input_X      // Normalize x
835     br.cond.sptk _COMMON_SINCOSL
837 GLOBAL_IEEE754_END(sincosl)
838 libm_alias_ldouble_other (__sincos, sincos)
840 GLOBAL_LIBM_ENTRY(__libm_sincosl)
841 { .mlx  ///////////////////////////// 1 /////////////////
842       alloc r32 = ar.pfs,3,27,2,0
843       movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
845 { .mlx
846       mov GR_N_Inc = 0x0
847       movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
850 { .mfi ///////////////////////////// 2 /////////////////
851       addl           GR_ad_p   = @ltoff(FSINCOSL_CONSTANTS#), gp
852       fclass.m p6, p0 =  FR_Input_X, 0x1E3 // Test x natval, nan, inf
853       mov GR_exp_2_to_m3 = 0xffff - 3      // Exponent of 2^-3
855 { .mfb
856       mov GR_Cis = 0x1
857       fnorm.s1 FR_norm_x = FR_Input_X      // Normalize x
858       nop.b 0
861 _COMMON_SINCOSL:
862 { .mfi ///////////////////////////// 3 /////////////////
863       setf.sig FR_inv_pi_2to63 = GR_sig_inv_pi // Form 1/pi * 2^63
864       nop.f 0
865       mov GR_exp_2tom64 = 0xffff - 64      // Scaling constant to compute N
867 { .mlx
868       setf.d FR_rshf_2to64 = GR_rshf_2to64    // Form const 1.1000 * 2^(63+64)
869       movl GR_rshf = 0x43e8000000000000       // Form const 1.1000 * 2^63
872 { .mfi ///////////////////////////// 4 /////////////////
873       ld8 GR_ad_p = [GR_ad_p]              // Point to Inv_pi_by_2
874       fclass.m p7, p0 = FR_Input_X, 0x0b   // Test x denormal
875       nop.i 0
878 { .mfi    ///////////////////////////// 5 /////////////////
879       getf.exp GR_signexp_x = FR_Input_X   // Get sign and exponent of x
880       fclass.m p10, p0 = FR_Input_X, 0x007 // Test x zero
881       nop.i 0
883 { .mib
884       mov GR_exp_mask = 0x1ffff            // Exponent mask
885       nop.i 0
886 (p6)  br.cond.spnt SINCOSL_SPECIAL         // Branch if x natval, nan, inf
889 { .mfi ///////////////////////////// 6 /////////////////
890       setf.exp FR_2tom64 = GR_exp_2tom64   // Form 2^-64 for scaling N_float
891       nop.f 0
892       add GR_ad_d = 0x70, GR_ad_p          // Point to constant table d
894 { .mib
895       setf.d FR_rshf = GR_rshf         // Form right shift const 1.1000 * 2^63
896       mov  GR_exp_m2_to_m3 = 0x2fffc       // Form -(2^-3)
897 (p7)  br.cond.spnt SINCOSL_DENORMAL        // Branch if x denormal
900 SINCOSL_COMMON2:
901 { .mfi ///////////////////////////// 7 /////////////////
902       and GR_exp_x = GR_exp_mask, GR_signexp_x // Get exponent of x
903       fclass.nm p8, p0 = FR_Input_X, 0x1FF // Test x unsupported type
904       mov GR_exp_2_to_63 = 0xffff + 63     // Exponent of 2^63
906 { .mib
907       add GR_ad_pp = 0x40, GR_ad_d         // Point to constant table pp
908       mov GR_exp_2_to_24 = 0xffff + 24     // Exponent of 2^24
909 (p10) br.cond.spnt SINCOSL_ZERO            // Branch if x zero
912 { .mfi ///////////////////////////// 8 /////////////////
913       ldfe FR_Inv_pi_by_2 = [GR_ad_p], 16  // Load 2/pi
914       fcmp.eq.s0 p15, p0 = FR_Input_X, f0  // Dummy to set denormal
915       add GR_ad_qq = 0xa0, GR_ad_pp        // Point to constant table qq
917 { .mfi
918       ldfe FR_Pi_by_4 = [GR_ad_d], 16      // Load pi/4 for range test
919       nop.f 0
920       cmp.ge p10,p0 = GR_exp_x, GR_exp_2_to_63   // Is |x| >= 2^63
923 { .mfi ///////////////////////////// 9 /////////////////
924       ldfe FR_P_0 = [GR_ad_p], 16          // Load P_0 for pi/4 <= |x| < 2^63
925       fmerge.s FR_abs_x = f1, FR_norm_x    // |x|
926       add GR_ad_c = 0x90, GR_ad_qq         // Point to constant table c
928 { .mfi
929       ldfe FR_Inv_P_0 = [GR_ad_d], 16      // Load 1/P_0 for pi/4 <= |x| < 2^63
930       nop.f 0
931       cmp.ge p7,p0 = GR_exp_x, GR_exp_2_to_24   // Is |x| >= 2^24
934 { .mfi ///////////////////////////// 10 /////////////////
935       ldfe FR_P_1 = [GR_ad_p], 16          // Load P_1 for pi/4 <= |x| < 2^63
936       nop.f 0
937       add GR_ad_s = 0x50, GR_ad_c          // Point to constant table s
939 { .mfi
940       ldfe FR_PP_8 = [GR_ad_pp], 16        // Load PP_8 for 2^-3 < |r| < pi/4
941       nop.f 0
942       nop.i 0
945 { .mfi ///////////////////////////// 11 /////////////////
946       ldfe FR_P_2 = [GR_ad_p], 16          // Load P_2 for pi/4 <= |x| < 2^63
947       nop.f 0
948       add GR_ad_ce = 0x40, GR_ad_c         // Point to end of constant table c
950 { .mfi
951       ldfe FR_QQ_8 = [GR_ad_qq], 16        // Load QQ_8 for 2^-3 < |r| < pi/4
952       nop.f 0
953       nop.i 0
956 { .mfi ///////////////////////////// 12 /////////////////
957       ldfe FR_QQ_7 = [GR_ad_qq], 16        // Load QQ_7 for 2^-3 < |r| < pi/4
958       fma.s1  FR_N_float_signif = FR_Input_X, FR_inv_pi_2to63, FR_rshf_2to64
959       add GR_ad_se = 0x40, GR_ad_s         // Point to end of constant table s
961 { .mib
962       ldfe FR_PP_7 = [GR_ad_pp], 16        // Load PP_7 for 2^-3 < |r| < pi/4
963       mov GR_ad_s1 = GR_ad_s               // Save pointer to S_1
964 (p10) br.cond.spnt SINCOSL_ARG_TOO_LARGE   // Branch if |x| >= 2^63
965                                            // Use Payne-Hanek Reduction
968 { .mfi ///////////////////////////// 13 /////////////////
969       ldfe FR_P_3 = [GR_ad_p], 16          // Load P_3 for pi/4 <= |x| < 2^63
970       fmerge.se FR_r = FR_norm_x, FR_norm_x // r = x, in case |x| < pi/4
971       add GR_ad_m14 = 0x50, GR_ad_s        // Point to constant table m14
973 { .mfb
974       ldfps FR_Two_to_M3, FR_Neg_Two_to_M3 = [GR_ad_d], 8
975       fma.s1 FR_rsq = FR_norm_x, FR_norm_x, f0 // rsq = x*x, in case |x| < pi/4
976 (p7)  br.cond.spnt SINCOSL_LARGER_ARG      // Branch if 2^24 <= |x| < 2^63
977                                            // Use pre-reduction
980 { .mmf ///////////////////////////// 14 /////////////////
981       ldfe FR_PP_6 = [GR_ad_pp], 16       // Load PP_6 for normal path
982       ldfe FR_QQ_6 = [GR_ad_qq], 16       // Load QQ_6 for normal path
983       fmerge.se FR_c = f0, f0             // c = 0 in case |x| < pi/4
986 { .mmf ///////////////////////////// 15 /////////////////
987       ldfe FR_PP_5 = [GR_ad_pp], 16       // Load PP_5 for normal path
988       ldfe FR_QQ_5 = [GR_ad_qq], 16       // Load QQ_5 for normal path
989       nop.f 0
992 // Here if 0 < |x| < 2^24
993 { .mfi ///////////////////////////// 17 /////////////////
994       ldfe FR_S_5 = [GR_ad_se], -16       // Load S_5 if i_1=0
995       fcmp.lt.s1  p6, p7 = FR_abs_x, FR_Pi_by_4  // Test |x| < pi/4
996       nop.i 0
998 { .mfi
999       ldfe FR_C_5 = [GR_ad_ce], -16       // Load C_5 if i_1=1
1000       fms.s1 FR_N_float = FR_N_float_signif, FR_2tom64, FR_rshf
1001       nop.i 0
1004 { .mmi ///////////////////////////// 18 /////////////////
1005       ldfe FR_S_4 = [GR_ad_se], -16       // Load S_4 if i_1=0
1006       ldfe FR_C_4 = [GR_ad_ce], -16       // Load C_4 if i_1=1
1007       nop.i 0
1011 //     N  = Arg * 2/pi
1012 //     Check if Arg < pi/4
1015 //     Case 2: Convert integer N_fix back to normalized floating-point value.
1016 //     Case 1: p8 is only affected  when p6 is set
1019 //     Grab the integer part of N and call it N_fix
1021 { .mfi ///////////////////////////// 19 /////////////////
1022 (p7)  ldfps FR_Two_to_M33, FR_Neg_Two_to_M33 = [GR_ad_d], 8
1023 (p6)  fma.s1 FR_r_cubed = FR_r, FR_rsq, f0        // r^3 if |x| < pi/4
1024 (p6)  mov GR_N_Inc = 0x0                         // N_IncS if |x| < pi/4
1027 //     If |x| < pi/4, r = x and c = 0
1028 //     lf |x| < pi/4, is x < 2**(-3).
1029 //     r = Arg
1030 //     c = 0
1031 { .mmi ///////////////////////////// 20 /////////////////
1032 (p7)  getf.sig  GR_N_Inc = FR_N_float_signif
1033       nop.m 0
1034 (p6)  cmp.lt.unc p8,p0 = GR_exp_x, GR_exp_2_to_m3   // Is |x| < 2^-3
1038 //     lf |x| < pi/4, is -2**(-3)< x < 2**(-3) - set p8.
1039 //     If |x| >= pi/4,
1040 //     Create the right N for |x| < pi/4 and otherwise
1041 //     Case 2: Place integer part of N in GP register
1044 { .mbb ///////////////////////////// 21 /////////////////
1045       nop.m 0
1046 (p8)  br.cond.spnt SINCOSL_SMALL_R_0    // Branch if 0 < |x| < 2^-3
1047 (p6)  br.cond.spnt SINCOSL_NORMAL_R_0   // Branch if 2^-3 <= |x| < pi/4
1050 // Here if pi/4 <= |x| < 2^24
1051 { .mfi
1052       ldfs FR_Neg_Two_to_M67 = [GR_ad_d], 8     // Load -2^-67
1053       fnma.s1 FR_s = FR_N_float, FR_P_1, FR_Input_X // s = -N * P_1  + Arg
1054       nop.i 0
1056 { .mfi
1057       nop.m 0
1058       fma.s1 FR_w = FR_N_float, FR_P_2, f0      // w = N * P_2
1059       nop.i 0
1062 { .mfi
1063       nop.m 0
1064       fms.s1 FR_r = FR_s, f1, FR_w        // r = s - w, assume |s| >= 2^-33
1065       nop.i 0
1068 { .mfi
1069       nop.m 0
1070       fcmp.lt.s1 p7, p6 = FR_s, FR_Two_to_M33
1071       nop.i 0
1074 { .mfi
1075       nop.m 0
1076 (p7)  fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33 // p6 if |s| >= 2^-33, else p7
1077       nop.i 0
1080 { .mfi
1081       nop.m 0
1082       fms.s1 FR_c = FR_s, f1, FR_r             // c = s - r, for |s| >= 2^-33
1083       nop.i 0
1085 { .mfi
1086       nop.m 0
1087       fma.s1 FR_rsq = FR_r, FR_r, f0           // rsq = r * r, for |s| >= 2^-33
1088       nop.i 0
1091 { .mfi
1092       nop.m 0
1093 (p7)  fma.s1 FR_w = FR_N_float, FR_P_3, f0
1094       nop.i 0
1097 { .mmf
1098       ldfe FR_C_1 = [GR_ad_pp], 16     // Load C_1 if i_1=0
1099       ldfe FR_S_1 = [GR_ad_qq], 16     // Load S_1 if i_1=1
1100       frcpa.s1 FR_r_hi, p15 = f1, FR_r  // r_hi = frcpa(r)
1103 { .mfi
1104       nop.m 0
1105 (p6)  fcmp.lt.unc.s1 p8, p13 = FR_r, FR_Two_to_M3 // If big s, test r with 2^-3
1106       nop.i 0
1109 { .mfi
1110       nop.m 0
1111 (p7)  fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1112       nop.i 0
1116 //     For big s: r = s - w: No futher reduction is necessary
1117 //     For small s: w = N * P_3 (change sign) More reduction
1119 { .mfi
1120     nop.m 0
1121 (p8)  fcmp.gt.s1 p8, p13 = FR_r, FR_Neg_Two_to_M3 // If big s, p8 if |r| < 2^-3
1122     nop.i 0
1125 { .mfi
1126       nop.m 0
1127       fma.s1 FR_polyS = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7
1128       nop.i 0
1130 { .mfi
1131       nop.m 0
1132       fma.s1 FR_polyC = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7
1133       nop.i 0
1136 { .mfi
1137       nop.m 0
1138 (p7)  fms.s1 FR_r = FR_s, f1, FR_U_1
1139       nop.i 0
1142 { .mfi
1143       nop.m 0
1144 (p6)  fma.s1 FR_r_cubed = FR_r, FR_rsq, f0  // rcubed = r * rsq
1145       nop.i 0
1148 { .mfi
1150 //     For big s: Is |r| < 2**(-3)?
1151 //     For big s: c = S - r
1152 //     For small s: U_1 = N * P_2 + w
1154 //     If p8 is set, prepare to branch to Small_R.
1155 //     If p9 is set, prepare to branch to Normal_R.
1156 //     For big s,  r is complete here.
1159 //     For big s: c = c + w (w has not been negated.)
1160 //     For small s: r = S - U_1
1162       nop.m 0
1163 (p6)  fms.s1 FR_c = FR_c, f1, FR_w
1164       nop.i 0
1166 { .mbb
1167       nop.m 0
1168 (p8)  br.cond.spnt  SINCOSL_SMALL_R_1  // Branch if |s|>=2^-33, |r| < 2^-3,
1169                                        // and pi/4 <= |x| < 2^24
1170 (p13) br.cond.sptk  SINCOSL_NORMAL_R_1 // Branch if |s|>=2^-33, |r| >= 2^-3,
1171                                        // and pi/4 <= |x| < 2^24
1174 SINCOSL_S_TINY:
1176 // Here if |s| < 2^-33, and pi/4 <= |x| < 2^24
1178 { .mfi
1179        and GR_N_SinCos = 0x1, GR_N_Inc
1180        fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1181        tbit.z p8,p12       = GR_N_Inc, 0
1186 //     For small s: U_2 = N * P_2 - U_1
1187 //     S_1 stored constant - grab the one stored with the
1188 //     coefficients.
1190 { .mfi
1191       ldfe      FR_S_1 = [GR_ad_s1], 16
1192       fma.s1  FR_polyC = f0, f1, FR_Neg_Two_to_M67
1193       sub GR_N_SignS =  GR_N_Inc, GR_N_SinCos
1195 { .mfi
1196       add GR_N_SignC =  GR_N_Inc, GR_N_SinCos
1197       nop.f 0
1198       nop.i 0
1201 { .mfi
1202       nop.m 0
1203       fms.s1  FR_s = FR_s, f1, FR_r
1204 (p8)  tbit.z.unc p10,p11   = GR_N_SignC, 1
1206 { .mfi
1207       nop.m 0
1208       fma.s1  FR_rsq = FR_r, FR_r, f0
1209       nop.i 0
1212 { .mfi
1213       nop.m 0
1214       fma.s1  FR_U_2 = FR_U_2, f1, FR_w
1215 (p8)  tbit.z.unc p8,p9    = GR_N_SignS, 1
1218 { .mfi
1219       nop.m 0
1220       fmerge.se FR_FirstS = FR_r, FR_r
1221 (p12) tbit.z.unc p14,p15  = GR_N_SignC, 1
1223 { .mfi
1224       nop.m 0
1225       fma.s1 FR_FirstC = f0, f1, f1
1226       nop.i 0
1229 { .mfi
1230       nop.m 0
1231       fms.s1  FR_c = FR_s, f1, FR_U_1
1232 (p12) tbit.z.unc p12,p13  = GR_N_SignS, 1
1235 { .mfi
1236       nop.m 0
1237       fma.s1  FR_r = FR_S_1, FR_r, f0
1238       nop.i 0
1241 { .mfi
1242       nop.m 0
1243       fma.s0  FR_S_1 = FR_S_1, FR_S_1, f0
1244       nop.i 0
1247 { .mfi
1248       nop.m 0
1249       fms.s1 FR_c = FR_c, f1, FR_U_2
1250       nop.i 0
1253 .pred.rel "mutex",p9,p15
1254 { .mfi
1255       nop.m 0
1256 (p9)  fms.s0 FR_FirstS   = f1, f0, FR_FirstS
1257       nop.i 0
1259 { .mfi
1260       nop.m 0
1261 (p15) fms.s0 FR_FirstS   = f1, f0, FR_FirstS
1262       nop.i 0
1265 .pred.rel "mutex",p11,p13
1266 { .mfi
1267       nop.m 0
1268 (p11) fms.s0 FR_FirstC   = f1, f0, FR_FirstC
1269       nop.i 0
1271 { .mfi
1272       nop.m 0
1273 (p13) fms.s0 FR_FirstC   = f1, f0, FR_FirstC
1274       nop.i 0
1277 { .mfi
1278       nop.m 0
1279       fma.s1 FR_polyS = FR_r, FR_rsq, FR_c
1280       nop.i 0
1284 .pred.rel "mutex",p8,p9
1285 { .mfi
1286       nop.m 0
1287 (p8)  fma.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1288       nop.i 0
1290 { .mfi
1291       nop.m 0
1292 (p9)  fms.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1293       nop.i 0
1296 .pred.rel "mutex",p10,p11
1297 { .mfi
1298       nop.m 0
1299 (p10) fma.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1300       nop.i 0
1302 { .mfi
1303       nop.m 0
1304 (p11) fms.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1305       nop.i 0
1310 .pred.rel "mutex",p12,p13
1311 { .mfi
1312       nop.m 0
1313 (p12) fma.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1314       nop.i 0
1316 { .mfi
1317       nop.m 0
1318 (p13) fms.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1319       nop.i 0
1322 .pred.rel "mutex",p14,p15
1323 { .mfi
1324       nop.m 0
1325 (p14) fma.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1326       nop.i 0
1328 { .mfb
1329       cmp.eq  p10, p0 = 0x1, GR_Cis
1330 (p15) fms.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1331 (p10) br.ret.sptk               b0
1334 { .mmb       // exit for sincosl
1335       stfe  [sincos_pResSin] =  FR_ResultS
1336       stfe  [sincos_pResCos] =  FR_ResultC
1337       br.ret.sptk               b0
1345 SINCOSL_LARGER_ARG:
1347 // Here if 2^24 <= |x| < 2^63
1349 { .mfi
1350       ldfe FR_d_1 = [GR_ad_p], 16          // Load d_1 for |x| >= 2^24 path
1351       fma.s1 FR_N_0 = FR_Input_X, FR_Inv_P_0, f0 //     N_0 = Arg * Inv_P_0
1352       nop.i 0
1355 { .mmi
1356       ldfps FR_Two_to_M14, FR_Neg_Two_to_M14 = [GR_ad_m14]
1357       nop.m 0
1358       nop.i 0
1361 { .mfi
1362       ldfe FR_d_2 = [GR_ad_p], 16          // Load d_2 for |x| >= 2^24 path
1363       nop.f 0
1364       nop.i 0
1367 { .mfi
1368       nop.m 0
1369       fcvt.fx.s1 FR_N_0_fix = FR_N_0 // N_0_fix  = integer part of N_0
1370       nop.i 0
1373 { .mfi
1374       nop.m 0
1375       fcvt.xf FR_N_0 = FR_N_0_fix //     Make N_0 the integer part
1376       nop.i 0
1379 { .mfi
1380       nop.m 0
1381       fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X // Arg'=-N_0*P_0+Arg
1382       nop.i 0
1384 { .mfi
1385       nop.m 0
1386       fma.s1 FR_w = FR_N_0, FR_d_1, f0 //     w  = N_0 * d_1
1387       nop.i 0
1391 { .mfi
1392       nop.m 0
1393       fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0 //  N = A' * 2/pi
1394       nop.i 0
1397 { .mfi
1398       nop.m 0
1399       fcvt.fx.s1 FR_N_fix = FR_N_float //     N_fix is the integer part
1400       nop.i 0
1403 { .mfi
1404       nop.m 0
1405       fcvt.xf FR_N_float = FR_N_fix
1406       nop.i 0
1409 { .mfi
1410       getf.sig GR_N_Inc = FR_N_fix // N is the integer part of
1411                                  // the reduced-reduced argument
1412       nop.f 0
1413       nop.i 0
1416 { .mfi
1417       nop.m 0
1418       fnma.s1 FR_s = FR_N_float, FR_P_1, FR_ArgPrime //     s = -N*P_1 + Arg'
1419       nop.i 0
1421 { .mfi
1422       nop.m 0
1423       fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w //     w = -N*P_2 + w
1424       nop.i 0
1428 //     For |s|  > 2**(-14) r = S + w (r complete)
1429 //     Else       U_hi = N_0 * d_1
1431 { .mfi
1432       nop.m 0
1433       fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1434       nop.i 0
1437 { .mfi
1438       nop.m 0
1439 (p9)  fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14  // p9 if |s| < 2^-14
1440       nop.i 0
1444 //     Either S <= -2**(-14) or S >= 2**(-14)
1445 //     or -2**(-14) < s < 2**(-14)
1447 { .mfi
1448       nop.m 0
1449 (p9)  fma.s1 FR_V_hi = FR_N_float, FR_P_2, f0
1450       nop.i 0
1452 { .mfi
1453       nop.m 0
1454 (p9)  fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1455       nop.i 0
1458 { .mfi
1459       nop.m 0
1460 (p8)  fma.s1 FR_r = FR_s, f1, FR_w
1461       nop.i 0
1463 { .mfi
1464       nop.m 0
1465 (p9)  fma.s1 FR_w = FR_N_float, FR_P_3, f0
1466       nop.i 0
1470 //    We need abs of both U_hi and V_hi - don't
1471 //    worry about switched sign of V_hi.
1473 //    Big s: finish up c = (S - r) + w (c complete)
1474 //    Case 4: A =  U_hi + V_hi
1475 //    Note: Worry about switched sign of V_hi, so subtract instead of add.
1477 { .mfi
1478       nop.m 0
1479 (p9)  fms.s1 FR_A = FR_U_hi, f1, FR_V_hi
1480       nop.i 0
1482 { .mfi
1483       nop.m 0
1484 (p9)  fnma.s1 FR_V_lo = FR_N_float, FR_P_2, FR_V_hi
1485       nop.i 0
1488 { .mfi
1489       nop.m 0
1490 (p9)  fmerge.s FR_V_hiabs = f0, FR_V_hi
1491       nop.i 0
1493 { .mfi
1494       nop.m 0
1495 (p9)  fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi // For small s: U_lo=N_0*d_1-U_hi
1496       nop.i 0
1500 //    For big s: Is |r| < 2**(-3)
1501 //    For big s: if p12 set, prepare to branch to Small_R.
1502 //    For big s: If p13 set, prepare to branch to Normal_R.
1504 { .mfi
1505       nop.m 0
1506 (p9)  fmerge.s FR_U_hiabs = f0, FR_U_hi
1507       nop.i 0
1509 { .mfi
1510       nop.m 0
1511 (p8)  fms.s1 FR_c = FR_s, f1, FR_r  //     For big s: c = S - r
1512       nop.i 0
1516 //    For small S: V_hi = N * P_2
1517 //                 w = N * P_3
1518 //    Note the product does not include the (-) as in the writeup
1519 //    so (-) missing for V_hi and w.
1521 { .mfi
1522       nop.m 0
1523 (p8)  fcmp.lt.unc.s1 p12, p13 = FR_r, FR_Two_to_M3
1524       nop.i 0
1527 { .mfi
1528       nop.m 0
1529 (p12) fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1530       nop.i 0
1533 { .mfi
1534       nop.m 0
1535 (p8)  fma.s1 FR_c = FR_c, f1, FR_w
1536       nop.i 0
1538 { .mfb
1539       nop.m 0
1540 (p9)  fms.s1 FR_w = FR_N_0, FR_d_2, FR_w
1541 (p12) br.cond.spnt SINCOSL_SMALL_R      // Branch if |r| < 2^-3
1542                                         // and 2^24 <= |x| < 2^63
1545 { .mib
1546       nop.m 0
1547       nop.i 0
1548 (p13) br.cond.sptk SINCOSL_NORMAL_R     // Branch if |r| >= 2^-3
1549                                         // and 2^24 <= |x| < 2^63
1552 SINCOSL_LARGER_S_TINY:
1553 //    Here if |s| < 2^-14, and 2^24 <= |x| < 2^63
1555 //    Big s: Vector off when |r| < 2**(-3).  Recall that p8 will be true.
1556 //    The remaining stuff is for Case 4.
1557 //    Small s: V_lo = N * P_2 + U_hi (U_hi is in place of V_hi in writeup)
1558 //    Note: the (-) is still missing for V_lo.
1559 //    Small s: w = w + N_0 * d_2
1560 //    Note: the (-) is now incorporated in w.
1562 { .mfi
1563       and GR_N_SinCos = 0x1, GR_N_Inc
1564       fcmp.ge.unc.s1 p6, p7 = FR_U_hiabs, FR_V_hiabs
1565       tbit.z p8,p12       = GR_N_Inc, 0
1567 { .mfi
1568       nop.m 0
1569       fma.s1 FR_t = FR_U_lo, f1, FR_V_lo //     C_hi = S + A
1570       nop.i 0
1573 { .mfi
1574       sub GR_N_SignS =  GR_N_Inc, GR_N_SinCos
1575 (p6)  fms.s1 FR_a = FR_U_hi, f1, FR_A
1576       add GR_N_SignC =  GR_N_Inc, GR_N_SinCos
1578 { .mfi
1579       nop.m 0
1580 (p7)  fma.s1 FR_a = FR_V_hi, f1, FR_A
1581       nop.i 0
1584 { .mmf
1585       ldfe FR_C_1 = [GR_ad_c], 16
1586       ldfe  FR_S_1 = [GR_ad_s], 16
1587       fma.s1 FR_C_hi = FR_s, f1, FR_A
1590 { .mmi
1591       ldfe FR_C_2 = [GR_ad_c], 64
1592       ldfe FR_S_2 = [GR_ad_s], 64
1593 (p8)  tbit.z.unc p10,p11   = GR_N_SignC, 1
1597 //    r and c have been computed.
1598 //    Make sure ftz mode is set - should be automatic when using wre
1599 //    |r| < 2**(-3)
1600 //    Get [i_0,i_1] - two lsb of N_fix.
1602 //    For larger u than v: a = U_hi - A
1603 //    Else a = V_hi - A (do an add to account for missing (-) on V_hi
1605 { .mfi
1606       nop.m 0
1607       fma.s1 FR_t = FR_t, f1, FR_w //     t = t + w
1608 (p8)  tbit.z.unc p8,p9    = GR_N_SignS, 1
1610 { .mfi
1611       nop.m 0
1612 (p6)  fms.s1 FR_a = FR_a, f1, FR_V_hi
1613       nop.i 0
1617 //     If u > v: a = (U_hi - A)  + V_hi
1618 //     Else      a = (V_hi - A)  + U_hi
1619 //     In each case account for negative missing from V_hi.
1621 { .mfi
1622       nop.m 0
1623       fms.s1 FR_C_lo = FR_s, f1, FR_C_hi
1624 (p12) tbit.z.unc p14,p15  = GR_N_SignC, 1
1626 { .mfi
1627       nop.m 0
1628 (p7)  fms.s1 FR_a = FR_U_hi, f1, FR_a
1629       nop.i 0
1632 { .mfi
1633       nop.m 0
1634       fma.s1 FR_C_lo = FR_C_lo, f1, FR_A //     C_lo = (S - C_hi) + A
1635 (p12) tbit.z.unc p12,p13  = GR_N_SignS, 1
1637 { .mfi
1638       nop.m 0
1639       fma.s1 FR_t = FR_t, f1, FR_a //     t = t + a
1640       nop.i 0
1643 { .mfi
1644       nop.m 0
1645       fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1646       nop.i 0
1649 { .mfi
1650       nop.m 0
1651       fma.s1 FR_C_lo = FR_C_lo, f1, FR_t //     C_lo = C_lo + t
1652       nop.i 0
1656 { .mfi
1657       nop.m 0
1658       fma.s1 FR_rsq = FR_r, FR_r, f0
1659       nop.i 0
1661 { .mfi
1662       nop.m 0
1663       fms.s1 FR_c = FR_C_hi, f1, FR_r
1664       nop.i 0
1667 { .mfi
1668       nop.m 0
1669       fma.s1 FR_FirstS = f0, f1, FR_r
1670       nop.i 0
1672 { .mfi
1673       nop.m 0
1674       fma.s1 FR_FirstC = f0, f1, f1
1675       nop.i 0
1678 { .mfi
1679       nop.m 0
1680       fma.s1 FR_polyS = FR_rsq, FR_S_2, FR_S_1
1681       nop.i 0
1683 { .mfi
1684       nop.m 0
1685       fma.s1 FR_polyC = FR_rsq, FR_C_2, FR_C_1
1686       nop.i 0
1689 { .mfi
1690       nop.m 0
1691       fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1692       nop.i 0
1694 { .mfi
1695       nop.m 0
1696       fma.s1 FR_c = FR_c, f1, FR_C_lo
1697       nop.i 0
1700 .pred.rel "mutex",p9,p15
1701 { .mfi
1702       nop.m 0
1703 (p9)  fms.s0 FR_FirstS   = f1, f0, FR_FirstS
1704       nop.i 0
1706 { .mfi
1707       nop.m 0
1708 (p15) fms.s0 FR_FirstS   = f1, f0, FR_FirstS
1709       nop.i 0
1712 .pred.rel "mutex",p11,p13
1713 { .mfi
1714       nop.m 0
1715 (p11) fms.s0 FR_FirstC   = f1, f0, FR_FirstC
1716       nop.i 0
1718 { .mfi
1719       nop.m 0
1720 (p13) fms.s0 FR_FirstC   = f1, f0, FR_FirstC
1721       nop.i 0
1725 { .mfi
1726       nop.m 0
1727       fma.s1 FR_polyS = FR_r_cubed, FR_polyS, FR_c
1728       nop.i 0
1730 { .mfi
1731       nop.m 0
1732       fma.s1 FR_polyC = FR_rsq, FR_polyC, f0
1733       nop.i 0
1738 .pred.rel "mutex",p8,p9
1739 { .mfi
1740       nop.m 0
1741 (p8)  fma.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1742       nop.i 0
1744 { .mfi
1745       nop.m 0
1746 (p9)  fms.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1747       nop.i 0
1750 .pred.rel "mutex",p10,p11
1751 { .mfi
1752       nop.m 0
1753 (p10) fma.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1754       nop.i 0
1756 { .mfi
1757       nop.m 0
1758 (p11) fms.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1759       nop.i 0
1764 .pred.rel "mutex",p12,p13
1765 { .mfi
1766       nop.m 0
1767 (p12) fma.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1768       nop.i 0
1770 { .mfi
1771       nop.m 0
1772 (p13) fms.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1773       nop.i 0
1776 .pred.rel "mutex",p14,p15
1777 { .mfi
1778       nop.m 0
1779 (p14) fma.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1780       nop.i 0
1782 { .mfb
1783       cmp.eq  p10, p0 = 0x1, GR_Cis
1784 (p15) fms.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1785 (p10) br.ret.sptk               b0
1789 { .mmb       // exit for sincosl
1790       stfe  [sincos_pResSin] =  FR_ResultS
1791       stfe  [sincos_pResCos] =  FR_ResultC
1792       br.ret.sptk               b0
1797 SINCOSL_SMALL_R:
1799 // Here if |r| < 2^-3
1801 // Enter with r, c, and N_Inc computed
1803 { .mfi
1804       nop.m 0
1805       fma.s1 FR_rsq = FR_r, FR_r, f0   // rsq = r * r
1806       nop.i 0
1809 { .mmi
1810       ldfe FR_S_5 = [GR_ad_se], -16    // Load S_5
1811       ldfe FR_C_5 = [GR_ad_ce], -16    // Load C_5
1812       nop.i 0
1815 { .mmi
1816       ldfe FR_S_4 = [GR_ad_se], -16    // Load S_4
1817       ldfe FR_C_4 = [GR_ad_ce], -16    // Load C_4
1818       nop.i 0
1821 SINCOSL_SMALL_R_0:
1822 // Entry point for 2^-3 < |x| < pi/4
1823 SINCOSL_SMALL_R_1:
1824 // Entry point for pi/4 < |x| < 2^24 and |r| < 2^-3
1825 { .mfi
1826       ldfe   FR_S_3 = [GR_ad_se], -16    // Load S_3
1827       fma.s1 FR_r6  = FR_rsq, FR_rsq, f0 // Z = rsq * rsq
1828       tbit.z p7,p11       = GR_N_Inc, 0
1830 { .mfi
1831       ldfe    FR_C_3 = [GR_ad_ce], -16   // Load C_3
1832       nop.f 0
1833       and GR_N_SinCos = 0x1, GR_N_Inc
1836 { .mfi
1837       ldfe   FR_S_2 = [GR_ad_se], -16    // Load S_2
1838       fnma.s1 FR_cC = FR_c, FR_r, f0     // c = -c * r
1839       sub GR_N_SignS =  GR_N_Inc, GR_N_SinCos
1841 { .mfi
1842       ldfe   FR_C_2 = [GR_ad_ce], -16    // Load C_2
1843       nop.f 0
1844       add GR_N_SignC =  GR_N_Inc, GR_N_SinCos
1847 { .mmi
1848       ldfe FR_S_1 = [GR_ad_se], -16    // Load S_1
1849       ldfe FR_C_1 = [GR_ad_ce], -16    // Load C_1
1850 (p7)  tbit.z.unc p9,p10   = GR_N_SignC, 1
1853 { .mfi
1854       nop.m 0
1855       fma.s1 FR_r7 = FR_r6, FR_r, f0     // Z = Z * r
1856 (p7)  tbit.z.unc p7,p8    = GR_N_SignS, 1
1859 { .mfi
1860       nop.m 0
1861       fma.s1 FR_poly_loS = FR_rsq, FR_S_5, FR_S_4 // poly_lo=rsq*S_5+S_4
1862 (p11) tbit.z.unc p13,p14  = GR_N_SignC, 1
1864 { .mfi
1865       nop.m 0
1866       fma.s1 FR_poly_loC = FR_rsq, FR_C_5, FR_C_4 // poly_lo=rsq*C_5+C_4
1867       nop.i 0
1870 { .mfi
1871       nop.m 0
1872       fma.s1 FR_poly_hiS = FR_rsq, FR_S_2, FR_S_1 // poly_hi=rsq*S_2+S_1
1873 (p11) tbit.z.unc p11,p12  = GR_N_SignS, 1
1875 { .mfi
1876       nop.m 0
1877       fma.s1 FR_poly_hiC = FR_rsq, FR_C_2, FR_C_1 // poly_hi=rsq*C_2+C_1
1878       nop.i 0
1881 { .mfi
1882       nop.m 0
1883       fma.s0 FR_FirstS = FR_r, f1, f0
1884       nop.i 0
1886 { .mfi
1887       nop.m 0
1888       fma.s0 FR_FirstC = f1, f1, f0
1889       nop.i 0
1893 { .mfi
1894       nop.m 0
1895       fma.s1 FR_r6 = FR_r6, FR_rsq, f0
1896       nop.i 0
1898 { .mfi
1899       nop.m 0
1900       fma.s1 FR_r7 = FR_r7, FR_rsq, f0
1901       nop.i 0
1904 { .mfi
1905       nop.m 0
1906       fma.s1 FR_poly_loS = FR_rsq, FR_poly_loS, FR_S_3 // p_lo=p_lo*rsq+S_3
1907       nop.i 0
1909 { .mfi
1910       nop.m 0
1911       fma.s1 FR_poly_loC = FR_rsq, FR_poly_loC, FR_C_3 // p_lo=p_lo*rsq+C_3
1912       nop.i 0
1915 { .mfi
1916       nop.m 0
1917       fma.s0 FR_inexact = FR_S_4, FR_S_4, f0     // Dummy op to set inexact
1918       nop.i 0
1921 { .mfi
1922       nop.m 0
1923       fma.s1 FR_poly_hiS = FR_poly_hiS, FR_rsq, f0     // p_hi=p_hi*rsq
1924       nop.i 0
1926 { .mfi
1927       nop.m 0
1928       fma.s1 FR_poly_hiC = FR_poly_hiC, FR_rsq, f0     // p_hi=p_hi*rsq
1929       nop.i 0
1932 .pred.rel "mutex",p8,p14
1933 { .mfi
1934       nop.m 0
1935 (p8)  fms.s0 FR_FirstS   = f1, f0, FR_FirstS
1936       nop.i 0
1938 { .mfi
1939       nop.m 0
1940 (p14) fms.s0 FR_FirstS   = f1, f0, FR_FirstS
1941       nop.i 0
1944 .pred.rel "mutex",p10,p12
1945 { .mfi
1946       nop.m 0
1947 (p10) fms.s0 FR_FirstC   = f1, f0, FR_FirstC
1948       nop.i 0
1950 { .mfi
1951       nop.m 0
1952 (p12) fms.s0 FR_FirstC   = f1, f0, FR_FirstC
1953       nop.i 0
1956 { .mfi
1957       nop.m 0
1958       fma.s1 FR_polyS = FR_r7, FR_poly_loS, FR_cS        // poly=Z*poly_lo+c
1959       nop.i 0
1961 { .mfi
1962       nop.m 0
1963       fma.s1 FR_polyC = FR_r6, FR_poly_loC, FR_cC        // poly=Z*poly_lo+c
1964       nop.i 0
1967 { .mfi
1968       nop.m 0
1969       fma.s1 FR_poly_hiS = FR_r, FR_poly_hiS, f0       // p_hi=r*p_hi
1970       nop.i 0
1974 { .mfi
1975       nop.m 0
1976       fma.s1 FR_polyS = FR_polyS, f1, FR_poly_hiS
1977       nop.i 0
1979 { .mfi
1980       nop.m 0
1981       fma.s1 FR_polyC = FR_polyC, f1, FR_poly_hiC
1982       nop.i 0
1985 .pred.rel "mutex",p7,p8
1986 { .mfi
1987       nop.m 0
1988 (p7)  fma.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1989       nop.i 0
1991 { .mfi
1992       nop.m 0
1993 (p8)  fms.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1994       nop.i 0
1997 .pred.rel "mutex",p9,p10
1998 { .mfi
1999       nop.m 0
2000 (p9)  fma.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
2001       nop.i 0
2003 { .mfi
2004       nop.m 0
2005 (p10) fms.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
2006       nop.i 0
2009 .pred.rel "mutex",p11,p12
2010 { .mfi
2011       nop.m 0
2012 (p11) fma.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
2013       nop.i 0
2015 { .mfi
2016       nop.m 0
2017 (p12) fms.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
2018       nop.i 0
2021 .pred.rel "mutex",p13,p14
2022 { .mfi
2023       nop.m 0
2024 (p13) fma.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
2025       nop.i 0
2027 { .mfb
2028       cmp.eq  p15, p0 = 0x1, GR_Cis
2029 (p14) fms.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
2030 (p15) br.ret.sptk               b0
2034 { .mmb       // exit for sincosl
2035       stfe  [sincos_pResSin] =  FR_ResultS
2036       stfe  [sincos_pResCos] =  FR_ResultC
2037       br.ret.sptk               b0
2045 SINCOSL_NORMAL_R:
2047 // Here if 2^-3 <= |r| < pi/4
2048 // THIS IS THE MAIN PATH
2050 // Enter with r, c, and N_Inc having been computed
2052 { .mfi
2053       ldfe FR_PP_6 = [GR_ad_pp], 16    // Load PP_6
2054       fma.s1 FR_rsq = FR_r, FR_r, f0   // rsq = r * r
2055       nop.i 0
2057 { .mfi
2058       ldfe FR_QQ_6 = [GR_ad_qq], 16    // Load QQ_6
2059       nop.f 0
2060       nop.i 0
2063 { .mmi
2064       ldfe FR_PP_5 = [GR_ad_pp], 16    // Load PP_5
2065       ldfe FR_QQ_5 = [GR_ad_qq], 16    // Load QQ_5
2066       nop.i 0
2071 SINCOSL_NORMAL_R_0:
2072 // Entry for 2^-3 < |x| < pi/4
2073 .pred.rel "mutex",p9,p10
2074 { .mmf
2075       ldfe FR_C_1 = [GR_ad_pp], 16     // Load C_1
2076       ldfe FR_S_1 = [GR_ad_qq], 16     // Load S_1
2077       frcpa.s1 FR_r_hi, p6 = f1, FR_r  // r_hi = frcpa(r)
2080 { .mfi
2081       nop.m 0
2082       fma.s1 FR_polyS = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7
2083       nop.i 0
2085 { .mfi
2086       nop.m 0
2087       fma.s1 FR_polyC = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7
2088       nop.i 0
2091 { .mfi
2092       nop.m 0
2093       fma.s1 FR_r_cubed = FR_r, FR_rsq, f0  // rcubed = r * rsq
2094       nop.i 0
2098 SINCOSL_NORMAL_R_1:
2099 // Entry for pi/4 <= |x| < 2^24
2100 .pred.rel "mutex",p9,p10
2101 { .mmf
2102       ldfe FR_PP_1 = [GR_ad_pp], 16             // Load PP_1_hi
2103       ldfe FR_QQ_1 = [GR_ad_qq], 16             // Load QQ_1
2104       frcpa.s1 FR_r_hi, p6 = f1, FR_r_hi        // r_hi = frpca(frcpa(r))
2107 { .mfi
2108       ldfe FR_PP_4 = [GR_ad_pp], 16             // Load PP_4
2109       fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_6 // poly = rsq*poly+PP_6
2110       and GR_N_SinCos = 0x1, GR_N_Inc
2112 { .mfi
2113       ldfe FR_QQ_4 = [GR_ad_qq], 16             // Load QQ_4
2114       fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_6 // poly = rsq*poly+QQ_6
2115       nop.i 0
2118 { .mfi
2119       nop.m 0
2120       fma.s1 FR_corrS = FR_C_1, FR_rsq, f0       // corr = C_1 * rsq
2121       sub GR_N_SignS =  GR_N_Inc, GR_N_SinCos
2123 { .mfi
2124       nop.m 0
2125       fma.s1 FR_corrC = FR_S_1, FR_r_cubed, FR_r // corr = S_1 * r^3 + r
2126       add GR_N_SignC =  GR_N_Inc, GR_N_SinCos
2129 { .mfi
2130       ldfe FR_PP_3 = [GR_ad_pp], 16             // Load PP_3
2131       fma.s1 FR_r_hi_sq = FR_r_hi, FR_r_hi, f0  // r_hi_sq = r_hi * r_hi
2132       tbit.z p7,p11       = GR_N_Inc, 0
2134 { .mfi
2135       ldfe FR_QQ_3 = [GR_ad_qq], 16             // Load QQ_3
2136       fms.s1 FR_r_lo = FR_r, f1, FR_r_hi        // r_lo = r - r_hi
2137       nop.i 0
2140 { .mfi
2141       ldfe FR_PP_2 = [GR_ad_pp], 16             // Load PP_2
2142       fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_5 // poly = rsq*poly+PP_5
2143 (p7)  tbit.z.unc p9,p10   = GR_N_SignC, 1
2145 { .mfi
2146       ldfe FR_QQ_2 = [GR_ad_qq], 16             // Load QQ_2
2147       fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_5 // poly = rsq*poly+QQ_5
2148       nop.i 0
2151 { .mfi
2152       ldfe FR_PP_1_lo = [GR_ad_pp], 16          // Load PP_1_lo
2153       fma.s1 FR_corrS = FR_corrS, FR_c, FR_c      // corr = corr * c + c
2154 (p7)  tbit.z.unc p7,p8    = GR_N_SignS, 1
2156 { .mfi
2157       nop.m 0
2158       fnma.s1 FR_corrC = FR_corrC, FR_c, f0       // corr = -corr * c
2159       nop.i 0
2162 { .mfi
2163       nop.m 0
2164       fma.s1 FR_U_loS = FR_r, FR_r_hi, FR_r_hi_sq // U_lo = r*r_hi+r_hi_sq
2165 (p11) tbit.z.unc p13,p14  = GR_N_SignC, 1
2167 { .mfi
2168       nop.m 0
2169       fma.s1 FR_U_loC = FR_r_hi, f1, FR_r        // U_lo = r_hi + r
2170       nop.i 0
2173 { .mfi
2174       nop.m 0
2175       fma.s1 FR_U_hiS = FR_r_hi, FR_r_hi_sq, f0  // U_hi = r_hi*r_hi_sq
2176 (p11) tbit.z.unc p11,p12  = GR_N_SignS, 1
2178 { .mfi
2179       nop.m 0
2180       fma.s1 FR_U_hiC = FR_QQ_1, FR_r_hi_sq, f1  // U_hi = QQ_1*r_hi_sq+1
2181       nop.i 0
2184 { .mfi
2185       nop.m 0
2186       fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_4 // poly = poly*rsq+PP_4
2187       nop.i 0
2189 { .mfi
2190       nop.m 0
2191       fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_4 // poly = poly*rsq+QQ_4
2192       nop.i 0
2195 { .mfi
2196       nop.m 0
2197       fma.s1 FR_U_loS = FR_r, FR_r, FR_U_loS      // U_lo = r * r + U_lo
2198       nop.i 0
2200 { .mfi
2201       nop.m 0
2202       fma.s1 FR_U_loC = FR_r_lo, FR_U_loC, f0     // U_lo = r_lo * U_lo
2203       nop.i 0
2206 { .mfi
2207       nop.m 0
2208       fma.s1 FR_U_hiS = FR_PP_1, FR_U_hiS, f0     // U_hi = PP_1 * U_hi
2209       nop.i 0
2212 { .mfi
2213       nop.m 0
2214       fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_3 // poly = poly*rsq+PP_3
2215       nop.i 0
2217 { .mfi
2218       nop.m 0
2219       fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_3 // poly = poly*rsq+QQ_3
2220       nop.i 0
2223 { .mfi
2224       nop.m 0
2225       fma.s1 FR_U_loS = FR_r_lo, FR_U_loS, f0     // U_lo = r_lo * U_lo
2226       nop.i 0
2228 { .mfi
2229       nop.m 0
2230       fma.s1 FR_U_loC = FR_QQ_1,FR_U_loC, f0      // U_lo = QQ_1 * U_lo
2231       nop.i 0
2234 { .mfi
2235       nop.m 0
2236       fma.s1 FR_U_hiS = FR_r, f1, FR_U_hiS        // U_hi = r + U_hi
2237       nop.i 0
2240 { .mfi
2241       nop.m 0
2242       fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_2 // poly = poly*rsq+PP_2
2243       nop.i 0
2245 { .mfi
2246       nop.m 0
2247       fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_2 // poly = poly*rsq+QQ_2
2248       nop.i 0
2251 { .mfi
2252       nop.m 0
2253       fma.s1 FR_U_loS = FR_PP_1, FR_U_loS, f0     // U_lo = PP_1 * U_lo
2254       nop.i 0
2257 { .mfi
2258       nop.m 0
2259       fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_1_lo // poly =poly*rsq+PP1lo
2260       nop.i 0
2262 { .mfi
2263       nop.m 0
2264       fma.s1 FR_polyC = FR_rsq, FR_polyC, f0      // poly = poly*rsq
2265       nop.i 0
2269 .pred.rel "mutex",p8,p14
2270 { .mfi
2271       nop.m 0
2272 (p8)  fms.s0 FR_U_hiS   = f1, f0, FR_U_hiS
2273       nop.i 0
2275 { .mfi
2276       nop.m 0
2277 (p14) fms.s0 FR_U_hiS   = f1, f0, FR_U_hiS
2278       nop.i 0
2281 .pred.rel "mutex",p10,p12
2282 { .mfi
2283       nop.m 0
2284 (p10) fms.s0 FR_U_hiC   = f1, f0, FR_U_hiC
2285       nop.i 0
2287 { .mfi
2288       nop.m 0
2289 (p12) fms.s0 FR_U_hiC   = f1, f0, FR_U_hiC
2290       nop.i 0
2294 { .mfi
2295       nop.m 0
2296       fma.s1 FR_VS = FR_U_loS, f1, FR_corrS        // V = U_lo + corr
2297       nop.i 0
2299 { .mfi
2300       nop.m 0
2301       fma.s1 FR_VC = FR_U_loC, f1, FR_corrC        // V = U_lo + corr
2302       nop.i 0
2305 { .mfi
2306       nop.m 0
2307       fma.s0 FR_inexact = FR_PP_5, FR_PP_4, f0  // Dummy op to set inexact
2308       nop.i 0
2312 { .mfi
2313       nop.m 0
2314       fma.s1 FR_polyS = FR_r_cubed, FR_polyS, f0  // poly = poly*r^3
2315       nop.i 0
2317 { .mfi
2318       nop.m 0
2319       fma.s1 FR_polyC = FR_rsq, FR_polyC, f0      // poly = poly*rsq
2320       nop.i 0
2324 { .mfi
2325       nop.m 0
2326       fma.s1 FR_VS = FR_polyS, f1, FR_VS           // V = poly + V
2327       nop.i 0
2329 { .mfi
2330       nop.m 0
2331       fma.s1 FR_VC = FR_polyC, f1, FR_VC           // V = poly + V
2332       nop.i 0
2337 .pred.rel "mutex",p7,p8
2338 { .mfi
2339       nop.m 0
2340 (p7)  fma.s0 FR_ResultS = FR_U_hiS, f1, FR_VS
2341       nop.i 0
2343 { .mfi
2344       nop.m 0
2345 (p8)  fms.s0 FR_ResultS = FR_U_hiS, f1, FR_VS
2346       nop.i 0
2349 .pred.rel "mutex",p9,p10
2350 { .mfi
2351       nop.m 0
2352 (p9)  fma.s0 FR_ResultC = FR_U_hiC, f1, FR_VC
2353       nop.i 0
2355 { .mfi
2356       nop.m 0
2357 (p10) fms.s0 FR_ResultC = FR_U_hiC, f1, FR_VC
2358       nop.i 0
2363 .pred.rel "mutex",p11,p12
2364 { .mfi
2365       nop.m 0
2366 (p11) fma.s0 FR_ResultS = FR_U_hiC, f1, FR_VC
2367       nop.i 0
2369 { .mfi
2370       nop.m 0
2371 (p12) fms.s0 FR_ResultS = FR_U_hiC, f1, FR_VC
2372       nop.i 0
2375 .pred.rel "mutex",p13,p14
2376 { .mfi
2377       nop.m 0
2378 (p13) fma.s0 FR_ResultC = FR_U_hiS, f1, FR_VS
2379       nop.i 0
2381 { .mfb
2382       cmp.eq  p15, p0 = 0x1, GR_Cis
2383 (p14) fms.s0 FR_ResultC = FR_U_hiS, f1, FR_VS
2384 (p15) br.ret.sptk               b0
2387 { .mmb       // exit for sincosl
2388       stfe  [sincos_pResSin] =  FR_ResultS
2389       stfe  [sincos_pResCos] =  FR_ResultC
2390       br.ret.sptk               b0
2397 SINCOSL_ZERO:
2399 { .mfi
2400       nop.m 0
2401       fmerge.s FR_ResultS = FR_Input_X, FR_Input_X // If sin, result = input
2402       nop.i 0
2404 { .mfb
2405       cmp.eq  p15, p0 = 0x1, GR_Cis
2406       fma.s0 FR_ResultC = f1, f1, f0    // If cos, result=1.0
2407 (p15) br.ret.sptk               b0
2410 { .mmb       // exit for sincosl
2411       stfe  [sincos_pResSin] =  FR_ResultS
2412       stfe  [sincos_pResCos] =  FR_ResultC
2413       br.ret.sptk               b0
2417 SINCOSL_DENORMAL:
2418 { .mmb
2419       getf.exp GR_signexp_x = FR_norm_x   // Get sign and exponent of x
2420       nop.m 999
2421       br.cond.sptk  SINCOSL_COMMON2        // Return to common code
2426 SINCOSL_SPECIAL:
2428 //    Path for Arg = +/- QNaN, SNaN, Inf
2429 //    Invalid can be raised. SNaNs
2430 //    become QNaNs
2432 { .mfi
2433       cmp.eq  p15, p0 = 0x1, GR_Cis
2434       fmpy.s0 FR_ResultS = FR_Input_X, f0
2435       nop.i 0
2437 { .mfb
2438       nop.m 0
2439       fmpy.s0 FR_ResultC = FR_Input_X, f0
2440 (p15) br.ret.sptk               b0
2443 { .mmb       // exit for sincosl
2444       stfe  [sincos_pResSin] =  FR_ResultS
2445       stfe  [sincos_pResCos] =  FR_ResultC
2446       br.ret.sptk               b0
2449 GLOBAL_LIBM_END(__libm_sincosl)
2452 // *******************************************************************
2453 // *******************************************************************
2454 // *******************************************************************
2456 //     Special Code to handle very large argument case.
2457 //     Call int __libm_pi_by_2_reduce(x,r,c) for |arguments| >= 2**63
2458 //     The interface is custom:
2459 //       On input:
2460 //         (Arg or x) is in f8
2461 //       On output:
2462 //         r is in f8
2463 //         c is in f9
2464 //         N is in r8
2465 //     Be sure to allocate at least 2 GP registers as output registers for
2466 //     __libm_pi_by_2_reduce.  This routine uses r62-63. These are used as
2467 //     scratch registers within the __libm_pi_by_2_reduce routine (for speed).
2469 //     We know also that __libm_pi_by_2_reduce preserves f10-15, f71-127.  We
2470 //     use this to eliminate save/restore of key fp registers in this calling
2471 //     function.
2473 // *******************************************************************
2474 // *******************************************************************
2475 // *******************************************************************
2477 LOCAL_LIBM_ENTRY(__libm_callout)
2478 SINCOSL_ARG_TOO_LARGE:
2479 .prologue
2480 { .mfi
2481         nop.f 0
2482 .save   ar.pfs,GR_SAVE_PFS
2483         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
2486 { .mmi
2487         setf.exp FR_Two_to_M3 = GR_exp_2_to_m3  // Form 2^-3
2488         mov GR_SAVE_GP=gp                       // Save gp
2489 .save   b0, GR_SAVE_B0
2490         mov GR_SAVE_B0=b0                       // Save b0
2493 .body
2495 //     Call argument reduction with x in f8
2496 //     Returns with N in r8, r in f8, c in f9
2497 //     Assumes f71-127 are preserved across the call
2499 { .mib
2500         setf.exp FR_Neg_Two_to_M3 = GR_exp_m2_to_m3 // Form -(2^-3)
2501         nop.i 0
2502         br.call.sptk b0=__libm_pi_by_2_reduce#
2505 { .mfi
2506         mov   GR_N_Inc = r8
2507         fcmp.lt.unc.s1  p6, p0 = FR_r, FR_Two_to_M3
2508         mov   b0 = GR_SAVE_B0                  // Restore return address
2511 { .mfi
2512         mov   gp = GR_SAVE_GP                  // Restore gp
2513 (p6)    fcmp.gt.unc.s1  p6, p0 = FR_r, FR_Neg_Two_to_M3
2514         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
2517 { .mbb
2518   nop.m 0
2519 (p6)    br.cond.spnt SINCOSL_SMALL_R     // Branch if |r|< 2^-3 for |x| >= 2^63
2520         br.cond.sptk SINCOSL_NORMAL_R    // Branch if |r|>=2^-3 for |x| >= 2^63
2523 LOCAL_LIBM_END(__libm_callout)
2525 .type   __libm_pi_by_2_reduce#,@function
2526 .global __libm_pi_by_2_reduce#