Updated to fedora-glibc-20050106T1443
[glibc.git] / sysdeps / ia64 / fpu / libm_sincos_large.S
blob42cf0940f03c74d8b414f5cbb0899a62be217a46
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)
795 GLOBAL_LIBM_ENTRY(__libm_sin_large)
797 { .mlx
798 alloc GR_Table_Base = ar.pfs,0,12,2,0
799        movl GR_Sin_or_Cos = 0x0 ;;
802 { .mmi
803       nop.m 999
804       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
805       nop.i 999
809 { .mmi
810       ld8 GR_Table_Base = [GR_Table_Base]
811       nop.m 999
812       nop.i 999
817 { .mib
818       nop.m 999
819       nop.i 999
820        br.cond.sptk SINCOS_CONTINUE ;;
823 GLOBAL_LIBM_END(__libm_sin_large)
824 GLOBAL_LIBM_ENTRY(__libm_cos_large)
826 { .mlx
827 alloc GR_Table_Base= ar.pfs,0,12,2,0
828        movl GR_Sin_or_Cos = 0x1 ;;
831 { .mmi
832       nop.m 999
833       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
834       nop.i 999
838 { .mmi
839       ld8 GR_Table_Base = [GR_Table_Base]
840       nop.m 999
841       nop.i 999
846 //     Load Table Address
848 SINCOS_CONTINUE:
850 { .mmi
851        add GR_Table_Base1 = 96, GR_Table_Base
852        ldfs FR_Two_to_24 = [GR_Table_Base], 4
853        nop.i 999
857 { .mmi
858       nop.m 999
860 //     Load 2**24, load 2**63.
862        ldfs FR_Neg_Two_to_24 = [GR_Table_Base], 12
863        mov   r41 = ar.pfs ;;
866 { .mfi
867        ldfs FR_Two_to_63 = [GR_Table_Base1], 4
869 //     Check for unnormals - unsupported operands. We do not want
870 //     to generate denormal exception
871 //     Check for NatVals, QNaNs, SNaNs, +/-Infs
872 //     Check for EM unsupporteds
873 //     Check for Zero
875        fclass.m.unc  p6, p8 =  FR_Input_X, 0x1E3
876        mov   r40 = gp ;;
879 { .mfi
880       nop.m 999
881        fclass.nm.unc p8, p0 =  FR_Input_X, 0x1FF
882 // GR_Sin_or_Cos denotes
883        mov   r39 = b0
886 { .mfb
887        ldfs FR_Neg_Two_to_63 = [GR_Table_Base1], 12
888        fclass.m.unc p10, p0 = FR_Input_X, 0x007
889 (p6)   br.cond.spnt SINCOS_SPECIAL ;;
892 { .mib
893       nop.m 999
894       nop.i 999
895 (p8)   br.cond.spnt SINCOS_SPECIAL ;;
898 { .mib
899       nop.m 999
900       nop.i 999
902 //     Branch if +/- NaN, Inf.
903 //     Load -2**24, load -2**63.
905 (p10)  br.cond.spnt SINCOS_ZERO ;;
908 { .mmb
909        ldfe FR_Inv_pi_by_2 = [GR_Table_Base], 16
910        ldfe FR_Inv_P_0 = [GR_Table_Base1], 16
911       nop.b 999 ;;
914 { .mmb
915       nop.m 999
916        ldfe     FR_d_1 = [GR_Table_Base1], 16
917       nop.b 999 ;;
920 //     Raise possible denormal operand flag with useful fcmp
921 //     Is x <= -2**63
922 //     Load Inv_P_0 for pre-reduction
923 //     Load Inv_pi_by_2
926 { .mmb
927        ldfe     FR_P_0 = [GR_Table_Base], 16
928        ldfe FR_d_2 = [GR_Table_Base1], 16
929       nop.b 999 ;;
932 //     Load P_0
933 //     Load d_1
934 //     Is x >= 2**63
935 //     Is x <= -2**24?
938 { .mmi
939        ldfe FR_P_1 = [GR_Table_Base], 16 ;;
941 //     Load P_1
942 //     Load d_2
943 //     Is x >= 2**24?
945        ldfe FR_P_2 = [GR_Table_Base], 16
946       nop.i 999 ;;
949 { .mmf
950       nop.m 999
951        ldfe FR_P_3 = [GR_Table_Base], 16
952        fcmp.le.unc.s1   p7, p8 = FR_Input_X, FR_Neg_Two_to_24
955 { .mfi
956       nop.m 999
958 //     Branch if +/- zero.
959 //     Decide about the paths to take:
960 //     If -2**24 < FR_Input_X < 2**24 - CASE 1 OR 2
961 //     OTHERWISE - CASE 3 OR 4
963        fcmp.le.unc.s1   p10, p11 = FR_Input_X, FR_Neg_Two_to_63
964       nop.i 999 ;;
967 { .mfi
968       nop.m 999
969 (p8)   fcmp.ge.s1 p7, p0 = FR_Input_X, FR_Two_to_24
970       nop.i 999
973 { .mfi
974        ldfe FR_Pi_by_4 = [GR_Table_Base1], 16
975 (p11)  fcmp.ge.s1   p10, p0 = FR_Input_X, FR_Two_to_63
976       nop.i 999 ;;
979 { .mmi
980        ldfe FR_Neg_Pi_by_4 = [GR_Table_Base1], 16 ;;
981        ldfs FR_Two_to_M3 = [GR_Table_Base1], 4
982       nop.i 999 ;;
985 { .mib
986        ldfs FR_Neg_Two_to_M3 = [GR_Table_Base1], 12
987       nop.i 999
989 //     Load P_2
990 //     Load P_3
991 //     Load pi_by_4
992 //     Load neg_pi_by_4
993 //     Load 2**(-3)
994 //     Load -2**(-3).
996 (p10)  br.cond.spnt SINCOS_ARG_TOO_LARGE ;;
999 { .mib
1000       nop.m 999
1001       nop.i 999
1003 //     Branch out if x >= 2**63. Use Payne-Hanek Reduction
1005 (p7)   br.cond.spnt SINCOS_LARGER_ARG ;;
1008 { .mfi
1009       nop.m 999
1011 //     Branch if Arg <= -2**24 or Arg >= 2**24 and use pre-reduction.
1013        fma.s1   FR_N_float = FR_Input_X, FR_Inv_pi_by_2, f0
1014       nop.i 999 ;;
1017 { .mfi
1018       nop.m 999
1019        fcmp.lt.unc.s1   p6, p7 = FR_Input_X, FR_Pi_by_4
1020       nop.i 999 ;;
1023 { .mfi
1024       nop.m 999
1026 //     Select the case when |Arg| < pi/4
1027 //     Else Select the case when |Arg| >= pi/4
1029        fcvt.fx.s1 FR_N_fix = FR_N_float
1030       nop.i 999 ;;
1033 { .mfi
1034       nop.m 999
1036 //     N  = Arg * 2/pi
1037 //     Check if Arg < pi/4
1039 (p6)   fcmp.gt.s1 p6, p7 = FR_Input_X, FR_Neg_Pi_by_4
1040       nop.i 999 ;;
1043 //     Case 2: Convert integer N_fix back to normalized floating-point value.
1044 //     Case 1: p8 is only affected  when p6 is set
1047 { .mfi
1048 (p7)   ldfs FR_Two_to_M33 = [GR_Table_Base1], 4
1050 //     Grab the integer part of N and call it N_fix
1052 (p6)   fmerge.se FR_r = FR_Input_X, FR_Input_X
1053 //     If |x| < pi/4, r = x and c = 0
1054 //     lf |x| < pi/4, is x < 2**(-3).
1055 //     r = Arg
1056 //     c = 0
1057 (p6)   mov GR_N_Inc = GR_Sin_or_Cos ;;
1060 { .mmf
1061       nop.m 999
1062 (p7)   ldfs FR_Neg_Two_to_M33 = [GR_Table_Base1], 4
1063 (p6)   fmerge.se FR_c = f0, f0
1066 { .mfi
1067       nop.m 999
1068 (p6)   fcmp.lt.unc.s1   p8, p9 = FR_Input_X, FR_Two_to_M3
1069       nop.i 999 ;;
1072 { .mfi
1073       nop.m 999
1075 //     lf |x| < pi/4, is -2**(-3)< x < 2**(-3) - set p8.
1076 //     If |x| >= pi/4,
1077 //     Create the right N for |x| < pi/4 and otherwise
1078 //     Case 2: Place integer part of N in GP register
1080 (p7)   fcvt.xf FR_N_float = FR_N_fix
1081       nop.i 999 ;;
1084 { .mmf
1085       nop.m 999
1086 (p7)   getf.sig GR_N_Inc = FR_N_fix
1087 (p8)   fcmp.gt.s1 p8, p0 = FR_Input_X, FR_Neg_Two_to_M3 ;;
1090 { .mib
1091       nop.m 999
1092       nop.i 999
1094 //     Load 2**(-33), -2**(-33)
1096 (p8)   br.cond.spnt SINCOS_SMALL_R ;;
1099 { .mib
1100       nop.m 999
1101       nop.i 999
1102 (p6)   br.cond.sptk SINCOS_NORMAL_R ;;
1105 //     if |x| < pi/4, branch based on |x| < 2**(-3) or otherwise.
1108 //     In this branch, |x| >= pi/4.
1111 { .mfi
1112        ldfs FR_Neg_Two_to_M67 = [GR_Table_Base1], 8
1114 //     Load -2**(-67)
1116        fnma.s1  FR_s = FR_N_float, FR_P_1, FR_Input_X
1118 //     w = N * P_2
1119 //     s = -N * P_1  + Arg
1121        add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos
1124 { .mfi
1125       nop.m 999
1126        fma.s1   FR_w = FR_N_float, FR_P_2, f0
1127       nop.i 999 ;;
1130 { .mfi
1131       nop.m 999
1133 //     Adjust N_fix by N_inc to determine whether sine or
1134 //     cosine is being calculated
1136        fcmp.lt.unc.s1 p7, p6 = FR_s, FR_Two_to_M33
1137       nop.i 999 ;;
1140 { .mfi
1141       nop.m 999
1142 (p7)   fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33
1143       nop.i 999 ;;
1146 { .mfi
1147       nop.m 999
1148 //     Remember x >= pi/4.
1149 //     Is s <= -2**(-33) or s >= 2**(-33) (p6)
1150 //     or -2**(-33) < s < 2**(-33) (p7)
1151 (p6)   fms.s1 FR_r = FR_s, f1, FR_w
1152       nop.i 999
1155 { .mfi
1156       nop.m 999
1157 (p7)   fma.s1 FR_w = FR_N_float, FR_P_3, f0
1158       nop.i 999 ;;
1161 { .mfi
1162       nop.m 999
1163 (p7)   fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1164       nop.i 999
1167 { .mfi
1168       nop.m 999
1169 (p6)   fms.s1 FR_c = FR_s, f1, FR_r
1170       nop.i 999 ;;
1173 { .mfi
1174       nop.m 999
1176 //     For big s: r = s - w: No futher reduction is necessary
1177 //     For small s: w = N * P_3 (change sign) More reduction
1179 (p6)   fcmp.lt.unc.s1 p8, p9 = FR_r, FR_Two_to_M3
1180       nop.i 999 ;;
1183 { .mfi
1184       nop.m 999
1185 (p8)   fcmp.gt.s1 p8, p9 = FR_r, FR_Neg_Two_to_M3
1186       nop.i 999 ;;
1189 { .mfi
1190       nop.m 999
1191 (p7)   fms.s1 FR_r = FR_s, f1, FR_U_1
1192       nop.i 999
1195 { .mfb
1196       nop.m 999
1198 //     For big s: Is |r| < 2**(-3)?
1199 //     For big s: c = S - r
1200 //     For small s: U_1 = N * P_2 + w
1202 //     If p8 is set, prepare to branch to Small_R.
1203 //     If p9 is set, prepare to branch to Normal_R.
1204 //     For big s,  r is complete here.
1206 (p6)   fms.s1 FR_c = FR_c, f1, FR_w
1208 //     For big s: c = c + w (w has not been negated.)
1209 //     For small s: r = S - U_1
1211 (p8)   br.cond.spnt SINCOS_SMALL_R ;;
1214 { .mib
1215       nop.m 999
1216       nop.i 999
1217 (p9)   br.cond.sptk SINCOS_NORMAL_R ;;
1220 { .mfi
1221 (p7)   add GR_Table_Base1 = 224, GR_Table_Base1
1223 //     Branch to SINCOS_SMALL_R or SINCOS_NORMAL_R
1225 (p7)   fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1227 //     c = S - U_1
1228 //     r = S_1 * r
1231 (p7)   extr.u   GR_i_1 = GR_N_Inc, 0, 1
1234 { .mmi
1235       nop.m 999 ;;
1237 //     Get [i_0,i_1] - two lsb of N_fix_gr.
1238 //     Do dummy fmpy so inexact is always set.
1240 (p7)   cmp.eq.unc p9, p10 = 0x0, GR_i_1
1241 (p7)   extr.u   GR_i_0 = GR_N_Inc, 1, 1 ;;
1244 //     For small s: U_2 = N * P_2 - U_1
1245 //     S_1 stored constant - grab the one stored with the
1246 //     coefficients.
1249 { .mfi
1250 (p7)   ldfe FR_S_1 = [GR_Table_Base1], 16
1252 //     Check if i_1 and i_0  != 0
1254 (p10)  fma.s1   FR_poly = f0, f1, FR_Neg_Two_to_M67
1255 (p7)   cmp.eq.unc p11, p12 = 0x0, GR_i_0 ;;
1258 { .mfi
1259       nop.m 999
1260 (p7)   fms.s1   FR_s = FR_s, f1, FR_r
1261       nop.i 999
1264 { .mfi
1265       nop.m 999
1267 //     S = S - r
1268 //     U_2 = U_2 + w
1269 //     load S_1
1271 (p7)   fma.s1   FR_rsq = FR_r, FR_r, f0
1272       nop.i 999 ;;
1275 { .mfi
1276       nop.m 999
1277 (p7)   fma.s1   FR_U_2 = FR_U_2, f1, FR_w
1278       nop.i 999
1281 { .mfi
1282       nop.m 999
1283 //(p7)   fmerge.se FR_Input_X = FR_r, FR_r
1284 (p7)   fmerge.se FR_prelim = FR_r, FR_r
1285       nop.i 999 ;;
1288 { .mfi
1289       nop.m 999
1290 //(p10)  fma.s1 FR_Input_X = f0, f1, f1
1291 (p10)  fma.s1 FR_prelim = f0, f1, f1
1292       nop.i 999 ;;
1295 { .mfi
1296       nop.m 999
1298 //     FR_rsq = r * r
1299 //     Save r as the result.
1301 (p7)   fms.s1   FR_c = FR_s, f1, FR_U_1
1302       nop.i 999 ;;
1305 { .mfi
1306       nop.m 999
1308 //     if ( i_1 ==0) poly = c + S_1*r*r*r
1309 //     else Result = 1
1311 //(p12)  fnma.s1 FR_Input_X = FR_Input_X, f1, f0
1312 (p12)  fnma.s1 FR_prelim = FR_prelim, f1, f0
1313       nop.i 999
1316 { .mfi
1317       nop.m 999
1318 (p7)   fma.s1   FR_r = FR_S_1, FR_r, f0
1319       nop.i 999 ;;
1322 { .mfi
1323       nop.m 999
1324 (p7)   fma.d.s1 FR_S_1 = FR_S_1, FR_S_1, f0
1325       nop.i 999 ;;
1328 { .mfi
1329       nop.m 999
1331 //     If i_1 != 0, poly = 2**(-67)
1333 (p7)   fms.s1 FR_c = FR_c, f1, FR_U_2
1334       nop.i 999 ;;
1337 { .mfi
1338       nop.m 999
1340 //     c = c - U_2
1342 (p9)   fma.s1 FR_poly = FR_r, FR_rsq, FR_c
1343       nop.i 999 ;;
1346 { .mfi
1347       nop.m 999
1349 //     i_0 != 0, so Result = -Result
1351 (p11)  fma.s1 FR_Input_X = FR_prelim, f1, FR_poly
1352       nop.i 999 ;;
1355 { .mfb
1356       nop.m 999
1357 (p12)  fms.s1 FR_Input_X = FR_prelim, f1, FR_poly
1359 //     if (i_0 == 0),  Result = Result + poly
1360 //     else            Result = Result - poly
1362        br.ret.sptk   b0 ;;
1364 SINCOS_LARGER_ARG:
1366 { .mfi
1367       nop.m 999
1368        fma.s1 FR_N_0 = FR_Input_X, FR_Inv_P_0, f0
1369       nop.i 999
1373 //     This path for argument > 2*24
1374 //     Adjust table_ptr1 to beginning of table.
1377 { .mmi
1378       nop.m 999
1379       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
1380       nop.i 999
1384 { .mmi
1385       ld8 GR_Table_Base = [GR_Table_Base]
1386       nop.m 999
1387       nop.i 999
1393 //     Point to  2*-14
1394 //     N_0 = Arg * Inv_P_0
1397 { .mmi
1398        add GR_Table_Base = 688, GR_Table_Base ;;
1399        ldfs FR_Two_to_M14 = [GR_Table_Base], 4
1400       nop.i 999 ;;
1403 { .mfi
1404        ldfs FR_Neg_Two_to_M14 = [GR_Table_Base], 0
1405       nop.f 999
1406       nop.i 999 ;;
1409 { .mfi
1410       nop.m 999
1412 //     Load values 2**(-14) and -2**(-14)
1414        fcvt.fx.s1 FR_N_0_fix = FR_N_0
1415       nop.i 999 ;;
1418 { .mfi
1419       nop.m 999
1421 //     N_0_fix  = integer part of N_0
1423        fcvt.xf FR_N_0 = FR_N_0_fix
1424       nop.i 999 ;;
1427 { .mfi
1428       nop.m 999
1430 //     Make N_0 the integer part
1432        fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X
1433       nop.i 999
1436 { .mfi
1437       nop.m 999
1438        fma.s1 FR_w = FR_N_0, FR_d_1, f0
1439       nop.i 999 ;;
1442 { .mfi
1443       nop.m 999
1445 //     Arg' = -N_0 * P_0 + Arg
1446 //     w  = N_0 * d_1
1448        fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0
1449       nop.i 999 ;;
1452 { .mfi
1453       nop.m 999
1455 //     N = A' * 2/pi
1457        fcvt.fx.s1 FR_N_fix = FR_N_float
1458       nop.i 999 ;;
1461 { .mfi
1462       nop.m 999
1464 //     N_fix is the integer part
1466        fcvt.xf FR_N_float = FR_N_fix
1467       nop.i 999 ;;
1470 { .mfi
1471        getf.sig GR_N_Inc = FR_N_fix
1472       nop.f 999
1473       nop.i 999 ;;
1476 { .mii
1477       nop.m 999
1478       nop.i 999 ;;
1479        add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos ;;
1482 { .mfi
1483       nop.m 999
1485 //     N is the integer part of the reduced-reduced argument.
1486 //     Put the integer in a GP register
1488        fnma.s1 FR_s = FR_N_float, FR_P_1, FR_ArgPrime
1489       nop.i 999
1492 { .mfi
1493       nop.m 999
1494        fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w
1495       nop.i 999 ;;
1498 { .mfi
1499       nop.m 999
1501 //     s = -N*P_1 + Arg'
1502 //     w = -N*P_2 + w
1503 //     N_fix_gr = N_fix_gr + N_inc
1505        fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1506       nop.i 999 ;;
1509 { .mfi
1510       nop.m 999
1511 (p9)   fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14
1512       nop.i 999 ;;
1515 { .mfi
1516       nop.m 999
1518 //     For |s|  > 2**(-14) r = S + w (r complete)
1519 //     Else       U_hi = N_0 * d_1
1521 (p9)   fma.s1 FR_V_hi = FR_N_float, FR_P_2, f0
1522       nop.i 999
1525 { .mfi
1526       nop.m 999
1527 (p9)   fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1528       nop.i 999 ;;
1531 { .mfi
1532       nop.m 999
1534 //     Either S <= -2**(-14) or S >= 2**(-14)
1535 //     or -2**(-14) < s < 2**(-14)
1537 (p8)   fma.s1 FR_r = FR_s, f1, FR_w
1538       nop.i 999
1541 { .mfi
1542       nop.m 999
1543 (p9)   fma.s1 FR_w = FR_N_float, FR_P_3, f0
1544       nop.i 999 ;;
1547 { .mfi
1548       nop.m 999
1550 //     We need abs of both U_hi and V_hi - don't
1551 //     worry about switched sign of V_hi.
1553 (p9)   fms.s1 FR_A = FR_U_hi, f1, FR_V_hi
1554       nop.i 999
1557 { .mfi
1558       nop.m 999
1560 //     Big s: finish up c = (S - r) + w (c complete)
1561 //     Case 4: A =  U_hi + V_hi
1562 //     Note: Worry about switched sign of V_hi, so subtract instead of add.
1564 (p9)   fnma.s1 FR_V_lo = FR_N_float, FR_P_2, FR_V_hi
1565       nop.i 999 ;;
1568 { .mfi
1569       nop.m 999
1570 (p9)   fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi
1571       nop.i 999 ;;
1574 { .mfi
1575       nop.m 999
1576 (p9)   fmerge.s FR_V_hiabs = f0, FR_V_hi
1577       nop.i 999
1580 { .mfi
1581       nop.m 999
1582 //     For big s: c = S - r
1583 //     For small s do more work: U_lo = N_0 * d_1 - U_hi
1585 (p9)   fmerge.s FR_U_hiabs = f0, FR_U_hi
1586       nop.i 999 ;;
1589 { .mfi
1590       nop.m 999
1592 //     For big s: Is |r| < 2**(-3)
1593 //     For big s: if p12 set, prepare to branch to Small_R.
1594 //     For big s: If p13 set, prepare to branch to Normal_R.
1596 (p8)   fms.s1 FR_c = FR_s, f1, FR_r
1597       nop.i 999
1600 { .mfi
1601       nop.m 999
1603 //     For small S: V_hi = N * P_2
1604 //                  w = N * P_3
1605 //     Note the product does not include the (-) as in the writeup
1606 //     so (-) missing for V_hi and w.
1608 (p8)   fcmp.lt.unc.s1 p12, p13 = FR_r, FR_Two_to_M3
1609       nop.i 999 ;;
1612 { .mfi
1613       nop.m 999
1614 (p12)  fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1615       nop.i 999 ;;
1618 { .mfi
1619       nop.m 999
1620 (p8)   fma.s1 FR_c = FR_c, f1, FR_w
1621       nop.i 999
1624 { .mfb
1625       nop.m 999
1626 (p9)   fms.s1 FR_w = FR_N_0, FR_d_2, FR_w
1627 (p12)  br.cond.spnt SINCOS_SMALL_R ;;
1630 { .mib
1631       nop.m 999
1632       nop.i 999
1633 (p13)  br.cond.sptk SINCOS_NORMAL_R ;;
1636 { .mfi
1637       nop.m 999
1639 //     Big s: Vector off when |r| < 2**(-3).  Recall that p8 will be true.
1640 //     The remaining stuff is for Case 4.
1641 //     Small s: V_lo = N * P_2 + U_hi (U_hi is in place of V_hi in writeup)
1642 //     Note: the (-) is still missing for V_lo.
1643 //     Small s: w = w + N_0 * d_2
1644 //     Note: the (-) is now incorporated in w.
1646 (p9)   fcmp.ge.unc.s1 p10, p11 = FR_U_hiabs, FR_V_hiabs
1647        extr.u   GR_i_1 = GR_N_Inc, 0, 1 ;;
1650 { .mfi
1651       nop.m 999
1653 //     C_hi = S + A
1655 (p9)   fma.s1 FR_t = FR_U_lo, f1, FR_V_lo
1656        extr.u   GR_i_0 = GR_N_Inc, 1, 1 ;;
1659 { .mfi
1660       nop.m 999
1662 //     t = U_lo + V_lo
1665 (p10)  fms.s1 FR_a = FR_U_hi, f1, FR_A
1666       nop.i 999 ;;
1669 { .mfi
1670       nop.m 999
1671 (p11)  fma.s1 FR_a = FR_V_hi, f1, FR_A
1672       nop.i 999
1676 { .mmi
1677       nop.m 999
1678       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
1679       nop.i 999
1683 { .mmi
1684       ld8 GR_Table_Base = [GR_Table_Base]
1685       nop.m 999
1686       nop.i 999
1691 { .mfi
1692        add GR_Table_Base = 528, GR_Table_Base
1694 //     Is U_hiabs >= V_hiabs?
1696 (p9)   fma.s1 FR_C_hi = FR_s, f1, FR_A
1697       nop.i 999 ;;
1700 { .mmi
1701        ldfe FR_C_1 = [GR_Table_Base], 16 ;;
1702        ldfe FR_C_2 = [GR_Table_Base], 64
1703       nop.i 999 ;;
1706 { .mmf
1707       nop.m 999
1709 //     c = c + C_lo  finished.
1710 //     Load  C_2
1712        ldfe FR_S_1 = [GR_Table_Base], 16
1714 //     C_lo = S - C_hi
1716        fma.s1 FR_t = FR_t, f1, FR_w ;;
1719 //     r and c have been computed.
1720 //     Make sure ftz mode is set - should be automatic when using wre
1721 //     |r| < 2**(-3)
1722 //     Get [i_0,i_1] - two lsb of N_fix.
1723 //     Load S_1
1726 { .mfi
1727        ldfe FR_S_2 = [GR_Table_Base], 64
1729 //     t = t + w
1731 (p10)  fms.s1 FR_a = FR_a, f1, FR_V_hi
1732        cmp.eq.unc p9, p10 = 0x0, GR_i_0
1735 { .mfi
1736       nop.m 999
1738 //     For larger u than v: a = U_hi - A
1739 //     Else a = V_hi - A (do an add to account for missing (-) on V_hi
1741        fms.s1 FR_C_lo = FR_s, f1, FR_C_hi
1742       nop.i 999 ;;
1745 { .mfi
1746       nop.m 999
1747 (p11)  fms.s1 FR_a = FR_U_hi, f1, FR_a
1748        cmp.eq.unc p11, p12 = 0x0, GR_i_1
1751 { .mfi
1752       nop.m 999
1754 //     If u > v: a = (U_hi - A)  + V_hi
1755 //     Else      a = (V_hi - A)  + U_hi
1756 //     In each case account for negative missing from V_hi.
1758        fma.s1 FR_C_lo = FR_C_lo, f1, FR_A
1759       nop.i 999 ;;
1762 { .mfi
1763       nop.m 999
1765 //     C_lo = (S - C_hi) + A
1767        fma.s1 FR_t = FR_t, f1, FR_a
1768       nop.i 999 ;;
1771 { .mfi
1772       nop.m 999
1774 //     t = t + a
1776        fma.s1 FR_C_lo = FR_C_lo, f1, FR_t
1777       nop.i 999 ;;
1780 { .mfi
1781       nop.m 999
1783 //     C_lo = C_lo + t
1784 //     Adjust Table_Base to beginning of table
1786        fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1787       nop.i 999 ;;
1790 { .mfi
1791       nop.m 999
1793 //     Load S_2
1795        fma.s1 FR_rsq = FR_r, FR_r, f0
1796       nop.i 999
1799 { .mfi
1800       nop.m 999
1802 //     Table_Base points to C_1
1803 //     r = C_hi + C_lo
1805        fms.s1 FR_c = FR_C_hi, f1, FR_r
1806       nop.i 999 ;;
1809 { .mfi
1810       nop.m 999
1812 //     if i_1 ==0: poly = S_2 * FR_rsq + S_1
1813 //     else        poly = C_2 * FR_rsq + C_1
1815 //(p11)  fma.s1 FR_Input_X = f0, f1, FR_r
1816 (p11)  fma.s1 FR_prelim = f0, f1, FR_r
1817       nop.i 999 ;;
1820 { .mfi
1821       nop.m 999
1822 //(p12)  fma.s1 FR_Input_X = f0, f1, f1
1823 (p12)  fma.s1 FR_prelim = f0, f1, f1
1824       nop.i 999 ;;
1827 { .mfi
1828       nop.m 999
1830 //     Compute r_cube = FR_rsq * r
1832 (p11)  fma.s1 FR_poly = FR_rsq, FR_S_2, FR_S_1
1833       nop.i 999 ;;
1836 { .mfi
1837       nop.m 999
1838 (p12)  fma.s1 FR_poly = FR_rsq, FR_C_2, FR_C_1
1839       nop.i 999
1842 { .mfi
1843       nop.m 999
1845 //     Compute FR_rsq = r * r
1846 //     Is i_1 == 0 ?
1848        fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1849       nop.i 999 ;;
1852 { .mfi
1853       nop.m 999
1855 //     c = C_hi - r
1856 //     Load  C_1
1858        fma.s1 FR_c = FR_c, f1, FR_C_lo
1859       nop.i 999
1862 { .mfi
1863       nop.m 999
1865 //     if i_1 ==0: poly = r_cube * poly + c
1866 //     else        poly = FR_rsq * poly
1868 //(p10)  fms.s1 FR_Input_X = f0, f1, FR_Input_X
1869 (p10)  fms.s1 FR_prelim = f0, f1, FR_prelim
1870       nop.i 999 ;;
1873 { .mfi
1874       nop.m 999
1876 //     if i_1 ==0: Result = r
1877 //     else        Result = 1.0
1879 (p11)  fma.s1 FR_poly = FR_r_cubed, FR_poly, FR_c
1880       nop.i 999 ;;
1883 { .mfi
1884       nop.m 999
1885 (p12)  fma.s1 FR_poly = FR_rsq, FR_poly, f0
1886       nop.i 999 ;;
1889 { .mfi
1890       nop.m 999
1892 //     if i_0 !=0: Result = -Result
1894 (p9)   fma.s1 FR_Input_X = FR_prelim, f1, FR_poly
1895       nop.i 999 ;;
1898 { .mfb
1899       nop.m 999
1900 (p10)  fms.s1 FR_Input_X = FR_prelim, f1, FR_poly
1902 //     if i_0 == 0: Result = Result + poly
1903 //     else         Result = Result - poly
1905        br.ret.sptk   b0 ;;
1907 SINCOS_SMALL_R:
1909 { .mii
1910       nop.m 999
1911         extr.u  GR_i_1 = GR_N_Inc, 0, 1 ;;
1914 //      Compare both i_1 and i_0 with 0.
1915 //      if i_1 == 0, set p9.
1916 //      if i_0 == 0, set p11.
1918         cmp.eq.unc p9, p10 = 0x0, GR_i_1 ;;
1921 { .mfi
1922       nop.m 999
1923         fma.s1 FR_rsq = FR_r, FR_r, f0
1924         extr.u  GR_i_0 = GR_N_Inc, 1, 1 ;;
1927 { .mfi
1928       nop.m 999
1930 //  Z = Z * FR_rsq
1932 (p10)   fnma.s1 FR_c = FR_c, FR_r, f0
1933         cmp.eq.unc p11, p12 = 0x0, GR_i_0
1937 // ******************************************************************
1938 // ******************************************************************
1939 // ******************************************************************
1940 //      r and c have been computed.
1941 //      We know whether this is the sine or cosine routine.
1942 //      Make sure ftz mode is set - should be automatic when using wre
1943 //      |r| < 2**(-3)
1945 //      Set table_ptr1 to beginning of constant table.
1946 //      Get [i_0,i_1] - two lsb of N_fix_gr.
1949 { .mmi
1950       nop.m 999
1951       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
1952       nop.i 999
1956 { .mmi
1957       ld8 GR_Table_Base = [GR_Table_Base]
1958       nop.m 999
1959       nop.i 999
1965 //      Set table_ptr1 to point to S_5.
1966 //      Set table_ptr1 to point to C_5.
1967 //      Compute FR_rsq = r * r
1970 { .mfi
1971 (p9)    add GR_Table_Base = 672, GR_Table_Base
1972 (p10)   fmerge.s FR_r = f1, f1
1973 (p10)   add GR_Table_Base = 592, GR_Table_Base ;;
1976 //      Set table_ptr1 to point to S_5.
1977 //      Set table_ptr1 to point to C_5.
1980 { .mmi
1981 (p9)    ldfe FR_S_5 = [GR_Table_Base], -16 ;;
1983 //      if (i_1 == 0) load S_5
1984 //      if (i_1 != 0) load C_5
1986 (p9)    ldfe FR_S_4 = [GR_Table_Base], -16
1987       nop.i 999 ;;
1990 { .mmf
1991 (p10)   ldfe FR_C_5 = [GR_Table_Base], -16
1993 //      Z = FR_rsq * FR_rsq
1995 (p9)    ldfe FR_S_3 = [GR_Table_Base], -16
1997 //      Compute FR_rsq = r * r
1998 //      if (i_1 == 0) load S_4
1999 //      if (i_1 != 0) load C_4
2001         fma.s1 FR_Z = FR_rsq, FR_rsq, f0 ;;
2004 //      if (i_1 == 0) load S_3
2005 //      if (i_1 != 0) load C_3
2008 { .mmi
2009 (p9)    ldfe FR_S_2 = [GR_Table_Base], -16 ;;
2011 //      if (i_1 == 0) load S_2
2012 //      if (i_1 != 0) load C_2
2014 (p9)    ldfe FR_S_1 = [GR_Table_Base], -16
2015       nop.i 999
2018 { .mmi
2019 (p10)   ldfe FR_C_4 = [GR_Table_Base], -16 ;;
2020 (p10)   ldfe FR_C_3 = [GR_Table_Base], -16
2021       nop.i 999 ;;
2024 { .mmi
2025 (p10)   ldfe FR_C_2 = [GR_Table_Base], -16 ;;
2026 (p10)   ldfe FR_C_1 = [GR_Table_Base], -16
2027       nop.i 999
2030 { .mfi
2031       nop.m 999
2033 //      if (i_1 != 0):
2034 //      poly_lo = FR_rsq * C_5 + C_4
2035 //      poly_hi = FR_rsq * C_2 + C_1
2037 (p9)    fma.s1 FR_Z = FR_Z, FR_r, f0
2038       nop.i 999 ;;
2041 { .mfi
2042       nop.m 999
2044 //      if (i_1 == 0) load S_1
2045 //      if (i_1 != 0) load C_1
2047 (p9)    fma.s1 FR_poly_lo = FR_rsq, FR_S_5, FR_S_4
2048       nop.i 999
2051 { .mfi
2052       nop.m 999
2054 //      c = -c * r
2055 //      dummy fmpy's to flag inexact.
2057 (p9)    fma.d.s1 FR_S_4 = FR_S_4, FR_S_4, f0
2058       nop.i 999 ;;
2061 { .mfi
2062       nop.m 999
2064 //      poly_lo = FR_rsq * poly_lo + C_3
2065 //      poly_hi = FR_rsq * poly_hi
2067         fma.s1  FR_Z = FR_Z, FR_rsq, f0
2068       nop.i 999 ;;
2071 { .mfi
2072       nop.m 999
2073 (p9)    fma.s1 FR_poly_hi = FR_rsq, FR_S_2, FR_S_1
2074       nop.i 999
2077 { .mfi
2078       nop.m 999
2080 //      if (i_1 == 0):
2081 //      poly_lo = FR_rsq * S_5 + S_4
2082 //      poly_hi = FR_rsq * S_2 + S_1
2084 (p10)   fma.s1 FR_poly_lo = FR_rsq, FR_C_5, FR_C_4
2085       nop.i 999 ;;
2088 { .mfi
2089       nop.m 999
2091 //      if (i_1 == 0):
2092 //      Z = Z * r  for only one of the small r cases - not there
2093 //      in original implementation notes.
2095 (p9)    fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_S_3
2096       nop.i 999 ;;
2099 { .mfi
2100       nop.m 999
2101 (p10)   fma.s1 FR_poly_hi = FR_rsq, FR_C_2, FR_C_1
2102       nop.i 999
2105 { .mfi
2106       nop.m 999
2107 (p10)   fma.d.s1 FR_C_1 = FR_C_1, FR_C_1, f0
2108       nop.i 999 ;;
2111 { .mfi
2112       nop.m 999
2113 (p9)    fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0
2114       nop.i 999
2117 { .mfi
2118       nop.m 999
2120 //      poly_lo = FR_rsq * poly_lo + S_3
2121 //      poly_hi = FR_rsq * poly_hi
2123 (p10)   fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_C_3
2124       nop.i 999 ;;
2127 { .mfi
2128       nop.m 999
2129 (p10)   fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0
2130       nop.i 999 ;;
2133 { .mfi
2134       nop.m 999
2136 //  if (i_1 == 0): dummy fmpy's to flag inexact
2137 //  r = 1
2139 (p9)    fma.s1 FR_poly_hi = FR_r, FR_poly_hi, f0
2140       nop.i 999
2143 { .mfi
2144       nop.m 999
2146 //  poly_hi = r * poly_hi
2148         fma.s1  FR_poly = FR_Z, FR_poly_lo, FR_c
2149       nop.i 999 ;;
2152 { .mfi
2153       nop.m 999
2154 (p12)   fms.s1  FR_r = f0, f1, FR_r
2155       nop.i 999 ;;
2158 { .mfi
2159       nop.m 999
2161 //      poly_hi = Z * poly_lo + c
2162 //  if i_0 == 1: r = -r
2164         fma.s1  FR_poly = FR_poly, f1, FR_poly_hi
2165       nop.i 999 ;;
2168 { .mfi
2169       nop.m 999
2170 (p12)   fms.s1 FR_Input_X = FR_r, f1, FR_poly
2171       nop.i 999
2174 { .mfb
2175       nop.m 999
2177 //      poly = poly + poly_hi
2179 (p11)   fma.s1 FR_Input_X = FR_r, f1, FR_poly
2181 //      if (i_0 == 0) Result = r + poly
2182 //      if (i_0 != 0) Result = r - poly
2184        br.ret.sptk   b0 ;;
2186 SINCOS_NORMAL_R:
2188 { .mii
2189       nop.m 999
2190         extr.u  GR_i_1 = GR_N_Inc, 0, 1 ;;
2192 //      Set table_ptr1 and table_ptr2 to base address of
2193 //      constant table.
2194         cmp.eq.unc p9, p10 = 0x0, GR_i_1 ;;
2197 { .mfi
2198       nop.m 999
2199         fma.s1  FR_rsq = FR_r, FR_r, f0
2200         extr.u  GR_i_0 = GR_N_Inc, 1, 1 ;;
2203 { .mfi
2204       nop.m 999
2205         frcpa.s1 FR_r_hi, p6 = f1, FR_r
2206         cmp.eq.unc p11, p12 = 0x0, GR_i_0
2210 // ******************************************************************
2211 // ******************************************************************
2212 // ******************************************************************
2214 //      r and c have been computed.
2215 //      We known whether this is the sine or cosine routine.
2216 //      Make sure ftz mode is set - should be automatic when using wre
2217 //      Get [i_0,i_1] - two lsb of N_fix_gr alone.
2220 { .mmi
2221       nop.m 999
2222       addl           GR_Table_Base   = @ltoff(FSINCOS_CONSTANTS#), gp
2223       nop.i 999
2227 { .mmi
2228       ld8 GR_Table_Base = [GR_Table_Base]
2229       nop.m 999
2230       nop.i 999
2235 { .mfi
2236 (p10)   add GR_Table_Base = 384, GR_Table_Base
2237 //(p12)   fms.s1 FR_Input_X = f0, f1, f1
2238 (p12)   fms.s1 FR_prelim = f0, f1, f1
2239 (p9)    add GR_Table_Base = 224, GR_Table_Base ;;
2242 { .mmf
2243       nop.m 999
2244 (p10)   ldfe FR_QQ_8 = [GR_Table_Base], 16
2246 //      if (i_1==0) poly = poly * FR_rsq + PP_1_lo
2247 //      else        poly = FR_rsq * poly
2249 //(p11)   fma.s1 FR_Input_X = f0, f1, f1 ;;
2250 (p11)   fma.s1 FR_prelim = f0, f1, f1 ;;
2253 { .mmf
2254 (p10)   ldfe FR_QQ_7 = [GR_Table_Base], 16
2256 //  Adjust table pointers based on i_0
2257 //      Compute rsq = r * r
2259 (p9)    ldfe FR_PP_8 = [GR_Table_Base], 16
2260         fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 ;;
2263 { .mmf
2264 (p9)    ldfe FR_PP_7 = [GR_Table_Base], 16
2265 (p10)   ldfe FR_QQ_6 = [GR_Table_Base], 16
2267 //      Load PP_8 and QQ_8; PP_7 and QQ_7
2269         frcpa.s1 FR_r_hi, p6 = f1, FR_r_hi ;;
2272 //      if (i_1==0) poly =   PP_7 + FR_rsq * PP_8.
2273 //      else        poly =   QQ_7 + FR_rsq * QQ_8.
2276 { .mmb
2277 (p9)    ldfe FR_PP_6 = [GR_Table_Base], 16
2278 (p10)   ldfe FR_QQ_5 = [GR_Table_Base], 16
2279       nop.b 999 ;;
2282 { .mmb
2283 (p9)    ldfe FR_PP_5 = [GR_Table_Base], 16
2284 (p10)   ldfe FR_S_1 = [GR_Table_Base], 16
2285       nop.b 999 ;;
2288 { .mmb
2289 (p10)   ldfe FR_QQ_1 = [GR_Table_Base], 16
2290 (p9)    ldfe FR_C_1 = [GR_Table_Base], 16
2291       nop.b 999 ;;
2294 { .mmi
2295 (p10)   ldfe FR_QQ_4 = [GR_Table_Base], 16 ;;
2296 (p9)    ldfe FR_PP_1 = [GR_Table_Base], 16
2297       nop.i 999 ;;
2300 { .mmf
2301 (p10)   ldfe FR_QQ_3 = [GR_Table_Base], 16
2303 //      if (i_1=0) corr = corr + c*c
2304 //      else       corr = corr * c
2306 (p9)    ldfe FR_PP_4 = [GR_Table_Base], 16
2307 (p10)   fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 ;;
2310 //      if (i_1=0) poly = rsq * poly + PP_5
2311 //      else       poly = rsq * poly + QQ_5
2312 //      Load PP_4 or QQ_4
2315 { .mmf
2316 (p9)    ldfe FR_PP_3 = [GR_Table_Base], 16
2317 (p10)   ldfe FR_QQ_2 = [GR_Table_Base], 16
2319 //      r_hi =   frcpa(frcpa(r)).
2320 //      r_cube = r * FR_rsq.
2322 (p9)    fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 ;;
2325 //      Do dummy multiplies so inexact is always set.
2328 { .mfi
2329 (p9)    ldfe FR_PP_2 = [GR_Table_Base], 16
2331 //      r_lo = r - r_hi
2333 (p9)    fma.s1 FR_U_lo = FR_r_hi, FR_r_hi, f0
2334       nop.i 999 ;;
2337 { .mmf
2338       nop.m 999
2339 (p9)    ldfe FR_PP_1_lo = [GR_Table_Base], 16
2340 (p10)   fma.s1 FR_corr = FR_S_1, FR_r_cubed, FR_r
2343 { .mfi
2344       nop.m 999
2345 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_6
2346       nop.i 999 ;;
2349 { .mfi
2350       nop.m 999
2352 //      if (i_1=0) U_lo = r_hi * r_hi
2353 //      else       U_lo = r_hi + r
2355 (p9)    fma.s1 FR_corr = FR_C_1, FR_rsq, f0
2356       nop.i 999 ;;
2359 { .mfi
2360       nop.m 999
2362 //      if (i_1=0) corr = C_1 * rsq
2363 //      else       corr = S_1 * r_cubed + r
2365 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_6
2366       nop.i 999
2369 { .mfi
2370       nop.m 999
2371 (p10)   fma.s1 FR_U_lo = FR_r_hi, f1, FR_r
2372       nop.i 999 ;;
2375 { .mfi
2376       nop.m 999
2378 //      if (i_1=0) U_hi = r_hi + U_hi
2379 //      else       U_hi = QQ_1 * U_hi + 1
2381 (p9)    fma.s1 FR_U_lo = FR_r, FR_r_hi, FR_U_lo
2382       nop.i 999
2385 { .mfi
2386       nop.m 999
2388 //      U_hi = r_hi * r_hi
2390         fms.s1 FR_r_lo = FR_r, f1, FR_r_hi
2391       nop.i 999 ;;
2394 { .mfi
2395       nop.m 999
2397 //      Load PP_1, PP_6, PP_5, and C_1
2398 //      Load QQ_1, QQ_6, QQ_5, and S_1
2400         fma.s1 FR_U_hi = FR_r_hi, FR_r_hi, f0
2401       nop.i 999 ;;
2404 { .mfi
2405       nop.m 999
2406 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_5
2407       nop.i 999
2410 { .mfi
2411       nop.m 999
2412 (p10)   fnma.s1 FR_corr = FR_corr, FR_c, f0
2413       nop.i 999 ;;
2416 { .mfi
2417       nop.m 999
2419 //      if (i_1=0) U_lo = r * r_hi + U_lo
2420 //      else       U_lo = r_lo * U_lo
2422 (p9)    fma.s1 FR_corr = FR_corr, FR_c, FR_c
2423       nop.i 999 ;;
2426 { .mfi
2427       nop.m 999
2428 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_5
2429       nop.i 999
2432 { .mfi
2433       nop.m 999
2435 //      if (i_1 =0) U_hi = r + U_hi
2436 //      if (i_1 =0) U_lo = r_lo * U_lo
2439 (p9)    fma.d.s1 FR_PP_5 = FR_PP_5, FR_PP_4, f0
2440       nop.i 999 ;;
2443 { .mfi
2444       nop.m 999
2445 (p9)    fma.s1 FR_U_lo = FR_r, FR_r, FR_U_lo
2446       nop.i 999
2449 { .mfi
2450       nop.m 999
2451 (p10)   fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0
2452       nop.i 999 ;;
2455 { .mfi
2456       nop.m 999
2458 //      if (i_1=0) poly = poly * rsq + PP_6
2459 //      else       poly = poly * rsq + QQ_6
2461 (p9)    fma.s1 FR_U_hi = FR_r_hi, FR_U_hi, f0
2462       nop.i 999 ;;
2465 { .mfi
2466       nop.m 999
2467 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_4
2468       nop.i 999
2471 { .mfi
2472       nop.m 999
2473 (p10)   fma.s1 FR_U_hi = FR_QQ_1, FR_U_hi, f1
2474       nop.i 999 ;;
2477 { .mfi
2478       nop.m 999
2479 (p10)   fma.d.s1 FR_QQ_5 = FR_QQ_5, FR_QQ_5, f0
2480       nop.i 999 ;;
2483 { .mfi
2484       nop.m 999
2486 //      if (i_1!=0) U_hi = PP_1 * U_hi
2487 //      if (i_1!=0) U_lo = r * r  + U_lo
2488 //      Load PP_3 or QQ_3
2490 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_4
2491       nop.i 999 ;;
2494 { .mfi
2495       nop.m 999
2496 (p9)    fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0
2497       nop.i 999
2500 { .mfi
2501       nop.m 999
2502 (p10)   fma.s1 FR_U_lo = FR_QQ_1,FR_U_lo, f0
2503       nop.i 999 ;;
2506 { .mfi
2507       nop.m 999
2508 (p9)    fma.s1 FR_U_hi = FR_PP_1, FR_U_hi, f0
2509       nop.i 999 ;;
2512 { .mfi
2513       nop.m 999
2514 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_3
2515       nop.i 999 ;;
2518 { .mfi
2519       nop.m 999
2521 //      Load PP_2, QQ_2
2523 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_3
2524       nop.i 999 ;;
2527 { .mfi
2528       nop.m 999
2530 //      if (i_1==0) poly = FR_rsq * poly  + PP_3
2531 //      else        poly = FR_rsq * poly  + QQ_3
2532 //      Load PP_1_lo
2534 (p9)    fma.s1 FR_U_lo = FR_PP_1, FR_U_lo, f0
2535       nop.i 999 ;;
2538 { .mfi
2539       nop.m 999
2541 //      if (i_1 =0) poly = poly * rsq + pp_r4
2542 //      else        poly = poly * rsq + qq_r4
2544 (p9)    fma.s1 FR_U_hi = FR_r, f1, FR_U_hi
2545       nop.i 999 ;;
2548 { .mfi
2549       nop.m 999
2550 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_2
2551       nop.i 999 ;;
2554 { .mfi
2555       nop.m 999
2557 //      if (i_1==0) U_lo =  PP_1_hi * U_lo
2558 //      else        U_lo =  QQ_1 * U_lo
2560 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_2
2561       nop.i 999 ;;
2564 { .mfi
2565       nop.m 999
2567 //      if (i_0==0)  Result = 1
2568 //      else         Result = -1
2570         fma.s1 FR_V = FR_U_lo, f1, FR_corr
2571       nop.i 999 ;;
2574 { .mfi
2575       nop.m 999
2576 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, f0
2577       nop.i 999 ;;
2580 { .mfi
2581       nop.m 999
2583 //      if (i_1==0) poly =  FR_rsq * poly + PP_2
2584 //      else poly =  FR_rsq * poly + QQ_2
2586 (p9)    fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_1_lo
2587       nop.i 999 ;;
2590 { .mfi
2591       nop.m 999
2592 (p10)   fma.s1 FR_poly = FR_rsq, FR_poly, f0
2593       nop.i 999 ;;
2596 { .mfi
2597       nop.m 999
2599 //      V = U_lo + corr
2601 (p9)    fma.s1 FR_poly = FR_r_cubed, FR_poly, f0
2602       nop.i 999 ;;
2605 { .mfi
2606       nop.m 999
2608 //      if (i_1==0) poly = r_cube * poly
2609 //      else        poly = FR_rsq * poly
2611         fma.s1  FR_V = FR_poly, f1, FR_V
2612       nop.i 999 ;;
2615 { .mfi
2616       nop.m 999
2617 //(p12)   fms.s1 FR_Input_X = FR_Input_X, FR_U_hi, FR_V
2618 (p12)   fms.s1 FR_Input_X = FR_prelim, FR_U_hi, FR_V
2619       nop.i 999
2622 { .mfb
2623       nop.m 999
2625 //      V = V + poly
2627 //(p11)   fma.s1 FR_Input_X = FR_Input_X, FR_U_hi, FR_V
2628 (p11)   fma.s1 FR_Input_X = FR_prelim, FR_U_hi, FR_V
2630 //      if (i_0==0) Result = Result * U_hi + V
2631 //      else        Result = Result * U_hi - V
2633        br.ret.sptk   b0 ;;
2637 //      If cosine, FR_Input_X = 1
2638 //      If sine, FR_Input_X = +/-Zero (Input FR_Input_X)
2639 //      Results are exact, no exceptions
2641 SINCOS_ZERO:
2643 { .mmb
2644         cmp.eq.unc p6, p7 = 0x1, GR_Sin_or_Cos
2645       nop.m 999
2646       nop.b 999 ;;
2649 { .mfi
2650       nop.m 999
2651 (p7)    fmerge.s FR_Input_X = FR_Input_X, FR_Input_X
2652       nop.i 999
2655 { .mfb
2656       nop.m 999
2657 (p6)    fmerge.s FR_Input_X = f1, f1
2658        br.ret.sptk   b0 ;;
2661 SINCOS_SPECIAL:
2664 //      Path for Arg = +/- QNaN, SNaN, Inf
2665 //      Invalid can be raised. SNaNs
2666 //      become QNaNs
2669 { .mfb
2670       nop.m 999
2671         fmpy.s1 FR_Input_X = FR_Input_X, f0
2672         br.ret.sptk   b0 ;;
2674 GLOBAL_LIBM_END(__libm_cos_large)
2676 // *******************************************************************
2677 // *******************************************************************
2678 // *******************************************************************
2680 //     Special Code to handle very large argument case.
2681 //     Call int __libm_pi_by_2_reduce(x,r,c) for |arguments| >= 2**63
2682 //     The interface is custom:
2683 //       On input:
2684 //         (Arg or x) is in f8
2685 //       On output:
2686 //         r is in f8
2687 //         c is in f9
2688 //         N is in r8
2689 //     Be sure to allocate at least 2 GP registers as output registers for
2690 //     __libm_pi_by_2_reduce.  This routine uses r49-50. These are used as
2691 //     scratch registers within the __libm_pi_by_2_reduce routine (for speed).
2693 //     We know also that __libm_pi_by_2_reduce preserves f10-15, f71-127.  We
2694 //     use this to eliminate save/restore of key fp registers in this calling
2695 //     function.
2697 // *******************************************************************
2698 // *******************************************************************
2699 // *******************************************************************
2701 LOCAL_LIBM_ENTRY(__libm_callout_2)
2702 SINCOS_ARG_TOO_LARGE:
2704 .prologue
2705 //      Readjust Table ptr
2706 { .mfi
2707         adds  GR_Table_Base1 = -16, GR_Table_Base1
2708         nop.f 999
2709 .save   ar.pfs,GR_SAVE_PFS
2710         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
2713 { .mmi
2714         ldfs FR_Two_to_M3 = [GR_Table_Base1],4
2715         mov GR_SAVE_GP=gp                       // Save gp
2716 .save   b0, GR_SAVE_B0
2717         mov GR_SAVE_B0=b0                       // Save b0
2720 .body
2722 //     Call argument reduction with x in f8
2723 //     Returns with N in r8, r in f8, c in f9
2724 //     Assumes f71-127 are preserved across the call
2726 { .mib
2727         ldfs FR_Neg_Two_to_M3 = [GR_Table_Base1],0
2728         nop.i 0
2729         br.call.sptk b0=__libm_pi_by_2_reduce#
2732 { .mfi
2733         add   GR_N_Inc = GR_Sin_or_Cos,r8
2734         fcmp.lt.unc.s1  p6, p0 = FR_r, FR_Two_to_M3
2735         mov   b0 = GR_SAVE_B0                  // Restore return address
2738 { .mfi
2739         mov   gp = GR_SAVE_GP                  // Restore gp
2740 (p6)    fcmp.gt.unc.s1  p6, p0 = FR_r, FR_Neg_Two_to_M3
2741         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
2744 { .mbb
2745         nop.m 999
2746 (p6)    br.cond.spnt SINCOS_SMALL_R            // Branch if |r| < 1/4
2747         br.cond.sptk SINCOS_NORMAL_R ;;        // Branch if 1/4 <= |r| < pi/4
2750 LOCAL_LIBM_END(__libm_callout_2)
2752 .type   __libm_pi_by_2_reduce#,@function
2753 .global __libm_pi_by_2_reduce#