2.9
[glibc/nacl-glibc.git] / sysdeps / ia64 / fpu / libm_sincos_large.S
blobb09d3693a63ec24da1873d73d2a1b01e4d452fc9
1 .file "libm_sincos_large.s"
4 // Copyright (c) 2002 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2002 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 // History
41 //==============================================================
42 // 02/15/02 Initial version
43 // 05/13/02 Changed interface to __libm_pi_by_2_reduce
44 // 02/10/03 Reordered header: .section, .global, .proc, .align;
45 //          used data8 for long double table values
46 // 05/15/03 Reformatted data tables
49 // Overview of operation
50 //==============================================================
52 // These functions calculate the sin and cos for inputs
53 // greater than 2^10
55 // __libm_sin_large#
56 // __libm_cos_large#
57 // They accept argument in f8
58 // and return result in f8 without final rounding
60 // __libm_sincos_large#
61 // It accepts argument in f8
62 // and returns cos in f8 and sin in f9 without final rounding
65 //*********************************************************************
67 // Accuracy:       Within .7 ulps for 80-bit floating point values
68 //                 Very accurate for double precision values
70 //*********************************************************************
72 // Resources Used:
74 //    Floating-Point Registers: f8 as Input Value, f8 and f9 as Return Values
75 //                              f32-f103
77 //    General Purpose Registers:
78 //      r32-r43
79 //      r44-r45 (Used to pass arguments to pi_by_2 reduce routine)
81 //    Predicate Registers:      p6-p13
83 //*********************************************************************
85 //  IEEE Special Conditions:
87 //    Denormal  fault raised on denormal inputs
88 //    Overflow exceptions do not occur
89 //    Underflow exceptions raised when appropriate for sin
90 //    (No specialized error handling for this routine)
91 //    Inexact raised when appropriate by algorithm
93 //    sin(SNaN) = QNaN
94 //    sin(QNaN) = QNaN
95 //    sin(inf) = QNaN
96 //    sin(+/-0) = +/-0
97 //    cos(inf) = QNaN
98 //    cos(SNaN) = QNaN
99 //    cos(QNaN) = QNaN
100 //    cos(0) = 1
102 //*********************************************************************
104 //  Mathematical Description
105 //  ========================
107 //  The computation of FSIN and FCOS is best handled in one piece of
108 //  code. The main reason is that given any argument Arg, computation
109 //  of trigonometric functions first calculate N and an approximation
110 //  to alpha where
112 //  Arg = N pi/2 + alpha, |alpha| <= pi/4.
114 //  Since
116 //  cos( Arg ) = sin( (N+1) pi/2 + alpha ),
118 //  therefore, the code for computing sine will produce cosine as long
119 //  as 1 is added to N immediately after the argument reduction
120 //  process.
122 //  Let M = N if sine
123 //      N+1 if cosine.
125 //  Now, given
127 //  Arg = M pi/2  + alpha, |alpha| <= pi/4,
129 //  let I = M mod 4, or I be the two lsb of M when M is represented
130 //  as 2's complement. I = [i_0 i_1]. Then
132 //  sin( Arg ) = (-1)^i_0  sin( alpha ) if i_1 = 0,
133 //             = (-1)^i_0  cos( alpha )     if i_1 = 1.
135 //  For example:
136 //       if M = -1, I = 11
137 //         sin ((-pi/2 + alpha) = (-1) cos (alpha)
138 //       if M = 0, I = 00
139 //         sin (alpha) = sin (alpha)
140 //       if M = 1, I = 01
141 //         sin (pi/2 + alpha) = cos (alpha)
142 //       if M = 2, I = 10
143 //         sin (pi + alpha) = (-1) sin (alpha)
144 //       if M = 3, I = 11
145 //         sin ((3/2)pi + alpha) = (-1) cos (alpha)
147 //  The value of alpha is obtained by argument reduction and
148 //  represented by two working precision numbers r and c where
150 //  alpha =  r  +  c     accurately.
152 //  The reduction method is described in a previous write up.
153 //  The argument reduction scheme identifies 4 cases. For Cases 2
154 //  and 4, because |alpha| is small, sin(r+c) and cos(r+c) can be
155 //  computed very easily by 2 or 3 terms of the Taylor series
156 //  expansion as follows:
158 //  Case 2:
159 //  -------
161 //  sin(r + c) = r + c - r^3/6  accurately
162 //  cos(r + c) = 1 - 2^(-67)    accurately
164 //  Case 4:
165 //  -------
167 //  sin(r + c) = r + c - r^3/6 + r^5/120    accurately
168 //  cos(r + c) = 1 - r^2/2 + r^4/24     accurately
170 //  The only cases left are Cases 1 and 3 of the argument reduction
171 //  procedure. These two cases will be merged since after the
172 //  argument is reduced in either cases, we have the reduced argument
173 //  represented as r + c and that the magnitude |r + c| is not small
174 //  enough to allow the usage of a very short approximation.
176 //  The required calculation is either
178 //  sin(r + c)  =  sin(r)  +  correction,  or
179 //  cos(r + c)  =  cos(r)  +  correction.
181 //  Specifically,
183 //  sin(r + c) = sin(r) + c sin'(r) + O(c^2)
184 //         = sin(r) + c cos (r) + O(c^2)
185 //         = sin(r) + c(1 - r^2/2)  accurately.
186 //  Similarly,
188 //  cos(r + c) = cos(r) - c sin(r) + O(c^2)
189 //         = cos(r) - c(r - r^3/6)  accurately.
191 //  We therefore concentrate on accurately calculating sin(r) and
192 //  cos(r) for a working-precision number r, |r| <= pi/4 to within
193 //  0.1% or so.
195 //  The greatest challenge of this task is that the second terms of
196 //  the Taylor series
198 //  r - r^3/3! + r^r/5! - ...
200 //  and
202 //  1 - r^2/2! + r^4/4! - ...
204 //  are not very small when |r| is close to pi/4 and the rounding
205 //  errors will be a concern if simple polynomial accumulation is
206 //  used. When |r| < 2^-3, however, the second terms will be small
207 //  enough (6 bits or so of right shift) that a normal Horner
208 //  recurrence suffices. Hence there are two cases that we consider
209 //  in the accurate computation of sin(r) and cos(r), |r| <= pi/4.
211 //  Case small_r: |r| < 2^(-3)
212 //  --------------------------
214 //  Since Arg = M pi/4 + r + c accurately, and M mod 4 is [i_0 i_1],
215 //  we have
217 //  sin(Arg) = (-1)^i_0 * sin(r + c)    if i_1 = 0
218 //       = (-1)^i_0 * cos(r + c)    if i_1 = 1
220 //  can be accurately approximated by
222 //  sin(Arg) = (-1)^i_0 * [sin(r) + c]  if i_1 = 0
223 //           = (-1)^i_0 * [cos(r) - c*r] if i_1 = 1
225 //  because |r| is small and thus the second terms in the correction
226 //  are unneccessary.
228 //  Finally, sin(r) and cos(r) are approximated by polynomials of
229 //  moderate lengths.
231 //  sin(r) =  r + S_1 r^3 + S_2 r^5 + ... + S_5 r^11
232 //  cos(r) =  1 + C_1 r^2 + C_2 r^4 + ... + C_5 r^10
234 //  We can make use of predicates to selectively calculate
235 //  sin(r) or cos(r) based on i_1.
237 //  Case normal_r: 2^(-3) <= |r| <= pi/4
238 //  ------------------------------------
240 //  This case is more likely than the previous one if one considers
241 //  r to be uniformly distributed in [-pi/4 pi/4]. Again,
243 //  sin(Arg) = (-1)^i_0 * sin(r + c)    if i_1 = 0
244 //           = (-1)^i_0 * cos(r + c)    if i_1 = 1.
246 //  Because |r| is now larger, we need one extra term in the
247 //  correction. sin(Arg) can be accurately approximated by
249 //  sin(Arg) = (-1)^i_0 * [sin(r) + c(1-r^2/2)]      if i_1 = 0
250 //           = (-1)^i_0 * [cos(r) - c*r*(1 - r^2/6)]    i_1 = 1.
252 //  Finally, sin(r) and cos(r) are approximated by polynomials of
253 //  moderate lengths.
255 //  sin(r) =  r + PP_1_hi r^3 + PP_1_lo r^3 +
256 //                PP_2 r^5 + ... + PP_8 r^17
258 //  cos(r) =  1 + QQ_1 r^2 + QQ_2 r^4 + ... + QQ_8 r^16
260 //  where PP_1_hi is only about 16 bits long and QQ_1 is -1/2.
261 //  The crux in accurate computation is to calculate
263 //  r + PP_1_hi r^3   or  1 + QQ_1 r^2
265 //  accurately as two pieces: U_hi and U_lo. The way to achieve this
266 //  is to obtain r_hi as a 10 sig. bit number that approximates r to
267 //  roughly 8 bits or so of accuracy. (One convenient way is
269 //  r_hi := frcpa( frcpa( r ) ).)
271 //  This way,
273 //  r + PP_1_hi r^3 =  r + PP_1_hi r_hi^3 +
274 //                          PP_1_hi (r^3 - r_hi^3)
275 //              =  [r + PP_1_hi r_hi^3]  +
276 //             [PP_1_hi (r - r_hi)
277 //                (r^2 + r_hi r + r_hi^2) ]
278 //              =  U_hi  +  U_lo
280 //  Since r_hi is only 10 bit long and PP_1_hi is only 16 bit long,
281 //  PP_1_hi * r_hi^3 is only at most 46 bit long and thus computed
282 //  exactly. Furthermore, r and PP_1_hi r_hi^3 are of opposite sign
283 //  and that there is no more than 8 bit shift off between r and
284 //  PP_1_hi * r_hi^3. Hence the sum, U_hi, is representable and thus
285 //  calculated without any error. Finally, the fact that
287 //  |U_lo| <= 2^(-8) |U_hi|
289 //  says that U_hi + U_lo is approximating r + PP_1_hi r^3 to roughly
290 //  8 extra bits of accuracy.
292 //  Similarly,
294 //  1 + QQ_1 r^2  =  [1 + QQ_1 r_hi^2]  +
295 //                      [QQ_1 (r - r_hi)(r + r_hi)]
296 //            =  U_hi  +  U_lo.
298 //  Summarizing, we calculate r_hi = frcpa( frcpa( r ) ).
300 //  If i_1 = 0, then
302 //    U_hi := r + PP_1_hi * r_hi^3
303 //    U_lo := PP_1_hi * (r - r_hi) * (r^2 + r*r_hi + r_hi^2)
304 //    poly := PP_1_lo r^3 + PP_2 r^5 + ... + PP_8 r^17
305 //    correction := c * ( 1 + C_1 r^2 )
307 //  Else ...i_1 = 1
309 //    U_hi := 1 + QQ_1 * r_hi * r_hi
310 //    U_lo := QQ_1 * (r - r_hi) * (r + r_hi)
311 //    poly := QQ_2 * r^4 + QQ_3 * r^6 + ... + QQ_8 r^16
312 //    correction := -c * r * (1 + S_1 * r^2)
314 //  End
316 //  Finally,
318 //  V := poly + ( U_lo + correction )
320 //                 /    U_hi  +  V         if i_0 = 0
321 //  result := |
322 //                 \  (-U_hi) -  V         if i_0 = 1
324 //  It is important that in the last step, negation of U_hi is
325 //  performed prior to the subtraction which is to be performed in
326 //  the user-set rounding mode.
329 //  Algorithmic Description
330 //  =======================
332 //  The argument reduction algorithm is tightly integrated into FSIN
333 //  and FCOS which share the same code. The following is complete and
334 //  self-contained. The argument reduction description given
335 //  previously is repeated below.
338 //  Step 0. Initialization.
340 //   If FSIN is invoked, set N_inc := 0; else if FCOS is invoked,
341 //   set N_inc := 1.
343 //  Step 1. Check for exceptional and special cases.
345 //   * If Arg is +-0, +-inf, NaN, NaT, go to Step 10 for special
346 //     handling.
347 //   * If |Arg| < 2^24, go to Step 2 for reduction of moderate
348 //     arguments. This is the most likely case.
349 //   * If |Arg| < 2^63, go to Step 8 for pre-reduction of large
350 //     arguments.
351 //   * If |Arg| >= 2^63, go to Step 10 for special handling.
353 //  Step 2. Reduction of moderate arguments.
355 //  If |Arg| < pi/4     ...quick branch
356 //     N_fix := N_inc   (integer)
357 //     r     := Arg
358 //     c     := 0.0
359 //     Branch to Step 4, Case_1_complete
360 //  Else        ...cf. argument reduction
361 //     N     := Arg * two_by_PI (fp)
362 //     N_fix := fcvt.fx( N )    (int)
363 //     N     := fcvt.xf( N_fix )
364 //     N_fix := N_fix + N_inc
365 //     s     := Arg - N * P_1   (first piece of pi/2)
366 //     w     := -N * P_2    (second piece of pi/2)
368 //     If |s| >= 2^(-33)
369 //        go to Step 3, Case_1_reduce
370 //     Else
371 //        go to Step 7, Case_2_reduce
372 //     Endif
373 //  Endif
375 //  Step 3. Case_1_reduce.
377 //  r := s + w
378 //  c := (s - r) + w    ...observe order
380 //  Step 4. Case_1_complete
382 //  ...At this point, the reduced argument alpha is
383 //  ...accurately represented as r + c.
384 //  If |r| < 2^(-3), go to Step 6, small_r.
386 //  Step 5. Normal_r.
388 //  Let [i_0 i_1] by the 2 lsb of N_fix.
389 //  FR_rsq  := r * r
390 //  r_hi := frcpa( frcpa( r ) )
391 //  r_lo := r - r_hi
393 //  If i_1 = 0, then
394 //    poly := r*FR_rsq*(PP_1_lo + FR_rsq*(PP_2 + ... FR_rsq*PP_8))
395 //    U_hi := r + PP_1_hi*r_hi*r_hi*r_hi    ...any order
396 //    U_lo := PP_1_hi*r_lo*(r*r + r*r_hi + r_hi*r_hi)
397 //    correction := c + c*C_1*FR_rsq        ...any order
398 //  Else
399 //    poly := FR_rsq*FR_rsq*(QQ_2 + FR_rsq*(QQ_3 + ... + FR_rsq*QQ_8))
400 //    U_hi := 1 + QQ_1 * r_hi * r_hi        ...any order
401 //    U_lo := QQ_1 * r_lo * (r + r_hi)
402 //    correction := -c*(r + S_1*FR_rsq*r)   ...any order
403 //  Endif
405 //  V := poly + (U_lo + correction) ...observe order
407 //  result := (i_0 == 0?   1.0 : -1.0)
409 //  Last instruction in user-set rounding mode
411 //  result := (i_0 == 0?   result*U_hi + V :
412 //                        result*U_hi - V)
414 //  Return
416 //  Step 6. Small_r.
418 //  ...Use flush to zero mode without causing exception
419 //    Let [i_0 i_1] be the two lsb of N_fix.
421 //  FR_rsq := r * r
423 //  If i_1 = 0 then
424 //     z := FR_rsq*FR_rsq; z := FR_rsq*z *r
425 //     poly_lo := S_3 + FR_rsq*(S_4 + FR_rsq*S_5)
426 //     poly_hi := r*FR_rsq*(S_1 + FR_rsq*S_2)
427 //     correction := c
428 //     result := r
429 //  Else
430 //     z := FR_rsq*FR_rsq; z := FR_rsq*z
431 //     poly_lo := C_3 + FR_rsq*(C_4 + FR_rsq*C_5)
432 //     poly_hi := FR_rsq*(C_1 + FR_rsq*C_2)
433 //     correction := -c*r
434 //     result := 1
435 //  Endif
437 //  poly := poly_hi + (z * poly_lo + correction)
439 //  If i_0 = 1, result := -result
441 //  Last operation. Perform in user-set rounding mode
443 //  result := (i_0 == 0?     result + poly :
444 //                          result - poly )
445 //  Return
447 //  Step 7. Case_2_reduce.
449 //  ...Refer to the write up for argument reduction for
450 //  ...rationale. The reduction algorithm below is taken from
451 //  ...argument reduction description and integrated this.
453 //  w := N*P_3
454 //  U_1 := N*P_2 + w        ...FMA
455 //  U_2 := (N*P_2 - U_1) + w    ...2 FMA
456 //  ...U_1 + U_2 is  N*(P_2+P_3) accurately
458 //  r := s - U_1
459 //  c := ( (s - r) - U_1 ) - U_2
461 //  ...The mathematical sum r + c approximates the reduced
462 //  ...argument accurately. Note that although compared to
463 //  ...Case 1, this case requires much more work to reduce
464 //  ...the argument, the subsequent calculation needed for
465 //  ...any of the trigonometric function is very little because
466 //  ...|alpha| < 1.01*2^(-33) and thus two terms of the
467 //  ...Taylor series expansion suffices.
469 //  If i_1 = 0 then
470 //     poly := c + S_1 * r * r * r  ...any order
471 //     result := r
472 //  Else
473 //     poly := -2^(-67)
474 //     result := 1.0
475 //  Endif
477 //  If i_0 = 1, result := -result
479 //  Last operation. Perform in user-set rounding mode
481 //  result := (i_0 == 0?     result + poly :
482 //                           result - poly )
484 //  Return
487 //  Step 8. Pre-reduction of large arguments.
489 //  ...Again, the following reduction procedure was described
490 //  ...in the separate write up for argument reduction, which
491 //  ...is tightly integrated here.
493 //  N_0 := Arg * Inv_P_0
494 //  N_0_fix := fcvt.fx( N_0 )
495 //  N_0 := fcvt.xf( N_0_fix)
497 //  Arg' := Arg - N_0 * P_0
498 //  w := N_0 * d_1
499 //  N := Arg' * two_by_PI
500 //  N_fix := fcvt.fx( N )
501 //  N := fcvt.xf( N_fix )
502 //  N_fix := N_fix + N_inc
504 //  s := Arg' - N * P_1
505 //  w := w - N * P_2
507 //  If |s| >= 2^(-14)
508 //     go to Step 3
509 //  Else
510 //     go to Step 9
511 //  Endif
513 //  Step 9. Case_4_reduce.
515 //    ...first obtain N_0*d_1 and -N*P_2 accurately
516 //   U_hi := N_0 * d_1      V_hi := -N*P_2
517 //   U_lo := N_0 * d_1 - U_hi   V_lo := -N*P_2 - U_hi   ...FMAs
519 //   ...compute the contribution from N_0*d_1 and -N*P_3
520 //   w := -N*P_3
521 //   w := w + N_0*d_2
522 //   t := U_lo + V_lo + w       ...any order
524 //   ...at this point, the mathematical value
525 //   ...s + U_hi + V_hi  + t approximates the true reduced argument
526 //   ...accurately. Just need to compute this accurately.
528 //   ...Calculate U_hi + V_hi accurately:
529 //   A := U_hi + V_hi
530 //   if |U_hi| >= |V_hi| then
531 //      a := (U_hi - A) + V_hi
532 //   else
533 //      a := (V_hi - A) + U_hi
534 //   endif
535 //   ...order in computing "a" must be observed. This branch is
536 //   ...best implemented by predicates.
537 //   ...A + a  is U_hi + V_hi accurately. Moreover, "a" is
538 //   ...much smaller than A: |a| <= (1/2)ulp(A).
540 //   ...Just need to calculate   s + A + a + t
541 //   C_hi := s + A      t := t + a
542 //   C_lo := (s - C_hi) + A
543 //   C_lo := C_lo + t
545 //   ...Final steps for reduction
546 //   r := C_hi + C_lo
547 //   c := (C_hi - r) + C_lo
549 //   ...At this point, we have r and c
550 //   ...And all we need is a couple of terms of the corresponding
551 //   ...Taylor series.
553 //   If i_1 = 0
554 //      poly := c + r*FR_rsq*(S_1 + FR_rsq*S_2)
555 //      result := r
556 //   Else
557 //      poly := FR_rsq*(C_1 + FR_rsq*C_2)
558 //      result := 1
559 //   Endif
561 //   If i_0 = 1, result := -result
563 //   Last operation. Perform in user-set rounding mode
565 //   result := (i_0 == 0?     result + poly :
566 //                            result - poly )
567 //   Return
569 //   Large Arguments: For arguments above 2**63, a Payne-Hanek
570 //   style argument reduction is used and pi_by_2 reduce is called.
574 RODATA
575 .align 16
577 LOCAL_OBJECT_START(FSINCOS_CONSTANTS)
579 data4 0x4B800000 // two**24
580 data4 0xCB800000 // -two**24
581 data4 0x00000000 // pad
582 data4 0x00000000 // pad
583 data8 0xA2F9836E4E44152A, 0x00003FFE // Inv_pi_by_2
584 data8 0xC84D32B0CE81B9F1, 0x00004016 // P_0
585 data8 0xC90FDAA22168C235, 0x00003FFF // P_1
586 data8 0xECE675D1FC8F8CBB, 0x0000BFBD // P_2
587 data8 0xB7ED8FBBACC19C60, 0x0000BF7C // P_3
588 data4 0x5F000000 // two**63
589 data4 0xDF000000 // -two**63
590 data4 0x00000000 // pad
591 data4 0x00000000 // pad
592 data8 0xA397E5046EC6B45A, 0x00003FE7 // Inv_P_0
593 data8 0x8D848E89DBD171A1, 0x0000BFBF // d_1
594 data8 0xD5394C3618A66F8E, 0x0000BF7C // d_2
595 data8 0xC90FDAA22168C234, 0x00003FFE // pi_by_4
596 data8 0xC90FDAA22168C234, 0x0000BFFE // neg_pi_by_4
597 data4 0x3E000000 // two**-3
598 data4 0xBE000000 // -two**-3
599 data4 0x00000000 // pad
600 data4 0x00000000 // pad
601 data4 0x2F000000 // two**-33
602 data4 0xAF000000 // -two**-33
603 data4 0x9E000000 // -two**-67
604 data4 0x00000000 // pad
605 data8 0xCC8ABEBCA21C0BC9, 0x00003FCE // PP_8
606 data8 0xD7468A05720221DA, 0x0000BFD6 // PP_7
607 data8 0xB092382F640AD517, 0x00003FDE // PP_6
608 data8 0xD7322B47D1EB75A4, 0x0000BFE5 // PP_5
609 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
610 data8 0xAAAA000000000000, 0x0000BFFC // PP_1_hi
611 data8 0xB8EF1D2ABAF69EEA, 0x00003FEC // PP_4
612 data8 0xD00D00D00D03BB69, 0x0000BFF2 // PP_3
613 data8 0x8888888888888962, 0x00003FF8 // PP_2
614 data8 0xAAAAAAAAAAAB0000, 0x0000BFEC // PP_1_lo
615 data8 0xD56232EFC2B0FE52, 0x00003FD2 // QQ_8
616 data8 0xC9C99ABA2B48DCA6, 0x0000BFDA // QQ_7
617 data8 0x8F76C6509C716658, 0x00003FE2 // QQ_6
618 data8 0x93F27DBAFDA8D0FC, 0x0000BFE9 // QQ_5
619 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
620 data8 0x8000000000000000, 0x0000BFFE // QQ_1
621 data8 0xD00D00D00C6E5041, 0x00003FEF // QQ_4
622 data8 0xB60B60B60B607F60, 0x0000BFF5 // QQ_3
623 data8 0xAAAAAAAAAAAAAA9B, 0x00003FFA // QQ_2
624 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
625 data8 0xAAAAAAAAAAAA719F, 0x00003FFA // C_2
626 data8 0xB60B60B60356F994, 0x0000BFF5 // C_3
627 data8 0xD00CFFD5B2385EA9, 0x00003FEF // C_4
628 data8 0x93E4BD18292A14CD, 0x0000BFE9 // C_5
629 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
630 data8 0x88888888888868DB, 0x00003FF8 // S_2
631 data8 0xD00D00D0055EFD4B, 0x0000BFF2 // S_3
632 data8 0xB8EF1C5D839730B9, 0x00003FEC // S_4
633 data8 0xD71EA3A4E5B3F492, 0x0000BFE5 // S_5
634 data4 0x38800000 // two**-14
635 data4 0xB8800000 // -two**-14
636 LOCAL_OBJECT_END(FSINCOS_CONSTANTS)
638 // sin and cos registers
640 // FR
641 FR_Input_X        = f8
643 FR_r              = f8
644 FR_c              = f9
646 FR_Two_to_63      = f32
647 FR_Two_to_24      = f33
648 FR_Pi_by_4        = f33
649 FR_Two_to_M14     = f34
650 FR_Two_to_M33     = f35
651 FR_Neg_Two_to_24  = f36
652 FR_Neg_Pi_by_4    = f36
653 FR_Neg_Two_to_M14 = f37
654 FR_Neg_Two_to_M33 = f38
655 FR_Neg_Two_to_M67 = f39
656 FR_Inv_pi_by_2    = f40
657 FR_N_float        = f41
658 FR_N_fix          = f42
659 FR_P_1            = f43
660 FR_P_2            = f44
661 FR_P_3            = f45
662 FR_s              = f46
663 FR_w              = f47
664 FR_d_2            = f48
665 FR_prelim         = f49
666 FR_Z              = f50
667 FR_A              = f51
668 FR_a              = f52
669 FR_t              = f53
670 FR_U_1            = f54
671 FR_U_2            = f55
672 FR_C_1            = f56
673 FR_C_2            = f57
674 FR_C_3            = f58
675 FR_C_4            = f59
676 FR_C_5            = f60
677 FR_S_1            = f61
678 FR_S_2            = f62
679 FR_S_3            = f63
680 FR_S_4            = f64
681 FR_S_5            = f65
682 FR_poly_hi        = f66
683 FR_poly_lo        = f67
684 FR_r_hi           = f68
685 FR_r_lo           = f69
686 FR_rsq            = f70
687 FR_r_cubed        = f71
688 FR_C_hi           = f72
689 FR_N_0            = f73
690 FR_d_1            = f74
691 FR_V              = f75
692 FR_V_hi           = f75
693 FR_V_lo           = f76
694 FR_U_hi           = f77
695 FR_U_lo           = f78
696 FR_U_hiabs        = f79
697 FR_V_hiabs        = f80
698 FR_PP_8           = f81
699 FR_QQ_8           = f81
700 FR_PP_7           = f82
701 FR_QQ_7           = f82
702 FR_PP_6           = f83
703 FR_QQ_6           = f83
704 FR_PP_5           = f84
705 FR_QQ_5           = f84
706 FR_PP_4           = f85
707 FR_QQ_4           = f85
708 FR_PP_3           = f86
709 FR_QQ_3           = f86
710 FR_PP_2           = f87
711 FR_QQ_2           = f87
712 FR_QQ_1           = f88
713 FR_N_0_fix        = f89
714 FR_Inv_P_0        = f90
715 FR_corr           = f91
716 FR_poly           = f92
717 FR_Neg_Two_to_M3  = f93
718 FR_Two_to_M3      = f94
719 FR_Neg_Two_to_63  = f94
720 FR_P_0            = f95
721 FR_C_lo           = f96
722 FR_PP_1           = f97
723 FR_PP_1_lo        = f98
724 FR_ArgPrime       = f99
726 // GR
727 GR_Table_Base     = r32
728 GR_Table_Base1    = r33
729 GR_i_0            = r34
730 GR_i_1            = r35
731 GR_N_Inc          = r36
732 GR_Sin_or_Cos     = r37
734 GR_SAVE_B0        = r39
735 GR_SAVE_GP        = r40
736 GR_SAVE_PFS       = r41
738 // sincos combined routine registers
740 // GR
741 GR_SINCOS_SAVE_PFS    = r32
742 GR_SINCOS_SAVE_B0     = r33
743 GR_SINCOS_SAVE_GP     = r34
745 // FR
746 FR_SINCOS_ARG         = f100
747 FR_SINCOS_RES_SIN     = f101
750 .section .text
753 GLOBAL_LIBM_ENTRY(__libm_sincos_large)
755 { .mfi
756         alloc GR_SINCOS_SAVE_PFS = ar.pfs,0,3,0,0
757         fma.s1 FR_SINCOS_ARG     = f8, f1, f0  // Save argument for sin and cos
758         mov GR_SINCOS_SAVE_B0    = b0
761 { .mfb
762         mov GR_SINCOS_SAVE_GP    = gp
763         nop.f  0
764         br.call.sptk b0          = __libm_sin_large // Call sin
767 { .mfi
768         nop.m  0
769         fma.s1 FR_SINCOS_RES_SIN = f8, f1, f0 // Save sin result
770         nop.i  0
773 { .mfb
774         nop.m  0
775         fma.s1 f8                = FR_SINCOS_ARG, f1, f0 // Arg for cos
776         br.call.sptk b0          = __libm_cos_large // Call cos
779 { .mfi
780         mov    gp                = GR_SINCOS_SAVE_GP
781         fma.s1 f9                = FR_SINCOS_RES_SIN, f1, f0 // Out sin result
782         mov    b0                = GR_SINCOS_SAVE_B0
785 { .mib
786         nop.m  0
787         mov ar.pfs               = GR_SINCOS_SAVE_PFS
788         br.ret.sptk                b0 // sincos_large exit
791 GLOBAL_LIBM_END(__libm_sincos_large)
796 GLOBAL_LIBM_ENTRY(__libm_sin_large)
798 { .mlx
799 alloc GR_Table_Base = ar.pfs,0,12,2,0
800        movl GR_Sin_or_Cos = 0x0 ;;
803 { .mmi
804       nop.m 999
805       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
806       nop.i 999
810 { .mmi
811       ld8 GR_Table_Base = [GR_Table_Base]
812       nop.m 999
813       nop.i 999
818 { .mib
819       nop.m 999
820       nop.i 999
821        br.cond.sptk SINCOS_CONTINUE ;;
824 GLOBAL_LIBM_END(__libm_sin_large)
826 GLOBAL_LIBM_ENTRY(__libm_cos_large)
828 { .mlx
829 alloc GR_Table_Base= ar.pfs,0,12,2,0
830        movl GR_Sin_or_Cos = 0x1 ;;
833 { .mmi
834       nop.m 999
835       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
836       nop.i 999
840 { .mmi
841       ld8 GR_Table_Base = [GR_Table_Base]
842       nop.m 999
843       nop.i 999
848 //     Load Table Address
850 SINCOS_CONTINUE:
852 { .mmi
853        add GR_Table_Base1 = 96, GR_Table_Base
854        ldfs FR_Two_to_24 = [GR_Table_Base], 4
855        nop.i 999
859 { .mmi
860       nop.m 999
862 //     Load 2**24, load 2**63.
864        ldfs FR_Neg_Two_to_24 = [GR_Table_Base], 12
865        mov   r41 = ar.pfs ;;
868 { .mfi
869        ldfs FR_Two_to_63 = [GR_Table_Base1], 4
871 //     Check for unnormals - unsupported operands. We do not want
872 //     to generate denormal exception
873 //     Check for NatVals, QNaNs, SNaNs, +/-Infs
874 //     Check for EM unsupporteds
875 //     Check for Zero
877        fclass.m.unc  p6, p8 =  FR_Input_X, 0x1E3
878        mov   r40 = gp ;;
881 { .mfi
882       nop.m 999
883        fclass.nm.unc p8, p0 =  FR_Input_X, 0x1FF
884 // GR_Sin_or_Cos denotes
885        mov   r39 = b0
888 { .mfb
889        ldfs FR_Neg_Two_to_63 = [GR_Table_Base1], 12
890        fclass.m.unc p10, p0 = FR_Input_X, 0x007
891 (p6)   br.cond.spnt SINCOS_SPECIAL ;;
894 { .mib
895       nop.m 999
896       nop.i 999
897 (p8)   br.cond.spnt SINCOS_SPECIAL ;;
900 { .mib
901       nop.m 999
902       nop.i 999
904 //     Branch if +/- NaN, Inf.
905 //     Load -2**24, load -2**63.
907 (p10)  br.cond.spnt SINCOS_ZERO ;;
910 { .mmb
911        ldfe FR_Inv_pi_by_2 = [GR_Table_Base], 16
912        ldfe FR_Inv_P_0 = [GR_Table_Base1], 16
913       nop.b 999 ;;
916 { .mmb
917       nop.m 999
918        ldfe     FR_d_1 = [GR_Table_Base1], 16
919       nop.b 999 ;;
922 //     Raise possible denormal operand flag with useful fcmp
923 //     Is x <= -2**63
924 //     Load Inv_P_0 for pre-reduction
925 //     Load Inv_pi_by_2
928 { .mmb
929        ldfe     FR_P_0 = [GR_Table_Base], 16
930        ldfe FR_d_2 = [GR_Table_Base1], 16
931       nop.b 999 ;;
934 //     Load P_0
935 //     Load d_1
936 //     Is x >= 2**63
937 //     Is x <= -2**24?
940 { .mmi
941        ldfe FR_P_1 = [GR_Table_Base], 16 ;;
943 //     Load P_1
944 //     Load d_2
945 //     Is x >= 2**24?
947        ldfe FR_P_2 = [GR_Table_Base], 16
948       nop.i 999 ;;
951 { .mmf
952       nop.m 999
953        ldfe FR_P_3 = [GR_Table_Base], 16
954        fcmp.le.unc.s1   p7, p8 = FR_Input_X, FR_Neg_Two_to_24
957 { .mfi
958       nop.m 999
960 //     Branch if +/- zero.
961 //     Decide about the paths to take:
962 //     If -2**24 < FR_Input_X < 2**24 - CASE 1 OR 2
963 //     OTHERWISE - CASE 3 OR 4
965        fcmp.le.unc.s1   p10, p11 = FR_Input_X, FR_Neg_Two_to_63
966       nop.i 999 ;;
969 { .mfi
970       nop.m 999
971 (p8)   fcmp.ge.s1 p7, p0 = FR_Input_X, FR_Two_to_24
972       nop.i 999
975 { .mfi
976        ldfe FR_Pi_by_4 = [GR_Table_Base1], 16
977 (p11)  fcmp.ge.s1   p10, p0 = FR_Input_X, FR_Two_to_63
978       nop.i 999 ;;
981 { .mmi
982        ldfe FR_Neg_Pi_by_4 = [GR_Table_Base1], 16 ;;
983        ldfs FR_Two_to_M3 = [GR_Table_Base1], 4
984       nop.i 999 ;;
987 { .mib
988        ldfs FR_Neg_Two_to_M3 = [GR_Table_Base1], 12
989       nop.i 999
991 //     Load P_2
992 //     Load P_3
993 //     Load pi_by_4
994 //     Load neg_pi_by_4
995 //     Load 2**(-3)
996 //     Load -2**(-3).
998 (p10)  br.cond.spnt SINCOS_ARG_TOO_LARGE ;;
1001 { .mib
1002       nop.m 999
1003       nop.i 999
1005 //     Branch out if x >= 2**63. Use Payne-Hanek Reduction
1007 (p7)   br.cond.spnt SINCOS_LARGER_ARG ;;
1010 { .mfi
1011       nop.m 999
1013 //     Branch if Arg <= -2**24 or Arg >= 2**24 and use pre-reduction.
1015        fma.s1   FR_N_float = FR_Input_X, FR_Inv_pi_by_2, f0
1016       nop.i 999 ;;
1019 { .mfi
1020       nop.m 999
1021        fcmp.lt.unc.s1   p6, p7 = FR_Input_X, FR_Pi_by_4
1022       nop.i 999 ;;
1025 { .mfi
1026       nop.m 999
1028 //     Select the case when |Arg| < pi/4
1029 //     Else Select the case when |Arg| >= pi/4
1031        fcvt.fx.s1 FR_N_fix = FR_N_float
1032       nop.i 999 ;;
1035 { .mfi
1036       nop.m 999
1038 //     N  = Arg * 2/pi
1039 //     Check if Arg < pi/4
1041 (p6)   fcmp.gt.s1 p6, p7 = FR_Input_X, FR_Neg_Pi_by_4
1042       nop.i 999 ;;
1045 //     Case 2: Convert integer N_fix back to normalized floating-point value.
1046 //     Case 1: p8 is only affected  when p6 is set
1049 { .mfi
1050 (p7)   ldfs FR_Two_to_M33 = [GR_Table_Base1], 4
1052 //     Grab the integer part of N and call it N_fix
1054 (p6)   fmerge.se FR_r = FR_Input_X, FR_Input_X
1055 //     If |x| < pi/4, r = x and c = 0
1056 //     lf |x| < pi/4, is x < 2**(-3).
1057 //     r = Arg
1058 //     c = 0
1059 (p6)   mov GR_N_Inc = GR_Sin_or_Cos ;;
1062 { .mmf
1063       nop.m 999
1064 (p7)   ldfs FR_Neg_Two_to_M33 = [GR_Table_Base1], 4
1065 (p6)   fmerge.se FR_c = f0, f0
1068 { .mfi
1069       nop.m 999
1070 (p6)   fcmp.lt.unc.s1   p8, p9 = FR_Input_X, FR_Two_to_M3
1071       nop.i 999 ;;
1074 { .mfi
1075       nop.m 999
1077 //     lf |x| < pi/4, is -2**(-3)< x < 2**(-3) - set p8.
1078 //     If |x| >= pi/4,
1079 //     Create the right N for |x| < pi/4 and otherwise
1080 //     Case 2: Place integer part of N in GP register
1082 (p7)   fcvt.xf FR_N_float = FR_N_fix
1083       nop.i 999 ;;
1086 { .mmf
1087       nop.m 999
1088 (p7)   getf.sig GR_N_Inc = FR_N_fix
1089 (p8)   fcmp.gt.s1 p8, p0 = FR_Input_X, FR_Neg_Two_to_M3 ;;
1092 { .mib
1093       nop.m 999
1094       nop.i 999
1096 //     Load 2**(-33), -2**(-33)
1098 (p8)   br.cond.spnt SINCOS_SMALL_R ;;
1101 { .mib
1102       nop.m 999
1103       nop.i 999
1104 (p6)   br.cond.sptk SINCOS_NORMAL_R ;;
1107 //     if |x| < pi/4, branch based on |x| < 2**(-3) or otherwise.
1110 //     In this branch, |x| >= pi/4.
1113 { .mfi
1114        ldfs FR_Neg_Two_to_M67 = [GR_Table_Base1], 8
1116 //     Load -2**(-67)
1118        fnma.s1  FR_s = FR_N_float, FR_P_1, FR_Input_X
1120 //     w = N * P_2
1121 //     s = -N * P_1  + Arg
1123        add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos
1126 { .mfi
1127       nop.m 999
1128        fma.s1   FR_w = FR_N_float, FR_P_2, f0
1129       nop.i 999 ;;
1132 { .mfi
1133       nop.m 999
1135 //     Adjust N_fix by N_inc to determine whether sine or
1136 //     cosine is being calculated
1138        fcmp.lt.unc.s1 p7, p6 = FR_s, FR_Two_to_M33
1139       nop.i 999 ;;
1142 { .mfi
1143       nop.m 999
1144 (p7)   fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33
1145       nop.i 999 ;;
1148 { .mfi
1149       nop.m 999
1150 //     Remember x >= pi/4.
1151 //     Is s <= -2**(-33) or s >= 2**(-33) (p6)
1152 //     or -2**(-33) < s < 2**(-33) (p7)
1153 (p6)   fms.s1 FR_r = FR_s, f1, FR_w
1154       nop.i 999
1157 { .mfi
1158       nop.m 999
1159 (p7)   fma.s1 FR_w = FR_N_float, FR_P_3, f0
1160       nop.i 999 ;;
1163 { .mfi
1164       nop.m 999
1165 (p7)   fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1166       nop.i 999
1169 { .mfi
1170       nop.m 999
1171 (p6)   fms.s1 FR_c = FR_s, f1, FR_r
1172       nop.i 999 ;;
1175 { .mfi
1176       nop.m 999
1178 //     For big s: r = s - w: No futher reduction is necessary
1179 //     For small s: w = N * P_3 (change sign) More reduction
1181 (p6)   fcmp.lt.unc.s1 p8, p9 = FR_r, FR_Two_to_M3
1182       nop.i 999 ;;
1185 { .mfi
1186       nop.m 999
1187 (p8)   fcmp.gt.s1 p8, p9 = FR_r, FR_Neg_Two_to_M3
1188       nop.i 999 ;;
1191 { .mfi
1192       nop.m 999
1193 (p7)   fms.s1 FR_r = FR_s, f1, FR_U_1
1194       nop.i 999
1197 { .mfb
1198       nop.m 999
1200 //     For big s: Is |r| < 2**(-3)?
1201 //     For big s: c = S - r
1202 //     For small s: U_1 = N * P_2 + w
1204 //     If p8 is set, prepare to branch to Small_R.
1205 //     If p9 is set, prepare to branch to Normal_R.
1206 //     For big s,  r is complete here.
1208 (p6)   fms.s1 FR_c = FR_c, f1, FR_w
1210 //     For big s: c = c + w (w has not been negated.)
1211 //     For small s: r = S - U_1
1213 (p8)   br.cond.spnt SINCOS_SMALL_R ;;
1216 { .mib
1217       nop.m 999
1218       nop.i 999
1219 (p9)   br.cond.sptk SINCOS_NORMAL_R ;;
1222 { .mfi
1223 (p7)   add GR_Table_Base1 = 224, GR_Table_Base1
1225 //     Branch to SINCOS_SMALL_R or SINCOS_NORMAL_R
1227 (p7)   fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1229 //     c = S - U_1
1230 //     r = S_1 * r
1233 (p7)   extr.u   GR_i_1 = GR_N_Inc, 0, 1
1236 { .mmi
1237       nop.m 999 ;;
1239 //     Get [i_0,i_1] - two lsb of N_fix_gr.
1240 //     Do dummy fmpy so inexact is always set.
1242 (p7)   cmp.eq.unc p9, p10 = 0x0, GR_i_1
1243 (p7)   extr.u   GR_i_0 = GR_N_Inc, 1, 1 ;;
1246 //     For small s: U_2 = N * P_2 - U_1
1247 //     S_1 stored constant - grab the one stored with the
1248 //     coefficients.
1251 { .mfi
1252 (p7)   ldfe FR_S_1 = [GR_Table_Base1], 16
1254 //     Check if i_1 and i_0  != 0
1256 (p10)  fma.s1   FR_poly = f0, f1, FR_Neg_Two_to_M67
1257 (p7)   cmp.eq.unc p11, p12 = 0x0, GR_i_0 ;;
1260 { .mfi
1261       nop.m 999
1262 (p7)   fms.s1   FR_s = FR_s, f1, FR_r
1263       nop.i 999
1266 { .mfi
1267       nop.m 999
1269 //     S = S - r
1270 //     U_2 = U_2 + w
1271 //     load S_1
1273 (p7)   fma.s1   FR_rsq = FR_r, FR_r, f0
1274       nop.i 999 ;;
1277 { .mfi
1278       nop.m 999
1279 (p7)   fma.s1   FR_U_2 = FR_U_2, f1, FR_w
1280       nop.i 999
1283 { .mfi
1284       nop.m 999
1285 //(p7)   fmerge.se FR_Input_X = FR_r, FR_r
1286 (p7)   fmerge.se FR_prelim = FR_r, FR_r
1287       nop.i 999 ;;
1290 { .mfi
1291       nop.m 999
1292 //(p10)  fma.s1 FR_Input_X = f0, f1, f1
1293 (p10)  fma.s1 FR_prelim = f0, f1, f1
1294       nop.i 999 ;;
1297 { .mfi
1298       nop.m 999
1300 //     FR_rsq = r * r
1301 //     Save r as the result.
1303 (p7)   fms.s1   FR_c = FR_s, f1, FR_U_1
1304       nop.i 999 ;;
1307 { .mfi
1308       nop.m 999
1310 //     if ( i_1 ==0) poly = c + S_1*r*r*r
1311 //     else Result = 1
1313 //(p12)  fnma.s1 FR_Input_X = FR_Input_X, f1, f0
1314 (p12)  fnma.s1 FR_prelim = FR_prelim, f1, f0
1315       nop.i 999
1318 { .mfi
1319       nop.m 999
1320 (p7)   fma.s1   FR_r = FR_S_1, FR_r, f0
1321       nop.i 999 ;;
1324 { .mfi
1325       nop.m 999
1326 (p7)   fma.d.s1 FR_S_1 = FR_S_1, FR_S_1, f0
1327       nop.i 999 ;;
1330 { .mfi
1331       nop.m 999
1333 //     If i_1 != 0, poly = 2**(-67)
1335 (p7)   fms.s1 FR_c = FR_c, f1, FR_U_2
1336       nop.i 999 ;;
1339 { .mfi
1340       nop.m 999
1342 //     c = c - U_2
1344 (p9)   fma.s1 FR_poly = FR_r, FR_rsq, FR_c
1345       nop.i 999 ;;
1348 { .mfi
1349       nop.m 999
1351 //     i_0 != 0, so Result = -Result
1353 (p11)  fma.s1 FR_Input_X = FR_prelim, f1, FR_poly
1354       nop.i 999 ;;
1357 { .mfb
1358       nop.m 999
1359 (p12)  fms.s1 FR_Input_X = FR_prelim, f1, FR_poly
1361 //     if (i_0 == 0),  Result = Result + poly
1362 //     else            Result = Result - poly
1364        br.ret.sptk   b0 ;;
1366 SINCOS_LARGER_ARG:
1368 { .mfi
1369       nop.m 999
1370        fma.s1 FR_N_0 = FR_Input_X, FR_Inv_P_0, f0
1371       nop.i 999
1375 //     This path for argument > 2*24
1376 //     Adjust table_ptr1 to beginning of table.
1379 { .mmi
1380       nop.m 999
1381       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
1382       nop.i 999
1386 { .mmi
1387       ld8 GR_Table_Base = [GR_Table_Base]
1388       nop.m 999
1389       nop.i 999
1395 //     Point to  2*-14
1396 //     N_0 = Arg * Inv_P_0
1399 { .mmi
1400        add GR_Table_Base = 688, GR_Table_Base ;;
1401        ldfs FR_Two_to_M14 = [GR_Table_Base], 4
1402       nop.i 999 ;;
1405 { .mfi
1406        ldfs FR_Neg_Two_to_M14 = [GR_Table_Base], 0
1407       nop.f 999
1408       nop.i 999 ;;
1411 { .mfi
1412       nop.m 999
1414 //     Load values 2**(-14) and -2**(-14)
1416        fcvt.fx.s1 FR_N_0_fix = FR_N_0
1417       nop.i 999 ;;
1420 { .mfi
1421       nop.m 999
1423 //     N_0_fix  = integer part of N_0
1425        fcvt.xf FR_N_0 = FR_N_0_fix
1426       nop.i 999 ;;
1429 { .mfi
1430       nop.m 999
1432 //     Make N_0 the integer part
1434        fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X
1435       nop.i 999
1438 { .mfi
1439       nop.m 999
1440        fma.s1 FR_w = FR_N_0, FR_d_1, f0
1441       nop.i 999 ;;
1444 { .mfi
1445       nop.m 999
1447 //     Arg' = -N_0 * P_0 + Arg
1448 //     w  = N_0 * d_1
1450        fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0
1451       nop.i 999 ;;
1454 { .mfi
1455       nop.m 999
1457 //     N = A' * 2/pi
1459        fcvt.fx.s1 FR_N_fix = FR_N_float
1460       nop.i 999 ;;
1463 { .mfi
1464       nop.m 999
1466 //     N_fix is the integer part
1468        fcvt.xf FR_N_float = FR_N_fix
1469       nop.i 999 ;;
1472 { .mfi
1473        getf.sig GR_N_Inc = FR_N_fix
1474       nop.f 999
1475       nop.i 999 ;;
1478 { .mii
1479       nop.m 999
1480       nop.i 999 ;;
1481        add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos ;;
1484 { .mfi
1485       nop.m 999
1487 //     N is the integer part of the reduced-reduced argument.
1488 //     Put the integer in a GP register
1490        fnma.s1 FR_s = FR_N_float, FR_P_1, FR_ArgPrime
1491       nop.i 999
1494 { .mfi
1495       nop.m 999
1496        fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w
1497       nop.i 999 ;;
1500 { .mfi
1501       nop.m 999
1503 //     s = -N*P_1 + Arg'
1504 //     w = -N*P_2 + w
1505 //     N_fix_gr = N_fix_gr + N_inc
1507        fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1508       nop.i 999 ;;
1511 { .mfi
1512       nop.m 999
1513 (p9)   fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14
1514       nop.i 999 ;;
1517 { .mfi
1518       nop.m 999
1520 //     For |s|  > 2**(-14) r = S + w (r complete)
1521 //     Else       U_hi = N_0 * d_1
1523 (p9)   fma.s1 FR_V_hi = FR_N_float, FR_P_2, f0
1524       nop.i 999
1527 { .mfi
1528       nop.m 999
1529 (p9)   fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1530       nop.i 999 ;;
1533 { .mfi
1534       nop.m 999
1536 //     Either S <= -2**(-14) or S >= 2**(-14)
1537 //     or -2**(-14) < s < 2**(-14)
1539 (p8)   fma.s1 FR_r = FR_s, f1, FR_w
1540       nop.i 999
1543 { .mfi
1544       nop.m 999
1545 (p9)   fma.s1 FR_w = FR_N_float, FR_P_3, f0
1546       nop.i 999 ;;
1549 { .mfi
1550       nop.m 999
1552 //     We need abs of both U_hi and V_hi - don't
1553 //     worry about switched sign of V_hi.
1555 (p9)   fms.s1 FR_A = FR_U_hi, f1, FR_V_hi
1556       nop.i 999
1559 { .mfi
1560       nop.m 999
1562 //     Big s: finish up c = (S - r) + w (c complete)
1563 //     Case 4: A =  U_hi + V_hi
1564 //     Note: Worry about switched sign of V_hi, so subtract instead of add.
1566 (p9)   fnma.s1 FR_V_lo = FR_N_float, FR_P_2, FR_V_hi
1567       nop.i 999 ;;
1570 { .mfi
1571       nop.m 999
1572 (p9)   fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi
1573       nop.i 999 ;;
1576 { .mfi
1577       nop.m 999
1578 (p9)   fmerge.s FR_V_hiabs = f0, FR_V_hi
1579       nop.i 999
1582 { .mfi
1583       nop.m 999
1584 //     For big s: c = S - r
1585 //     For small s do more work: U_lo = N_0 * d_1 - U_hi
1587 (p9)   fmerge.s FR_U_hiabs = f0, FR_U_hi
1588       nop.i 999 ;;
1591 { .mfi
1592       nop.m 999
1594 //     For big s: Is |r| < 2**(-3)
1595 //     For big s: if p12 set, prepare to branch to Small_R.
1596 //     For big s: If p13 set, prepare to branch to Normal_R.
1598 (p8)   fms.s1 FR_c = FR_s, f1, FR_r
1599       nop.i 999
1602 { .mfi
1603       nop.m 999
1605 //     For small S: V_hi = N * P_2
1606 //                  w = N * P_3
1607 //     Note the product does not include the (-) as in the writeup
1608 //     so (-) missing for V_hi and w.
1610 (p8)   fcmp.lt.unc.s1 p12, p13 = FR_r, FR_Two_to_M3
1611       nop.i 999 ;;
1614 { .mfi
1615       nop.m 999
1616 (p12)  fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1617       nop.i 999 ;;
1620 { .mfi
1621       nop.m 999
1622 (p8)   fma.s1 FR_c = FR_c, f1, FR_w
1623       nop.i 999
1626 { .mfb
1627       nop.m 999
1628 (p9)   fms.s1 FR_w = FR_N_0, FR_d_2, FR_w
1629 (p12)  br.cond.spnt SINCOS_SMALL_R ;;
1632 { .mib
1633       nop.m 999
1634       nop.i 999
1635 (p13)  br.cond.sptk SINCOS_NORMAL_R ;;
1638 { .mfi
1639       nop.m 999
1641 //     Big s: Vector off when |r| < 2**(-3).  Recall that p8 will be true.
1642 //     The remaining stuff is for Case 4.
1643 //     Small s: V_lo = N * P_2 + U_hi (U_hi is in place of V_hi in writeup)
1644 //     Note: the (-) is still missing for V_lo.
1645 //     Small s: w = w + N_0 * d_2
1646 //     Note: the (-) is now incorporated in w.
1648 (p9)   fcmp.ge.unc.s1 p10, p11 = FR_U_hiabs, FR_V_hiabs
1649        extr.u   GR_i_1 = GR_N_Inc, 0, 1 ;;
1652 { .mfi
1653       nop.m 999
1655 //     C_hi = S + A
1657 (p9)   fma.s1 FR_t = FR_U_lo, f1, FR_V_lo
1658        extr.u   GR_i_0 = GR_N_Inc, 1, 1 ;;
1661 { .mfi
1662       nop.m 999
1664 //     t = U_lo + V_lo
1667 (p10)  fms.s1 FR_a = FR_U_hi, f1, FR_A
1668       nop.i 999 ;;
1671 { .mfi
1672       nop.m 999
1673 (p11)  fma.s1 FR_a = FR_V_hi, f1, FR_A
1674       nop.i 999
1678 { .mmi
1679       nop.m 999
1680       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
1681       nop.i 999
1685 { .mmi
1686       ld8 GR_Table_Base = [GR_Table_Base]
1687       nop.m 999
1688       nop.i 999
1693 { .mfi
1694        add GR_Table_Base = 528, GR_Table_Base
1696 //     Is U_hiabs >= V_hiabs?
1698 (p9)   fma.s1 FR_C_hi = FR_s, f1, FR_A
1699       nop.i 999 ;;
1702 { .mmi
1703        ldfe FR_C_1 = [GR_Table_Base], 16 ;;
1704        ldfe FR_C_2 = [GR_Table_Base], 64
1705       nop.i 999 ;;
1708 { .mmf
1709       nop.m 999
1711 //     c = c + C_lo  finished.
1712 //     Load  C_2
1714        ldfe FR_S_1 = [GR_Table_Base], 16
1716 //     C_lo = S - C_hi
1718        fma.s1 FR_t = FR_t, f1, FR_w ;;
1721 //     r and c have been computed.
1722 //     Make sure ftz mode is set - should be automatic when using wre
1723 //     |r| < 2**(-3)
1724 //     Get [i_0,i_1] - two lsb of N_fix.
1725 //     Load S_1
1728 { .mfi
1729        ldfe FR_S_2 = [GR_Table_Base], 64
1731 //     t = t + w
1733 (p10)  fms.s1 FR_a = FR_a, f1, FR_V_hi
1734        cmp.eq.unc p9, p10 = 0x0, GR_i_0
1737 { .mfi
1738       nop.m 999
1740 //     For larger u than v: a = U_hi - A
1741 //     Else a = V_hi - A (do an add to account for missing (-) on V_hi
1743        fms.s1 FR_C_lo = FR_s, f1, FR_C_hi
1744       nop.i 999 ;;
1747 { .mfi
1748       nop.m 999
1749 (p11)  fms.s1 FR_a = FR_U_hi, f1, FR_a
1750        cmp.eq.unc p11, p12 = 0x0, GR_i_1
1753 { .mfi
1754       nop.m 999
1756 //     If u > v: a = (U_hi - A)  + V_hi
1757 //     Else      a = (V_hi - A)  + U_hi
1758 //     In each case account for negative missing from V_hi.
1760        fma.s1 FR_C_lo = FR_C_lo, f1, FR_A
1761       nop.i 999 ;;
1764 { .mfi
1765       nop.m 999
1767 //     C_lo = (S - C_hi) + A
1769        fma.s1 FR_t = FR_t, f1, FR_a
1770       nop.i 999 ;;
1773 { .mfi
1774       nop.m 999
1776 //     t = t + a
1778        fma.s1 FR_C_lo = FR_C_lo, f1, FR_t
1779       nop.i 999 ;;
1782 { .mfi
1783       nop.m 999
1785 //     C_lo = C_lo + t
1786 //     Adjust Table_Base to beginning of table
1788        fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1789       nop.i 999 ;;
1792 { .mfi
1793       nop.m 999
1795 //     Load S_2
1797        fma.s1 FR_rsq = FR_r, FR_r, f0
1798       nop.i 999
1801 { .mfi
1802       nop.m 999
1804 //     Table_Base points to C_1
1805 //     r = C_hi + C_lo
1807        fms.s1 FR_c = FR_C_hi, f1, FR_r
1808       nop.i 999 ;;
1811 { .mfi
1812       nop.m 999
1814 //     if i_1 ==0: poly = S_2 * FR_rsq + S_1
1815 //     else        poly = C_2 * FR_rsq + C_1
1817 //(p11)  fma.s1 FR_Input_X = f0, f1, FR_r
1818 (p11)  fma.s1 FR_prelim = f0, f1, FR_r
1819       nop.i 999 ;;
1822 { .mfi
1823       nop.m 999
1824 //(p12)  fma.s1 FR_Input_X = f0, f1, f1
1825 (p12)  fma.s1 FR_prelim = f0, f1, f1
1826       nop.i 999 ;;
1829 { .mfi
1830       nop.m 999
1832 //     Compute r_cube = FR_rsq * r
1834 (p11)  fma.s1 FR_poly = FR_rsq, FR_S_2, FR_S_1
1835       nop.i 999 ;;
1838 { .mfi
1839       nop.m 999
1840 (p12)  fma.s1 FR_poly = FR_rsq, FR_C_2, FR_C_1
1841       nop.i 999
1844 { .mfi
1845       nop.m 999
1847 //     Compute FR_rsq = r * r
1848 //     Is i_1 == 0 ?
1850        fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1851       nop.i 999 ;;
1854 { .mfi
1855       nop.m 999
1857 //     c = C_hi - r
1858 //     Load  C_1
1860        fma.s1 FR_c = FR_c, f1, FR_C_lo
1861       nop.i 999
1864 { .mfi
1865       nop.m 999
1867 //     if i_1 ==0: poly = r_cube * poly + c
1868 //     else        poly = FR_rsq * poly
1870 //(p10)  fms.s1 FR_Input_X = f0, f1, FR_Input_X
1871 (p10)  fms.s1 FR_prelim = f0, f1, FR_prelim
1872       nop.i 999 ;;
1875 { .mfi
1876       nop.m 999
1878 //     if i_1 ==0: Result = r
1879 //     else        Result = 1.0
1881 (p11)  fma.s1 FR_poly = FR_r_cubed, FR_poly, FR_c
1882       nop.i 999 ;;
1885 { .mfi
1886       nop.m 999
1887 (p12)  fma.s1 FR_poly = FR_rsq, FR_poly, f0
1888       nop.i 999 ;;
1891 { .mfi
1892       nop.m 999
1894 //     if i_0 !=0: Result = -Result
1896 (p9)   fma.s1 FR_Input_X = FR_prelim, f1, FR_poly
1897       nop.i 999 ;;
1900 { .mfb
1901       nop.m 999
1902 (p10)  fms.s1 FR_Input_X = FR_prelim, f1, FR_poly
1904 //     if i_0 == 0: Result = Result + poly
1905 //     else         Result = Result - poly
1907        br.ret.sptk   b0 ;;
1909 SINCOS_SMALL_R:
1911 { .mii
1912       nop.m 999
1913         extr.u  GR_i_1 = GR_N_Inc, 0, 1 ;;
1916 //      Compare both i_1 and i_0 with 0.
1917 //      if i_1 == 0, set p9.
1918 //      if i_0 == 0, set p11.
1920         cmp.eq.unc p9, p10 = 0x0, GR_i_1 ;;
1923 { .mfi
1924       nop.m 999
1925         fma.s1 FR_rsq = FR_r, FR_r, f0
1926         extr.u  GR_i_0 = GR_N_Inc, 1, 1 ;;
1929 { .mfi
1930       nop.m 999
1932 //  Z = Z * FR_rsq
1934 (p10)   fnma.s1 FR_c = FR_c, FR_r, f0
1935         cmp.eq.unc p11, p12 = 0x0, GR_i_0
1939 // ******************************************************************
1940 // ******************************************************************
1941 // ******************************************************************
1942 //      r and c have been computed.
1943 //      We know whether this is the sine or cosine routine.
1944 //      Make sure ftz mode is set - should be automatic when using wre
1945 //      |r| < 2**(-3)
1947 //      Set table_ptr1 to beginning of constant table.
1948 //      Get [i_0,i_1] - two lsb of N_fix_gr.
1951 { .mmi
1952       nop.m 999
1953       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
1954       nop.i 999
1958 { .mmi
1959       ld8 GR_Table_Base = [GR_Table_Base]
1960       nop.m 999
1961       nop.i 999
1967 //      Set table_ptr1 to point to S_5.
1968 //      Set table_ptr1 to point to C_5.
1969 //      Compute FR_rsq = r * r
1972 { .mfi
1973 (p9)    add GR_Table_Base = 672, GR_Table_Base
1974 (p10)   fmerge.s FR_r = f1, f1
1975 (p10)   add GR_Table_Base = 592, GR_Table_Base ;;
1978 //      Set table_ptr1 to point to S_5.
1979 //      Set table_ptr1 to point to C_5.
1982 { .mmi
1983 (p9)    ldfe FR_S_5 = [GR_Table_Base], -16 ;;
1985 //      if (i_1 == 0) load S_5
1986 //      if (i_1 != 0) load C_5
1988 (p9)    ldfe FR_S_4 = [GR_Table_Base], -16
1989       nop.i 999 ;;
1992 { .mmf
1993 (p10)   ldfe FR_C_5 = [GR_Table_Base], -16
1995 //      Z = FR_rsq * FR_rsq
1997 (p9)    ldfe FR_S_3 = [GR_Table_Base], -16
1999 //      Compute FR_rsq = r * r
2000 //      if (i_1 == 0) load S_4
2001 //      if (i_1 != 0) load C_4
2003         fma.s1 FR_Z = FR_rsq, FR_rsq, f0 ;;
2006 //      if (i_1 == 0) load S_3
2007 //      if (i_1 != 0) load C_3
2010 { .mmi
2011 (p9)    ldfe FR_S_2 = [GR_Table_Base], -16 ;;
2013 //      if (i_1 == 0) load S_2
2014 //      if (i_1 != 0) load C_2
2016 (p9)    ldfe FR_S_1 = [GR_Table_Base], -16
2017       nop.i 999
2020 { .mmi
2021 (p10)   ldfe FR_C_4 = [GR_Table_Base], -16 ;;
2022 (p10)   ldfe FR_C_3 = [GR_Table_Base], -16
2023       nop.i 999 ;;
2026 { .mmi
2027 (p10)   ldfe FR_C_2 = [GR_Table_Base], -16 ;;
2028 (p10)   ldfe FR_C_1 = [GR_Table_Base], -16
2029       nop.i 999
2032 { .mfi
2033       nop.m 999
2035 //      if (i_1 != 0):
2036 //      poly_lo = FR_rsq * C_5 + C_4
2037 //      poly_hi = FR_rsq * C_2 + C_1
2039 (p9)    fma.s1 FR_Z = FR_Z, FR_r, f0
2040       nop.i 999 ;;
2043 { .mfi
2044       nop.m 999
2046 //      if (i_1 == 0) load S_1
2047 //      if (i_1 != 0) load C_1
2049 (p9)    fma.s1 FR_poly_lo = FR_rsq, FR_S_5, FR_S_4
2050       nop.i 999
2053 { .mfi
2054       nop.m 999
2056 //      c = -c * r
2057 //      dummy fmpy's to flag inexact.
2059 (p9)    fma.d.s1 FR_S_4 = FR_S_4, FR_S_4, f0
2060       nop.i 999 ;;
2063 { .mfi
2064       nop.m 999
2066 //      poly_lo = FR_rsq * poly_lo + C_3
2067 //      poly_hi = FR_rsq * poly_hi
2069         fma.s1  FR_Z = FR_Z, FR_rsq, f0
2070       nop.i 999 ;;
2073 { .mfi
2074       nop.m 999
2075 (p9)    fma.s1 FR_poly_hi = FR_rsq, FR_S_2, FR_S_1
2076       nop.i 999
2079 { .mfi
2080       nop.m 999
2082 //      if (i_1 == 0):
2083 //      poly_lo = FR_rsq * S_5 + S_4
2084 //      poly_hi = FR_rsq * S_2 + S_1
2086 (p10)   fma.s1 FR_poly_lo = FR_rsq, FR_C_5, FR_C_4
2087       nop.i 999 ;;
2090 { .mfi
2091       nop.m 999
2093 //      if (i_1 == 0):
2094 //      Z = Z * r  for only one of the small r cases - not there
2095 //      in original implementation notes.
2097 (p9)    fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_S_3
2098       nop.i 999 ;;
2101 { .mfi
2102       nop.m 999
2103 (p10)   fma.s1 FR_poly_hi = FR_rsq, FR_C_2, FR_C_1
2104       nop.i 999
2107 { .mfi
2108       nop.m 999
2109 (p10)   fma.d.s1 FR_C_1 = FR_C_1, FR_C_1, f0
2110       nop.i 999 ;;
2113 { .mfi
2114       nop.m 999
2115 (p9)    fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0
2116       nop.i 999
2119 { .mfi
2120       nop.m 999
2122 //      poly_lo = FR_rsq * poly_lo + S_3
2123 //      poly_hi = FR_rsq * poly_hi
2125 (p10)   fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_C_3
2126       nop.i 999 ;;
2129 { .mfi
2130       nop.m 999
2131 (p10)   fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0
2132       nop.i 999 ;;
2135 { .mfi
2136       nop.m 999
2138 //  if (i_1 == 0): dummy fmpy's to flag inexact
2139 //  r = 1
2141 (p9)    fma.s1 FR_poly_hi = FR_r, FR_poly_hi, f0
2142       nop.i 999
2145 { .mfi
2146       nop.m 999
2148 //  poly_hi = r * poly_hi
2150         fma.s1  FR_poly = FR_Z, FR_poly_lo, FR_c
2151       nop.i 999 ;;
2154 { .mfi
2155       nop.m 999
2156 (p12)   fms.s1  FR_r = f0, f1, FR_r
2157       nop.i 999 ;;
2160 { .mfi
2161       nop.m 999
2163 //      poly_hi = Z * poly_lo + c
2164 //  if i_0 == 1: r = -r
2166         fma.s1  FR_poly = FR_poly, f1, FR_poly_hi
2167       nop.i 999 ;;
2170 { .mfi
2171       nop.m 999
2172 (p12)   fms.s1 FR_Input_X = FR_r, f1, FR_poly
2173       nop.i 999
2176 { .mfb
2177       nop.m 999
2179 //      poly = poly + poly_hi
2181 (p11)   fma.s1 FR_Input_X = FR_r, f1, FR_poly
2183 //      if (i_0 == 0) Result = r + poly
2184 //      if (i_0 != 0) Result = r - poly
2186        br.ret.sptk   b0 ;;
2188 SINCOS_NORMAL_R:
2190 { .mii
2191       nop.m 999
2192         extr.u  GR_i_1 = GR_N_Inc, 0, 1 ;;
2194 //      Set table_ptr1 and table_ptr2 to base address of
2195 //      constant table.
2196         cmp.eq.unc p9, p10 = 0x0, GR_i_1 ;;
2199 { .mfi
2200       nop.m 999
2201         fma.s1  FR_rsq = FR_r, FR_r, f0
2202         extr.u  GR_i_0 = GR_N_Inc, 1, 1 ;;
2205 { .mfi
2206       nop.m 999
2207         frcpa.s1 FR_r_hi, p6 = f1, FR_r
2208         cmp.eq.unc p11, p12 = 0x0, GR_i_0
2212 // ******************************************************************
2213 // ******************************************************************
2214 // ******************************************************************
2216 //      r and c have been computed.
2217 //      We known whether this is the sine or cosine routine.
2218 //      Make sure ftz mode is set - should be automatic when using wre
2219 //      Get [i_0,i_1] - two lsb of N_fix_gr alone.
2222 { .mmi
2223       nop.m 999
2224       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
2225       nop.i 999
2229 { .mmi
2230       ld8 GR_Table_Base = [GR_Table_Base]
2231       nop.m 999
2232       nop.i 999
2237 { .mfi
2238 (p10)   add GR_Table_Base = 384, GR_Table_Base
2239 //(p12)   fms.s1 FR_Input_X = f0, f1, f1
2240 (p12)   fms.s1 FR_prelim = f0, f1, f1
2241 (p9)    add GR_Table_Base = 224, GR_Table_Base ;;
2244 { .mmf
2245       nop.m 999
2246 (p10)   ldfe FR_QQ_8 = [GR_Table_Base], 16
2248 //      if (i_1==0) poly = poly * FR_rsq + PP_1_lo
2249 //      else        poly = FR_rsq * poly
2251 //(p11)   fma.s1 FR_Input_X = f0, f1, f1 ;;
2252 (p11)   fma.s1 FR_prelim = f0, f1, f1 ;;
2255 { .mmf
2256 (p10)   ldfe FR_QQ_7 = [GR_Table_Base], 16
2258 //  Adjust table pointers based on i_0
2259 //      Compute rsq = r * r
2261 (p9)    ldfe FR_PP_8 = [GR_Table_Base], 16
2262         fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 ;;
2265 { .mmf
2266 (p9)    ldfe FR_PP_7 = [GR_Table_Base], 16
2267 (p10)   ldfe FR_QQ_6 = [GR_Table_Base], 16
2269 //      Load PP_8 and QQ_8; PP_7 and QQ_7
2271         frcpa.s1 FR_r_hi, p6 = f1, FR_r_hi ;;
2274 //      if (i_1==0) poly =   PP_7 + FR_rsq * PP_8.
2275 //      else        poly =   QQ_7 + FR_rsq * QQ_8.
2278 { .mmb
2279 (p9)    ldfe FR_PP_6 = [GR_Table_Base], 16
2280 (p10)   ldfe FR_QQ_5 = [GR_Table_Base], 16
2281       nop.b 999 ;;
2284 { .mmb
2285 (p9)    ldfe FR_PP_5 = [GR_Table_Base], 16
2286 (p10)   ldfe FR_S_1 = [GR_Table_Base], 16
2287       nop.b 999 ;;
2290 { .mmb
2291 (p10)   ldfe FR_QQ_1 = [GR_Table_Base], 16
2292 (p9)    ldfe FR_C_1 = [GR_Table_Base], 16
2293       nop.b 999 ;;
2296 { .mmi
2297 (p10)   ldfe FR_QQ_4 = [GR_Table_Base], 16 ;;
2298 (p9)    ldfe FR_PP_1 = [GR_Table_Base], 16
2299       nop.i 999 ;;
2302 { .mmf
2303 (p10)   ldfe FR_QQ_3 = [GR_Table_Base], 16
2305 //      if (i_1=0) corr = corr + c*c
2306 //      else       corr = corr * c
2308 (p9)    ldfe FR_PP_4 = [GR_Table_Base], 16
2309 (p10)   fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 ;;
2312 //      if (i_1=0) poly = rsq * poly + PP_5
2313 //      else       poly = rsq * poly + QQ_5
2314 //      Load PP_4 or QQ_4
2317 { .mmf
2318 (p9)    ldfe FR_PP_3 = [GR_Table_Base], 16
2319 (p10)   ldfe FR_QQ_2 = [GR_Table_Base], 16
2321 //      r_hi =   frcpa(frcpa(r)).
2322 //      r_cube = r * FR_rsq.
2324 (p9)    fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 ;;
2327 //      Do dummy multiplies so inexact is always set.
2330 { .mfi
2331 (p9)    ldfe FR_PP_2 = [GR_Table_Base], 16
2333 //      r_lo = r - r_hi
2335 (p9)    fma.s1 FR_U_lo = FR_r_hi, FR_r_hi, f0
2336       nop.i 999 ;;
2339 { .mmf
2340       nop.m 999
2341 (p9)    ldfe FR_PP_1_lo = [GR_Table_Base], 16
2342 (p10)   fma.s1 FR_corr = FR_S_1, FR_r_cubed, FR_r
2345 { .mfi
2346       nop.m 999
2347 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_6
2348       nop.i 999 ;;
2351 { .mfi
2352       nop.m 999
2354 //      if (i_1=0) U_lo = r_hi * r_hi
2355 //      else       U_lo = r_hi + r
2357 (p9)    fma.s1 FR_corr = FR_C_1, FR_rsq, f0
2358       nop.i 999 ;;
2361 { .mfi
2362       nop.m 999
2364 //      if (i_1=0) corr = C_1 * rsq
2365 //      else       corr = S_1 * r_cubed + r
2367 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_6
2368       nop.i 999
2371 { .mfi
2372       nop.m 999
2373 (p10)   fma.s1 FR_U_lo = FR_r_hi, f1, FR_r
2374       nop.i 999 ;;
2377 { .mfi
2378       nop.m 999
2380 //      if (i_1=0) U_hi = r_hi + U_hi
2381 //      else       U_hi = QQ_1 * U_hi + 1
2383 (p9)    fma.s1 FR_U_lo = FR_r, FR_r_hi, FR_U_lo
2384       nop.i 999
2387 { .mfi
2388       nop.m 999
2390 //      U_hi = r_hi * r_hi
2392         fms.s1 FR_r_lo = FR_r, f1, FR_r_hi
2393       nop.i 999 ;;
2396 { .mfi
2397       nop.m 999
2399 //      Load PP_1, PP_6, PP_5, and C_1
2400 //      Load QQ_1, QQ_6, QQ_5, and S_1
2402         fma.s1 FR_U_hi = FR_r_hi, FR_r_hi, f0
2403       nop.i 999 ;;
2406 { .mfi
2407       nop.m 999
2408 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_5
2409       nop.i 999
2412 { .mfi
2413       nop.m 999
2414 (p10)   fnma.s1 FR_corr = FR_corr, FR_c, f0
2415       nop.i 999 ;;
2418 { .mfi
2419       nop.m 999
2421 //      if (i_1=0) U_lo = r * r_hi + U_lo
2422 //      else       U_lo = r_lo * U_lo
2424 (p9)    fma.s1 FR_corr = FR_corr, FR_c, FR_c
2425       nop.i 999 ;;
2428 { .mfi
2429       nop.m 999
2430 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_5
2431       nop.i 999
2434 { .mfi
2435       nop.m 999
2437 //      if (i_1 =0) U_hi = r + U_hi
2438 //      if (i_1 =0) U_lo = r_lo * U_lo
2441 (p9)    fma.d.s1 FR_PP_5 = FR_PP_5, FR_PP_4, f0
2442       nop.i 999 ;;
2445 { .mfi
2446       nop.m 999
2447 (p9)    fma.s1 FR_U_lo = FR_r, FR_r, FR_U_lo
2448       nop.i 999
2451 { .mfi
2452       nop.m 999
2453 (p10)   fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0
2454       nop.i 999 ;;
2457 { .mfi
2458       nop.m 999
2460 //      if (i_1=0) poly = poly * rsq + PP_6
2461 //      else       poly = poly * rsq + QQ_6
2463 (p9)    fma.s1 FR_U_hi = FR_r_hi, FR_U_hi, f0
2464       nop.i 999 ;;
2467 { .mfi
2468       nop.m 999
2469 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_4
2470       nop.i 999
2473 { .mfi
2474       nop.m 999
2475 (p10)   fma.s1 FR_U_hi = FR_QQ_1, FR_U_hi, f1
2476       nop.i 999 ;;
2479 { .mfi
2480       nop.m 999
2481 (p10)   fma.d.s1 FR_QQ_5 = FR_QQ_5, FR_QQ_5, f0
2482       nop.i 999 ;;
2485 { .mfi
2486       nop.m 999
2488 //      if (i_1!=0) U_hi = PP_1 * U_hi
2489 //      if (i_1!=0) U_lo = r * r  + U_lo
2490 //      Load PP_3 or QQ_3
2492 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_4
2493       nop.i 999 ;;
2496 { .mfi
2497       nop.m 999
2498 (p9)    fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0
2499       nop.i 999
2502 { .mfi
2503       nop.m 999
2504 (p10)   fma.s1 FR_U_lo = FR_QQ_1,FR_U_lo, f0
2505       nop.i 999 ;;
2508 { .mfi
2509       nop.m 999
2510 (p9)    fma.s1 FR_U_hi = FR_PP_1, FR_U_hi, f0
2511       nop.i 999 ;;
2514 { .mfi
2515       nop.m 999
2516 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_3
2517       nop.i 999 ;;
2520 { .mfi
2521       nop.m 999
2523 //      Load PP_2, QQ_2
2525 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_3
2526       nop.i 999 ;;
2529 { .mfi
2530       nop.m 999
2532 //      if (i_1==0) poly = FR_rsq * poly  + PP_3
2533 //      else        poly = FR_rsq * poly  + QQ_3
2534 //      Load PP_1_lo
2536 (p9)    fma.s1 FR_U_lo = FR_PP_1, FR_U_lo, f0
2537       nop.i 999 ;;
2540 { .mfi
2541       nop.m 999
2543 //      if (i_1 =0) poly = poly * rsq + pp_r4
2544 //      else        poly = poly * rsq + qq_r4
2546 (p9)    fma.s1 FR_U_hi = FR_r, f1, FR_U_hi
2547       nop.i 999 ;;
2550 { .mfi
2551       nop.m 999
2552 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_2
2553       nop.i 999 ;;
2556 { .mfi
2557       nop.m 999
2559 //      if (i_1==0) U_lo =  PP_1_hi * U_lo
2560 //      else        U_lo =  QQ_1 * U_lo
2562 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_2
2563       nop.i 999 ;;
2566 { .mfi
2567       nop.m 999
2569 //      if (i_0==0)  Result = 1
2570 //      else         Result = -1
2572         fma.s1 FR_V = FR_U_lo, f1, FR_corr
2573       nop.i 999 ;;
2576 { .mfi
2577       nop.m 999
2578 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, f0
2579       nop.i 999 ;;
2582 { .mfi
2583       nop.m 999
2585 //      if (i_1==0) poly =  FR_rsq * poly + PP_2
2586 //      else poly =  FR_rsq * poly + QQ_2
2588 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_1_lo
2589       nop.i 999 ;;
2592 { .mfi
2593       nop.m 999
2594 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, f0
2595       nop.i 999 ;;
2598 { .mfi
2599       nop.m 999
2601 //      V = U_lo + corr
2603 (p9)    fma.s1 FR_poly = FR_r_cubed, FR_poly, f0
2604       nop.i 999 ;;
2607 { .mfi
2608       nop.m 999
2610 //      if (i_1==0) poly = r_cube * poly
2611 //      else        poly = FR_rsq * poly
2613         fma.s1  FR_V = FR_poly, f1, FR_V
2614       nop.i 999 ;;
2617 { .mfi
2618       nop.m 999
2619 //(p12)   fms.s1 FR_Input_X = FR_Input_X, FR_U_hi, FR_V
2620 (p12)   fms.s1 FR_Input_X = FR_prelim, FR_U_hi, FR_V
2621       nop.i 999
2624 { .mfb
2625       nop.m 999
2627 //      V = V + poly
2629 //(p11)   fma.s1 FR_Input_X = FR_Input_X, FR_U_hi, FR_V
2630 (p11)   fma.s1 FR_Input_X = FR_prelim, FR_U_hi, FR_V
2632 //      if (i_0==0) Result = Result * U_hi + V
2633 //      else        Result = Result * U_hi - V
2635        br.ret.sptk   b0 ;;
2639 //      If cosine, FR_Input_X = 1
2640 //      If sine, FR_Input_X = +/-Zero (Input FR_Input_X)
2641 //      Results are exact, no exceptions
2643 SINCOS_ZERO:
2645 { .mmb
2646         cmp.eq.unc p6, p7 = 0x1, GR_Sin_or_Cos
2647       nop.m 999
2648       nop.b 999 ;;
2651 { .mfi
2652       nop.m 999
2653 (p7)    fmerge.s FR_Input_X = FR_Input_X, FR_Input_X
2654       nop.i 999
2657 { .mfb
2658       nop.m 999
2659 (p6)    fmerge.s FR_Input_X = f1, f1
2660        br.ret.sptk   b0 ;;
2663 SINCOS_SPECIAL:
2666 //      Path for Arg = +/- QNaN, SNaN, Inf
2667 //      Invalid can be raised. SNaNs
2668 //      become QNaNs
2671 { .mfb
2672       nop.m 999
2673         fmpy.s1 FR_Input_X = FR_Input_X, f0
2674         br.ret.sptk   b0 ;;
2676 GLOBAL_LIBM_END(__libm_cos_large)
2679 // *******************************************************************
2680 // *******************************************************************
2681 // *******************************************************************
2683 //     Special Code to handle very large argument case.
2684 //     Call int __libm_pi_by_2_reduce(x,r,c) for |arguments| >= 2**63
2685 //     The interface is custom:
2686 //       On input:
2687 //         (Arg or x) is in f8
2688 //       On output:
2689 //         r is in f8
2690 //         c is in f9
2691 //         N is in r8
2692 //     Be sure to allocate at least 2 GP registers as output registers for
2693 //     __libm_pi_by_2_reduce.  This routine uses r49-50. These are used as
2694 //     scratch registers within the __libm_pi_by_2_reduce routine (for speed).
2696 //     We know also that __libm_pi_by_2_reduce preserves f10-15, f71-127.  We
2697 //     use this to eliminate save/restore of key fp registers in this calling
2698 //     function.
2700 // *******************************************************************
2701 // *******************************************************************
2702 // *******************************************************************
2704 LOCAL_LIBM_ENTRY(__libm_callout_2)
2705 SINCOS_ARG_TOO_LARGE:
2707 .prologue
2708 //      Readjust Table ptr
2709 { .mfi
2710         adds  GR_Table_Base1 = -16, GR_Table_Base1
2711         nop.f 999
2712 .save   ar.pfs,GR_SAVE_PFS
2713         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
2716 { .mmi
2717         ldfs FR_Two_to_M3 = [GR_Table_Base1],4
2718         mov GR_SAVE_GP=gp                       // Save gp
2719 .save   b0, GR_SAVE_B0
2720         mov GR_SAVE_B0=b0                       // Save b0
2723 .body
2725 //     Call argument reduction with x in f8
2726 //     Returns with N in r8, r in f8, c in f9
2727 //     Assumes f71-127 are preserved across the call
2729 { .mib
2730         ldfs FR_Neg_Two_to_M3 = [GR_Table_Base1],0
2731         nop.i 0
2732         br.call.sptk b0=__libm_pi_by_2_reduce#
2735 { .mfi
2736         add   GR_N_Inc = GR_Sin_or_Cos,r8
2737         fcmp.lt.unc.s1  p6, p0 = FR_r, FR_Two_to_M3
2738         mov   b0 = GR_SAVE_B0                  // Restore return address
2741 { .mfi
2742         mov   gp = GR_SAVE_GP                  // Restore gp
2743 (p6)    fcmp.gt.unc.s1  p6, p0 = FR_r, FR_Neg_Two_to_M3
2744         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
2747 { .mbb
2748         nop.m 999
2749 (p6)    br.cond.spnt SINCOS_SMALL_R            // Branch if |r| < 1/4
2750         br.cond.sptk SINCOS_NORMAL_R ;;        // Branch if 1/4 <= |r| < pi/4
2753 LOCAL_LIBM_END(__libm_callout_2)
2755 .type   __libm_pi_by_2_reduce#,@function
2756 .global __libm_pi_by_2_reduce#