1 .file "libm_sincosl.asm"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at
38 // http://www.intel.com/software/products/opensource/libraries/num.htm.
40 //*********************************************************************
43 // 05/13/02 Initial version of sincosl (based on libm's sinl and cosl)
44 // 02/10/03 Reordered header: .section, .global, .proc, .align;
45 // used data8 for long double table values
47 //*********************************************************************
49 // Function: Combined sincosl routine with 3 different API's
52 //==============================================================
53 // 1) long double _Complex cisl(long double)
54 // 2) void sincosl(long double, long double*s, long double*c)
55 // 3) __libm_sincosl - internal LIBM function, that accepts
56 // argument in f8 and returns cosine through f8, sine through f9
59 //*********************************************************************
63 // Floating-Point Registers: f8 (Input x and cosl return value),
67 // General Purpose Registers:
70 // Predicate Registers: p6-p15
72 //*********************************************************************
74 // IEEE Special Conditions:
76 // Denormal fault raised on denormal inputs
77 // Overflow exceptions do not occur
78 // Underflow exceptions raised when appropriate for sincosl
79 // (No specialized error handling for this routine)
80 // Inexact raised when appropriate by algorithm
82 // sincosl(SNaN) = QNaN, QNaN
83 // sincosl(QNaN) = QNaN, QNaN
84 // sincosl(inf) = QNaN, QNaN
85 // sincosl(+/-0) = +/-0, 1
87 //*********************************************************************
89 // Mathematical Description
90 // ========================
92 // The computation of FSIN and FCOS performed in parallel.
94 // Arg = N pi/2 + alpha, |alpha| <= pi/4.
96 // cosl( Arg ) = sinl( (N+1) pi/2 + alpha ),
98 // therefore, the code for computing sine will produce cosine as long
99 // as 1 is added to N immediately after the argument reduction
107 // Arg = M pi/2 + alpha, |alpha| <= pi/4,
109 // let I = M mod 4, or I be the two lsb of M when M is represented
110 // as 2's complement. I = [i_0 i_1]. Then
112 // sinl( Arg ) = (-1)^i_0 sinl( alpha ) if i_1 = 0,
113 // = (-1)^i_0 cosl( alpha ) if i_1 = 1.
117 // sin ((-pi/2 + alpha) = (-1) cos (alpha)
119 // sin (alpha) = sin (alpha)
121 // sin (pi/2 + alpha) = cos (alpha)
123 // sin (pi + alpha) = (-1) sin (alpha)
125 // sin ((3/2)pi + alpha) = (-1) cos (alpha)
127 // The value of alpha is obtained by argument reduction and
128 // represented by two working precision numbers r and c where
130 // alpha = r + c accurately.
132 // The reduction method is described in a previous write up.
133 // The argument reduction scheme identifies 4 cases. For Cases 2
134 // and 4, because |alpha| is small, sinl(r+c) and cosl(r+c) can be
135 // computed very easily by 2 or 3 terms of the Taylor series
136 // expansion as follows:
141 // sinl(r + c) = r + c - r^3/6 accurately
142 // cosl(r + c) = 1 - 2^(-67) accurately
147 // sinl(r + c) = r + c - r^3/6 + r^5/120 accurately
148 // cosl(r + c) = 1 - r^2/2 + r^4/24 accurately
150 // The only cases left are Cases 1 and 3 of the argument reduction
151 // procedure. These two cases will be merged since after the
152 // argument is reduced in either cases, we have the reduced argument
153 // represented as r + c and that the magnitude |r + c| is not small
154 // enough to allow the usage of a very short approximation.
156 // The required calculation is either
158 // sinl(r + c) = sinl(r) + correction, or
159 // cosl(r + c) = cosl(r) + correction.
163 // sinl(r + c) = sinl(r) + c sin'(r) + O(c^2)
164 // = sinl(r) + c cos (r) + O(c^2)
165 // = sinl(r) + c(1 - r^2/2) accurately.
168 // cosl(r + c) = cosl(r) - c sinl(r) + O(c^2)
169 // = cosl(r) - c(r - r^3/6) accurately.
171 // We therefore concentrate on accurately calculating sinl(r) and
172 // cosl(r) for a working-precision number r, |r| <= pi/4 to within
175 // The greatest challenge of this task is that the second terms of
178 // r - r^3/3! + r^r/5! - ...
182 // 1 - r^2/2! + r^4/4! - ...
184 // are not very small when |r| is close to pi/4 and the rounding
185 // errors will be a concern if simple polynomial accumulation is
186 // used. When |r| < 2^-3, however, the second terms will be small
187 // enough (6 bits or so of right shift) that a normal Horner
188 // recurrence suffices. Hence there are two cases that we consider
189 // in the accurate computation of sinl(r) and cosl(r), |r| <= pi/4.
191 // Case small_r: |r| < 2^(-3)
192 // --------------------------
194 // Since Arg = M pi/4 + r + c accurately, and M mod 4 is [i_0 i_1],
197 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
198 // = (-1)^i_0 * cosl(r + c) if i_1 = 1
200 // can be accurately approximated by
202 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c] if i_1 = 0
203 // = (-1)^i_0 * [cosl(r) - c*r] if i_1 = 1
205 // because |r| is small and thus the second terms in the correction
208 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
211 // sinl(r) = r + S_1 r^3 + S_2 r^5 + ... + S_5 r^11
212 // cosl(r) = 1 + C_1 r^2 + C_2 r^4 + ... + C_5 r^10
214 // We can make use of predicates to selectively calculate
215 // sinl(r) or cosl(r) based on i_1.
217 // Case normal_r: 2^(-3) <= |r| <= pi/4
218 // ------------------------------------
220 // This case is more likely than the previous one if one considers
221 // r to be uniformly distributed in [-pi/4 pi/4]. Again,
223 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
224 // = (-1)^i_0 * cosl(r + c) if i_1 = 1.
226 // Because |r| is now larger, we need one extra term in the
227 // correction. sinl(Arg) can be accurately approximated by
229 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c(1-r^2/2)] if i_1 = 0
230 // = (-1)^i_0 * [cosl(r) - c*r*(1 - r^2/6)] i_1 = 1.
232 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
235 // sinl(r) = r + PP_1_hi r^3 + PP_1_lo r^3 +
236 // PP_2 r^5 + ... + PP_8 r^17
238 // cosl(r) = 1 + QQ_1 r^2 + QQ_2 r^4 + ... + QQ_8 r^16
240 // where PP_1_hi is only about 16 bits long and QQ_1 is -1/2.
241 // The crux in accurate computation is to calculate
243 // r + PP_1_hi r^3 or 1 + QQ_1 r^2
245 // accurately as two pieces: U_hi and U_lo. The way to achieve this
246 // is to obtain r_hi as a 10 sig. bit number that approximates r to
247 // roughly 8 bits or so of accuracy. (One convenient way is
249 // r_hi := frcpa( frcpa( r ) ).)
253 // r + PP_1_hi r^3 = r + PP_1_hi r_hi^3 +
254 // PP_1_hi (r^3 - r_hi^3)
255 // = [r + PP_1_hi r_hi^3] +
256 // [PP_1_hi (r - r_hi)
257 // (r^2 + r_hi r + r_hi^2) ]
260 // Since r_hi is only 10 bit long and PP_1_hi is only 16 bit long,
261 // PP_1_hi * r_hi^3 is only at most 46 bit long and thus computed
262 // exactly. Furthermore, r and PP_1_hi r_hi^3 are of opposite sign
263 // and that there is no more than 8 bit shift off between r and
264 // PP_1_hi * r_hi^3. Hence the sum, U_hi, is representable and thus
265 // calculated without any error. Finally, the fact that
267 // |U_lo| <= 2^(-8) |U_hi|
269 // says that U_hi + U_lo is approximating r + PP_1_hi r^3 to roughly
270 // 8 extra bits of accuracy.
274 // 1 + QQ_1 r^2 = [1 + QQ_1 r_hi^2] +
275 // [QQ_1 (r - r_hi)(r + r_hi)]
278 // Summarizing, we calculate r_hi = frcpa( frcpa( r ) ).
282 // U_hi := r + PP_1_hi * r_hi^3
283 // U_lo := PP_1_hi * (r - r_hi) * (r^2 + r*r_hi + r_hi^2)
284 // poly := PP_1_lo r^3 + PP_2 r^5 + ... + PP_8 r^17
285 // correction := c * ( 1 + C_1 r^2 )
289 // U_hi := 1 + QQ_1 * r_hi * r_hi
290 // U_lo := QQ_1 * (r - r_hi) * (r + r_hi)
291 // poly := QQ_2 * r^4 + QQ_3 * r^6 + ... + QQ_8 r^16
292 // correction := -c * r * (1 + S_1 * r^2)
298 // V := poly + ( U_lo + correction )
300 // / U_hi + V if i_0 = 0
302 // \ (-U_hi) - V if i_0 = 1
304 // It is important that in the last step, negation of U_hi is
305 // performed prior to the subtraction which is to be performed in
306 // the user-set rounding mode.
309 // Algorithmic Description
310 // =======================
312 // The argument reduction algorithm shares the same code between FSIN and FCOS.
313 // The argument reduction description given
314 // previously is repeated below.
317 // Step 0. Initialization.
319 // Step 1. Check for exceptional and special cases.
321 // * If Arg is +-0, +-inf, NaN, NaT, go to Step 10 for special
323 // * If |Arg| < 2^24, go to Step 2 for reduction of moderate
324 // arguments. This is the most likely case.
325 // * If |Arg| < 2^63, go to Step 8 for pre-reduction of large
327 // * If |Arg| >= 2^63, go to Step 10 for special handling.
329 // Step 2. Reduction of moderate arguments.
331 // If |Arg| < pi/4 ...quick branch
332 // N_fix := N_inc (integer)
335 // Branch to Step 4, Case_1_complete
336 // Else ...cf. argument reduction
337 // N := Arg * two_by_PI (fp)
338 // N_fix := fcvt.fx( N ) (int)
339 // N := fcvt.xf( N_fix )
340 // N_fix := N_fix + N_inc
341 // s := Arg - N * P_1 (first piece of pi/2)
342 // w := -N * P_2 (second piece of pi/2)
345 // go to Step 3, Case_1_reduce
347 // go to Step 7, Case_2_reduce
351 // Step 3. Case_1_reduce.
354 // c := (s - r) + w ...observe order
356 // Step 4. Case_1_complete
358 // ...At this point, the reduced argument alpha is
359 // ...accurately represented as r + c.
360 // If |r| < 2^(-3), go to Step 6, small_r.
364 // Let [i_0 i_1] by the 2 lsb of N_fix.
366 // r_hi := frcpa( frcpa( r ) )
370 // poly := r*FR_rsq*(PP_1_lo + FR_rsq*(PP_2 + ... FR_rsq*PP_8))
371 // U_hi := r + PP_1_hi*r_hi*r_hi*r_hi ...any order
372 // U_lo := PP_1_hi*r_lo*(r*r + r*r_hi + r_hi*r_hi)
373 // correction := c + c*C_1*FR_rsq ...any order
375 // poly := FR_rsq*FR_rsq*(QQ_2 + FR_rsq*(QQ_3 + ... + FR_rsq*QQ_8))
376 // U_hi := 1 + QQ_1 * r_hi * r_hi ...any order
377 // U_lo := QQ_1 * r_lo * (r + r_hi)
378 // correction := -c*(r + S_1*FR_rsq*r) ...any order
381 // V := poly + (U_lo + correction) ...observe order
383 // result := (i_0 == 0? 1.0 : -1.0)
385 // Last instruction in user-set rounding mode
387 // result := (i_0 == 0? result*U_hi + V :
394 // ...Use flush to zero mode without causing exception
395 // Let [i_0 i_1] be the two lsb of N_fix.
400 // z := FR_rsq*FR_rsq; z := FR_rsq*z *r
401 // poly_lo := S_3 + FR_rsq*(S_4 + FR_rsq*S_5)
402 // poly_hi := r*FR_rsq*(S_1 + FR_rsq*S_2)
406 // z := FR_rsq*FR_rsq; z := FR_rsq*z
407 // poly_lo := C_3 + FR_rsq*(C_4 + FR_rsq*C_5)
408 // poly_hi := FR_rsq*(C_1 + FR_rsq*C_2)
409 // correction := -c*r
413 // poly := poly_hi + (z * poly_lo + correction)
415 // If i_0 = 1, result := -result
417 // Last operation. Perform in user-set rounding mode
419 // result := (i_0 == 0? result + poly :
423 // Step 7. Case_2_reduce.
425 // ...Refer to the write up for argument reduction for
426 // ...rationale. The reduction algorithm below is taken from
427 // ...argument reduction description and integrated this.
430 // U_1 := N*P_2 + w ...FMA
431 // U_2 := (N*P_2 - U_1) + w ...2 FMA
432 // ...U_1 + U_2 is N*(P_2+P_3) accurately
435 // c := ( (s - r) - U_1 ) - U_2
437 // ...The mathematical sum r + c approximates the reduced
438 // ...argument accurately. Note that although compared to
439 // ...Case 1, this case requires much more work to reduce
440 // ...the argument, the subsequent calculation needed for
441 // ...any of the trigonometric function is very little because
442 // ...|alpha| < 1.01*2^(-33) and thus two terms of the
443 // ...Taylor series expansion suffices.
446 // poly := c + S_1 * r * r * r ...any order
453 // If i_0 = 1, result := -result
455 // Last operation. Perform in user-set rounding mode
457 // result := (i_0 == 0? result + poly :
463 // Step 8. Pre-reduction of large arguments.
465 // ...Again, the following reduction procedure was described
466 // ...in the separate write up for argument reduction, which
467 // ...is tightly integrated here.
469 // N_0 := Arg * Inv_P_0
470 // N_0_fix := fcvt.fx( N_0 )
471 // N_0 := fcvt.xf( N_0_fix)
473 // Arg' := Arg - N_0 * P_0
475 // N := Arg' * two_by_PI
476 // N_fix := fcvt.fx( N )
477 // N := fcvt.xf( N_fix )
478 // N_fix := N_fix + N_inc
480 // s := Arg' - N * P_1
489 // Step 9. Case_4_reduce.
491 // ...first obtain N_0*d_1 and -N*P_2 accurately
492 // U_hi := N_0 * d_1 V_hi := -N*P_2
493 // U_lo := N_0 * d_1 - U_hi V_lo := -N*P_2 - U_hi ...FMAs
495 // ...compute the contribution from N_0*d_1 and -N*P_3
498 // t := U_lo + V_lo + w ...any order
500 // ...at this point, the mathematical value
501 // ...s + U_hi + V_hi + t approximates the true reduced argument
502 // ...accurately. Just need to compute this accurately.
504 // ...Calculate U_hi + V_hi accurately:
506 // if |U_hi| >= |V_hi| then
507 // a := (U_hi - A) + V_hi
509 // a := (V_hi - A) + U_hi
511 // ...order in computing "a" must be observed. This branch is
512 // ...best implemented by predicates.
513 // ...A + a is U_hi + V_hi accurately. Moreover, "a" is
514 // ...much smaller than A: |a| <= (1/2)ulp(A).
516 // ...Just need to calculate s + A + a + t
517 // C_hi := s + A t := t + a
518 // C_lo := (s - C_hi) + A
521 // ...Final steps for reduction
523 // c := (C_hi - r) + C_lo
525 // ...At this point, we have r and c
526 // ...And all we need is a couple of terms of the corresponding
530 // poly := c + r*FR_rsq*(S_1 + FR_rsq*S_2)
533 // poly := FR_rsq*(C_1 + FR_rsq*C_2)
537 // If i_0 = 1, result := -result
539 // Last operation. Perform in user-set rounding mode
541 // result := (i_0 == 0? result + poly :
545 // Large Arguments: For arguments above 2**63, a Payne-Hanek
546 // style argument reduction is used and pi_by_2 reduce is called.
553 LOCAL_OBJECT_START(FSINCOSL_CONSTANTS)
556 //data4 0x4E44152A, 0xA2F9836E, 0x00003FFE,0x00000000 // Inv_pi_by_2
557 //data4 0xCE81B9F1, 0xC84D32B0, 0x00004016,0x00000000 // P_0
558 //data4 0x2168C235, 0xC90FDAA2, 0x00003FFF,0x00000000 // P_1
559 //data4 0xFC8F8CBB, 0xECE675D1, 0x0000BFBD,0x00000000 // P_2
560 //data4 0xACC19C60, 0xB7ED8FBB, 0x0000BF7C,0x00000000 // P_3
561 //data4 0xDBD171A1, 0x8D848E89, 0x0000BFBF,0x00000000 // d_1
562 //data4 0x18A66F8E, 0xD5394C36, 0x0000BF7C,0x00000000 // d_2
563 data8 0xA2F9836E4E44152A, 0x00003FFE // Inv_pi_by_2
564 data8 0xC84D32B0CE81B9F1, 0x00004016 // P_0
565 data8 0xC90FDAA22168C235, 0x00003FFF // P_1
566 data8 0xECE675D1FC8F8CBB, 0x0000BFBD // P_2
567 data8 0xB7ED8FBBACC19C60, 0x0000BF7C // P_3
568 data8 0x8D848E89DBD171A1, 0x0000BFBF // d_1
569 data8 0xD5394C3618A66F8E, 0x0000BF7C // d_2
570 LOCAL_OBJECT_END(FSINCOSL_CONSTANTS)
572 LOCAL_OBJECT_START(sincosl_table_d)
573 //data4 0x2168C234, 0xC90FDAA2, 0x00003FFE,0x00000000 // pi_by_4
574 //data4 0x6EC6B45A, 0xA397E504, 0x00003FE7,0x00000000 // Inv_P_0
575 data8 0xC90FDAA22168C234, 0x00003FFE // pi_by_4
576 data8 0xA397E5046EC6B45A, 0x00003FE7 // Inv_P_0
577 data4 0x3E000000, 0xBE000000 // 2^-3 and -2^-3
578 data4 0x2F000000, 0xAF000000 // 2^-33 and -2^-33
579 data4 0x9E000000, 0x00000000 // -2^-67
580 data4 0x00000000, 0x00000000 // pad
581 LOCAL_OBJECT_END(sincosl_table_d)
583 LOCAL_OBJECT_START(sincosl_table_pp)
584 //data4 0xA21C0BC9, 0xCC8ABEBC, 0x00003FCE,0x00000000 // PP_8
585 //data4 0x720221DA, 0xD7468A05, 0x0000BFD6,0x00000000 // PP_7
586 //data4 0x640AD517, 0xB092382F, 0x00003FDE,0x00000000 // PP_6
587 //data4 0xD1EB75A4, 0xD7322B47, 0x0000BFE5,0x00000000 // PP_5
588 //data4 0xFFFFFFFE, 0xFFFFFFFF, 0x0000BFFD,0x00000000 // C_1
589 //data4 0x00000000, 0xAAAA0000, 0x0000BFFC,0x00000000 // PP_1_hi
590 //data4 0xBAF69EEA, 0xB8EF1D2A, 0x00003FEC,0x00000000 // PP_4
591 //data4 0x0D03BB69, 0xD00D00D0, 0x0000BFF2,0x00000000 // PP_3
592 //data4 0x88888962, 0x88888888, 0x00003FF8,0x00000000 // PP_2
593 //data4 0xAAAB0000, 0xAAAAAAAA, 0x0000BFEC,0x00000000 // PP_1_lo
594 data8 0xCC8ABEBCA21C0BC9, 0x00003FCE // PP_8
595 data8 0xD7468A05720221DA, 0x0000BFD6 // PP_7
596 data8 0xB092382F640AD517, 0x00003FDE // PP_6
597 data8 0xD7322B47D1EB75A4, 0x0000BFE5 // PP_5
598 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
599 data8 0xAAAA000000000000, 0x0000BFFC // PP_1_hi
600 data8 0xB8EF1D2ABAF69EEA, 0x00003FEC // PP_4
601 data8 0xD00D00D00D03BB69, 0x0000BFF2 // PP_3
602 data8 0x8888888888888962, 0x00003FF8 // PP_2
603 data8 0xAAAAAAAAAAAB0000, 0x0000BFEC // PP_1_lo
604 LOCAL_OBJECT_END(sincosl_table_pp)
606 LOCAL_OBJECT_START(sincosl_table_qq)
607 //data4 0xC2B0FE52, 0xD56232EF, 0x00003FD2 // QQ_8
608 //data4 0x2B48DCA6, 0xC9C99ABA, 0x0000BFDA // QQ_7
609 //data4 0x9C716658, 0x8F76C650, 0x00003FE2 // QQ_6
610 //data4 0xFDA8D0FC, 0x93F27DBA, 0x0000BFE9 // QQ_5
611 //data4 0xAAAAAAAA, 0xAAAAAAAA, 0x0000BFFC // S_1
612 //data4 0x00000000, 0x80000000, 0x0000BFFE,0x00000000 // QQ_1
613 //data4 0x0C6E5041, 0xD00D00D0, 0x00003FEF,0x00000000 // QQ_4
614 //data4 0x0B607F60, 0xB60B60B6, 0x0000BFF5,0x00000000 // QQ_3
615 //data4 0xAAAAAA9B, 0xAAAAAAAA, 0x00003FFA,0x00000000 // QQ_2
616 data8 0xD56232EFC2B0FE52, 0x00003FD2 // QQ_8
617 data8 0xC9C99ABA2B48DCA6, 0x0000BFDA // QQ_7
618 data8 0x8F76C6509C716658, 0x00003FE2 // QQ_6
619 data8 0x93F27DBAFDA8D0FC, 0x0000BFE9 // QQ_5
620 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
621 data8 0x8000000000000000, 0x0000BFFE // QQ_1
622 data8 0xD00D00D00C6E5041, 0x00003FEF // QQ_4
623 data8 0xB60B60B60B607F60, 0x0000BFF5 // QQ_3
624 data8 0xAAAAAAAAAAAAAA9B, 0x00003FFA // QQ_2
625 LOCAL_OBJECT_END(sincosl_table_qq)
627 LOCAL_OBJECT_START(sincosl_table_c)
628 //data4 0xFFFFFFFE, 0xFFFFFFFF, 0x0000BFFD,0x00000000 // C_1
629 //data4 0xAAAA719F, 0xAAAAAAAA, 0x00003FFA,0x00000000 // C_2
630 //data4 0x0356F994, 0xB60B60B6, 0x0000BFF5,0x00000000 // C_3
631 //data4 0xB2385EA9, 0xD00CFFD5, 0x00003FEF,0x00000000 // C_4
632 //data4 0x292A14CD, 0x93E4BD18, 0x0000BFE9,0x00000000 // C_5
633 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
634 data8 0xAAAAAAAAAAAA719F, 0x00003FFA // C_2
635 data8 0xB60B60B60356F994, 0x0000BFF5 // C_3
636 data8 0xD00CFFD5B2385EA9, 0x00003FEF // C_4
637 data8 0x93E4BD18292A14CD, 0x0000BFE9 // C_5
638 LOCAL_OBJECT_END(sincosl_table_c)
640 LOCAL_OBJECT_START(sincosl_table_s)
641 //data4 0xAAAAAAAA, 0xAAAAAAAA, 0x0000BFFC,0x00000000 // S_1
642 //data4 0x888868DB, 0x88888888, 0x00003FF8,0x00000000 // S_2
643 //data4 0x055EFD4B, 0xD00D00D0, 0x0000BFF2,0x00000000 // S_3
644 //data4 0x839730B9, 0xB8EF1C5D, 0x00003FEC,0x00000000 // S_4
645 //data4 0xE5B3F492, 0xD71EA3A4, 0x0000BFE5,0x00000000 // S_5
646 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
647 data8 0x88888888888868DB, 0x00003FF8 // S_2
648 data8 0xD00D00D0055EFD4B, 0x0000BFF2 // S_3
649 data8 0xB8EF1C5D839730B9, 0x00003FEC // S_4
650 data8 0xD71EA3A4E5B3F492, 0x0000BFE5 // S_5
651 data4 0x38800000, 0xB8800000 // two**-14 and -two**-14
652 LOCAL_OBJECT_END(sincosl_table_s)
662 FR_inv_pi_2to63 = f10
666 FR_N_float_signif = f14
673 FR_Neg_Two_to_M14 = f36
675 FR_Neg_Two_to_M33 = f38
676 FR_Neg_Two_to_M67 = f39
740 FR_Neg_Two_to_M3 = f109
807 // For unwind support
815 GLOBAL_IEEE754_ENTRY(sincosl)
816 { .mlx ///////////////////////////// 1 /////////////////
817 alloc r32 = ar.pfs,3,13,2,0
818 movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
822 movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
825 { .mfi ///////////////////////////// 2 /////////////////
826 addl GR_ad_p = @ltoff(FSINCOSL_CONSTANTS#), gp
827 fclass.m p6, p0 = FR_Input_X, 0x1E3 // Test x natval, nan, inf
828 mov GR_exp_2_to_m3 = 0xffff - 3 // Exponent of 2^-3
832 fnorm.s1 FR_norm_x = FR_Input_X // Normalize x
833 br.cond.sptk _COMMON_SINCOSL
835 GLOBAL_IEEE754_END(sincosl)
837 LOCAL_LIBM_ENTRY(cisl)
839 GLOBAL_LIBM_ENTRY(__libm_sincosl)
840 { .mlx ///////////////////////////// 1 /////////////////
841 alloc r32 = ar.pfs,3,14,2,0
842 movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
846 movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
849 { .mfi ///////////////////////////// 2 /////////////////
850 addl GR_ad_p = @ltoff(FSINCOSL_CONSTANTS#), gp
851 fclass.m p6, p0 = FR_Input_X, 0x1E3 // Test x natval, nan, inf
852 mov GR_exp_2_to_m3 = 0xffff - 3 // Exponent of 2^-3
856 fnorm.s1 FR_norm_x = FR_Input_X // Normalize x
861 { .mfi ///////////////////////////// 3 /////////////////
862 setf.sig FR_inv_pi_2to63 = GR_sig_inv_pi // Form 1/pi * 2^63
864 mov GR_exp_2tom64 = 0xffff - 64 // Scaling constant to compute N
867 setf.d FR_rshf_2to64 = GR_rshf_2to64 // Form const 1.1000 * 2^(63+64)
868 movl GR_rshf = 0x43e8000000000000 // Form const 1.1000 * 2^63
871 { .mfi ///////////////////////////// 4 /////////////////
872 ld8 GR_ad_p = [GR_ad_p] // Point to Inv_pi_by_2
873 fclass.m p7, p0 = FR_Input_X, 0x0b // Test x denormal
877 { .mfi ///////////////////////////// 5 /////////////////
878 getf.exp GR_signexp_x = FR_Input_X // Get sign and exponent of x
879 fclass.m p10, p0 = FR_Input_X, 0x007 // Test x zero
883 mov GR_exp_mask = 0x1ffff // Exponent mask
885 (p6) br.cond.spnt SINCOSL_SPECIAL // Branch if x natval, nan, inf
888 { .mfi ///////////////////////////// 6 /////////////////
889 setf.exp FR_2tom64 = GR_exp_2tom64 // Form 2^-64 for scaling N_float
891 add GR_ad_d = 0x70, GR_ad_p // Point to constant table d
894 setf.d FR_rshf = GR_rshf // Form right shift const 1.1000 * 2^63
895 mov GR_exp_m2_to_m3 = 0x2fffc // Form -(2^-3)
896 (p7) br.cond.spnt SINCOSL_DENORMAL // Branch if x denormal
900 { .mfi ///////////////////////////// 7 /////////////////
901 and GR_exp_x = GR_exp_mask, GR_signexp_x // Get exponent of x
902 fclass.nm p8, p0 = FR_Input_X, 0x1FF // Test x unsupported type
903 mov GR_exp_2_to_63 = 0xffff + 63 // Exponent of 2^63
906 add GR_ad_pp = 0x40, GR_ad_d // Point to constant table pp
907 mov GR_exp_2_to_24 = 0xffff + 24 // Exponent of 2^24
908 (p10) br.cond.spnt SINCOSL_ZERO // Branch if x zero
911 { .mfi ///////////////////////////// 8 /////////////////
912 ldfe FR_Inv_pi_by_2 = [GR_ad_p], 16 // Load 2/pi
913 fcmp.eq.s0 p15, p0 = FR_Input_X, f0 // Dummy to set denormal
914 add GR_ad_qq = 0xa0, GR_ad_pp // Point to constant table qq
917 ldfe FR_Pi_by_4 = [GR_ad_d], 16 // Load pi/4 for range test
919 cmp.ge p10,p0 = GR_exp_x, GR_exp_2_to_63 // Is |x| >= 2^63
922 { .mfi ///////////////////////////// 9 /////////////////
923 ldfe FR_P_0 = [GR_ad_p], 16 // Load P_0 for pi/4 <= |x| < 2^63
924 fmerge.s FR_abs_x = f1, FR_norm_x // |x|
925 add GR_ad_c = 0x90, GR_ad_qq // Point to constant table c
928 ldfe FR_Inv_P_0 = [GR_ad_d], 16 // Load 1/P_0 for pi/4 <= |x| < 2^63
930 cmp.ge p7,p0 = GR_exp_x, GR_exp_2_to_24 // Is |x| >= 2^24
933 { .mfi ///////////////////////////// 10 /////////////////
934 ldfe FR_P_1 = [GR_ad_p], 16 // Load P_1 for pi/4 <= |x| < 2^63
936 add GR_ad_s = 0x50, GR_ad_c // Point to constant table s
939 ldfe FR_PP_8 = [GR_ad_pp], 16 // Load PP_8 for 2^-3 < |r| < pi/4
944 { .mfi ///////////////////////////// 11 /////////////////
945 ldfe FR_P_2 = [GR_ad_p], 16 // Load P_2 for pi/4 <= |x| < 2^63
947 add GR_ad_ce = 0x40, GR_ad_c // Point to end of constant table c
950 ldfe FR_QQ_8 = [GR_ad_qq], 16 // Load QQ_8 for 2^-3 < |r| < pi/4
955 { .mfi ///////////////////////////// 12 /////////////////
956 ldfe FR_QQ_7 = [GR_ad_qq], 16 // Load QQ_7 for 2^-3 < |r| < pi/4
957 fma.s1 FR_N_float_signif = FR_Input_X, FR_inv_pi_2to63, FR_rshf_2to64
958 add GR_ad_se = 0x40, GR_ad_s // Point to end of constant table s
961 ldfe FR_PP_7 = [GR_ad_pp], 16 // Load PP_7 for 2^-3 < |r| < pi/4
962 mov GR_ad_s1 = GR_ad_s // Save pointer to S_1
963 (p10) br.cond.spnt SINCOSL_ARG_TOO_LARGE // Branch if |x| >= 2^63
964 // Use Payne-Hanek Reduction
967 { .mfi ///////////////////////////// 13 /////////////////
968 ldfe FR_P_3 = [GR_ad_p], 16 // Load P_3 for pi/4 <= |x| < 2^63
969 fmerge.se FR_r = FR_norm_x, FR_norm_x // r = x, in case |x| < pi/4
970 add GR_ad_m14 = 0x50, GR_ad_s // Point to constant table m14
973 ldfps FR_Two_to_M3, FR_Neg_Two_to_M3 = [GR_ad_d], 8
974 fma.s1 FR_rsq = FR_norm_x, FR_norm_x, f0 // rsq = x*x, in case |x| < pi/4
975 (p7) br.cond.spnt SINCOSL_LARGER_ARG // Branch if 2^24 <= |x| < 2^63
979 { .mmf ///////////////////////////// 14 /////////////////
980 ldfe FR_PP_6 = [GR_ad_pp], 16 // Load PP_6 for normal path
981 ldfe FR_QQ_6 = [GR_ad_qq], 16 // Load QQ_6 for normal path
982 fmerge.se FR_c = f0, f0 // c = 0 in case |x| < pi/4
985 { .mmf ///////////////////////////// 15 /////////////////
986 ldfe FR_PP_5 = [GR_ad_pp], 16 // Load PP_5 for normal path
987 ldfe FR_QQ_5 = [GR_ad_qq], 16 // Load QQ_5 for normal path
991 // Here if 0 < |x| < 2^24
992 { .mfi ///////////////////////////// 17 /////////////////
993 ldfe FR_S_5 = [GR_ad_se], -16 // Load S_5 if i_1=0
994 fcmp.lt.s1 p6, p7 = FR_abs_x, FR_Pi_by_4 // Test |x| < pi/4
998 ldfe FR_C_5 = [GR_ad_ce], -16 // Load C_5 if i_1=1
999 fms.s1 FR_N_float = FR_N_float_signif, FR_2tom64, FR_rshf
1003 { .mmi ///////////////////////////// 18 /////////////////
1004 ldfe FR_S_4 = [GR_ad_se], -16 // Load S_4 if i_1=0
1005 ldfe FR_C_4 = [GR_ad_ce], -16 // Load C_4 if i_1=1
1011 // Check if Arg < pi/4
1014 // Case 2: Convert integer N_fix back to normalized floating-point value.
1015 // Case 1: p8 is only affected when p6 is set
1018 // Grab the integer part of N and call it N_fix
1020 { .mfi ///////////////////////////// 19 /////////////////
1021 (p7) ldfps FR_Two_to_M33, FR_Neg_Two_to_M33 = [GR_ad_d], 8
1022 (p6) fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // r^3 if |x| < pi/4
1023 (p6) mov GR_N_Inc = 0x0 // N_IncS if |x| < pi/4
1026 // If |x| < pi/4, r = x and c = 0
1027 // lf |x| < pi/4, is x < 2**(-3).
1030 { .mmi ///////////////////////////// 20 /////////////////
1031 (p7) getf.sig GR_N_Inc = FR_N_float_signif
1033 (p6) cmp.lt.unc p8,p0 = GR_exp_x, GR_exp_2_to_m3 // Is |x| < 2^-3
1037 // lf |x| < pi/4, is -2**(-3)< x < 2**(-3) - set p8.
1039 // Create the right N for |x| < pi/4 and otherwise
1040 // Case 2: Place integer part of N in GP register
1043 { .mbb ///////////////////////////// 21 /////////////////
1045 (p8) br.cond.spnt SINCOSL_SMALL_R_0 // Branch if 0 < |x| < 2^-3
1046 (p6) br.cond.spnt SINCOSL_NORMAL_R_0 // Branch if 2^-3 <= |x| < pi/4
1049 // Here if pi/4 <= |x| < 2^24
1051 ldfs FR_Neg_Two_to_M67 = [GR_ad_d], 8 // Load -2^-67
1052 fnma.s1 FR_s = FR_N_float, FR_P_1, FR_Input_X // s = -N * P_1 + Arg
1057 fma.s1 FR_w = FR_N_float, FR_P_2, f0 // w = N * P_2
1063 fms.s1 FR_r = FR_s, f1, FR_w // r = s - w, assume |s| >= 2^-33
1069 fcmp.lt.s1 p7, p6 = FR_s, FR_Two_to_M33
1075 (p7) fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33 // p6 if |s| >= 2^-33, else p7
1081 fms.s1 FR_c = FR_s, f1, FR_r // c = s - r, for |s| >= 2^-33
1086 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r, for |s| >= 2^-33
1092 (p7) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1097 ldfe FR_C_1 = [GR_ad_pp], 16 // Load C_1 if i_1=0
1098 ldfe FR_S_1 = [GR_ad_qq], 16 // Load S_1 if i_1=1
1099 frcpa.s1 FR_r_hi, p15 = f1, FR_r // r_hi = frcpa(r)
1104 (p6) fcmp.lt.unc.s1 p8, p13 = FR_r, FR_Two_to_M3 // If big s, test r with 2^-3
1110 (p7) fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1115 // For big s: r = s - w: No futher reduction is necessary
1116 // For small s: w = N * P_3 (change sign) More reduction
1120 (p8) fcmp.gt.s1 p8, p13 = FR_r, FR_Neg_Two_to_M3 // If big s, p8 if |r| < 2^-3
1126 fma.s1 FR_polyS = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7
1131 fma.s1 FR_polyC = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7
1137 (p7) fms.s1 FR_r = FR_s, f1, FR_U_1
1143 (p6) fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // rcubed = r * rsq
1149 // For big s: Is |r| < 2**(-3)?
1150 // For big s: c = S - r
1151 // For small s: U_1 = N * P_2 + w
1153 // If p8 is set, prepare to branch to Small_R.
1154 // If p9 is set, prepare to branch to Normal_R.
1155 // For big s, r is complete here.
1158 // For big s: c = c + w (w has not been negated.)
1159 // For small s: r = S - U_1
1162 (p6) fms.s1 FR_c = FR_c, f1, FR_w
1167 (p8) br.cond.spnt SINCOSL_SMALL_R_1 // Branch if |s|>=2^-33, |r| < 2^-3,
1168 // and pi/4 <= |x| < 2^24
1169 (p13) br.cond.sptk SINCOSL_NORMAL_R_1 // Branch if |s|>=2^-33, |r| >= 2^-3,
1170 // and pi/4 <= |x| < 2^24
1175 // Here if |s| < 2^-33, and pi/4 <= |x| < 2^24
1178 and GR_N_SinCos = 0x1, GR_N_Inc
1179 fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1180 tbit.z p8,p12 = GR_N_Inc, 0
1185 // For small s: U_2 = N * P_2 - U_1
1186 // S_1 stored constant - grab the one stored with the
1190 ldfe FR_S_1 = [GR_ad_s1], 16
1191 fma.s1 FR_polyC = f0, f1, FR_Neg_Two_to_M67
1192 sub GR_N_SignS = GR_N_Inc, GR_N_SinCos
1195 add GR_N_SignC = GR_N_Inc, GR_N_SinCos
1202 fms.s1 FR_s = FR_s, f1, FR_r
1203 (p8) tbit.z.unc p10,p11 = GR_N_SignC, 1
1207 fma.s1 FR_rsq = FR_r, FR_r, f0
1213 fma.s1 FR_U_2 = FR_U_2, f1, FR_w
1214 (p8) tbit.z.unc p8,p9 = GR_N_SignS, 1
1219 fmerge.se FR_FirstS = FR_r, FR_r
1220 (p12) tbit.z.unc p14,p15 = GR_N_SignC, 1
1224 fma.s1 FR_FirstC = f0, f1, f1
1230 fms.s1 FR_c = FR_s, f1, FR_U_1
1231 (p12) tbit.z.unc p12,p13 = GR_N_SignS, 1
1236 fma.s1 FR_r = FR_S_1, FR_r, f0
1242 fma.s0 FR_S_1 = FR_S_1, FR_S_1, f0
1248 fms.s1 FR_c = FR_c, f1, FR_U_2
1252 .pred.rel "mutex",p9,p15
1255 (p9) fms.s0 FR_FirstS = f1, f0, FR_FirstS
1260 (p15) fms.s0 FR_FirstS = f1, f0, FR_FirstS
1264 .pred.rel "mutex",p11,p13
1267 (p11) fms.s0 FR_FirstC = f1, f0, FR_FirstC
1272 (p13) fms.s0 FR_FirstC = f1, f0, FR_FirstC
1278 fma.s1 FR_polyS = FR_r, FR_rsq, FR_c
1283 .pred.rel "mutex",p8,p9
1286 (p8) fma.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1291 (p9) fms.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1295 .pred.rel "mutex",p10,p11
1298 (p10) fma.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1303 (p11) fms.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1309 .pred.rel "mutex",p12,p13
1312 (p12) fma.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1317 (p13) fms.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1321 .pred.rel "mutex",p14,p15
1324 (p14) fma.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1328 cmp.eq p10, p0 = 0x1, GR_Cis
1329 (p15) fms.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1330 (p10) br.ret.sptk b0
1333 { .mmb // exit for sincosl
1334 stfe [sincos_pResSin] = FR_ResultS
1335 stfe [sincos_pResCos] = FR_ResultC
1346 // Here if 2^24 <= |x| < 2^63
1349 ldfe FR_d_1 = [GR_ad_p], 16 // Load d_1 for |x| >= 2^24 path
1350 fma.s1 FR_N_0 = FR_Input_X, FR_Inv_P_0, f0 // N_0 = Arg * Inv_P_0
1355 ldfps FR_Two_to_M14, FR_Neg_Two_to_M14 = [GR_ad_m14]
1361 ldfe FR_d_2 = [GR_ad_p], 16 // Load d_2 for |x| >= 2^24 path
1368 fcvt.fx.s1 FR_N_0_fix = FR_N_0 // N_0_fix = integer part of N_0
1374 fcvt.xf FR_N_0 = FR_N_0_fix // Make N_0 the integer part
1380 fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X // Arg'=-N_0*P_0+Arg
1385 fma.s1 FR_w = FR_N_0, FR_d_1, f0 // w = N_0 * d_1
1392 fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0 // N = A' * 2/pi
1398 fcvt.fx.s1 FR_N_fix = FR_N_float // N_fix is the integer part
1404 fcvt.xf FR_N_float = FR_N_fix
1409 getf.sig GR_N_Inc = FR_N_fix // N is the integer part of
1410 // the reduced-reduced argument
1417 fnma.s1 FR_s = FR_N_float, FR_P_1, FR_ArgPrime // s = -N*P_1 + Arg'
1422 fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w // w = -N*P_2 + w
1427 // For |s| > 2**(-14) r = S + w (r complete)
1428 // Else U_hi = N_0 * d_1
1432 fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1438 (p9) fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14 // p9 if |s| < 2^-14
1443 // Either S <= -2**(-14) or S >= 2**(-14)
1444 // or -2**(-14) < s < 2**(-14)
1448 (p9) fma.s1 FR_V_hi = FR_N_float, FR_P_2, f0
1453 (p9) fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1459 (p8) fma.s1 FR_r = FR_s, f1, FR_w
1464 (p9) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1469 // We need abs of both U_hi and V_hi - don't
1470 // worry about switched sign of V_hi.
1472 // Big s: finish up c = (S - r) + w (c complete)
1473 // Case 4: A = U_hi + V_hi
1474 // Note: Worry about switched sign of V_hi, so subtract instead of add.
1478 (p9) fms.s1 FR_A = FR_U_hi, f1, FR_V_hi
1483 (p9) fnma.s1 FR_V_lo = FR_N_float, FR_P_2, FR_V_hi
1489 (p9) fmerge.s FR_V_hiabs = f0, FR_V_hi
1494 (p9) fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi // For small s: U_lo=N_0*d_1-U_hi
1499 // For big s: Is |r| < 2**(-3)
1500 // For big s: if p12 set, prepare to branch to Small_R.
1501 // For big s: If p13 set, prepare to branch to Normal_R.
1505 (p9) fmerge.s FR_U_hiabs = f0, FR_U_hi
1510 (p8) fms.s1 FR_c = FR_s, f1, FR_r // For big s: c = S - r
1515 // For small S: V_hi = N * P_2
1517 // Note the product does not include the (-) as in the writeup
1518 // so (-) missing for V_hi and w.
1522 (p8) fcmp.lt.unc.s1 p12, p13 = FR_r, FR_Two_to_M3
1528 (p12) fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1534 (p8) fma.s1 FR_c = FR_c, f1, FR_w
1539 (p9) fms.s1 FR_w = FR_N_0, FR_d_2, FR_w
1540 (p12) br.cond.spnt SINCOSL_SMALL_R // Branch if |r| < 2^-3
1541 // and 2^24 <= |x| < 2^63
1547 (p13) br.cond.sptk SINCOSL_NORMAL_R // Branch if |r| >= 2^-3
1548 // and 2^24 <= |x| < 2^63
1551 SINCOSL_LARGER_S_TINY:
1552 // Here if |s| < 2^-14, and 2^24 <= |x| < 2^63
1554 // Big s: Vector off when |r| < 2**(-3). Recall that p8 will be true.
1555 // The remaining stuff is for Case 4.
1556 // Small s: V_lo = N * P_2 + U_hi (U_hi is in place of V_hi in writeup)
1557 // Note: the (-) is still missing for V_lo.
1558 // Small s: w = w + N_0 * d_2
1559 // Note: the (-) is now incorporated in w.
1562 and GR_N_SinCos = 0x1, GR_N_Inc
1563 fcmp.ge.unc.s1 p6, p7 = FR_U_hiabs, FR_V_hiabs
1564 tbit.z p8,p12 = GR_N_Inc, 0
1568 fma.s1 FR_t = FR_U_lo, f1, FR_V_lo // C_hi = S + A
1573 sub GR_N_SignS = GR_N_Inc, GR_N_SinCos
1574 (p6) fms.s1 FR_a = FR_U_hi, f1, FR_A
1575 add GR_N_SignC = GR_N_Inc, GR_N_SinCos
1579 (p7) fma.s1 FR_a = FR_V_hi, f1, FR_A
1584 ldfe FR_C_1 = [GR_ad_c], 16
1585 ldfe FR_S_1 = [GR_ad_s], 16
1586 fma.s1 FR_C_hi = FR_s, f1, FR_A
1590 ldfe FR_C_2 = [GR_ad_c], 64
1591 ldfe FR_S_2 = [GR_ad_s], 64
1592 (p8) tbit.z.unc p10,p11 = GR_N_SignC, 1
1596 // r and c have been computed.
1597 // Make sure ftz mode is set - should be automatic when using wre
1599 // Get [i_0,i_1] - two lsb of N_fix.
1601 // For larger u than v: a = U_hi - A
1602 // Else a = V_hi - A (do an add to account for missing (-) on V_hi
1606 fma.s1 FR_t = FR_t, f1, FR_w // t = t + w
1607 (p8) tbit.z.unc p8,p9 = GR_N_SignS, 1
1611 (p6) fms.s1 FR_a = FR_a, f1, FR_V_hi
1616 // If u > v: a = (U_hi - A) + V_hi
1617 // Else a = (V_hi - A) + U_hi
1618 // In each case account for negative missing from V_hi.
1622 fms.s1 FR_C_lo = FR_s, f1, FR_C_hi
1623 (p12) tbit.z.unc p14,p15 = GR_N_SignC, 1
1627 (p7) fms.s1 FR_a = FR_U_hi, f1, FR_a
1633 fma.s1 FR_C_lo = FR_C_lo, f1, FR_A // C_lo = (S - C_hi) + A
1634 (p12) tbit.z.unc p12,p13 = GR_N_SignS, 1
1638 fma.s1 FR_t = FR_t, f1, FR_a // t = t + a
1644 fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1650 fma.s1 FR_C_lo = FR_C_lo, f1, FR_t // C_lo = C_lo + t
1657 fma.s1 FR_rsq = FR_r, FR_r, f0
1662 fms.s1 FR_c = FR_C_hi, f1, FR_r
1668 fma.s1 FR_FirstS = f0, f1, FR_r
1673 fma.s1 FR_FirstC = f0, f1, f1
1679 fma.s1 FR_polyS = FR_rsq, FR_S_2, FR_S_1
1684 fma.s1 FR_polyC = FR_rsq, FR_C_2, FR_C_1
1690 fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1695 fma.s1 FR_c = FR_c, f1, FR_C_lo
1699 .pred.rel "mutex",p9,p15
1702 (p9) fms.s0 FR_FirstS = f1, f0, FR_FirstS
1707 (p15) fms.s0 FR_FirstS = f1, f0, FR_FirstS
1711 .pred.rel "mutex",p11,p13
1714 (p11) fms.s0 FR_FirstC = f1, f0, FR_FirstC
1719 (p13) fms.s0 FR_FirstC = f1, f0, FR_FirstC
1726 fma.s1 FR_polyS = FR_r_cubed, FR_polyS, FR_c
1731 fma.s1 FR_polyC = FR_rsq, FR_polyC, f0
1737 .pred.rel "mutex",p8,p9
1740 (p8) fma.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1745 (p9) fms.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1749 .pred.rel "mutex",p10,p11
1752 (p10) fma.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1757 (p11) fms.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
1763 .pred.rel "mutex",p12,p13
1766 (p12) fma.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1771 (p13) fms.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
1775 .pred.rel "mutex",p14,p15
1778 (p14) fma.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1782 cmp.eq p10, p0 = 0x1, GR_Cis
1783 (p15) fms.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
1784 (p10) br.ret.sptk b0
1788 { .mmb // exit for sincosl
1789 stfe [sincos_pResSin] = FR_ResultS
1790 stfe [sincos_pResCos] = FR_ResultC
1798 // Here if |r| < 2^-3
1800 // Enter with r, c, and N_Inc computed
1804 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r
1809 ldfe FR_S_5 = [GR_ad_se], -16 // Load S_5
1810 ldfe FR_C_5 = [GR_ad_ce], -16 // Load C_5
1815 ldfe FR_S_4 = [GR_ad_se], -16 // Load S_4
1816 ldfe FR_C_4 = [GR_ad_ce], -16 // Load C_4
1821 // Entry point for 2^-3 < |x| < pi/4
1823 // Entry point for pi/4 < |x| < 2^24 and |r| < 2^-3
1825 ldfe FR_S_3 = [GR_ad_se], -16 // Load S_3
1826 fma.s1 FR_r6 = FR_rsq, FR_rsq, f0 // Z = rsq * rsq
1827 tbit.z p7,p11 = GR_N_Inc, 0
1830 ldfe FR_C_3 = [GR_ad_ce], -16 // Load C_3
1832 and GR_N_SinCos = 0x1, GR_N_Inc
1836 ldfe FR_S_2 = [GR_ad_se], -16 // Load S_2
1837 fnma.s1 FR_cC = FR_c, FR_r, f0 // c = -c * r
1838 sub GR_N_SignS = GR_N_Inc, GR_N_SinCos
1841 ldfe FR_C_2 = [GR_ad_ce], -16 // Load C_2
1843 add GR_N_SignC = GR_N_Inc, GR_N_SinCos
1847 ldfe FR_S_1 = [GR_ad_se], -16 // Load S_1
1848 ldfe FR_C_1 = [GR_ad_ce], -16 // Load C_1
1849 (p7) tbit.z.unc p9,p10 = GR_N_SignC, 1
1854 fma.s1 FR_r7 = FR_r6, FR_r, f0 // Z = Z * r
1855 (p7) tbit.z.unc p7,p8 = GR_N_SignS, 1
1860 fma.s1 FR_poly_loS = FR_rsq, FR_S_5, FR_S_4 // poly_lo=rsq*S_5+S_4
1861 (p11) tbit.z.unc p13,p14 = GR_N_SignC, 1
1865 fma.s1 FR_poly_loC = FR_rsq, FR_C_5, FR_C_4 // poly_lo=rsq*C_5+C_4
1871 fma.s1 FR_poly_hiS = FR_rsq, FR_S_2, FR_S_1 // poly_hi=rsq*S_2+S_1
1872 (p11) tbit.z.unc p11,p12 = GR_N_SignS, 1
1876 fma.s1 FR_poly_hiC = FR_rsq, FR_C_2, FR_C_1 // poly_hi=rsq*C_2+C_1
1882 fma.s0 FR_FirstS = FR_r, f1, f0
1887 fma.s0 FR_FirstC = f1, f1, f0
1894 fma.s1 FR_r6 = FR_r6, FR_rsq, f0
1899 fma.s1 FR_r7 = FR_r7, FR_rsq, f0
1905 fma.s1 FR_poly_loS = FR_rsq, FR_poly_loS, FR_S_3 // p_lo=p_lo*rsq+S_3
1910 fma.s1 FR_poly_loC = FR_rsq, FR_poly_loC, FR_C_3 // p_lo=p_lo*rsq+C_3
1916 fma.s0 FR_inexact = FR_S_4, FR_S_4, f0 // Dummy op to set inexact
1922 fma.s1 FR_poly_hiS = FR_poly_hiS, FR_rsq, f0 // p_hi=p_hi*rsq
1927 fma.s1 FR_poly_hiC = FR_poly_hiC, FR_rsq, f0 // p_hi=p_hi*rsq
1931 .pred.rel "mutex",p8,p14
1934 (p8) fms.s0 FR_FirstS = f1, f0, FR_FirstS
1939 (p14) fms.s0 FR_FirstS = f1, f0, FR_FirstS
1943 .pred.rel "mutex",p10,p12
1946 (p10) fms.s0 FR_FirstC = f1, f0, FR_FirstC
1951 (p12) fms.s0 FR_FirstC = f1, f0, FR_FirstC
1957 fma.s1 FR_polyS = FR_r7, FR_poly_loS, FR_cS // poly=Z*poly_lo+c
1962 fma.s1 FR_polyC = FR_r6, FR_poly_loC, FR_cC // poly=Z*poly_lo+c
1968 fma.s1 FR_poly_hiS = FR_r, FR_poly_hiS, f0 // p_hi=r*p_hi
1975 fma.s1 FR_polyS = FR_polyS, f1, FR_poly_hiS
1980 fma.s1 FR_polyC = FR_polyC, f1, FR_poly_hiC
1984 .pred.rel "mutex",p7,p8
1987 (p7) fma.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1992 (p8) fms.s0 FR_ResultS = FR_FirstS, f1, FR_polyS
1996 .pred.rel "mutex",p9,p10
1999 (p9) fma.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
2004 (p10) fms.s0 FR_ResultC = FR_FirstC, f1, FR_polyC
2008 .pred.rel "mutex",p11,p12
2011 (p11) fma.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
2016 (p12) fms.s0 FR_ResultS = FR_FirstC, f1, FR_polyC
2020 .pred.rel "mutex",p13,p14
2023 (p13) fma.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
2027 cmp.eq p15, p0 = 0x1, GR_Cis
2028 (p14) fms.s0 FR_ResultC = FR_FirstS, f1, FR_polyS
2029 (p15) br.ret.sptk b0
2033 { .mmb // exit for sincosl
2034 stfe [sincos_pResSin] = FR_ResultS
2035 stfe [sincos_pResCos] = FR_ResultC
2046 // Here if 2^-3 <= |r| < pi/4
2047 // THIS IS THE MAIN PATH
2049 // Enter with r, c, and N_Inc having been computed
2052 ldfe FR_PP_6 = [GR_ad_pp], 16 // Load PP_6
2053 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r
2057 ldfe FR_QQ_6 = [GR_ad_qq], 16 // Load QQ_6
2063 ldfe FR_PP_5 = [GR_ad_pp], 16 // Load PP_5
2064 ldfe FR_QQ_5 = [GR_ad_qq], 16 // Load QQ_5
2071 // Entry for 2^-3 < |x| < pi/4
2072 .pred.rel "mutex",p9,p10
2074 ldfe FR_C_1 = [GR_ad_pp], 16 // Load C_1
2075 ldfe FR_S_1 = [GR_ad_qq], 16 // Load S_1
2076 frcpa.s1 FR_r_hi, p6 = f1, FR_r // r_hi = frcpa(r)
2081 fma.s1 FR_polyS = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7
2086 fma.s1 FR_polyC = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7
2092 fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // rcubed = r * rsq
2098 // Entry for pi/4 <= |x| < 2^24
2099 .pred.rel "mutex",p9,p10
2101 ldfe FR_PP_1 = [GR_ad_pp], 16 // Load PP_1_hi
2102 ldfe FR_QQ_1 = [GR_ad_qq], 16 // Load QQ_1
2103 frcpa.s1 FR_r_hi, p6 = f1, FR_r_hi // r_hi = frpca(frcpa(r))
2107 ldfe FR_PP_4 = [GR_ad_pp], 16 // Load PP_4
2108 fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_6 // poly = rsq*poly+PP_6
2109 and GR_N_SinCos = 0x1, GR_N_Inc
2112 ldfe FR_QQ_4 = [GR_ad_qq], 16 // Load QQ_4
2113 fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_6 // poly = rsq*poly+QQ_6
2119 fma.s1 FR_corrS = FR_C_1, FR_rsq, f0 // corr = C_1 * rsq
2120 sub GR_N_SignS = GR_N_Inc, GR_N_SinCos
2124 fma.s1 FR_corrC = FR_S_1, FR_r_cubed, FR_r // corr = S_1 * r^3 + r
2125 add GR_N_SignC = GR_N_Inc, GR_N_SinCos
2129 ldfe FR_PP_3 = [GR_ad_pp], 16 // Load PP_3
2130 fma.s1 FR_r_hi_sq = FR_r_hi, FR_r_hi, f0 // r_hi_sq = r_hi * r_hi
2131 tbit.z p7,p11 = GR_N_Inc, 0
2134 ldfe FR_QQ_3 = [GR_ad_qq], 16 // Load QQ_3
2135 fms.s1 FR_r_lo = FR_r, f1, FR_r_hi // r_lo = r - r_hi
2140 ldfe FR_PP_2 = [GR_ad_pp], 16 // Load PP_2
2141 fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_5 // poly = rsq*poly+PP_5
2142 (p7) tbit.z.unc p9,p10 = GR_N_SignC, 1
2145 ldfe FR_QQ_2 = [GR_ad_qq], 16 // Load QQ_2
2146 fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_5 // poly = rsq*poly+QQ_5
2151 ldfe FR_PP_1_lo = [GR_ad_pp], 16 // Load PP_1_lo
2152 fma.s1 FR_corrS = FR_corrS, FR_c, FR_c // corr = corr * c + c
2153 (p7) tbit.z.unc p7,p8 = GR_N_SignS, 1
2157 fnma.s1 FR_corrC = FR_corrC, FR_c, f0 // corr = -corr * c
2163 fma.s1 FR_U_loS = FR_r, FR_r_hi, FR_r_hi_sq // U_lo = r*r_hi+r_hi_sq
2164 (p11) tbit.z.unc p13,p14 = GR_N_SignC, 1
2168 fma.s1 FR_U_loC = FR_r_hi, f1, FR_r // U_lo = r_hi + r
2174 fma.s1 FR_U_hiS = FR_r_hi, FR_r_hi_sq, f0 // U_hi = r_hi*r_hi_sq
2175 (p11) tbit.z.unc p11,p12 = GR_N_SignS, 1
2179 fma.s1 FR_U_hiC = FR_QQ_1, FR_r_hi_sq, f1 // U_hi = QQ_1*r_hi_sq+1
2185 fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_4 // poly = poly*rsq+PP_4
2190 fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_4 // poly = poly*rsq+QQ_4
2196 fma.s1 FR_U_loS = FR_r, FR_r, FR_U_loS // U_lo = r * r + U_lo
2201 fma.s1 FR_U_loC = FR_r_lo, FR_U_loC, f0 // U_lo = r_lo * U_lo
2207 fma.s1 FR_U_hiS = FR_PP_1, FR_U_hiS, f0 // U_hi = PP_1 * U_hi
2213 fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_3 // poly = poly*rsq+PP_3
2218 fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_3 // poly = poly*rsq+QQ_3
2224 fma.s1 FR_U_loS = FR_r_lo, FR_U_loS, f0 // U_lo = r_lo * U_lo
2229 fma.s1 FR_U_loC = FR_QQ_1,FR_U_loC, f0 // U_lo = QQ_1 * U_lo
2235 fma.s1 FR_U_hiS = FR_r, f1, FR_U_hiS // U_hi = r + U_hi
2241 fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_2 // poly = poly*rsq+PP_2
2246 fma.s1 FR_polyC = FR_rsq, FR_polyC, FR_QQ_2 // poly = poly*rsq+QQ_2
2252 fma.s1 FR_U_loS = FR_PP_1, FR_U_loS, f0 // U_lo = PP_1 * U_lo
2258 fma.s1 FR_polyS = FR_rsq, FR_polyS, FR_PP_1_lo // poly =poly*rsq+PP1lo
2263 fma.s1 FR_polyC = FR_rsq, FR_polyC, f0 // poly = poly*rsq
2268 .pred.rel "mutex",p8,p14
2271 (p8) fms.s0 FR_U_hiS = f1, f0, FR_U_hiS
2276 (p14) fms.s0 FR_U_hiS = f1, f0, FR_U_hiS
2280 .pred.rel "mutex",p10,p12
2283 (p10) fms.s0 FR_U_hiC = f1, f0, FR_U_hiC
2288 (p12) fms.s0 FR_U_hiC = f1, f0, FR_U_hiC
2295 fma.s1 FR_VS = FR_U_loS, f1, FR_corrS // V = U_lo + corr
2300 fma.s1 FR_VC = FR_U_loC, f1, FR_corrC // V = U_lo + corr
2306 fma.s0 FR_inexact = FR_PP_5, FR_PP_4, f0 // Dummy op to set inexact
2313 fma.s1 FR_polyS = FR_r_cubed, FR_polyS, f0 // poly = poly*r^3
2318 fma.s1 FR_polyC = FR_rsq, FR_polyC, f0 // poly = poly*rsq
2325 fma.s1 FR_VS = FR_polyS, f1, FR_VS // V = poly + V
2330 fma.s1 FR_VC = FR_polyC, f1, FR_VC // V = poly + V
2336 .pred.rel "mutex",p7,p8
2339 (p7) fma.s0 FR_ResultS = FR_U_hiS, f1, FR_VS
2344 (p8) fms.s0 FR_ResultS = FR_U_hiS, f1, FR_VS
2348 .pred.rel "mutex",p9,p10
2351 (p9) fma.s0 FR_ResultC = FR_U_hiC, f1, FR_VC
2356 (p10) fms.s0 FR_ResultC = FR_U_hiC, f1, FR_VC
2362 .pred.rel "mutex",p11,p12
2365 (p11) fma.s0 FR_ResultS = FR_U_hiC, f1, FR_VC
2370 (p12) fms.s0 FR_ResultS = FR_U_hiC, f1, FR_VC
2374 .pred.rel "mutex",p13,p14
2377 (p13) fma.s0 FR_ResultC = FR_U_hiS, f1, FR_VS
2381 cmp.eq p15, p0 = 0x1, GR_Cis
2382 (p14) fms.s0 FR_ResultC = FR_U_hiS, f1, FR_VS
2383 (p15) br.ret.sptk b0
2386 { .mmb // exit for sincosl
2387 stfe [sincos_pResSin] = FR_ResultS
2388 stfe [sincos_pResCos] = FR_ResultC
2400 fmerge.s FR_ResultS = FR_Input_X, FR_Input_X // If sin, result = input
2404 cmp.eq p15, p0 = 0x1, GR_Cis
2405 fma.s0 FR_ResultC = f1, f1, f0 // If cos, result=1.0
2406 (p15) br.ret.sptk b0
2409 { .mmb // exit for sincosl
2410 stfe [sincos_pResSin] = FR_ResultS
2411 stfe [sincos_pResCos] = FR_ResultC
2418 getf.exp GR_signexp_x = FR_norm_x // Get sign and exponent of x
2420 br.cond.sptk SINCOSL_COMMON2 // Return to common code
2427 // Path for Arg = +/- QNaN, SNaN, Inf
2428 // Invalid can be raised. SNaNs
2432 cmp.eq p15, p0 = 0x1, GR_Cis
2433 fmpy.s0 FR_ResultS = FR_Input_X, f0
2438 fmpy.s0 FR_ResultC = FR_Input_X, f0
2439 (p15) br.ret.sptk b0
2442 { .mmb // exit for sincosl
2443 stfe [sincos_pResSin] = FR_ResultS
2444 stfe [sincos_pResCos] = FR_ResultC
2448 GLOBAL_LIBM_END(__libm_sincosl)
2450 // *******************************************************************
2451 // *******************************************************************
2452 // *******************************************************************
2454 // Special Code to handle very large argument case.
2455 // Call int __libm_pi_by_2_reduce(x,r,c) for |arguments| >= 2**63
2456 // The interface is custom:
2458 // (Arg or x) is in f8
2463 // Be sure to allocate at least 2 GP registers as output registers for
2464 // __libm_pi_by_2_reduce. This routine uses r49-50. These are used as
2465 // scratch registers within the __libm_pi_by_2_reduce routine (for speed).
2467 // We know also that __libm_pi_by_2_reduce preserves f10-15, f71-127. We
2468 // use this to eliminate save/restore of key fp registers in this calling
2471 // *******************************************************************
2472 // *******************************************************************
2473 // *******************************************************************
2475 LOCAL_LIBM_ENTRY(__libm_callout)
2476 SINCOSL_ARG_TOO_LARGE:
2480 .save ar.pfs,GR_SAVE_PFS
2481 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
2485 setf.exp FR_Two_to_M3 = GR_exp_2_to_m3 // Form 2^-3
2486 mov GR_SAVE_GP=gp // Save gp
2487 .save b0, GR_SAVE_B0
2488 mov GR_SAVE_B0=b0 // Save b0
2493 // Call argument reduction with x in f8
2494 // Returns with N in r8, r in f8, c in f9
2495 // Assumes f71-127 are preserved across the call
2498 setf.exp FR_Neg_Two_to_M3 = GR_exp_m2_to_m3 // Form -(2^-3)
2500 br.call.sptk b0=__libm_pi_by_2_reduce#
2505 fcmp.lt.unc.s1 p6, p0 = FR_r, FR_Two_to_M3
2506 mov b0 = GR_SAVE_B0 // Restore return address
2510 mov gp = GR_SAVE_GP // Restore gp
2511 (p6) fcmp.gt.unc.s1 p6, p0 = FR_r, FR_Neg_Two_to_M3
2512 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
2517 (p6) br.cond.spnt SINCOSL_SMALL_R // Branch if |r|< 2^-3 for |x| >= 2^63
2518 br.cond.sptk SINCOSL_NORMAL_R // Branch if |r|>=2^-3 for |x| >= 2^63
2521 LOCAL_LIBM_END(__libm_callout)
2523 .type __libm_pi_by_2_reduce#,@function
2524 .global __libm_pi_by_2_reduce#