localedata: dz_BT, bo_CN: convert to UTF-8
[glibc.git] / sysdeps / ia64 / fpu / s_cos.S
blobcc79aca17edc8baf2ca78c96f053c51f59edcc26
1 .file "sincos.s"
4 // Copyright (c) 2000 - 2005, 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:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
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.
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.
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.
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.
39 // History
40 //==============================================================
41 // 02/02/00 Initial version
42 // 04/02/00 Unwind support added.
43 // 06/16/00 Updated tables to enforce symmetry
44 // 08/31/00 Saved 2 cycles in main path, and 9 in other paths.
45 // 09/20/00 The updated tables regressed to an old version, so reinstated them
46 // 10/18/00 Changed one table entry to ensure symmetry
47 // 01/03/01 Improved speed, fixed flag settings for small arguments.
48 // 02/18/02 Large arguments processing routine excluded
49 // 05/20/02 Cleaned up namespace and sf0 syntax
50 // 06/03/02 Insure inexact flag set for large arg result
51 // 09/05/02 Work range is widened by reduction strengthen (3 parts of Pi/16)
52 // 02/10/03 Reordered header: .section, .global, .proc, .align
53 // 08/08/03 Improved performance
54 // 10/28/04 Saved sincos_r_sincos to avoid clobber by dynamic loader
55 // 03/31/05 Reformatted delimiters between data tables
57 // API
58 //==============================================================
59 // double sin( double x);
60 // double cos( double x);
62 // Overview of operation
63 //==============================================================
65 // Step 1
66 // ======
67 // Reduce x to region -1/2*pi/2^k ===== 0 ===== +1/2*pi/2^k  where k=4
68 //    divide x by pi/2^k.
69 //    Multiply by 2^k/pi.
70 //    nfloat = Round result to integer (round-to-nearest)
72 // r = x -  nfloat * pi/2^k
73 //    Do this as ((((x -  nfloat * HIGH(pi/2^k))) -
74 //                        nfloat * LOW(pi/2^k)) -
75 //                        nfloat * LOWEST(pi/2^k) for increased accuracy.
76 //    pi/2^k is stored as two numbers that when added make pi/2^k.
77 //       pi/2^k = HIGH(pi/2^k) + LOW(pi/2^k)
78 //    HIGH and LOW parts are rounded to zero values,
79 //    and LOWEST is rounded to nearest one.
81 // x = (nfloat * pi/2^k) + r
82 //    r is small enough that we can use a polynomial approximation
83 //    and is referred to as the reduced argument.
85 // Step 3
86 // ======
87 // Take the unreduced part and remove the multiples of 2pi.
88 // So nfloat = nfloat (with lower k+1 bits cleared) + lower k+1 bits
90 //    nfloat (with lower k+1 bits cleared) is a multiple of 2^(k+1)
91 //    N * 2^(k+1)
92 //    nfloat * pi/2^k = N * 2^(k+1) * pi/2^k + (lower k+1 bits) * pi/2^k
93 //    nfloat * pi/2^k = N * 2 * pi + (lower k+1 bits) * pi/2^k
94 //    nfloat * pi/2^k = N2pi + M * pi/2^k
97 // Sin(x) = Sin((nfloat * pi/2^k) + r)
98 //        = Sin(nfloat * pi/2^k) * Cos(r) + Cos(nfloat * pi/2^k) * Sin(r)
100 //          Sin(nfloat * pi/2^k) = Sin(N2pi + Mpi/2^k)
101 //                               = Sin(N2pi)Cos(Mpi/2^k) + Cos(N2pi)Sin(Mpi/2^k)
102 //                               = Sin(Mpi/2^k)
104 //          Cos(nfloat * pi/2^k) = Cos(N2pi + Mpi/2^k)
105 //                               = Cos(N2pi)Cos(Mpi/2^k) + Sin(N2pi)Sin(Mpi/2^k)
106 //                               = Cos(Mpi/2^k)
108 // Sin(x) = Sin(Mpi/2^k) Cos(r) + Cos(Mpi/2^k) Sin(r)
111 // Step 4
112 // ======
113 // 0 <= M < 2^(k+1)
114 // There are 2^(k+1) Sin entries in a table.
115 // There are 2^(k+1) Cos entries in a table.
117 // Get Sin(Mpi/2^k) and Cos(Mpi/2^k) by table lookup.
120 // Step 5
121 // ======
122 // Calculate Cos(r) and Sin(r) by polynomial approximation.
124 // Cos(r) = 1 + r^2 q1  + r^4 q2 + r^6 q3 + ... = Series for Cos
125 // Sin(r) = r + r^3 p1  + r^5 p2 + r^7 p3 + ... = Series for Sin
127 // and the coefficients q1, q2, ... and p1, p2, ... are stored in a table
130 // Calculate
131 // Sin(x) = Sin(Mpi/2^k) Cos(r) + Cos(Mpi/2^k) Sin(r)
133 // as follows
135 //    S[m] = Sin(Mpi/2^k) and C[m] = Cos(Mpi/2^k)
136 //    rsq = r*r
139 //    P = p1 + r^2p2 + r^4p3 + r^6p4
140 //    Q = q1 + r^2q2 + r^4q3 + r^6q4
142 //       rcub = r * rsq
143 //       Sin(r) = r + rcub * P
144 //              = r + r^3p1  + r^5p2 + r^7p3 + r^9p4 + ... = Sin(r)
146 //            The coefficients are not exactly these values, but almost.
148 //            p1 = -1/6  = -1/3!
149 //            p2 = 1/120 =  1/5!
150 //            p3 = -1/5040 = -1/7!
151 //            p4 = 1/362889 = 1/9!
153 //       P =  r + rcub * P
155 //    Answer = S[m] Cos(r) + [Cm] P
157 //       Cos(r) = 1 + rsq Q
158 //       Cos(r) = 1 + r^2 Q
159 //       Cos(r) = 1 + r^2 (q1 + r^2q2 + r^4q3 + r^6q4)
160 //       Cos(r) = 1 + r^2q1 + r^4q2 + r^6q3 + r^8q4 + ...
162 //       S[m] Cos(r) = S[m](1 + rsq Q)
163 //       S[m] Cos(r) = S[m] + Sm rsq Q
164 //       S[m] Cos(r) = S[m] + s_rsq Q
165 //       Q         = S[m] + s_rsq Q
167 // Then,
169 //    Answer = Q + C[m] P
172 // Registers used
173 //==============================================================
174 // general input registers:
175 // r14 -> r26
176 // r32 -> r35
178 // predicate registers used:
179 // p6 -> p11
181 // floating-point registers used
182 // f9 -> f15
183 // f32 -> f61
185 // Assembly macros
186 //==============================================================
187 sincos_NORM_f8                 = f9
188 sincos_W                       = f10
189 sincos_int_Nfloat              = f11
190 sincos_Nfloat                  = f12
192 sincos_r                       = f13
193 sincos_rsq                     = f14
194 sincos_rcub                    = f15
195 sincos_save_tmp                = f15
197 sincos_Inv_Pi_by_16            = f32
198 sincos_Pi_by_16_1              = f33
199 sincos_Pi_by_16_2              = f34
201 sincos_Inv_Pi_by_64            = f35
203 sincos_Pi_by_16_3              = f36
205 sincos_r_exact                 = f37
207 sincos_Sm                      = f38
208 sincos_Cm                      = f39
210 sincos_P1                      = f40
211 sincos_Q1                      = f41
212 sincos_P2                      = f42
213 sincos_Q2                      = f43
214 sincos_P3                      = f44
215 sincos_Q3                      = f45
216 sincos_P4                      = f46
217 sincos_Q4                      = f47
219 sincos_P_temp1                 = f48
220 sincos_P_temp2                 = f49
222 sincos_Q_temp1                 = f50
223 sincos_Q_temp2                 = f51
225 sincos_P                       = f52
226 sincos_Q                       = f53
228 sincos_srsq                    = f54
230 sincos_SIG_INV_PI_BY_16_2TO61  = f55
231 sincos_RSHF_2TO61              = f56
232 sincos_RSHF                    = f57
233 sincos_2TOM61                  = f58
234 sincos_NFLOAT                  = f59
235 sincos_W_2TO61_RSH             = f60
237 fp_tmp                         = f61
239 /////////////////////////////////////////////////////////////
241 sincos_GR_sig_inv_pi_by_16     = r14
242 sincos_GR_rshf_2to61           = r15
243 sincos_GR_rshf                 = r16
244 sincos_GR_exp_2tom61           = r17
245 sincos_GR_n                    = r18
246 sincos_GR_m                    = r19
247 sincos_GR_32m                  = r19
248 sincos_GR_all_ones             = r19
249 sincos_AD_1                    = r20
250 sincos_AD_2                    = r21
251 sincos_exp_limit               = r22
252 sincos_r_signexp               = r23
253 sincos_r_17_ones               = r24
254 sincos_r_sincos                = r25
255 sincos_r_exp                   = r26
257 GR_SAVE_PFS                    = r33
258 GR_SAVE_B0                     = r34
259 GR_SAVE_GP                     = r35
260 GR_SAVE_r_sincos               = r36
263 RODATA
265 // Pi/16 parts
266 .align 16
267 LOCAL_OBJECT_START(double_sincos_pi)
268    data8 0xC90FDAA22168C234, 0x00003FFC // pi/16 1st part
269    data8 0xC4C6628B80DC1CD1, 0x00003FBC // pi/16 2nd part
270    data8 0xA4093822299F31D0, 0x00003F7A // pi/16 3rd part
271 LOCAL_OBJECT_END(double_sincos_pi)
273 // Coefficients for polynomials
274 LOCAL_OBJECT_START(double_sincos_pq_k4)
275    data8 0x3EC71C963717C63A // P4
276    data8 0x3EF9FFBA8F191AE6 // Q4
277    data8 0xBF2A01A00F4E11A8 // P3
278    data8 0xBF56C16C05AC77BF // Q3
279    data8 0x3F8111111110F167 // P2
280    data8 0x3FA555555554DD45 // Q2
281    data8 0xBFC5555555555555 // P1
282    data8 0xBFDFFFFFFFFFFFFC // Q1
283 LOCAL_OBJECT_END(double_sincos_pq_k4)
285 // Sincos table (S[m], C[m])
286 LOCAL_OBJECT_START(double_sin_cos_beta_k4)
288 data8 0x0000000000000000 , 0x00000000 // sin( 0 pi/16)  S0
289 data8 0x8000000000000000 , 0x00003fff // cos( 0 pi/16)  C0
291 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // sin( 1 pi/16)  S1
292 data8 0xfb14be7fbae58157 , 0x00003ffe // cos( 1 pi/16)  C1
294 data8 0xc3ef1535754b168e , 0x00003ffd // sin( 2 pi/16)  S2
295 data8 0xec835e79946a3146 , 0x00003ffe // cos( 2 pi/16)  C2
297 data8 0x8e39d9cd73464364 , 0x00003ffe // sin( 3 pi/16)  S3
298 data8 0xd4db3148750d181a , 0x00003ffe // cos( 3 pi/16)  C3
300 data8 0xb504f333f9de6484 , 0x00003ffe // sin( 4 pi/16)  S4
301 data8 0xb504f333f9de6484 , 0x00003ffe // cos( 4 pi/16)  C4
303 data8 0xd4db3148750d181a , 0x00003ffe // sin( 5 pi/16)  C3
304 data8 0x8e39d9cd73464364 , 0x00003ffe // cos( 5 pi/16)  S3
306 data8 0xec835e79946a3146 , 0x00003ffe // sin( 6 pi/16)  C2
307 data8 0xc3ef1535754b168e , 0x00003ffd // cos( 6 pi/16)  S2
309 data8 0xfb14be7fbae58157 , 0x00003ffe // sin( 7 pi/16)  C1
310 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // cos( 7 pi/16)  S1
312 data8 0x8000000000000000 , 0x00003fff // sin( 8 pi/16)  C0
313 data8 0x0000000000000000 , 0x00000000 // cos( 8 pi/16)  S0
315 data8 0xfb14be7fbae58157 , 0x00003ffe // sin( 9 pi/16)  C1
316 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // cos( 9 pi/16)  -S1
318 data8 0xec835e79946a3146 , 0x00003ffe // sin(10 pi/16)  C2
319 data8 0xc3ef1535754b168e , 0x0000bffd // cos(10 pi/16)  -S2
321 data8 0xd4db3148750d181a , 0x00003ffe // sin(11 pi/16)  C3
322 data8 0x8e39d9cd73464364 , 0x0000bffe // cos(11 pi/16)  -S3
324 data8 0xb504f333f9de6484 , 0x00003ffe // sin(12 pi/16)  S4
325 data8 0xb504f333f9de6484 , 0x0000bffe // cos(12 pi/16)  -S4
327 data8 0x8e39d9cd73464364 , 0x00003ffe // sin(13 pi/16) S3
328 data8 0xd4db3148750d181a , 0x0000bffe // cos(13 pi/16) -C3
330 data8 0xc3ef1535754b168e , 0x00003ffd // sin(14 pi/16) S2
331 data8 0xec835e79946a3146 , 0x0000bffe // cos(14 pi/16) -C2
333 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // sin(15 pi/16) S1
334 data8 0xfb14be7fbae58157 , 0x0000bffe // cos(15 pi/16) -C1
336 data8 0x0000000000000000 , 0x00000000 // sin(16 pi/16) S0
337 data8 0x8000000000000000 , 0x0000bfff // cos(16 pi/16) -C0
339 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // sin(17 pi/16) -S1
340 data8 0xfb14be7fbae58157 , 0x0000bffe // cos(17 pi/16) -C1
342 data8 0xc3ef1535754b168e , 0x0000bffd // sin(18 pi/16) -S2
343 data8 0xec835e79946a3146 , 0x0000bffe // cos(18 pi/16) -C2
345 data8 0x8e39d9cd73464364 , 0x0000bffe // sin(19 pi/16) -S3
346 data8 0xd4db3148750d181a , 0x0000bffe // cos(19 pi/16) -C3
348 data8 0xb504f333f9de6484 , 0x0000bffe // sin(20 pi/16) -S4
349 data8 0xb504f333f9de6484 , 0x0000bffe // cos(20 pi/16) -S4
351 data8 0xd4db3148750d181a , 0x0000bffe // sin(21 pi/16) -C3
352 data8 0x8e39d9cd73464364 , 0x0000bffe // cos(21 pi/16) -S3
354 data8 0xec835e79946a3146 , 0x0000bffe // sin(22 pi/16) -C2
355 data8 0xc3ef1535754b168e , 0x0000bffd // cos(22 pi/16) -S2
357 data8 0xfb14be7fbae58157 , 0x0000bffe // sin(23 pi/16) -C1
358 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // cos(23 pi/16) -S1
360 data8 0x8000000000000000 , 0x0000bfff // sin(24 pi/16) -C0
361 data8 0x0000000000000000 , 0x00000000 // cos(24 pi/16) S0
363 data8 0xfb14be7fbae58157 , 0x0000bffe // sin(25 pi/16) -C1
364 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // cos(25 pi/16) S1
366 data8 0xec835e79946a3146 , 0x0000bffe // sin(26 pi/16) -C2
367 data8 0xc3ef1535754b168e , 0x00003ffd // cos(26 pi/16) S2
369 data8 0xd4db3148750d181a , 0x0000bffe // sin(27 pi/16) -C3
370 data8 0x8e39d9cd73464364 , 0x00003ffe // cos(27 pi/16) S3
372 data8 0xb504f333f9de6484 , 0x0000bffe // sin(28 pi/16) -S4
373 data8 0xb504f333f9de6484 , 0x00003ffe // cos(28 pi/16) S4
375 data8 0x8e39d9cd73464364 , 0x0000bffe // sin(29 pi/16) -S3
376 data8 0xd4db3148750d181a , 0x00003ffe // cos(29 pi/16) C3
378 data8 0xc3ef1535754b168e , 0x0000bffd // sin(30 pi/16) -S2
379 data8 0xec835e79946a3146 , 0x00003ffe // cos(30 pi/16) C2
381 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // sin(31 pi/16) -S1
382 data8 0xfb14be7fbae58157 , 0x00003ffe // cos(31 pi/16) C1
384 data8 0x0000000000000000 , 0x00000000 // sin(32 pi/16) S0
385 data8 0x8000000000000000 , 0x00003fff // cos(32 pi/16) C0
386 LOCAL_OBJECT_END(double_sin_cos_beta_k4)
388 .section .text
390 ////////////////////////////////////////////////////////
391 // There are two entry points: sin and cos
394 // If from sin, p8 is true
395 // If from cos, p9 is true
397 GLOBAL_IEEE754_ENTRY(sin)
399 { .mlx
400       getf.exp      sincos_r_signexp    = f8
401       movl sincos_GR_sig_inv_pi_by_16   = 0xA2F9836E4E44152A // signd of 16/pi
403 { .mlx
404       addl          sincos_AD_1         = @ltoff(double_sincos_pi), gp
405       movl sincos_GR_rshf_2to61         = 0x47b8000000000000 // 1.1 2^(63+63-2)
409 { .mfi
410       ld8           sincos_AD_1         = [sincos_AD_1]
411       fnorm.s0      sincos_NORM_f8      = f8  // Normalize argument
412       cmp.eq        p8,p9               = r0, r0 // set p8 (clear p9) for sin
414 { .mib
415       mov           sincos_GR_exp_2tom61  = 0xffff-61 // exponent of scale 2^-61
416       mov           sincos_r_sincos       = 0x0 // sincos_r_sincos = 0 for sin
417       br.cond.sptk  _SINCOS_COMMON  // go to common part
421 GLOBAL_IEEE754_END(sin)
422 libm_alias_double_other (__sin, sin)
424 GLOBAL_IEEE754_ENTRY(cos)
426 { .mlx
427       getf.exp      sincos_r_signexp    = f8
428       movl sincos_GR_sig_inv_pi_by_16   = 0xA2F9836E4E44152A // signd of 16/pi
430 { .mlx
431       addl          sincos_AD_1         = @ltoff(double_sincos_pi), gp
432       movl sincos_GR_rshf_2to61         = 0x47b8000000000000 // 1.1 2^(63+63-2)
436 { .mfi
437       ld8           sincos_AD_1         = [sincos_AD_1]
438       fnorm.s1      sincos_NORM_f8      = f8 // Normalize argument
439       cmp.eq        p9,p8               = r0, r0 // set p9 (clear p8) for cos
441 { .mib
442       mov           sincos_GR_exp_2tom61  = 0xffff-61 // exp of scale 2^-61
443       mov           sincos_r_sincos       = 0x8 // sincos_r_sincos = 8 for cos
444       nop.b         999
448 ////////////////////////////////////////////////////////
449 // All entry points end up here.
450 // If from sin, sincos_r_sincos is 0 and p8 is true
451 // If from cos, sincos_r_sincos is 8 = 2^(k-1) and p9 is true
452 // We add sincos_r_sincos to N
454 ///////////// Common sin and cos part //////////////////
455 _SINCOS_COMMON:
458 // Form two constants we need
459 //  16/pi * 2^-2 * 2^63, scaled by 2^61 since we just loaded the significand
460 //  1.1000...000 * 2^(63+63-2) to right shift int(W) into the low significand
461 { .mfi
462       setf.sig      sincos_SIG_INV_PI_BY_16_2TO61 = sincos_GR_sig_inv_pi_by_16
463       fclass.m      p6,p0                         = f8, 0xe7 // if x = 0,inf,nan
464       mov           sincos_exp_limit              = 0x1001a
466 { .mlx
467       setf.d        sincos_RSHF_2TO61   = sincos_GR_rshf_2to61
468       movl          sincos_GR_rshf      = 0x43e8000000000000 // 1.1 2^63
469 }                                                            // Right shift
472 // Form another constant
473 //  2^-61 for scaling Nfloat
474 // 0x1001a is register_bias + 27.
475 // So if f8 >= 2^27, go to large argument routines
476 { .mfi
477       alloc         r32                 = ar.pfs, 1, 4, 0, 0
478       fclass.m      p11,p0              = f8, 0x0b // Test for x=unorm
479       mov           sincos_GR_all_ones  = -1 // For "inexect" constant create
481 { .mib
482       setf.exp      sincos_2TOM61       = sincos_GR_exp_2tom61
483       nop.i         999
484 (p6)  br.cond.spnt  _SINCOS_SPECIAL_ARGS
488 // Load the two pieces of pi/16
489 // Form another constant
490 //  1.1000...000 * 2^63, the right shift constant
491 { .mmb
492       ldfe          sincos_Pi_by_16_1   = [sincos_AD_1],16
493       setf.d        sincos_RSHF         = sincos_GR_rshf
494 (p11) br.cond.spnt  _SINCOS_UNORM       // Branch if x=unorm
498 _SINCOS_COMMON2:
499 // Return here if x=unorm
500 // Create constant used to set inexact
501 { .mmi
502       ldfe          sincos_Pi_by_16_2   = [sincos_AD_1],16
503       setf.sig      fp_tmp              = sincos_GR_all_ones
504       nop.i         999
507 // Select exponent (17 lsb)
508 { .mfi
509       ldfe          sincos_Pi_by_16_3   = [sincos_AD_1],16
510       nop.f         999
511       dep.z         sincos_r_exp        = sincos_r_signexp, 0, 17
514 // Polynomial coefficients (Q4, P4, Q3, P3, Q2, Q1, P2, P1) loading
515 // p10 is true if we must call routines to handle larger arguments
516 // p10 is true if f8 exp is >= 0x1001a (2^27)
517 { .mmb
518       ldfpd         sincos_P4,sincos_Q4 = [sincos_AD_1],16
519       cmp.ge        p10,p0              = sincos_r_exp,sincos_exp_limit
520 (p10) br.cond.spnt  _SINCOS_LARGE_ARGS // Go to "large args" routine
523 // sincos_W          = x * sincos_Inv_Pi_by_16
524 // Multiply x by scaled 16/pi and add large const to shift integer part of W to
525 //   rightmost bits of significand
526 { .mfi
527       ldfpd         sincos_P3,sincos_Q3 = [sincos_AD_1],16
528       fma.s1 sincos_W_2TO61_RSH = sincos_NORM_f8,sincos_SIG_INV_PI_BY_16_2TO61,sincos_RSHF_2TO61
529       nop.i         999
532 // get N = (int)sincos_int_Nfloat
533 // sincos_NFLOAT = Round_Int_Nearest(sincos_W)
534 // This is done by scaling back by 2^-61 and subtracting the shift constant
535 { .mmf
536       getf.sig      sincos_GR_n         = sincos_W_2TO61_RSH
537       ldfpd         sincos_P2,sincos_Q2 = [sincos_AD_1],16
538       fms.s1 sincos_NFLOAT = sincos_W_2TO61_RSH,sincos_2TOM61,sincos_RSHF
541 // sincos_r          = -sincos_Nfloat * sincos_Pi_by_16_1 + x
542 { .mfi
543       ldfpd         sincos_P1,sincos_Q1 = [sincos_AD_1],16
544       fnma.s1 sincos_r = sincos_NFLOAT, sincos_Pi_by_16_1, sincos_NORM_f8
545       nop.i         999
548 // Add 2^(k-1) (which is in sincos_r_sincos) to N
549 { .mmi
550       add           sincos_GR_n         = sincos_GR_n, sincos_r_sincos
552 // Get M (least k+1 bits of N)
553       and           sincos_GR_m         = 0x1f,sincos_GR_n
554       nop.i         999
557 // sincos_r          = sincos_r -sincos_Nfloat * sincos_Pi_by_16_2
558 { .mfi
559       nop.m         999
560       fnma.s1 sincos_r = sincos_NFLOAT, sincos_Pi_by_16_2,  sincos_r
561       shl           sincos_GR_32m       = sincos_GR_m,5
564 // Add 32*M to address of sin_cos_beta table
565 // For sin denorm. - set uflow
566 { .mfi
567       add           sincos_AD_2         = sincos_GR_32m, sincos_AD_1
568 (p8)  fclass.m.unc  p10,p0              = f8,0x0b
569       nop.i         999
572 // Load Sin and Cos table value using obtained index m  (sincosf_AD_2)
573 { .mfi
574       ldfe          sincos_Sm           = [sincos_AD_2],16
575       nop.f         999
576       nop.i         999
579 // get rsq = r*r
580 { .mfi
581       ldfe          sincos_Cm           = [sincos_AD_2]
582       fma.s1        sincos_rsq          = sincos_r, sincos_r,   f0 // r^2 = r*r
583       nop.i         999
585 { .mfi
586       nop.m         999
587       fmpy.s0       fp_tmp              = fp_tmp,fp_tmp // forces inexact flag
588       nop.i         999
591 // sincos_r_exact = sincos_r -sincos_Nfloat * sincos_Pi_by_16_3
592 { .mfi
593       nop.m         999
594       fnma.s1 sincos_r_exact = sincos_NFLOAT, sincos_Pi_by_16_3, sincos_r
595       nop.i         999
598 // Polynomials calculation
599 // P_1 = P4*r^2 + P3
600 // Q_2 = Q4*r^2 + Q3
601 { .mfi
602       nop.m         999
603       fma.s1        sincos_P_temp1      = sincos_rsq, sincos_P4, sincos_P3
604       nop.i         999
606 { .mfi
607       nop.m         999
608       fma.s1        sincos_Q_temp1      = sincos_rsq, sincos_Q4, sincos_Q3
609       nop.i         999
612 // get rcube = r^3 and S[m]*r^2
613 { .mfi
614       nop.m         999
615       fmpy.s1       sincos_srsq         = sincos_Sm,sincos_rsq
616       nop.i         999
618 { .mfi
619       nop.m         999
620       fmpy.s1       sincos_rcub         = sincos_r_exact, sincos_rsq
621       nop.i         999
624 // Polynomials calculation
625 // Q_2 = Q_1*r^2 + Q2
626 // P_1 = P_1*r^2 + P2
627 { .mfi
628       nop.m         999
629       fma.s1        sincos_Q_temp2      = sincos_rsq, sincos_Q_temp1, sincos_Q2
630       nop.i         999
632 { .mfi
633       nop.m         999
634       fma.s1        sincos_P_temp2      = sincos_rsq, sincos_P_temp1, sincos_P2
635       nop.i         999
638 // Polynomials calculation
639 // Q = Q_2*r^2 + Q1
640 // P = P_2*r^2 + P1
641 { .mfi
642       nop.m         999
643       fma.s1        sincos_Q            = sincos_rsq, sincos_Q_temp2, sincos_Q1
644       nop.i         999
646 { .mfi
647       nop.m         999
648       fma.s1        sincos_P            = sincos_rsq, sincos_P_temp2, sincos_P1
649       nop.i         999
652 // Get final P and Q
653 // Q = Q*S[m]*r^2 + S[m]
654 // P = P*r^3 + r
655 { .mfi
656       nop.m         999
657       fma.s1        sincos_Q            = sincos_srsq,sincos_Q, sincos_Sm
658       nop.i         999
660 { .mfi
661       nop.m         999
662       fma.s1        sincos_P            = sincos_rcub,sincos_P, sincos_r_exact
663       nop.i         999
666 // If sin(denormal), force underflow to be set
667 { .mfi
668       nop.m         999
669 (p10) fmpy.d.s0     fp_tmp              = sincos_NORM_f8,sincos_NORM_f8
670       nop.i         999
673 // Final calculation
674 // result = C[m]*P + Q
675 { .mfb
676       nop.m         999
677       fma.d.s0      f8                  = sincos_Cm, sincos_P, sincos_Q
678       br.ret.sptk   b0  // Exit for common path
681 ////////// x = 0/Inf/NaN path //////////////////
682 _SINCOS_SPECIAL_ARGS:
683 .pred.rel "mutex",p8,p9
684 // sin(+/-0) = +/-0
685 // sin(Inf)  = NaN
686 // sin(NaN)  = NaN
687 { .mfi
688       nop.m         999
689 (p8)  fma.d.s0      f8                  = f8, f0, f0 // sin(+/-0,NaN,Inf)
690       nop.i         999
692 // cos(+/-0) = 1.0
693 // cos(Inf)  = NaN
694 // cos(NaN)  = NaN
695 { .mfb
696       nop.m         999
697 (p9)  fma.d.s0      f8                  = f8, f0, f1 // cos(+/-0,NaN,Inf)
698       br.ret.sptk   b0 // Exit for x = 0/Inf/NaN path
701 _SINCOS_UNORM:
702 // Here if x=unorm
703 { .mfb
704       getf.exp      sincos_r_signexp    = sincos_NORM_f8 // Get signexp of x
705       fcmp.eq.s0    p11,p0              = f8, f0  // Dummy op to set denorm flag
706       br.cond.sptk  _SINCOS_COMMON2     // Return to main path
709 GLOBAL_IEEE754_END(cos)
710 libm_alias_double_other (__cos, cos)
712 //////////// x >= 2^27 - large arguments routine call ////////////
713 LOCAL_LIBM_ENTRY(__libm_callout_sincos)
714 _SINCOS_LARGE_ARGS:
715 .prologue
716 { .mfi
717       mov           GR_SAVE_r_sincos    = sincos_r_sincos // Save sin or cos
718       nop.f         999
719 .save ar.pfs,GR_SAVE_PFS
720       mov           GR_SAVE_PFS         = ar.pfs
724 { .mfi
725       mov           GR_SAVE_GP          = gp
726       nop.f         999
727 .save b0, GR_SAVE_B0
728       mov           GR_SAVE_B0          = b0
731 .body
732 { .mbb
733       setf.sig      sincos_save_tmp     = sincos_GR_all_ones// inexact set
734       nop.b         999
735 (p8)  br.call.sptk.many b0              = __libm_sin_large# // sin(large_X)
739 { .mbb
740       cmp.ne        p9,p0               = GR_SAVE_r_sincos, r0 // set p9 if cos
741       nop.b         999
742 (p9)  br.call.sptk.many b0              = __libm_cos_large# // cos(large_X)
745 { .mfi
746       mov           gp                  = GR_SAVE_GP
747       fma.d.s0      f8                  = f8, f1, f0 // Round result to double
748       mov           b0                  = GR_SAVE_B0
750 // Force inexact set
751 { .mfi
752       nop.m         999
753       fmpy.s0       sincos_save_tmp     = sincos_save_tmp, sincos_save_tmp
754       nop.i         999
757 { .mib
758       nop.m         999
759       mov           ar.pfs              = GR_SAVE_PFS
760       br.ret.sptk   b0 // Exit for large arguments routine call
763 LOCAL_LIBM_END(__libm_callout_sincos)
765 .type    __libm_sin_large#,@function
766 .global  __libm_sin_large#
767 .type    __libm_cos_large#,@function
768 .global  __libm_cos_large#