initial commit
[glibc.git] / sysdeps / ia64 / fpu / s_cosl.S
1 .file "sincosl.s"
2
3
4 // Copyright (c) 2000 - 2004, Intel Corporation
5 // All rights reserved.
6 //
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
18 //
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
21 // permission.
22
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
27 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 // Intel Corporation is the author of this code, and requests that all
36 // problem reports or change requests be submitted to it directly at
37 // http://www.intel.com/software/products/opensource/libraries/num.htm.
38 //
39 //*********************************************************************
40 //
41 // History:
42 // 02/02/00 (hand-optimized)
43 // 04/04/00 Unwind support added
44 // 07/30/01 Improved speed on all paths
45 // 08/20/01 Fixed bundling typo
46 // 05/13/02 Changed interface to __libm_pi_by_2_reduce
47 // 02/10/03 Reordered header: .section, .global, .proc, .align;
48 // used data8 for long double table values
49 // 10/13/03 Corrected final .endp name to match .proc
50 // 10/26/04 Avoided using r14-31 as scratch so not clobbered by dynamic loader
51 //
52 //*********************************************************************
53 //
54 // Function: Combined sinl(x) and cosl(x), where
55 //
56 // sinl(x) = sine(x), for double-extended precision x values
57 // cosl(x) = cosine(x), for double-extended precision x values
58 //
59 //*********************************************************************
60 //
61 // Resources Used:
62 //
63 // Floating-Point Registers: f8 (Input and Return Value)
64 // f32-f99
65 //
66 // General Purpose Registers:
67 // r32-r58
68 //
69 // Predicate Registers: p6-p13
70 //
71 //*********************************************************************
72 //
73 // IEEE Special Conditions:
74 //
75 // Denormal fault raised on denormal inputs
76 // Overflow exceptions do not occur
77 // Underflow exceptions raised when appropriate for sin
78 // (No specialized error handling for this routine)
79 // Inexact raised when appropriate by algorithm
80 //
81 // sinl(SNaN) = QNaN
82 // sinl(QNaN) = QNaN
83 // sinl(inf) = QNaN
84 // sinl(+/-0) = +/-0
85 // cosl(inf) = QNaN
86 // cosl(SNaN) = QNaN
87 // cosl(QNaN) = QNaN
88 // cosl(0) = 1
89 //
90 //*********************************************************************
91 //
92 // Mathematical Description
93 // ========================
94 //
95 // The computation of FSIN and FCOS is best handled in one piece of
96 // code. The main reason is that given any argument Arg, computation
97 // of trigonometric functions first calculate N and an approximation
98 // to alpha where
99 //
100 // Arg = N pi/2 + alpha, |alpha| <= pi/4.
101 //
102 // Since
103 //
104 // cosl( Arg ) = sinl( (N+1) pi/2 + alpha ),
105 //
106 // therefore, the code for computing sine will produce cosine as long
107 // as 1 is added to N immediately after the argument reduction
108 // process.
109 //
110 // Let M = N if sine
111 // N+1 if cosine.
112 //
113 // Now, given
114 //
115 // Arg = M pi/2 + alpha, |alpha| <= pi/4,
116 //
117 // let I = M mod 4, or I be the two lsb of M when M is represented
118 // as 2's complement. I = [i_0 i_1]. Then
119 //
120 // sinl( Arg ) = (-1)^i_0 sinl( alpha ) if i_1 = 0,
121 // = (-1)^i_0 cosl( alpha ) if i_1 = 1.
122 //
123 // For example:
124 // if M = -1, I = 11
125 // sin ((-pi/2 + alpha) = (-1) cos (alpha)
126 // if M = 0, I = 00
127 // sin (alpha) = sin (alpha)
128 // if M = 1, I = 01
129 // sin (pi/2 + alpha) = cos (alpha)
130 // if M = 2, I = 10
131 // sin (pi + alpha) = (-1) sin (alpha)
132 // if M = 3, I = 11
133 // sin ((3/2)pi + alpha) = (-1) cos (alpha)
134 //
135 // The value of alpha is obtained by argument reduction and
136 // represented by two working precision numbers r and c where
137 //
138 // alpha = r + c accurately.
139 //
140 // The reduction method is described in a previous write up.
141 // The argument reduction scheme identifies 4 cases. For Cases 2
142 // and 4, because |alpha| is small, sinl(r+c) and cosl(r+c) can be
143 // computed very easily by 2 or 3 terms of the Taylor series
144 // expansion as follows:
145 //
146 // Case 2:
147 // -------
148 //
149 // sinl(r + c) = r + c - r^3/6 accurately
150 // cosl(r + c) = 1 - 2^(-67) accurately
151 //
152 // Case 4:
153 // -------
154 //
155 // sinl(r + c) = r + c - r^3/6 + r^5/120 accurately
156 // cosl(r + c) = 1 - r^2/2 + r^4/24 accurately
157 //
158 // The only cases left are Cases 1 and 3 of the argument reduction
159 // procedure. These two cases will be merged since after the
160 // argument is reduced in either cases, we have the reduced argument
161 // represented as r + c and that the magnitude |r + c| is not small
162 // enough to allow the usage of a very short approximation.
163 //
164 // The required calculation is either
165 //
166 // sinl(r + c) = sinl(r) + correction, or
167 // cosl(r + c) = cosl(r) + correction.
168 //
169 // Specifically,
170 //
171 // sinl(r + c) = sinl(r) + c sin'(r) + O(c^2)
172 // = sinl(r) + c cos (r) + O(c^2)
173 // = sinl(r) + c(1 - r^2/2) accurately.
174 // Similarly,
175 //
176 // cosl(r + c) = cosl(r) - c sinl(r) + O(c^2)
177 // = cosl(r) - c(r - r^3/6) accurately.
178 //
179 // We therefore concentrate on accurately calculating sinl(r) and
180 // cosl(r) for a working-precision number r, |r| <= pi/4 to within
181 // 0.1% or so.
182 //
183 // The greatest challenge of this task is that the second terms of
184 // the Taylor series
185 //
186 // r - r^3/3! + r^r/5! - ...
187 //
188 // and
189 //
190 // 1 - r^2/2! + r^4/4! - ...
191 //
192 // are not very small when |r| is close to pi/4 and the rounding
193 // errors will be a concern if simple polynomial accumulation is
194 // used. When |r| < 2^-3, however, the second terms will be small
195 // enough (6 bits or so of right shift) that a normal Horner
196 // recurrence suffices. Hence there are two cases that we consider
197 // in the accurate computation of sinl(r) and cosl(r), |r| <= pi/4.
198 //
199 // Case small_r: |r| < 2^(-3)
200 // --------------------------
201 //
202 // Since Arg = M pi/4 + r + c accurately, and M mod 4 is [i_0 i_1],
203 // we have
204 //
205 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
206 // = (-1)^i_0 * cosl(r + c) if i_1 = 1
207 //
208 // can be accurately approximated by
209 //
210 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c] if i_1 = 0
211 // = (-1)^i_0 * [cosl(r) - c*r] if i_1 = 1
212 //
213 // because |r| is small and thus the second terms in the correction
214 // are unnecessary.
215 //
216 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
217 // moderate lengths.
218 //
219 // sinl(r) = r + S_1 r^3 + S_2 r^5 + ... + S_5 r^11
220 // cosl(r) = 1 + C_1 r^2 + C_2 r^4 + ... + C_5 r^10
221 //
222 // We can make use of predicates to selectively calculate
223 // sinl(r) or cosl(r) based on i_1.
224 //
225 // Case normal_r: 2^(-3) <= |r| <= pi/4
226 // ------------------------------------
227 //
228 // This case is more likely than the previous one if one considers
229 // r to be uniformly distributed in [-pi/4 pi/4]. Again,
230 //
231 // sinl(Arg) = (-1)^i_0 * sinl(r + c) if i_1 = 0
232 // = (-1)^i_0 * cosl(r + c) if i_1 = 1.
233 //
234 // Because |r| is now larger, we need one extra term in the
235 // correction. sinl(Arg) can be accurately approximated by
236 //
237 // sinl(Arg) = (-1)^i_0 * [sinl(r) + c(1-r^2/2)] if i_1 = 0
238 // = (-1)^i_0 * [cosl(r) - c*r*(1 - r^2/6)] i_1 = 1.
239 //
240 // Finally, sinl(r) and cosl(r) are approximated by polynomials of
241 // moderate lengths.
242 //
243 // sinl(r) = r + PP_1_hi r^3 + PP_1_lo r^3 +
244 // PP_2 r^5 + ... + PP_8 r^17
245 //
246 // cosl(r) = 1 + QQ_1 r^2 + QQ_2 r^4 + ... + QQ_8 r^16
247 //
248 // where PP_1_hi is only about 16 bits long and QQ_1 is -1/2.
249 // The crux in accurate computation is to calculate
250 //
251 // r + PP_1_hi r^3 or 1 + QQ_1 r^2
252 //
253 // accurately as two pieces: U_hi and U_lo. The way to achieve this
254 // is to obtain r_hi as a 10 sig. bit number that approximates r to
255 // roughly 8 bits or so of accuracy. (One convenient way is
256 //
257 // r_hi := frcpa( frcpa( r ) ).)
258 //
259 // This way,
260 //
261 // r + PP_1_hi r^3 = r + PP_1_hi r_hi^3 +
262 // PP_1_hi (r^3 - r_hi^3)
263 // = [r + PP_1_hi r_hi^3] +
264 // [PP_1_hi (r - r_hi)
265 // (r^2 + r_hi r + r_hi^2) ]
266 // = U_hi + U_lo
267 //
268 // Since r_hi is only 10 bit long and PP_1_hi is only 16 bit long,
269 // PP_1_hi * r_hi^3 is only at most 46 bit long and thus computed
270 // exactly. Furthermore, r and PP_1_hi r_hi^3 are of opposite sign
271 // and that there is no more than 8 bit shift off between r and
272 // PP_1_hi * r_hi^3. Hence the sum, U_hi, is representable and thus
273 // calculated without any error. Finally, the fact that
274 //
275 // |U_lo| <= 2^(-8) |U_hi|
276 //
277 // says that U_hi + U_lo is approximating r + PP_1_hi r^3 to roughly
278 // 8 extra bits of accuracy.
279 //
280 // Similarly,
281 //
282 // 1 + QQ_1 r^2 = [1 + QQ_1 r_hi^2] +
283 // [QQ_1 (r - r_hi)(r + r_hi)]
284 // = U_hi + U_lo.
285 //
286 // Summarizing, we calculate r_hi = frcpa( frcpa( r ) ).
287 //
288 // If i_1 = 0, then
289 //
290 // U_hi := r + PP_1_hi * r_hi^3
291 // U_lo := PP_1_hi * (r - r_hi) * (r^2 + r*r_hi + r_hi^2)
292 // poly := PP_1_lo r^3 + PP_2 r^5 + ... + PP_8 r^17
293 // correction := c * ( 1 + C_1 r^2 )
294 //
295 // Else ...i_1 = 1
296 //
297 // U_hi := 1 + QQ_1 * r_hi * r_hi
298 // U_lo := QQ_1 * (r - r_hi) * (r + r_hi)
299 // poly := QQ_2 * r^4 + QQ_3 * r^6 + ... + QQ_8 r^16
300 // correction := -c * r * (1 + S_1 * r^2)
301 //
302 // End
303 //
304 // Finally,
305 //
306 // V := poly + ( U_lo + correction )
307 //
308 // / U_hi + V if i_0 = 0
309 // result := |
310 // \ (-U_hi) - V if i_0 = 1
311 //
312 // It is important that in the last step, negation of U_hi is
313 // performed prior to the subtraction which is to be performed in
314 // the user-set rounding mode.
315 //
316 //
317 // Algorithmic Description
318 // =======================
319 //
320 // The argument reduction algorithm is tightly integrated into FSIN
321 // and FCOS which share the same code. The following is complete and
322 // self-contained. The argument reduction description given
323 // previously is repeated below.
324 //
325 //
326 // Step 0. Initialization.
327 //
328 // If FSIN is invoked, set N_inc := 0; else if FCOS is invoked,
329 // set N_inc := 1.
330 //
331 // Step 1. Check for exceptional and special cases.
332 //
333 // * If Arg is +-0, +-inf, NaN, NaT, go to Step 10 for special
334 // handling.
335 // * If |Arg| < 2^24, go to Step 2 for reduction of moderate
336 // arguments. This is the most likely case.
337 // * If |Arg| < 2^63, go to Step 8 for pre-reduction of large
338 // arguments.
339 // * If |Arg| >= 2^63, go to Step 10 for special handling.
340 //
341 // Step 2. Reduction of moderate arguments.
342 //
343 // If |Arg| < pi/4 ...quick branch
344 // N_fix := N_inc (integer)
345 // r := Arg
346 // c := 0.0
347 // Branch to Step 4, Case_1_complete
348 // Else ...cf. argument reduction
349 // N := Arg * two_by_PI (fp)
350 // N_fix := fcvt.fx( N ) (int)
351 // N := fcvt.xf( N_fix )
352 // N_fix := N_fix + N_inc
353 // s := Arg - N * P_1 (first piece of pi/2)
354 // w := -N * P_2 (second piece of pi/2)
355 //
356 // If |s| >= 2^(-33)
357 // go to Step 3, Case_1_reduce
358 // Else
359 // go to Step 7, Case_2_reduce
360 // Endif
361 // Endif
362 //
363 // Step 3. Case_1_reduce.
364 //
365 // r := s + w
366 // c := (s - r) + w ...observe order
367 //
368 // Step 4. Case_1_complete
369 //
370 // ...At this point, the reduced argument alpha is
371 // ...accurately represented as r + c.
372 // If |r| < 2^(-3), go to Step 6, small_r.
373 //
374 // Step 5. Normal_r.
375 //
376 // Let [i_0 i_1] by the 2 lsb of N_fix.
377 // FR_rsq := r * r
378 // r_hi := frcpa( frcpa( r ) )
379 // r_lo := r - r_hi
380 //
381 // If i_1 = 0, then
382 // poly := r*FR_rsq*(PP_1_lo + FR_rsq*(PP_2 + ... FR_rsq*PP_8))
383 // U_hi := r + PP_1_hi*r_hi*r_hi*r_hi ...any order
384 // U_lo := PP_1_hi*r_lo*(r*r + r*r_hi + r_hi*r_hi)
385 // correction := c + c*C_1*FR_rsq ...any order
386 // Else
387 // poly := FR_rsq*FR_rsq*(QQ_2 + FR_rsq*(QQ_3 + ... + FR_rsq*QQ_8))
388 // U_hi := 1 + QQ_1 * r_hi * r_hi ...any order
389 // U_lo := QQ_1 * r_lo * (r + r_hi)
390 // correction := -c*(r + S_1*FR_rsq*r) ...any order
391 // Endif
392 //
393 // V := poly + (U_lo + correction) ...observe order
394 //
395 // result := (i_0 == 0? 1.0 : -1.0)
396 //
397 // Last instruction in user-set rounding mode
398 //
399 // result := (i_0 == 0? result*U_hi + V :
400 // result*U_hi - V)
401 //
402 // Return
403 //
404 // Step 6. Small_r.
405 //
406 // ...Use flush to zero mode without causing exception
407 // Let [i_0 i_1] be the two lsb of N_fix.
408 //
409 // FR_rsq := r * r
410 //
411 // If i_1 = 0 then
412 // z := FR_rsq*FR_rsq; z := FR_rsq*z *r
413 // poly_lo := S_3 + FR_rsq*(S_4 + FR_rsq*S_5)
414 // poly_hi := r*FR_rsq*(S_1 + FR_rsq*S_2)
415 // correction := c
416 // result := r
417 // Else
418 // z := FR_rsq*FR_rsq; z := FR_rsq*z
419 // poly_lo := C_3 + FR_rsq*(C_4 + FR_rsq*C_5)
420 // poly_hi := FR_rsq*(C_1 + FR_rsq*C_2)
421 // correction := -c*r
422 // result := 1
423 // Endif
424 //
425 // poly := poly_hi + (z * poly_lo + correction)
426 //
427 // If i_0 = 1, result := -result
428 //
429 // Last operation. Perform in user-set rounding mode
430 //
431 // result := (i_0 == 0? result + poly :
432 // result - poly )
433 // Return
434 //
435 // Step 7. Case_2_reduce.
436 //
437 // ...Refer to the write up for argument reduction for
438 // ...rationale. The reduction algorithm below is taken from
439 // ...argument reduction description and integrated this.
440 //
441 // w := N*P_3
442 // U_1 := N*P_2 + w ...FMA
443 // U_2 := (N*P_2 - U_1) + w ...2 FMA
444 // ...U_1 + U_2 is N*(P_2+P_3) accurately
445 //
446 // r := s - U_1
447 // c := ( (s - r) - U_1 ) - U_2
448 //
449 // ...The mathematical sum r + c approximates the reduced
450 // ...argument accurately. Note that although compared to
451 // ...Case 1, this case requires much more work to reduce
452 // ...the argument, the subsequent calculation needed for
453 // ...any of the trigonometric function is very little because
454 // ...|alpha| < 1.01*2^(-33) and thus two terms of the
455 // ...Taylor series expansion suffices.
456 //
457 // If i_1 = 0 then
458 // poly := c + S_1 * r * r * r ...any order
459 // result := r
460 // Else
461 // poly := -2^(-67)
462 // result := 1.0
463 // Endif
464 //
465 // If i_0 = 1, result := -result
466 //
467 // Last operation. Perform in user-set rounding mode
468 //
469 // result := (i_0 == 0? result + poly :
470 // result - poly )
471 //
472 // Return
473 //
474 //
475 // Step 8. Pre-reduction of large arguments.
476 //
477 // ...Again, the following reduction procedure was described
478 // ...in the separate write up for argument reduction, which
479 // ...is tightly integrated here.
480
481 // N_0 := Arg * Inv_P_0
482 // N_0_fix := fcvt.fx( N_0 )
483 // N_0 := fcvt.xf( N_0_fix)
484
485 // Arg' := Arg - N_0 * P_0
486 // w := N_0 * d_1
487 // N := Arg' * two_by_PI
488 // N_fix := fcvt.fx( N )
489 // N := fcvt.xf( N_fix )
490 // N_fix := N_fix + N_inc
491 //
492 // s := Arg' - N * P_1
493 // w := w - N * P_2
494 //
495 // If |s| >= 2^(-14)
496 // go to Step 3
497 // Else
498 // go to Step 9
499 // Endif
500 //
501 // Step 9. Case_4_reduce.
502 //
503 // ...first obtain N_0*d_1 and -N*P_2 accurately
504 // U_hi := N_0 * d_1 V_hi := -N*P_2
505 // U_lo := N_0 * d_1 - U_hi V_lo := -N*P_2 - U_hi ...FMAs
506 //
507 // ...compute the contribution from N_0*d_1 and -N*P_3
508 // w := -N*P_3
509 // w := w + N_0*d_2
510 // t := U_lo + V_lo + w ...any order
511 //
512 // ...at this point, the mathematical value
513 // ...s + U_hi + V_hi + t approximates the true reduced argument
514 // ...accurately. Just need to compute this accurately.
515 //
516 // ...Calculate U_hi + V_hi accurately:
517 // A := U_hi + V_hi
518 // if |U_hi| >= |V_hi| then
519 // a := (U_hi - A) + V_hi
520 // else
521 // a := (V_hi - A) + U_hi
522 // endif
523 // ...order in computing "a" must be observed. This branch is
524 // ...best implemented by predicates.
525 // ...A + a is U_hi + V_hi accurately. Moreover, "a" is
526 // ...much smaller than A: |a| <= (1/2)ulp(A).
527 //
528 // ...Just need to calculate s + A + a + t
529 // C_hi := s + A t := t + a
530 // C_lo := (s - C_hi) + A
531 // C_lo := C_lo + t
532 //
533 // ...Final steps for reduction
534 // r := C_hi + C_lo
535 // c := (C_hi - r) + C_lo
536 //
537 // ...At this point, we have r and c
538 // ...And all we need is a couple of terms of the corresponding
539 // ...Taylor series.
540 //
541 // If i_1 = 0
542 // poly := c + r*FR_rsq*(S_1 + FR_rsq*S_2)
543 // result := r
544 // Else
545 // poly := FR_rsq*(C_1 + FR_rsq*C_2)
546 // result := 1
547 // Endif
548 //
549 // If i_0 = 1, result := -result
550 //
551 // Last operation. Perform in user-set rounding mode
552 //
553 // result := (i_0 == 0? result + poly :
554 // result - poly )
555 // Return
556 //
557 // Large Arguments: For arguments above 2**63, a Payne-Hanek
558 // style argument reduction is used and pi_by_2 reduce is called.
559 //
560
561
562 RODATA
563 .align 16
564
565 LOCAL_OBJECT_START(FSINCOSL_CONSTANTS)
566
567 sincosl_table_p:
568 data8 0xA2F9836E4E44152A, 0x00003FFE // Inv_pi_by_2
569 data8 0xC84D32B0CE81B9F1, 0x00004016 // P_0
570 data8 0xC90FDAA22168C235, 0x00003FFF // P_1
571 data8 0xECE675D1FC8F8CBB, 0x0000BFBD // P_2
572 data8 0xB7ED8FBBACC19C60, 0x0000BF7C // P_3
573 data8 0x8D848E89DBD171A1, 0x0000BFBF // d_1
574 data8 0xD5394C3618A66F8E, 0x0000BF7C // d_2
575 LOCAL_OBJECT_END(FSINCOSL_CONSTANTS)
576
577 LOCAL_OBJECT_START(sincosl_table_d)
578 data8 0xC90FDAA22168C234, 0x00003FFE // pi_by_4
579 data8 0xA397E5046EC6B45A, 0x00003FE7 // Inv_P_0
580 data4 0x3E000000, 0xBE000000 // 2^-3 and -2^-3
581 data4 0x2F000000, 0xAF000000 // 2^-33 and -2^-33
582 data4 0x9E000000, 0x00000000 // -2^-67
583 data4 0x00000000, 0x00000000 // pad
584 LOCAL_OBJECT_END(sincosl_table_d)
585
586 LOCAL_OBJECT_START(sincosl_table_pp)
587 data8 0xCC8ABEBCA21C0BC9, 0x00003FCE // PP_8
588 data8 0xD7468A05720221DA, 0x0000BFD6 // PP_7
589 data8 0xB092382F640AD517, 0x00003FDE // PP_6
590 data8 0xD7322B47D1EB75A4, 0x0000BFE5 // PP_5
591 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
592 data8 0xAAAA000000000000, 0x0000BFFC // PP_1_hi
593 data8 0xB8EF1D2ABAF69EEA, 0x00003FEC // PP_4
594 data8 0xD00D00D00D03BB69, 0x0000BFF2 // PP_3
595 data8 0x8888888888888962, 0x00003FF8 // PP_2
596 data8 0xAAAAAAAAAAAB0000, 0x0000BFEC // PP_1_lo
597 LOCAL_OBJECT_END(sincosl_table_pp)
598
599 LOCAL_OBJECT_START(sincosl_table_qq)
600 data8 0xD56232EFC2B0FE52, 0x00003FD2 // QQ_8
601 data8 0xC9C99ABA2B48DCA6, 0x0000BFDA // QQ_7
602 data8 0x8F76C6509C716658, 0x00003FE2 // QQ_6
603 data8 0x93F27DBAFDA8D0FC, 0x0000BFE9 // QQ_5
604 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
605 data8 0x8000000000000000, 0x0000BFFE // QQ_1
606 data8 0xD00D00D00C6E5041, 0x00003FEF // QQ_4
607 data8 0xB60B60B60B607F60, 0x0000BFF5 // QQ_3
608 data8 0xAAAAAAAAAAAAAA9B, 0x00003FFA // QQ_2
609 LOCAL_OBJECT_END(sincosl_table_qq)
610
611 LOCAL_OBJECT_START(sincosl_table_c)
612 data8 0xFFFFFFFFFFFFFFFE, 0x0000BFFD // C_1
613 data8 0xAAAAAAAAAAAA719F, 0x00003FFA // C_2
614 data8 0xB60B60B60356F994, 0x0000BFF5 // C_3
615 data8 0xD00CFFD5B2385EA9, 0x00003FEF // C_4
616 data8 0x93E4BD18292A14CD, 0x0000BFE9 // C_5
617 LOCAL_OBJECT_END(sincosl_table_c)
618
619 LOCAL_OBJECT_START(sincosl_table_s)
620 data8 0xAAAAAAAAAAAAAAAA, 0x0000BFFC // S_1
621 data8 0x88888888888868DB, 0x00003FF8 // S_2
622 data8 0xD00D00D0055EFD4B, 0x0000BFF2 // S_3
623 data8 0xB8EF1C5D839730B9, 0x00003FEC // S_4
624 data8 0xD71EA3A4E5B3F492, 0x0000BFE5 // S_5
625 data4 0x38800000, 0xB8800000 // two**-14 and -two**-14
626 LOCAL_OBJECT_END(sincosl_table_s)
627
628 FR_Input_X = f8
629 FR_Result = f8
630
631 FR_r = f8
632 FR_c = f9
633
634 FR_norm_x = f9
635 FR_inv_pi_2to63 = f10
636 FR_rshf_2to64 = f11
637 FR_2tom64 = f12
638 FR_rshf = f13
639 FR_N_float_signif = f14
640 FR_abs_x = f15
641 FR_Pi_by_4 = f34
642 FR_Two_to_M14 = f35
643 FR_Neg_Two_to_M14 = f36
644 FR_Two_to_M33 = f37
645 FR_Neg_Two_to_M33 = f38
646 FR_Neg_Two_to_M67 = f39
647 FR_Inv_pi_by_2 = f40
648 FR_N_float = f41
649 FR_N_fix = f42
650 FR_P_1 = f43
651 FR_P_2 = f44
652 FR_P_3 = f45
653 FR_s = f46
654 FR_w = f47
655 FR_d_2 = f48
656 FR_tmp_result = f49
657 FR_Z = f50
658 FR_A = f51
659 FR_a = f52
660 FR_t = f53
661 FR_U_1 = f54
662 FR_U_2 = f55
663 FR_C_1 = f56
664 FR_C_2 = f57
665 FR_C_3 = f58
666 FR_C_4 = f59
667 FR_C_5 = f60
668 FR_S_1 = f61
669 FR_S_2 = f62
670 FR_S_3 = f63
671 FR_S_4 = f64
672 FR_S_5 = f65
673 FR_poly_hi = f66
674 FR_poly_lo = f67
675 FR_r_hi = f68
676 FR_r_lo = f69
677 FR_rsq = f70
678 FR_r_cubed = f71
679 FR_C_hi = f72
680 FR_N_0 = f73
681 FR_d_1 = f74
682 FR_V = f75
683 FR_V_hi = f75
684 FR_V_lo = f76
685 FR_U_hi = f77
686 FR_U_lo = f78
687 FR_U_hiabs = f79
688 FR_V_hiabs = f80
689 FR_PP_8 = f81
690 FR_QQ_8 = f101
691 FR_PP_7 = f82
692 FR_QQ_7 = f102
693 FR_PP_6 = f83
694 FR_QQ_6 = f103
695 FR_PP_5 = f84
696 FR_QQ_5 = f104
697 FR_PP_4 = f85
698 FR_QQ_4 = f105
699 FR_PP_3 = f86
700 FR_QQ_3 = f106
701 FR_PP_2 = f87
702 FR_QQ_2 = f107
703 FR_QQ_1 = f108
704 FR_r_hi_sq = f88
705 FR_N_0_fix = f89
706 FR_Inv_P_0 = f90
707 FR_corr = f91
708 FR_poly = f92
709 FR_Neg_Two_to_M3 = f93
710 FR_Two_to_M3 = f94
711 FR_P_0 = f95
712 FR_C_lo = f96
713 FR_PP_1 = f97
714 FR_PP_1_lo = f98
715 FR_ArgPrime = f99
716 FR_inexact = f100
717
718 GR_exp_m2_to_m3= r36
719 GR_N_Inc = r37
720 GR_Sin_or_Cos = r38
721 GR_signexp_x = r40
722 GR_exp_x = r40
723 GR_exp_mask = r41
724 GR_exp_2_to_63 = r42
725 GR_exp_2_to_m3 = r43
726 GR_exp_2_to_24 = r44
727
728 GR_sig_inv_pi = r45
729 GR_rshf_2to64 = r46
730 GR_exp_2tom64 = r47
731 GR_rshf = r48
732 GR_ad_p = r49
733 GR_ad_d = r50
734 GR_ad_pp = r51
735 GR_ad_qq = r52
736 GR_ad_c = r53
737 GR_ad_s = r54
738 GR_ad_ce = r55
739 GR_ad_se = r56
740 GR_ad_m14 = r57
741 GR_ad_s1 = r58
742
743 // Added for unwind support
744
745 GR_SAVE_B0 = r39
746 GR_SAVE_GP = r40
747 GR_SAVE_PFS = r41
748
749
750 .section .text
751
752 GLOBAL_IEEE754_ENTRY(sinl)
753 { .mlx
754 alloc r32 = ar.pfs,0,27,2,0
755 movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
756 }
757 { .mlx
758 mov GR_Sin_or_Cos = 0x0
759 movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
760 }
761 ;;
762
763 { .mfi
764 addl GR_ad_p = @ltoff(FSINCOSL_CONSTANTS#), gp
765 fclass.m p6, p0 = FR_Input_X, 0x1E3 // Test x natval, nan, inf
766 mov GR_exp_2_to_m3 = 0xffff - 3 // Exponent of 2^-3
767 }
768 { .mfb
769 nop.m 999
770 fnorm.s1 FR_norm_x = FR_Input_X // Normalize x
771 br.cond.sptk SINCOSL_CONTINUE
772 }
773 ;;
774
775 GLOBAL_IEEE754_END(sinl)
776 libm_alias_ldouble_other (__sin, sin)
777
778 GLOBAL_IEEE754_ENTRY(cosl)
779 { .mlx
780 alloc r32 = ar.pfs,0,27,2,0
781 movl GR_sig_inv_pi = 0xa2f9836e4e44152a // significand of 1/pi
782 }
783 { .mlx
784 mov GR_Sin_or_Cos = 0x1
785 movl GR_rshf_2to64 = 0x47e8000000000000 // 1.1000 2^(63+64)
786 }
787 ;;
788
789 { .mfi
790 addl GR_ad_p = @ltoff(FSINCOSL_CONSTANTS#), gp
791 fclass.m p6, p0 = FR_Input_X, 0x1E3 // Test x natval, nan, inf
792 mov GR_exp_2_to_m3 = 0xffff - 3 // Exponent of 2^-3
793 }
794 { .mfi
795 nop.m 999
796 fnorm.s1 FR_norm_x = FR_Input_X // Normalize x
797 nop.i 999
798 }
799 ;;
800
801 SINCOSL_CONTINUE:
802 { .mfi
803 setf.sig FR_inv_pi_2to63 = GR_sig_inv_pi // Form 1/pi * 2^63
804 nop.f 999
805 mov GR_exp_2tom64 = 0xffff - 64 // Scaling constant to compute N
806 }
807 { .mlx
808 setf.d FR_rshf_2to64 = GR_rshf_2to64 // Form const 1.1000 * 2^(63+64)
809 movl GR_rshf = 0x43e8000000000000 // Form const 1.1000 * 2^63
810 }
811 ;;
812
813 { .mfi
814 ld8 GR_ad_p = [GR_ad_p] // Point to Inv_pi_by_2
815 fclass.m p7, p0 = FR_Input_X, 0x0b // Test x denormal
816 nop.i 999
817 }
818 ;;
819
820 { .mfi
821 getf.exp GR_signexp_x = FR_Input_X // Get sign and exponent of x
822 fclass.m p10, p0 = FR_Input_X, 0x007 // Test x zero
823 nop.i 999
824 }
825 { .mib
826 mov GR_exp_mask = 0x1ffff // Exponent mask
827 nop.i 999
828 (p6) br.cond.spnt SINCOSL_SPECIAL // Branch if x natval, nan, inf
829 }
830 ;;
831
832 { .mfi
833 setf.exp FR_2tom64 = GR_exp_2tom64 // Form 2^-64 for scaling N_float
834 nop.f 0
835 add GR_ad_d = 0x70, GR_ad_p // Point to constant table d
836 }
837 { .mib
838 setf.d FR_rshf = GR_rshf // Form right shift const 1.1000 * 2^63
839 mov GR_exp_m2_to_m3 = 0x2fffc // Form -(2^-3)
840 (p7) br.cond.spnt SINCOSL_DENORMAL // Branch if x denormal
841 }
842 ;;
843
844 SINCOSL_COMMON:
845 { .mfi
846 and GR_exp_x = GR_exp_mask, GR_signexp_x // Get exponent of x
847 fclass.nm p8, p0 = FR_Input_X, 0x1FF // Test x unsupported type
848 mov GR_exp_2_to_63 = 0xffff + 63 // Exponent of 2^63
849 }
850 { .mib
851 add GR_ad_pp = 0x40, GR_ad_d // Point to constant table pp
852 mov GR_exp_2_to_24 = 0xffff + 24 // Exponent of 2^24
853 (p10) br.cond.spnt SINCOSL_ZERO // Branch if x zero
854 }
855 ;;
856
857 { .mfi
858 ldfe FR_Inv_pi_by_2 = [GR_ad_p], 16 // Load 2/pi
859 fcmp.eq.s0 p15, p0 = FR_Input_X, f0 // Dummy to set denormal
860 add GR_ad_qq = 0xa0, GR_ad_pp // Point to constant table qq
861 }
862 { .mfi
863 ldfe FR_Pi_by_4 = [GR_ad_d], 16 // Load pi/4 for range test
864 nop.f 999
865 cmp.ge p10,p0 = GR_exp_x, GR_exp_2_to_63 // Is |x| >= 2^63
866 }
867 ;;
868
869 { .mfi
870 ldfe FR_P_0 = [GR_ad_p], 16 // Load P_0 for pi/4 <= |x| < 2^63
871 fmerge.s FR_abs_x = f1, FR_norm_x // |x|
872 add GR_ad_c = 0x90, GR_ad_qq // Point to constant table c
873 }
874 { .mfi
875 ldfe FR_Inv_P_0 = [GR_ad_d], 16 // Load 1/P_0 for pi/4 <= |x| < 2^63
876 nop.f 999
877 cmp.ge p7,p0 = GR_exp_x, GR_exp_2_to_24 // Is |x| >= 2^24
878 }
879 ;;
880
881 { .mfi
882 ldfe FR_P_1 = [GR_ad_p], 16 // Load P_1 for pi/4 <= |x| < 2^63
883 nop.f 999
884 add GR_ad_s = 0x50, GR_ad_c // Point to constant table s
885 }
886 { .mfi
887 ldfe FR_PP_8 = [GR_ad_pp], 16 // Load PP_8 for 2^-3 < |r| < pi/4
888 nop.f 999
889 nop.i 999
890 }
891 ;;
892
893 { .mfi
894 ldfe FR_P_2 = [GR_ad_p], 16 // Load P_2 for pi/4 <= |x| < 2^63
895 nop.f 999
896 add GR_ad_ce = 0x40, GR_ad_c // Point to end of constant table c
897 }
898 { .mfi
899 ldfe FR_QQ_8 = [GR_ad_qq], 16 // Load QQ_8 for 2^-3 < |r| < pi/4
900 nop.f 999
901 nop.i 999
902 }
903 ;;
904
905 { .mfi
906 ldfe FR_QQ_7 = [GR_ad_qq], 16 // Load QQ_7 for 2^-3 < |r| < pi/4
907 fma.s1 FR_N_float_signif = FR_Input_X, FR_inv_pi_2to63, FR_rshf_2to64
908 add GR_ad_se = 0x40, GR_ad_s // Point to end of constant table s
909 }
910 { .mib
911 ldfe FR_PP_7 = [GR_ad_pp], 16 // Load PP_7 for 2^-3 < |r| < pi/4
912 mov GR_ad_s1 = GR_ad_s // Save pointer to S_1
913 (p10) br.cond.spnt SINCOSL_ARG_TOO_LARGE // Branch if |x| >= 2^63
914 // Use Payne-Hanek Reduction
915 }
916 ;;
917
918 { .mfi
919 ldfe FR_P_3 = [GR_ad_p], 16 // Load P_3 for pi/4 <= |x| < 2^63
920 fmerge.se FR_r = FR_norm_x, FR_norm_x // r = x, in case |x| < pi/4
921 add GR_ad_m14 = 0x50, GR_ad_s // Point to constant table m14
922 }
923 { .mfb
924 ldfps FR_Two_to_M3, FR_Neg_Two_to_M3 = [GR_ad_d], 8
925 fma.s1 FR_rsq = FR_norm_x, FR_norm_x, f0 // rsq = x*x, in case |x| < pi/4
926 (p7) br.cond.spnt SINCOSL_LARGER_ARG // Branch if 2^24 <= |x| < 2^63
927 // Use pre-reduction
928 }
929 ;;
930
931 { .mmf
932 ldfe FR_PP_6 = [GR_ad_pp], 16 // Load PP_6 for normal path
933 ldfe FR_QQ_6 = [GR_ad_qq], 16 // Load QQ_6 for normal path
934 fmerge.se FR_c = f0, f0 // c = 0 in case |x| < pi/4
935 }
936 ;;
937
938 { .mmf
939 ldfe FR_PP_5 = [GR_ad_pp], 16 // Load PP_5 for normal path
940 ldfe FR_QQ_5 = [GR_ad_qq], 16 // Load QQ_5 for normal path
941 nop.f 999
942 }
943 ;;
944
945 // Here if 0 < |x| < 2^24
946 { .mfi
947 ldfe FR_S_5 = [GR_ad_se], -16 // Load S_5 if i_1=0
948 fcmp.lt.s1 p6, p7 = FR_abs_x, FR_Pi_by_4 // Test |x| < pi/4
949 nop.i 999
950 }
951 { .mfi
952 ldfe FR_C_5 = [GR_ad_ce], -16 // Load C_5 if i_1=1
953 fms.s1 FR_N_float = FR_N_float_signif, FR_2tom64, FR_rshf
954 nop.i 999
955 }
956 ;;
957
958 { .mmi
959 ldfe FR_S_4 = [GR_ad_se], -16 // Load S_4 if i_1=0
960 ldfe FR_C_4 = [GR_ad_ce], -16 // Load C_4 if i_1=1
961 nop.i 999
962 }
963 ;;
964
965 //
966 // N = Arg * 2/pi
967 // Check if Arg < pi/4
968 //
969 //
970 // Case 2: Convert integer N_fix back to normalized floating-point value.
971 // Case 1: p8 is only affected when p6 is set
972 //
973 //
974 // Grab the integer part of N and call it N_fix
975 //
976 { .mfi
977 (p7) ldfps FR_Two_to_M33, FR_Neg_Two_to_M33 = [GR_ad_d], 8
978 (p6) fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // r^3 if |x| < pi/4
979 (p6) mov GR_N_Inc = GR_Sin_or_Cos // N_Inc if |x| < pi/4
980 }
981 ;;
982
983 // If |x| < pi/4, r = x and c = 0
984 // lf |x| < pi/4, is x < 2**(-3).
985 // r = Arg
986 // c = 0
987 { .mmi
988 (p7) getf.sig GR_N_Inc = FR_N_float_signif
989 (p6) cmp.lt.unc p8,p0 = GR_exp_x, GR_exp_2_to_m3 // Is |x| < 2^-3
990 (p6) tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
991 // p10 if i_1=1, N mod 4 = 2,3
992 }
993 ;;
994
995 //
996 // lf |x| < pi/4, is -2**(-3)< x < 2**(-3) - set p8.
997 // If |x| >= pi/4,
998 // Create the right N for |x| < pi/4 and otherwise
999 // Case 2: Place integer part of N in GP register
1000 //
1001
1002
1003 { .mbb
1004 nop.m 999
1005 (p8) br.cond.spnt SINCOSL_SMALL_R_0 // Branch if 0 < |x| < 2^-3
1006 (p6) br.cond.spnt SINCOSL_NORMAL_R_0 // Branch if 2^-3 <= |x| < pi/4
1007 }
1008 ;;
1009
1010 // Here if pi/4 <= |x| < 2^24
1011 { .mfi
1012 ldfs FR_Neg_Two_to_M67 = [GR_ad_d], 8 // Load -2^-67
1013 fnma.s1 FR_s = FR_N_float, FR_P_1, FR_Input_X // s = -N * P_1 + Arg
1014 add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos // Adjust N_Inc for sin/cos
1015 }
1016 { .mfi
1017 nop.m 999
1018 fma.s1 FR_w = FR_N_float, FR_P_2, f0 // w = N * P_2
1019 nop.i 999
1020 }
1021 ;;
1022
1023 { .mfi
1024 nop.m 999
1025 fms.s1 FR_r = FR_s, f1, FR_w // r = s - w, assume |s| >= 2^-33
1026 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1027 // p10 if i_1=1, N mod 4 = 2,3
1028 }
1029 ;;
1030
1031 { .mfi
1032 nop.m 999
1033 fcmp.lt.s1 p7, p6 = FR_s, FR_Two_to_M33
1034 nop.i 999
1035 }
1036 ;;
1037
1038 { .mfi
1039 nop.m 999
1040 (p7) fcmp.gt.s1 p7, p6 = FR_s, FR_Neg_Two_to_M33 // p6 if |s| >= 2^-33, else p7
1041 nop.i 999
1042 }
1043 ;;
1044
1045 { .mfi
1046 nop.m 999
1047 fms.s1 FR_c = FR_s, f1, FR_r // c = s - r, for |s| >= 2^-33
1048 nop.i 999
1049 }
1050 { .mfi
1051 nop.m 999
1052 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r, for |s| >= 2^-33
1053 nop.i 999
1054 }
1055 ;;
1056
1057 { .mfi
1058 nop.m 999
1059 (p7) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1060 nop.i 999
1061 }
1062 ;;
1063
1064 { .mmf
1065 (p9) ldfe FR_C_1 = [GR_ad_pp], 16 // Load C_1 if i_1=0
1066 (p10) ldfe FR_S_1 = [GR_ad_qq], 16 // Load S_1 if i_1=1
1067 frcpa.s1 FR_r_hi, p15 = f1, FR_r // r_hi = frcpa(r)
1068 }
1069 ;;
1070
1071 { .mfi
1072 nop.m 999
1073 (p6) fcmp.lt.unc.s1 p8, p13 = FR_r, FR_Two_to_M3 // If big s, test r with 2^-3
1074 nop.i 999
1075 }
1076 ;;
1077
1078 { .mfi
1079 nop.m 999
1080 (p7) fma.s1 FR_U_1 = FR_N_float, FR_P_2, FR_w
1081 nop.i 999
1082 }
1083 ;;
1084
1085 //
1086 // For big s: r = s - w: No futher reduction is necessary
1087 // For small s: w = N * P_3 (change sign) More reduction
1088 //
1089 { .mfi
1090 nop.m 999
1091 (p8) fcmp.gt.s1 p8, p13 = FR_r, FR_Neg_Two_to_M3 // If big s, p8 if |r| < 2^-3
1092 nop.i 999 ;;
1093 }
1094
1095 { .mfi
1096 nop.m 999
1097 (p9) fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7 if i_1=0
1098 nop.i 999
1099 }
1100 { .mfi
1101 nop.m 999
1102 (p10) fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7 if i_1=1
1103 nop.i 999
1104 }
1105 ;;
1106
1107 { .mfi
1108 nop.m 999
1109 (p7) fms.s1 FR_r = FR_s, f1, FR_U_1
1110 nop.i 999
1111 }
1112 ;;
1113
1114 { .mfi
1115 nop.m 999
1116 (p6) fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // rcubed = r * rsq
1117 nop.i 999
1118 }
1119 ;;
1120
1121 { .mfi
1122 //
1123 // For big s: Is |r| < 2**(-3)?
1124 // For big s: c = S - r
1125 // For small s: U_1 = N * P_2 + w
1126 //
1127 // If p8 is set, prepare to branch to Small_R.
1128 // If p9 is set, prepare to branch to Normal_R.
1129 // For big s, r is complete here.
1130 //
1131 //
1132 // For big s: c = c + w (w has not been negated.)
1133 // For small s: r = S - U_1
1134 //
1135 nop.m 999
1136 (p6) fms.s1 FR_c = FR_c, f1, FR_w
1137 nop.i 999
1138 }
1139 { .mbb
1140 nop.m 999
1141 (p8) br.cond.spnt SINCOSL_SMALL_R_1 // Branch if |s|>=2^-33, |r| < 2^-3,
1142 // and pi/4 <= |x| < 2^24
1143 (p13) br.cond.sptk SINCOSL_NORMAL_R_1 // Branch if |s|>=2^-33, |r| >= 2^-3,
1144 // and pi/4 <= |x| < 2^24
1145 }
1146 ;;
1147
1148 SINCOSL_S_TINY:
1149 //
1150 // Here if |s| < 2^-33, and pi/4 <= |x| < 2^24
1151 //
1152 { .mfi
1153 fms.s1 FR_U_2 = FR_N_float, FR_P_2, FR_U_1
1154 //
1155 // c = S - U_1
1156 // r = S_1 * r
1157 //
1158 //
1159 }
1160 ;;
1161
1162 { .mmi
1163 nop.m 999
1164 //
1165 // Get [i_0,i_1] - two lsb of N_fix_gr.
1166 // Do dummy fmpy so inexact is always set.
1167 //
1168 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1169 // p10 if i_1=1, N mod 4 = 2,3
1170 }
1171 ;;
1172
1173 //
1174 // For small s: U_2 = N * P_2 - U_1
1175 // S_1 stored constant - grab the one stored with the
1176 // coefficients.
1177 //
1178 { .mfi
1179 ldfe FR_S_1 = [GR_ad_s1], 16
1180 //
1181 // Check if i_1 and i_0 != 0
1182 //
1183 (p10) fma.s1 FR_poly = f0, f1, FR_Neg_Two_to_M67
1184 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
1185 // p12 if i_0=1, N mod 4 = 1,3
1186 }
1187 ;;
1188
1189 { .mfi
1190 nop.m 999
1191 fms.s1 FR_s = FR_s, f1, FR_r
1192 nop.i 999
1193 }
1194 { .mfi
1195 nop.m 999
1196 //
1197 // S = S - r
1198 // U_2 = U_2 + w
1199 // load S_1
1200 //
1201 fma.s1 FR_rsq = FR_r, FR_r, f0
1202 nop.i 999 ;;
1203 }
1204 { .mfi
1205 nop.m 999
1206 fma.s1 FR_U_2 = FR_U_2, f1, FR_w
1207 nop.i 999
1208 }
1209 { .mfi
1210 nop.m 999
1211 fmerge.se FR_tmp_result = FR_r, FR_r
1212 nop.i 999 ;;
1213 }
1214 { .mfi
1215 nop.m 999
1216 (p10) fma.s1 FR_tmp_result = f0, f1, f1
1217 nop.i 999 ;;
1218 }
1219 { .mfi
1220 nop.m 999
1221 //
1222 // FR_rsq = r * r
1223 // Save r as the result.
1224 //
1225 fms.s1 FR_c = FR_s, f1, FR_U_1
1226 nop.i 999 ;;
1227 }
1228 { .mfi
1229 nop.m 999
1230 //
1231 // if ( i_1 ==0) poly = c + S_1*r*r*r
1232 // else Result = 1
1233 //
1234 (p12) fnma.s1 FR_tmp_result = FR_tmp_result, f1, f0
1235 nop.i 999
1236 }
1237 { .mfi
1238 nop.m 999
1239 fma.s1 FR_r = FR_S_1, FR_r, f0
1240 nop.i 999 ;;
1241 }
1242 { .mfi
1243 nop.m 999
1244 fma.s0 FR_S_1 = FR_S_1, FR_S_1, f0
1245 nop.i 999 ;;
1246 }
1247 { .mfi
1248 nop.m 999
1249 //
1250 // If i_1 != 0, poly = 2**(-67)
1251 //
1252 fms.s1 FR_c = FR_c, f1, FR_U_2
1253 nop.i 999 ;;
1254 }
1255 { .mfi
1256 nop.m 999
1257 //
1258 // c = c - U_2
1259 //
1260 (p9) fma.s1 FR_poly = FR_r, FR_rsq, FR_c
1261 nop.i 999 ;;
1262 }
1263 { .mfi
1264 nop.m 999
1265 //
1266 // i_0 != 0, so Result = -Result
1267 //
1268 (p11) fma.s0 FR_Result = FR_tmp_result, f1, FR_poly
1269 nop.i 999 ;;
1270 }
1271 { .mfb
1272 nop.m 999
1273 (p12) fms.s0 FR_Result = FR_tmp_result, f1, FR_poly
1274 //
1275 // if (i_0 == 0), Result = Result + poly
1276 // else Result = Result - poly
1277 //
1278 br.ret.sptk b0 // Exit if |s| < 2^-33, and pi/4 <= |x| < 2^24
1279 }
1280 ;;
1281
1282 SINCOSL_LARGER_ARG:
1283 //
1284 // Here if 2^24 <= |x| < 2^63
1285 //
1286 { .mfi
1287 ldfe FR_d_1 = [GR_ad_p], 16 // Load d_1 for |x| >= 2^24 path
1288 fma.s1 FR_N_0 = FR_Input_X, FR_Inv_P_0, f0
1289 nop.i 999
1290 }
1291 ;;
1292
1293 //
1294 // N_0 = Arg * Inv_P_0
1295 //
1296 // Load values 2**(-14) and -2**(-14)
1297 { .mmi
1298 ldfps FR_Two_to_M14, FR_Neg_Two_to_M14 = [GR_ad_m14]
1299 nop.i 999 ;;
1300 }
1301 { .mfi
1302 ldfe FR_d_2 = [GR_ad_p], 16 // Load d_2 for |x| >= 2^24 path
1303 nop.f 999
1304 nop.i 999 ;;
1305 }
1306 { .mfi
1307 nop.m 999
1308 //
1309 //
1310 fcvt.fx.s1 FR_N_0_fix = FR_N_0
1311 nop.i 999 ;;
1312 }
1313 { .mfi
1314 nop.m 999
1315 //
1316 // N_0_fix = integer part of N_0
1317 //
1318 fcvt.xf FR_N_0 = FR_N_0_fix
1319 nop.i 999 ;;
1320 }
1321 { .mfi
1322 nop.m 999
1323 //
1324 // Make N_0 the integer part
1325 //
1326 fnma.s1 FR_ArgPrime = FR_N_0, FR_P_0, FR_Input_X
1327 nop.i 999
1328 }
1329 { .mfi
1330 nop.m 999
1331 fma.s1 FR_w = FR_N_0, FR_d_1, f0
1332 nop.i 999 ;;
1333 }
1334 { .mfi
1335 nop.m 999
1336 //
1337 // Arg' = -N_0 * P_0 + Arg
1338 // w = N_0 * d_1
1339 //
1340 fma.s1 FR_N_float = FR_ArgPrime, FR_Inv_pi_by_2, f0
1341 nop.i 999 ;;
1342 }
1343 { .mfi
1344 nop.m 999
1345 //
1346 // N = A' * 2/pi
1347 //
1348 fcvt.fx.s1 FR_N_fix = FR_N_float
1349 nop.i 999 ;;
1350 }
1351 { .mfi
1352 nop.m 999
1353 //
1354 // N_fix is the integer part
1355 //
1356 fcvt.xf FR_N_float = FR_N_fix
1357 nop.i 999 ;;
1358 }
1359 { .mfi
1360 getf.sig GR_N_Inc = FR_N_fix
1361 nop.f 999
1362 nop.i 999 ;;
1363 }
1364 { .mii
1365 nop.m 999
1366 nop.i 999 ;;
1367 add GR_N_Inc = GR_N_Inc, GR_Sin_or_Cos ;;
1368 }
1369 { .mfi
1370 nop.m 999
1371 //
1372 // N is the integer part of the reduced-reduced argument.
1373 // Put the integer in a GP register
1374 //
1375 fnma.s1 FR_s = FR_N_float, FR_P_1, FR_ArgPrime
1376 nop.i 999
1377 }
1378 { .mfi
1379 nop.m 999
1380 fnma.s1 FR_w = FR_N_float, FR_P_2, FR_w
1381 nop.i 999 ;;
1382 }
1383 { .mfi
1384 nop.m 999
1385 //
1386 // s = -N*P_1 + Arg'
1387 // w = -N*P_2 + w
1388 // N_fix_gr = N_fix_gr + N_inc
1389 //
1390 fcmp.lt.unc.s1 p9, p8 = FR_s, FR_Two_to_M14
1391 nop.i 999 ;;
1392 }
1393 { .mfi
1394 nop.m 999
1395 (p9) fcmp.gt.s1 p9, p8 = FR_s, FR_Neg_Two_to_M14 // p9 if |s| < 2^-14
1396 nop.i 999 ;;
1397 }
1398
1399 { .mfi
1400 nop.m 999
1401 //
1402 // For |s| > 2**(-14) r = S + w (r complete)
1403 // Else U_hi = N_0 * d_1
1404 //
1405 (p9) fma.s1 FR_V_hi = FR_N_float, FR_P_2, f0
1406 nop.i 999
1407 }
1408 { .mfi
1409 nop.m 999
1410 (p9) fma.s1 FR_U_hi = FR_N_0, FR_d_1, f0
1411 nop.i 999 ;;
1412 }
1413 { .mfi
1414 nop.m 999
1415 //
1416 // Either S <= -2**(-14) or S >= 2**(-14)
1417 // or -2**(-14) < s < 2**(-14)
1418 //
1419 (p8) fma.s1 FR_r = FR_s, f1, FR_w
1420 nop.i 999
1421 }
1422 { .mfi
1423 nop.m 999
1424 (p9) fma.s1 FR_w = FR_N_float, FR_P_3, f0
1425 nop.i 999 ;;
1426 }
1427 { .mfi
1428 nop.m 999
1429 //
1430 // We need abs of both U_hi and V_hi - don't
1431 // worry about switched sign of V_hi.
1432 //
1433 (p9) fms.s1 FR_A = FR_U_hi, f1, FR_V_hi
1434 nop.i 999
1435 }
1436 { .mfi
1437 nop.m 999
1438 //
1439 // Big s: finish up c = (S - r) + w (c complete)
1440 // Case 4: A = U_hi + V_hi
1441 // Note: Worry about switched sign of V_hi, so subtract instead of add.
1442 //
1443 (p9) fnma.s1 FR_V_lo = FR_N_float, FR_P_2, FR_V_hi
1444 nop.i 999 ;;
1445 }
1446 { .mmf
1447 nop.m 999
1448 nop.m 999
1449 (p9) fms.s1 FR_U_lo = FR_N_0, FR_d_1, FR_U_hi
1450 }
1451 { .mfi
1452 nop.m 999
1453 (p9) fmerge.s FR_V_hiabs = f0, FR_V_hi
1454 nop.i 999 ;;
1455 }
1456 //{ .mfb
1457 //(p9) fmerge.s f8= FR_V_lo,FR_V_lo
1458 //(p9) br.ret.sptk b0
1459 //}
1460 //;;
1461 { .mfi
1462 nop.m 999
1463 // For big s: c = S - r
1464 // For small s do more work: U_lo = N_0 * d_1 - U_hi
1465 //
1466 (p9) fmerge.s FR_U_hiabs = f0, FR_U_hi
1467 nop.i 999
1468 }
1469 { .mfi
1470 nop.m 999
1471 //
1472 // For big s: Is |r| < 2**(-3)
1473 // For big s: if p12 set, prepare to branch to Small_R.
1474 // For big s: If p13 set, prepare to branch to Normal_R.
1475 //
1476 (p8) fms.s1 FR_c = FR_s, f1, FR_r
1477 nop.i 999 ;;
1478 }
1479 { .mfi
1480 nop.m 999
1481 //
1482 // For small S: V_hi = N * P_2
1483 // w = N * P_3
1484 // Note the product does not include the (-) as in the writeup
1485 // so (-) missing for V_hi and w.
1486 //
1487 (p8) fcmp.lt.unc.s1 p12, p13 = FR_r, FR_Two_to_M3
1488 nop.i 999 ;;
1489 }
1490 { .mfi
1491 nop.m 999
1492 (p12) fcmp.gt.s1 p12, p13 = FR_r, FR_Neg_Two_to_M3
1493 nop.i 999 ;;
1494 }
1495 { .mfi
1496 nop.m 999
1497 (p8) fma.s1 FR_c = FR_c, f1, FR_w
1498 nop.i 999
1499 }
1500 { .mfb
1501 nop.m 999
1502 (p9) fms.s1 FR_w = FR_N_0, FR_d_2, FR_w
1503 (p12) br.cond.spnt SINCOSL_SMALL_R // Branch if |r| < 2^-3
1504 // and 2^24 <= |x| < 2^63
1505 }
1506 ;;
1507
1508 { .mib
1509 nop.m 999
1510 nop.i 999
1511 (p13) br.cond.sptk SINCOSL_NORMAL_R // Branch if |r| >= 2^-3
1512 // and 2^24 <= |x| < 2^63
1513 }
1514 ;;
1515
1516 SINCOSL_LARGER_S_TINY:
1517 //
1518 // Here if |s| < 2^-14, and 2^24 <= |x| < 2^63
1519 //
1520 { .mfi
1521 nop.m 999
1522 //
1523 // Big s: Vector off when |r| < 2**(-3). Recall that p8 will be true.
1524 // The remaining stuff is for Case 4.
1525 // Small s: V_lo = N * P_2 + U_hi (U_hi is in place of V_hi in writeup)
1526 // Note: the (-) is still missing for V_lo.
1527 // Small s: w = w + N_0 * d_2
1528 // Note: the (-) is now incorporated in w.
1529 //
1530 fcmp.ge.unc.s1 p7, p8 = FR_U_hiabs, FR_V_hiabs
1531 }
1532 { .mfi
1533 nop.m 999
1534 //
1535 // C_hi = S + A
1536 //
1537 fma.s1 FR_t = FR_U_lo, f1, FR_V_lo
1538 }
1539 ;;
1540
1541 { .mfi
1542 nop.m 999
1543 //
1544 // t = U_lo + V_lo
1545 //
1546 //
1547 (p7) fms.s1 FR_a = FR_U_hi, f1, FR_A
1548 nop.i 999 ;;
1549 }
1550 { .mfi
1551 nop.m 999
1552 (p8) fma.s1 FR_a = FR_V_hi, f1, FR_A
1553 nop.i 999
1554 }
1555 ;;
1556
1557 { .mfi
1558 //
1559 // Is U_hiabs >= V_hiabs?
1560 //
1561 nop.m 999
1562 fma.s1 FR_C_hi = FR_s, f1, FR_A
1563 nop.i 999 ;;
1564 }
1565 { .mmi
1566 ldfe FR_C_1 = [GR_ad_c], 16 ;;
1567 ldfe FR_C_2 = [GR_ad_c], 64
1568 nop.i 999 ;;
1569 }
1570 //
1571 // c = c + C_lo finished.
1572 // Load C_2
1573 //
1574 { .mfi
1575 ldfe FR_S_1 = [GR_ad_s], 16
1576 //
1577 // C_lo = S - C_hi
1578 //
1579 fma.s1 FR_t = FR_t, f1, FR_w
1580 nop.i 999 ;;
1581 }
1582 //
1583 // r and c have been computed.
1584 // Make sure ftz mode is set - should be automatic when using wre
1585 // |r| < 2**(-3)
1586 // Get [i_0,i_1] - two lsb of N_fix.
1587 // Load S_1
1588 //
1589 { .mfi
1590 ldfe FR_S_2 = [GR_ad_s], 64
1591 //
1592 // t = t + w
1593 //
1594 (p7) fms.s1 FR_a = FR_a, f1, FR_V_hi
1595 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1596 // p10 if i_1=1, N mod 4 = 2,3
1597 }
1598 ;;
1599 { .mfi
1600 nop.m 999
1601 //
1602 // For larger u than v: a = U_hi - A
1603 // Else a = V_hi - A (do an add to account for missing (-) on V_hi
1604 //
1605 fms.s1 FR_C_lo = FR_s, f1, FR_C_hi
1606 nop.i 999 ;;
1607 }
1608 { .mfi
1609 nop.m 999
1610 (p8) fms.s1 FR_a = FR_U_hi, f1, FR_a
1611 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
1612 // p12 if i_0=1, N mod 4 = 1,3
1613 }
1614 ;;
1615
1616 { .mfi
1617 nop.m 999
1618 //
1619 // If u > v: a = (U_hi - A) + V_hi
1620 // Else a = (V_hi - A) + U_hi
1621 // In each case account for negative missing from V_hi.
1622 //
1623 fma.s1 FR_C_lo = FR_C_lo, f1, FR_A
1624 nop.i 999 ;;
1625 }
1626 { .mfi
1627 nop.m 999
1628 //
1629 // C_lo = (S - C_hi) + A
1630 //
1631 fma.s1 FR_t = FR_t, f1, FR_a
1632 nop.i 999 ;;
1633 }
1634 { .mfi
1635 nop.m 999
1636 //
1637 // t = t + a
1638 //
1639 fma.s1 FR_C_lo = FR_C_lo, f1, FR_t
1640 nop.i 999 ;;
1641 }
1642 { .mfi
1643 nop.m 999
1644 //
1645 // C_lo = C_lo + t
1646 //
1647 fma.s1 FR_r = FR_C_hi, f1, FR_C_lo
1648 nop.i 999 ;;
1649 }
1650 { .mfi
1651 nop.m 999
1652 //
1653 // Load S_2
1654 //
1655 fma.s1 FR_rsq = FR_r, FR_r, f0
1656 nop.i 999
1657 }
1658 { .mfi
1659 nop.m 999
1660 //
1661 // r = C_hi + C_lo
1662 //
1663 fms.s1 FR_c = FR_C_hi, f1, FR_r
1664 nop.i 999 ;;
1665 }
1666 { .mfi
1667 nop.m 999
1668 //
1669 // if i_1 ==0: poly = S_2 * FR_rsq + S_1
1670 // else poly = C_2 * FR_rsq + C_1
1671 //
1672 (p9) fma.s1 FR_tmp_result = f0, f1, FR_r
1673 nop.i 999 ;;
1674 }
1675 { .mfi
1676 nop.m 999
1677 (p10) fma.s1 FR_tmp_result = f0, f1, f1
1678 nop.i 999 ;;
1679 }
1680 { .mfi
1681 nop.m 999
1682 //
1683 // Compute r_cube = FR_rsq * r
1684 //
1685 (p9) fma.s1 FR_poly = FR_rsq, FR_S_2, FR_S_1
1686 nop.i 999 ;;
1687 }
1688 { .mfi
1689 nop.m 999
1690 (p10) fma.s1 FR_poly = FR_rsq, FR_C_2, FR_C_1
1691 nop.i 999
1692 }
1693 { .mfi
1694 nop.m 999
1695 //
1696 // Compute FR_rsq = r * r
1697 // Is i_1 == 0 ?
1698 //
1699 fma.s1 FR_r_cubed = FR_rsq, FR_r, f0
1700 nop.i 999 ;;
1701 }
1702 { .mfi
1703 nop.m 999
1704 //
1705 // c = C_hi - r
1706 // Load C_1
1707 //
1708 fma.s1 FR_c = FR_c, f1, FR_C_lo
1709 nop.i 999
1710 }
1711 { .mfi
1712 nop.m 999
1713 //
1714 // if i_1 ==0: poly = r_cube * poly + c
1715 // else poly = FR_rsq * poly
1716 //
1717 (p12) fms.s1 FR_tmp_result = f0, f1, FR_tmp_result
1718 nop.i 999 ;;
1719 }
1720 { .mfi
1721 nop.m 999
1722 //
1723 // if i_1 ==0: Result = r
1724 // else Result = 1.0
1725 //
1726 (p9) fma.s1 FR_poly = FR_r_cubed, FR_poly, FR_c
1727 nop.i 999 ;;
1728 }
1729 { .mfi
1730 nop.m 999
1731 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0
1732 nop.i 999 ;;
1733 }
1734 { .mfi
1735 nop.m 999
1736 //
1737 // if i_0 !=0: Result = -Result
1738 //
1739 (p11) fma.s0 FR_Result = FR_tmp_result, f1, FR_poly
1740 nop.i 999 ;;
1741 }
1742 { .mfb
1743 nop.m 999
1744 (p12) fms.s0 FR_Result = FR_tmp_result, f1, FR_poly
1745 //
1746 // if i_0 == 0: Result = Result + poly
1747 // else Result = Result - poly
1748 //
1749 br.ret.sptk b0 // Exit for |s| < 2^-14, and 2^24 <= |x| < 2^63
1750 }
1751 ;;
1752
1753
1754 SINCOSL_SMALL_R:
1755 //
1756 // Here if |r| < 2^-3
1757 //
1758 // Enter with r, c, and N_Inc computed
1759 //
1760 // Compare both i_1 and i_0 with 0.
1761 // if i_1 == 0, set p9.
1762 // if i_0 == 0, set p11.
1763 //
1764
1765 { .mfi
1766 nop.m 999
1767 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r
1768 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1769 // p10 if i_1=1, N mod 4 = 2,3
1770 }
1771 ;;
1772
1773 { .mmi
1774 (p9) ldfe FR_S_5 = [GR_ad_se], -16 // Load S_5 if i_1=0
1775 (p10) ldfe FR_C_5 = [GR_ad_ce], -16 // Load C_5 if i_1=1
1776 nop.i 999
1777 }
1778 ;;
1779
1780 { .mmi
1781 (p9) ldfe FR_S_4 = [GR_ad_se], -16 // Load S_4 if i_1=0
1782 (p10) ldfe FR_C_4 = [GR_ad_ce], -16 // Load C_4 if i_1=1
1783 nop.i 999
1784 }
1785 ;;
1786
1787 SINCOSL_SMALL_R_0:
1788 // Entry point for 2^-3 < |x| < pi/4
1789 .pred.rel "mutex",p9,p10
1790 SINCOSL_SMALL_R_1:
1791 // Entry point for pi/4 < |x| < 2^24 and |r| < 2^-3
1792 .pred.rel "mutex",p9,p10
1793 { .mfi
1794 (p9) ldfe FR_S_3 = [GR_ad_se], -16 // Load S_3 if i_1=0
1795 fma.s1 FR_Z = FR_rsq, FR_rsq, f0 // Z = rsq * rsq
1796 nop.i 999
1797 }
1798 { .mfi
1799 (p10) ldfe FR_C_3 = [GR_ad_ce], -16 // Load C_3 if i_1=1
1800 (p10) fnma.s1 FR_c = FR_c, FR_r, f0 // c = -c * r if i_1=0
1801 nop.i 999
1802 }
1803 ;;
1804
1805 { .mmf
1806 (p9) ldfe FR_S_2 = [GR_ad_se], -16 // Load S_2 if i_1=0
1807 (p10) ldfe FR_C_2 = [GR_ad_ce], -16 // Load C_2 if i_1=1
1808 (p10) fmerge.s FR_r = f1, f1
1809 }
1810 ;;
1811
1812 { .mmi
1813 (p9) ldfe FR_S_1 = [GR_ad_se], -16 // Load S_1 if i_1=0
1814 (p10) ldfe FR_C_1 = [GR_ad_ce], -16 // Load C_1 if i_1=1
1815 nop.i 999
1816 }
1817 ;;
1818
1819 { .mfi
1820 nop.m 999
1821 (p9) fma.s1 FR_Z = FR_Z, FR_r, f0 // Z = Z * r if i_1=0
1822 nop.i 999
1823 }
1824 ;;
1825
1826 { .mfi
1827 nop.m 999
1828 (p9) fma.s1 FR_poly_lo = FR_rsq, FR_S_5, FR_S_4 // poly_lo=rsq*S_5+S_4 if i_1=0
1829 nop.i 999
1830 }
1831 { .mfi
1832 nop.m 999
1833 (p10) fma.s1 FR_poly_lo = FR_rsq, FR_C_5, FR_C_4 // poly_lo=rsq*C_5+C_4 if i_1=1
1834 nop.i 999
1835 }
1836 ;;
1837
1838 { .mfi
1839 nop.m 999
1840 (p9) fma.s1 FR_poly_hi = FR_rsq, FR_S_2, FR_S_1 // poly_hi=rsq*S_2+S_1 if i_1=0
1841 nop.i 999
1842 }
1843 { .mfi
1844 nop.m 999
1845 (p10) fma.s1 FR_poly_hi = FR_rsq, FR_C_2, FR_C_1 // poly_hi=rsq*C_2+C_1 if i_1=1
1846 nop.i 999
1847 }
1848 ;;
1849
1850 { .mfi
1851 nop.m 999
1852 fma.s1 FR_Z = FR_Z, FR_rsq, f0 // Z = Z * rsq
1853 nop.i 999
1854 }
1855 ;;
1856
1857 { .mfi
1858 nop.m 999
1859 (p9) fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_S_3 // p_lo=p_lo*rsq+S_3, i_1=0
1860 nop.i 999
1861 }
1862 { .mfi
1863 nop.m 999
1864 (p10) fma.s1 FR_poly_lo = FR_rsq, FR_poly_lo, FR_C_3 // p_lo=p_lo*rsq+C_3, i_1=1
1865 nop.i 999
1866 }
1867 ;;
1868
1869 { .mfi
1870 nop.m 999
1871 (p9) fma.s0 FR_inexact = FR_S_4, FR_S_4, f0 // Dummy op to set inexact
1872 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
1873 // p12 if i_0=1, N mod 4 = 1,3
1874 }
1875 { .mfi
1876 nop.m 999
1877 (p10) fma.s0 FR_inexact = FR_C_1, FR_C_1, f0 // Dummy op to set inexact
1878 nop.i 999
1879 }
1880 ;;
1881
1882 { .mfi
1883 nop.m 999
1884 (p9) fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0 // p_hi=p_hi*rsq if i_1=0
1885 nop.i 999
1886 }
1887 { .mfi
1888 nop.m 999
1889 (p10) fma.s1 FR_poly_hi = FR_poly_hi, FR_rsq, f0 // p_hi=p_hi*rsq if i_1=1
1890 nop.i 999
1891 }
1892 ;;
1893
1894 { .mfi
1895 nop.m 999
1896 fma.s1 FR_poly = FR_Z, FR_poly_lo, FR_c // poly=Z*poly_lo+c
1897 nop.i 999
1898 }
1899 ;;
1900
1901 { .mfi
1902 nop.m 999
1903 (p9) fma.s1 FR_poly_hi = FR_r, FR_poly_hi, f0 // p_hi=r*p_hi if i_1=0
1904 nop.i 999
1905 }
1906 ;;
1907
1908 { .mfi
1909 nop.m 999
1910 (p12) fms.s1 FR_r = f0, f1, FR_r // r = -r if i_0=1
1911 nop.i 999
1912 }
1913 ;;
1914
1915 { .mfi
1916 nop.m 999
1917 fma.s1 FR_poly = FR_poly, f1, FR_poly_hi // poly=poly+poly_hi
1918 nop.i 999
1919 }
1920 ;;
1921
1922 //
1923 // if (i_0 == 0) Result = r + poly
1924 // if (i_0 != 0) Result = r - poly
1925 //
1926 { .mfi
1927 nop.m 999
1928 (p11) fma.s0 FR_Result = FR_r, f1, FR_poly
1929 nop.i 999
1930 }
1931 { .mfb
1932 nop.m 999
1933 (p12) fms.s0 FR_Result = FR_r, f1, FR_poly
1934 br.ret.sptk b0 // Exit for |r| < 2^-3
1935 }
1936 ;;
1937
1938
1939 SINCOSL_NORMAL_R:
1940 //
1941 // Here if 2^-3 <= |r| < pi/4
1942 // THIS IS THE MAIN PATH
1943 //
1944 // Enter with r, c, and N_Inc having been computed
1945 //
1946 { .mfi
1947 ldfe FR_PP_6 = [GR_ad_pp], 16 // Load PP_6
1948 fma.s1 FR_rsq = FR_r, FR_r, f0 // rsq = r * r
1949 tbit.z p9,p10 = GR_N_Inc, 0 // p9 if i_1=0, N mod 4 = 0,1
1950 // p10 if i_1=1, N mod 4 = 2,3
1951 }
1952 { .mfi
1953 ldfe FR_QQ_6 = [GR_ad_qq], 16 // Load QQ_6
1954 nop.f 999
1955 nop.i 999
1956 }
1957 ;;
1958
1959 { .mmi
1960 (p9) ldfe FR_PP_5 = [GR_ad_pp], 16 // Load PP_5 if i_1=0
1961 (p10) ldfe FR_QQ_5 = [GR_ad_qq], 16 // Load QQ_5 if i_1=1
1962 nop.i 999
1963 }
1964 ;;
1965
1966 SINCOSL_NORMAL_R_0:
1967 // Entry for 2^-3 < |x| < pi/4
1968 .pred.rel "mutex",p9,p10
1969 { .mmf
1970 (p9) ldfe FR_C_1 = [GR_ad_pp], 16 // Load C_1 if i_1=0
1971 (p10) ldfe FR_S_1 = [GR_ad_qq], 16 // Load S_1 if i_1=1
1972 frcpa.s1 FR_r_hi, p6 = f1, FR_r // r_hi = frcpa(r)
1973 }
1974 ;;
1975
1976 { .mfi
1977 nop.m 999
1978 (p9) fma.s1 FR_poly = FR_rsq, FR_PP_8, FR_PP_7 // poly = rsq*PP_8+PP_7 if i_1=0
1979 nop.i 999
1980 }
1981 { .mfi
1982 nop.m 999
1983 (p10) fma.s1 FR_poly = FR_rsq, FR_QQ_8, FR_QQ_7 // poly = rsq*QQ_8+QQ_7 if i_1=1
1984 nop.i 999
1985 }
1986 ;;
1987
1988 { .mfi
1989 nop.m 999
1990 fma.s1 FR_r_cubed = FR_r, FR_rsq, f0 // rcubed = r * rsq
1991 nop.i 999
1992 }
1993 ;;
1994
1995
1996 SINCOSL_NORMAL_R_1:
1997 // Entry for pi/4 <= |x| < 2^24
1998 .pred.rel "mutex",p9,p10
1999 { .mmf
2000 (p9) ldfe FR_PP_1 = [GR_ad_pp], 16 // Load PP_1_hi if i_1=0
2001 (p10) ldfe FR_QQ_1 = [GR_ad_qq], 16 // Load QQ_1 if i_1=1
2002 frcpa.s1 FR_r_hi, p6 = f1, FR_r_hi // r_hi = frpca(frcpa(r))
2003 }
2004 ;;
2005
2006 { .mfi
2007 (p9) ldfe FR_PP_4 = [GR_ad_pp], 16 // Load PP_4 if i_1=0
2008 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_6 // poly = rsq*poly+PP_6 if i_1=0
2009 nop.i 999
2010 }
2011 { .mfi
2012 (p10) ldfe FR_QQ_4 = [GR_ad_qq], 16 // Load QQ_4 if i_1=1
2013 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_6 // poly = rsq*poly+QQ_6 if i_1=1
2014 nop.i 999
2015 }
2016 ;;
2017
2018 { .mfi
2019 nop.m 999
2020 (p9) fma.s1 FR_corr = FR_C_1, FR_rsq, f0 // corr = C_1 * rsq if i_1=0
2021 nop.i 999
2022 }
2023 { .mfi
2024 nop.m 999
2025 (p10) fma.s1 FR_corr = FR_S_1, FR_r_cubed, FR_r // corr = S_1 * r^3 + r if i_1=1
2026 nop.i 999
2027 }
2028 ;;
2029
2030 { .mfi
2031 (p9) ldfe FR_PP_3 = [GR_ad_pp], 16 // Load PP_3 if i_1=0
2032 fma.s1 FR_r_hi_sq = FR_r_hi, FR_r_hi, f0 // r_hi_sq = r_hi * r_hi
2033 nop.i 999
2034 }
2035 { .mfi
2036 (p10) ldfe FR_QQ_3 = [GR_ad_qq], 16 // Load QQ_3 if i_1=1
2037 fms.s1 FR_r_lo = FR_r, f1, FR_r_hi // r_lo = r - r_hi
2038 nop.i 999
2039 }
2040 ;;
2041
2042 { .mfi
2043 (p9) ldfe FR_PP_2 = [GR_ad_pp], 16 // Load PP_2 if i_1=0
2044 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_5 // poly = rsq*poly+PP_5 if i_1=0
2045 nop.i 999
2046 }
2047 { .mfi
2048 (p10) ldfe FR_QQ_2 = [GR_ad_qq], 16 // Load QQ_2 if i_1=1
2049 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_5 // poly = rsq*poly+QQ_5 if i_1=1
2050 nop.i 999
2051 }
2052 ;;
2053
2054 { .mfi
2055 (p9) ldfe FR_PP_1_lo = [GR_ad_pp], 16 // Load PP_1_lo if i_1=0
2056 (p9) fma.s1 FR_corr = FR_corr, FR_c, FR_c // corr = corr * c + c if i_1=0
2057 nop.i 999
2058 }
2059 { .mfi
2060 nop.m 999
2061 (p10) fnma.s1 FR_corr = FR_corr, FR_c, f0 // corr = -corr * c if i_1=1
2062 nop.i 999
2063 }
2064 ;;
2065
2066 { .mfi
2067 nop.m 999
2068 (p9) fma.s1 FR_U_lo = FR_r, FR_r_hi, FR_r_hi_sq // U_lo = r*r_hi+r_hi_sq, i_1=0
2069 nop.i 999
2070 }
2071 { .mfi
2072 nop.m 999
2073 (p10) fma.s1 FR_U_lo = FR_r_hi, f1, FR_r // U_lo = r_hi + r if i_1=1
2074 nop.i 999
2075 }
2076 ;;
2077
2078 { .mfi
2079 nop.m 999
2080 (p9) fma.s1 FR_U_hi = FR_r_hi, FR_r_hi_sq, f0 // U_hi = r_hi*r_hi_sq if i_1=0
2081 nop.i 999
2082 }
2083 { .mfi
2084 nop.m 999
2085 (p10) fma.s1 FR_U_hi = FR_QQ_1, FR_r_hi_sq, f1 // U_hi = QQ_1*r_hi_sq+1, i_1=1
2086 nop.i 999
2087 }
2088 ;;
2089
2090 { .mfi
2091 nop.m 999
2092 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_4 // poly = poly*rsq+PP_4 if i_1=0
2093 nop.i 999
2094 }
2095 { .mfi
2096 nop.m 999
2097 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_4 // poly = poly*rsq+QQ_4 if i_1=1
2098 nop.i 999
2099 }
2100 ;;
2101
2102 { .mfi
2103 nop.m 999
2104 (p9) fma.s1 FR_U_lo = FR_r, FR_r, FR_U_lo // U_lo = r * r + U_lo if i_1=0
2105 nop.i 999
2106 }
2107 { .mfi
2108 nop.m 999
2109 (p10) fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0 // U_lo = r_lo * U_lo if i_1=1
2110 nop.i 999
2111 }
2112 ;;
2113
2114 { .mfi
2115 nop.m 999
2116 (p9) fma.s1 FR_U_hi = FR_PP_1, FR_U_hi, f0 // U_hi = PP_1 * U_hi if i_1=0
2117 nop.i 999
2118 }
2119 ;;
2120
2121 { .mfi
2122 nop.m 999
2123 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_3 // poly = poly*rsq+PP_3 if i_1=0
2124 nop.i 999
2125 }
2126 { .mfi
2127 nop.m 999
2128 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_3 // poly = poly*rsq+QQ_3 if i_1=1
2129 nop.i 999
2130 }
2131 ;;
2132
2133 { .mfi
2134 nop.m 999
2135 (p9) fma.s1 FR_U_lo = FR_r_lo, FR_U_lo, f0 // U_lo = r_lo * U_lo if i_1=0
2136 nop.i 999
2137 }
2138 { .mfi
2139 nop.m 999
2140 (p10) fma.s1 FR_U_lo = FR_QQ_1,FR_U_lo, f0 // U_lo = QQ_1 * U_lo if i_1=1
2141 nop.i 999
2142 }
2143 ;;
2144
2145 { .mfi
2146 nop.m 999
2147 (p9) fma.s1 FR_U_hi = FR_r, f1, FR_U_hi // U_hi = r + U_hi if i_1=0
2148 nop.i 999
2149 }
2150 ;;
2151
2152 { .mfi
2153 nop.m 999
2154 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_2 // poly = poly*rsq+PP_2 if i_1=0
2155 nop.i 999
2156 }
2157 { .mfi
2158 nop.m 999
2159 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, FR_QQ_2 // poly = poly*rsq+QQ_2 if i_1=1
2160 nop.i 999
2161 }
2162 ;;
2163
2164 { .mfi
2165 nop.m 999
2166 (p9) fma.s1 FR_U_lo = FR_PP_1, FR_U_lo, f0 // U_lo = PP_1 * U_lo if i_1=0
2167 nop.i 999
2168 }
2169 ;;
2170
2171 { .mfi
2172 nop.m 999
2173 (p9) fma.s1 FR_poly = FR_rsq, FR_poly, FR_PP_1_lo // poly =poly*rsq+PP1lo i_1=0
2174 nop.i 999
2175 }
2176 { .mfi
2177 nop.m 999
2178 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0 // poly = poly*rsq if i_1=1
2179 nop.i 999
2180 }
2181 ;;
2182
2183 { .mfi
2184 nop.m 999
2185 fma.s1 FR_V = FR_U_lo, f1, FR_corr // V = U_lo + corr
2186 tbit.z p11,p12 = GR_N_Inc, 1 // p11 if i_0=0, N mod 4 = 0,2
2187 // p12 if i_0=1, N mod 4 = 1,3
2188 }
2189 ;;
2190
2191 { .mfi
2192 nop.m 999
2193 (p9) fma.s0 FR_inexact = FR_PP_5, FR_PP_4, f0 // Dummy op to set inexact
2194 nop.i 999
2195 }
2196 { .mfi
2197 nop.m 999
2198 (p10) fma.s0 FR_inexact = FR_QQ_5, FR_QQ_5, f0 // Dummy op to set inexact
2199 nop.i 999
2200 }
2201 ;;
2202
2203 { .mfi
2204 nop.m 999
2205 (p9) fma.s1 FR_poly = FR_r_cubed, FR_poly, f0 // poly = poly*r^3 if i_1=0
2206 nop.i 999
2207 }
2208 { .mfi
2209 nop.m 999
2210 (p10) fma.s1 FR_poly = FR_rsq, FR_poly, f0 // poly = poly*rsq if i_1=1
2211 nop.i 999
2212 }
2213 ;;
2214
2215 { .mfi
2216 nop.m 999
2217 (p11) fma.s1 FR_tmp_result = f0, f1, f1// tmp_result=+1.0 if i_0=0
2218 nop.i 999
2219 }
2220 { .mfi
2221 nop.m 999
2222 (p12) fms.s1 FR_tmp_result = f0, f1, f1// tmp_result=-1.0 if i_0=1
2223 nop.i 999
2224 }
2225 ;;
2226
2227 { .mfi
2228 nop.m 999
2229 fma.s1 FR_V = FR_poly, f1, FR_V // V = poly + V
2230 nop.i 999
2231 }
2232 ;;
2233
2234 // If i_0 = 0 Result = U_hi + V
2235 // If i_0 = 1 Result = -U_hi - V
2236 { .mfi
2237 nop.m 999
2238 (p11) fma.s0 FR_Result = FR_tmp_result, FR_U_hi, FR_V
2239 nop.i 999
2240 }
2241 { .mfb
2242 nop.m 999
2243 (p12) fms.s0 FR_Result = FR_tmp_result, FR_U_hi, FR_V
2244 br.ret.sptk b0 // Exit for 2^-3 <= |r| < pi/4
2245 }
2246 ;;
2247
2248 SINCOSL_ZERO:
2249 // Here if x = 0
2250 { .mfi
2251 cmp.eq.unc p6, p7 = 0x1, GR_Sin_or_Cos
2252 nop.f 999
2253 nop.i 999
2254 }
2255 ;;
2256
2257 { .mfi
2258 nop.m 999
2259 (p7) fmerge.s FR_Result = FR_Input_X, FR_Input_X // If sin, result = input
2260 nop.i 999
2261 }
2262 { .mfb
2263 nop.m 999
2264 (p6) fma.s0 FR_Result = f1, f1, f0 // If cos, result=1.0
2265 br.ret.sptk b0 // Exit for x=0
2266 }
2267 ;;
2268
2269
2270 SINCOSL_DENORMAL:
2271 { .mmb
2272 getf.exp GR_signexp_x = FR_norm_x // Get sign and exponent of x
2273 nop.m 999
2274 br.cond.sptk SINCOSL_COMMON // Return to common code
2275 }
2276 ;;
2277
2278 SINCOSL_SPECIAL:
2279 { .mfb
2280 nop.m 999
2281 //
2282 // Path for Arg = +/- QNaN, SNaN, Inf
2283 // Invalid can be raised. SNaNs
2284 // become QNaNs
2285 //
2286 fmpy.s0 FR_Result = FR_Input_X, f0
2287 br.ret.sptk b0 ;;
2288 }
2289
2290 GLOBAL_IEEE754_END(cosl)
2291 libm_alias_ldouble_other (__cos, cos)
2292
2293 // *******************************************************************
2294 // *******************************************************************
2295 // *******************************************************************
2296 //
2297 // Special Code to handle very large argument case.
2298 // Call int __libm_pi_by_2_reduce(x,r,c) for |arguments| >= 2**63
2299 // The interface is custom:
2300 // On input:
2301 // (Arg or x) is in f8
2302 // On output:
2303 // r is in f8
2304 // c is in f9
2305 // N is in r8
2306 // Be sure to allocate at least 2 GP registers as output registers for
2307 // __libm_pi_by_2_reduce. This routine uses r59-60. These are used as
2308 // scratch registers within the __libm_pi_by_2_reduce routine (for speed).
2309 //
2310 // We know also that __libm_pi_by_2_reduce preserves f10-15, f71-127. We
2311 // use this to eliminate save/restore of key fp registers in this calling
2312 // function.
2313 //
2314 // *******************************************************************
2315 // *******************************************************************
2316 // *******************************************************************
2317
2318 LOCAL_LIBM_ENTRY(__libm_callout)
2319 SINCOSL_ARG_TOO_LARGE:
2320 .prologue
2321 { .mfi
2322 nop.f 0
2323 .save ar.pfs,GR_SAVE_PFS
2324 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
2325 };;
2326
2327 { .mmi
2328 setf.exp FR_Two_to_M3 = GR_exp_2_to_m3 // Form 2^-3
2329 mov GR_SAVE_GP=gp // Save gp
2330 .save b0, GR_SAVE_B0
2331 mov GR_SAVE_B0=b0 // Save b0
2332 };;
2333
2334 .body
2335 //
2336 // Call argument reduction with x in f8
2337 // Returns with N in r8, r in f8, c in f9
2338 // Assumes f71-127 are preserved across the call
2339 //
2340 { .mib
2341 setf.exp FR_Neg_Two_to_M3 = GR_exp_m2_to_m3 // Form -(2^-3)
2342 nop.i 0
2343 br.call.sptk b0=__libm_pi_by_2_reduce#
2344 };;
2345
2346 { .mfi
2347 add GR_N_Inc = GR_Sin_or_Cos,r8
2348 fcmp.lt.unc.s1 p6, p0 = FR_r, FR_Two_to_M3
2349 mov b0 = GR_SAVE_B0 // Restore return address
2350 };;
2351
2352 { .mfi
2353 mov gp = GR_SAVE_GP // Restore gp
2354 (p6) fcmp.gt.unc.s1 p6, p0 = FR_r, FR_Neg_Two_to_M3
2355 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
2356 };;
2357
2358 { .mbb
2359 nop.m 999
2360 (p6) br.cond.spnt SINCOSL_SMALL_R // Branch if |r|< 2^-3 for |x| >= 2^63
2361 br.cond.sptk SINCOSL_NORMAL_R // Branch if |r|>=2^-3 for |x| >= 2^63
2362 };;
2363
2364 LOCAL_LIBM_END(__libm_callout)
2365 .type __libm_pi_by_2_reduce#,@function
2366 .global __libm_pi_by_2_reduce#