2.9
[glibc/nacl-glibc.git] / sysdeps / ia64 / fpu / s_cos.S
blobfc121fce19391d4e75306c78572adbd507e5d4c1
1 .file "sincos.s"
4 // Copyright (c) 2000 - 2005, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
22 // permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at
38 // http://www.intel.com/software/products/opensource/libraries/num.htm.
40 // History
41 //==============================================================
42 // 02/02/00 Initial version
43 // 04/02/00 Unwind support added.
44 // 06/16/00 Updated tables to enforce symmetry
45 // 08/31/00 Saved 2 cycles in main path, and 9 in other paths.
46 // 09/20/00 The updated tables regressed to an old version, so reinstated them
47 // 10/18/00 Changed one table entry to ensure symmetry
48 // 01/03/01 Improved speed, fixed flag settings for small arguments.
49 // 02/18/02 Large arguments processing routine excluded
50 // 05/20/02 Cleaned up namespace and sf0 syntax
51 // 06/03/02 Insure inexact flag set for large arg result
52 // 09/05/02 Work range is widened by reduction strengthen (3 parts of Pi/16)
53 // 02/10/03 Reordered header: .section, .global, .proc, .align
54 // 08/08/03 Improved performance
55 // 10/28/04 Saved sincos_r_sincos to avoid clobber by dynamic loader 
56 // 03/31/05 Reformatted delimiters between data tables
58 // API
59 //==============================================================
60 // double sin( double x);
61 // double cos( double x);
63 // Overview of operation
64 //==============================================================
66 // Step 1
67 // ======
68 // Reduce x to region -1/2*pi/2^k ===== 0 ===== +1/2*pi/2^k  where k=4
69 //    divide x by pi/2^k.
70 //    Multiply by 2^k/pi.
71 //    nfloat = Round result to integer (round-to-nearest)
73 // r = x -  nfloat * pi/2^k
74 //    Do this as ((((x -  nfloat * HIGH(pi/2^k))) - 
75 //                        nfloat * LOW(pi/2^k)) - 
76 //                        nfloat * LOWEST(pi/2^k) for increased accuracy.
77 //    pi/2^k is stored as two numbers that when added make pi/2^k.
78 //       pi/2^k = HIGH(pi/2^k) + LOW(pi/2^k)
79 //    HIGH and LOW parts are rounded to zero values, 
80 //    and LOWEST is rounded to nearest one.
82 // x = (nfloat * pi/2^k) + r
83 //    r is small enough that we can use a polynomial approximation
84 //    and is referred to as the reduced argument.
86 // Step 3
87 // ======
88 // Take the unreduced part and remove the multiples of 2pi.
89 // So nfloat = nfloat (with lower k+1 bits cleared) + lower k+1 bits
91 //    nfloat (with lower k+1 bits cleared) is a multiple of 2^(k+1)
92 //    N * 2^(k+1)
93 //    nfloat * pi/2^k = N * 2^(k+1) * pi/2^k + (lower k+1 bits) * pi/2^k
94 //    nfloat * pi/2^k = N * 2 * pi + (lower k+1 bits) * pi/2^k
95 //    nfloat * pi/2^k = N2pi + M * pi/2^k
98 // Sin(x) = Sin((nfloat * pi/2^k) + r)
99 //        = Sin(nfloat * pi/2^k) * Cos(r) + Cos(nfloat * pi/2^k) * Sin(r)
101 //          Sin(nfloat * pi/2^k) = Sin(N2pi + Mpi/2^k)
102 //                               = Sin(N2pi)Cos(Mpi/2^k) + Cos(N2pi)Sin(Mpi/2^k)
103 //                               = Sin(Mpi/2^k)
105 //          Cos(nfloat * pi/2^k) = Cos(N2pi + Mpi/2^k)
106 //                               = Cos(N2pi)Cos(Mpi/2^k) + Sin(N2pi)Sin(Mpi/2^k)
107 //                               = Cos(Mpi/2^k)
109 // Sin(x) = Sin(Mpi/2^k) Cos(r) + Cos(Mpi/2^k) Sin(r)
112 // Step 4
113 // ======
114 // 0 <= M < 2^(k+1)
115 // There are 2^(k+1) Sin entries in a table.
116 // There are 2^(k+1) Cos entries in a table.
118 // Get Sin(Mpi/2^k) and Cos(Mpi/2^k) by table lookup.
121 // Step 5
122 // ======
123 // Calculate Cos(r) and Sin(r) by polynomial approximation.
125 // Cos(r) = 1 + r^2 q1  + r^4 q2 + r^6 q3 + ... = Series for Cos
126 // Sin(r) = r + r^3 p1  + r^5 p2 + r^7 p3 + ... = Series for Sin
128 // and the coefficients q1, q2, ... and p1, p2, ... are stored in a table
131 // Calculate
132 // Sin(x) = Sin(Mpi/2^k) Cos(r) + Cos(Mpi/2^k) Sin(r)
134 // as follows
136 //    S[m] = Sin(Mpi/2^k) and C[m] = Cos(Mpi/2^k)
137 //    rsq = r*r
140 //    P = p1 + r^2p2 + r^4p3 + r^6p4
141 //    Q = q1 + r^2q2 + r^4q3 + r^6q4
143 //       rcub = r * rsq
144 //       Sin(r) = r + rcub * P
145 //              = r + r^3p1  + r^5p2 + r^7p3 + r^9p4 + ... = Sin(r)
147 //            The coefficients are not exactly these values, but almost.
149 //            p1 = -1/6  = -1/3!
150 //            p2 = 1/120 =  1/5!
151 //            p3 = -1/5040 = -1/7!
152 //            p4 = 1/362889 = 1/9!
154 //       P =  r + rcub * P
156 //    Answer = S[m] Cos(r) + [Cm] P
158 //       Cos(r) = 1 + rsq Q
159 //       Cos(r) = 1 + r^2 Q
160 //       Cos(r) = 1 + r^2 (q1 + r^2q2 + r^4q3 + r^6q4)
161 //       Cos(r) = 1 + r^2q1 + r^4q2 + r^6q3 + r^8q4 + ...
163 //       S[m] Cos(r) = S[m](1 + rsq Q)
164 //       S[m] Cos(r) = S[m] + Sm rsq Q
165 //       S[m] Cos(r) = S[m] + s_rsq Q
166 //       Q         = S[m] + s_rsq Q
168 // Then,
170 //    Answer = Q + C[m] P
173 // Registers used
174 //==============================================================
175 // general input registers:
176 // r14 -> r26
177 // r32 -> r35
179 // predicate registers used:
180 // p6 -> p11
182 // floating-point registers used
183 // f9 -> f15
184 // f32 -> f61
186 // Assembly macros
187 //==============================================================
188 sincos_NORM_f8                 = f9
189 sincos_W                       = f10
190 sincos_int_Nfloat              = f11
191 sincos_Nfloat                  = f12
193 sincos_r                       = f13
194 sincos_rsq                     = f14
195 sincos_rcub                    = f15
196 sincos_save_tmp                = f15
198 sincos_Inv_Pi_by_16            = f32
199 sincos_Pi_by_16_1              = f33
200 sincos_Pi_by_16_2              = f34
202 sincos_Inv_Pi_by_64            = f35
204 sincos_Pi_by_16_3              = f36
206 sincos_r_exact                 = f37
208 sincos_Sm                      = f38
209 sincos_Cm                      = f39
211 sincos_P1                      = f40
212 sincos_Q1                      = f41
213 sincos_P2                      = f42
214 sincos_Q2                      = f43
215 sincos_P3                      = f44
216 sincos_Q3                      = f45
217 sincos_P4                      = f46
218 sincos_Q4                      = f47
220 sincos_P_temp1                 = f48
221 sincos_P_temp2                 = f49
223 sincos_Q_temp1                 = f50
224 sincos_Q_temp2                 = f51
226 sincos_P                       = f52
227 sincos_Q                       = f53
229 sincos_srsq                    = f54
231 sincos_SIG_INV_PI_BY_16_2TO61  = f55
232 sincos_RSHF_2TO61              = f56
233 sincos_RSHF                    = f57
234 sincos_2TOM61                  = f58
235 sincos_NFLOAT                  = f59
236 sincos_W_2TO61_RSH             = f60
238 fp_tmp                         = f61
240 /////////////////////////////////////////////////////////////
242 sincos_GR_sig_inv_pi_by_16     = r14
243 sincos_GR_rshf_2to61           = r15
244 sincos_GR_rshf                 = r16
245 sincos_GR_exp_2tom61           = r17
246 sincos_GR_n                    = r18
247 sincos_GR_m                    = r19
248 sincos_GR_32m                  = r19
249 sincos_GR_all_ones             = r19
250 sincos_AD_1                    = r20
251 sincos_AD_2                    = r21
252 sincos_exp_limit               = r22
253 sincos_r_signexp               = r23
254 sincos_r_17_ones               = r24
255 sincos_r_sincos                = r25
256 sincos_r_exp                   = r26
258 GR_SAVE_PFS                    = r33
259 GR_SAVE_B0                     = r34
260 GR_SAVE_GP                     = r35
261 GR_SAVE_r_sincos               = r36
264 RODATA
266 // Pi/16 parts
267 .align 16
268 LOCAL_OBJECT_START(double_sincos_pi)
269    data8 0xC90FDAA22168C234, 0x00003FFC // pi/16 1st part
270    data8 0xC4C6628B80DC1CD1, 0x00003FBC // pi/16 2nd part
271    data8 0xA4093822299F31D0, 0x00003F7A // pi/16 3rd part
272 LOCAL_OBJECT_END(double_sincos_pi)
274 // Coefficients for polynomials
275 LOCAL_OBJECT_START(double_sincos_pq_k4)
276    data8 0x3EC71C963717C63A // P4
277    data8 0x3EF9FFBA8F191AE6 // Q4
278    data8 0xBF2A01A00F4E11A8 // P3
279    data8 0xBF56C16C05AC77BF // Q3
280    data8 0x3F8111111110F167 // P2
281    data8 0x3FA555555554DD45 // Q2
282    data8 0xBFC5555555555555 // P1
283    data8 0xBFDFFFFFFFFFFFFC // Q1
284 LOCAL_OBJECT_END(double_sincos_pq_k4)
286 // Sincos table (S[m], C[m])
287 LOCAL_OBJECT_START(double_sin_cos_beta_k4)
289 data8 0x0000000000000000 , 0x00000000 // sin( 0 pi/16)  S0
290 data8 0x8000000000000000 , 0x00003fff // cos( 0 pi/16)  C0
292 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // sin( 1 pi/16)  S1
293 data8 0xfb14be7fbae58157 , 0x00003ffe // cos( 1 pi/16)  C1
295 data8 0xc3ef1535754b168e , 0x00003ffd // sin( 2 pi/16)  S2
296 data8 0xec835e79946a3146 , 0x00003ffe // cos( 2 pi/16)  C2
298 data8 0x8e39d9cd73464364 , 0x00003ffe // sin( 3 pi/16)  S3
299 data8 0xd4db3148750d181a , 0x00003ffe // cos( 3 pi/16)  C3
301 data8 0xb504f333f9de6484 , 0x00003ffe // sin( 4 pi/16)  S4
302 data8 0xb504f333f9de6484 , 0x00003ffe // cos( 4 pi/16)  C4
304 data8 0xd4db3148750d181a , 0x00003ffe // sin( 5 pi/16)  C3
305 data8 0x8e39d9cd73464364 , 0x00003ffe // cos( 5 pi/16)  S3
307 data8 0xec835e79946a3146 , 0x00003ffe // sin( 6 pi/16)  C2
308 data8 0xc3ef1535754b168e , 0x00003ffd // cos( 6 pi/16)  S2
310 data8 0xfb14be7fbae58157 , 0x00003ffe // sin( 7 pi/16)  C1
311 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // cos( 7 pi/16)  S1
313 data8 0x8000000000000000 , 0x00003fff // sin( 8 pi/16)  C0
314 data8 0x0000000000000000 , 0x00000000 // cos( 8 pi/16)  S0
316 data8 0xfb14be7fbae58157 , 0x00003ffe // sin( 9 pi/16)  C1
317 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // cos( 9 pi/16)  -S1
319 data8 0xec835e79946a3146 , 0x00003ffe // sin(10 pi/16)  C2
320 data8 0xc3ef1535754b168e , 0x0000bffd // cos(10 pi/16)  -S2
322 data8 0xd4db3148750d181a , 0x00003ffe // sin(11 pi/16)  C3
323 data8 0x8e39d9cd73464364 , 0x0000bffe // cos(11 pi/16)  -S3
325 data8 0xb504f333f9de6484 , 0x00003ffe // sin(12 pi/16)  S4
326 data8 0xb504f333f9de6484 , 0x0000bffe // cos(12 pi/16)  -S4
328 data8 0x8e39d9cd73464364 , 0x00003ffe // sin(13 pi/16) S3
329 data8 0xd4db3148750d181a , 0x0000bffe // cos(13 pi/16) -C3
331 data8 0xc3ef1535754b168e , 0x00003ffd // sin(14 pi/16) S2
332 data8 0xec835e79946a3146 , 0x0000bffe // cos(14 pi/16) -C2
334 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // sin(15 pi/16) S1
335 data8 0xfb14be7fbae58157 , 0x0000bffe // cos(15 pi/16) -C1
337 data8 0x0000000000000000 , 0x00000000 // sin(16 pi/16) S0
338 data8 0x8000000000000000 , 0x0000bfff // cos(16 pi/16) -C0
340 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // sin(17 pi/16) -S1
341 data8 0xfb14be7fbae58157 , 0x0000bffe // cos(17 pi/16) -C1
343 data8 0xc3ef1535754b168e , 0x0000bffd // sin(18 pi/16) -S2
344 data8 0xec835e79946a3146 , 0x0000bffe // cos(18 pi/16) -C2
346 data8 0x8e39d9cd73464364 , 0x0000bffe // sin(19 pi/16) -S3
347 data8 0xd4db3148750d181a , 0x0000bffe // cos(19 pi/16) -C3
349 data8 0xb504f333f9de6484 , 0x0000bffe // sin(20 pi/16) -S4
350 data8 0xb504f333f9de6484 , 0x0000bffe // cos(20 pi/16) -S4
352 data8 0xd4db3148750d181a , 0x0000bffe // sin(21 pi/16) -C3
353 data8 0x8e39d9cd73464364 , 0x0000bffe // cos(21 pi/16) -S3
355 data8 0xec835e79946a3146 , 0x0000bffe // sin(22 pi/16) -C2
356 data8 0xc3ef1535754b168e , 0x0000bffd // cos(22 pi/16) -S2
358 data8 0xfb14be7fbae58157 , 0x0000bffe // sin(23 pi/16) -C1
359 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // cos(23 pi/16) -S1
361 data8 0x8000000000000000 , 0x0000bfff // sin(24 pi/16) -C0
362 data8 0x0000000000000000 , 0x00000000 // cos(24 pi/16) S0
364 data8 0xfb14be7fbae58157 , 0x0000bffe // sin(25 pi/16) -C1
365 data8 0xc7c5c1e34d3055b3 , 0x00003ffc // cos(25 pi/16) S1
367 data8 0xec835e79946a3146 , 0x0000bffe // sin(26 pi/16) -C2
368 data8 0xc3ef1535754b168e , 0x00003ffd // cos(26 pi/16) S2
370 data8 0xd4db3148750d181a , 0x0000bffe // sin(27 pi/16) -C3
371 data8 0x8e39d9cd73464364 , 0x00003ffe // cos(27 pi/16) S3
373 data8 0xb504f333f9de6484 , 0x0000bffe // sin(28 pi/16) -S4
374 data8 0xb504f333f9de6484 , 0x00003ffe // cos(28 pi/16) S4
376 data8 0x8e39d9cd73464364 , 0x0000bffe // sin(29 pi/16) -S3
377 data8 0xd4db3148750d181a , 0x00003ffe // cos(29 pi/16) C3
379 data8 0xc3ef1535754b168e , 0x0000bffd // sin(30 pi/16) -S2
380 data8 0xec835e79946a3146 , 0x00003ffe // cos(30 pi/16) C2
382 data8 0xc7c5c1e34d3055b3 , 0x0000bffc // sin(31 pi/16) -S1
383 data8 0xfb14be7fbae58157 , 0x00003ffe // cos(31 pi/16) C1
385 data8 0x0000000000000000 , 0x00000000 // sin(32 pi/16) S0
386 data8 0x8000000000000000 , 0x00003fff // cos(32 pi/16) C0
387 LOCAL_OBJECT_END(double_sin_cos_beta_k4)
389 .section .text
391 ////////////////////////////////////////////////////////
392 // There are two entry points: sin and cos
395 // If from sin, p8 is true
396 // If from cos, p9 is true
398 GLOBAL_IEEE754_ENTRY(sin)
400 { .mlx
401       getf.exp      sincos_r_signexp    = f8
402       movl sincos_GR_sig_inv_pi_by_16   = 0xA2F9836E4E44152A // signd of 16/pi
404 { .mlx
405       addl          sincos_AD_1         = @ltoff(double_sincos_pi), gp
406       movl sincos_GR_rshf_2to61         = 0x47b8000000000000 // 1.1 2^(63+63-2)
410 { .mfi
411       ld8           sincos_AD_1         = [sincos_AD_1]
412       fnorm.s0      sincos_NORM_f8      = f8  // Normalize argument
413       cmp.eq        p8,p9               = r0, r0 // set p8 (clear p9) for sin
415 { .mib
416       mov           sincos_GR_exp_2tom61  = 0xffff-61 // exponent of scale 2^-61
417       mov           sincos_r_sincos       = 0x0 // sincos_r_sincos = 0 for sin
418       br.cond.sptk  _SINCOS_COMMON  // go to common part
422 GLOBAL_IEEE754_END(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)
711 //////////// x >= 2^27 - large arguments routine call ////////////
712 LOCAL_LIBM_ENTRY(__libm_callout_sincos)
713 _SINCOS_LARGE_ARGS:
714 .prologue
715 { .mfi
716       mov           GR_SAVE_r_sincos    = sincos_r_sincos // Save sin or cos
717       nop.f         999
718 .save ar.pfs,GR_SAVE_PFS
719       mov           GR_SAVE_PFS         = ar.pfs
723 { .mfi
724       mov           GR_SAVE_GP          = gp
725       nop.f         999
726 .save b0, GR_SAVE_B0
727       mov           GR_SAVE_B0          = b0
730 .body
731 { .mbb
732       setf.sig      sincos_save_tmp     = sincos_GR_all_ones// inexact set
733       nop.b         999
734 (p8)  br.call.sptk.many b0              = __libm_sin_large# // sin(large_X)
738 { .mbb
739       cmp.ne        p9,p0               = GR_SAVE_r_sincos, r0 // set p9 if cos
740       nop.b         999
741 (p9)  br.call.sptk.many b0              = __libm_cos_large# // cos(large_X)
744 { .mfi
745       mov           gp                  = GR_SAVE_GP
746       fma.d.s0      f8                  = f8, f1, f0 // Round result to double
747       mov           b0                  = GR_SAVE_B0
749 // Force inexact set
750 { .mfi
751       nop.m         999
752       fmpy.s0       sincos_save_tmp     = sincos_save_tmp, sincos_save_tmp
753       nop.i         999 
756 { .mib
757       nop.m         999
758       mov           ar.pfs              = GR_SAVE_PFS
759       br.ret.sptk   b0 // Exit for large arguments routine call
762 LOCAL_LIBM_END(__libm_callout_sincos)
764 .type    __libm_sin_large#,@function
765 .global  __libm_sin_large#
766 .type    __libm_cos_large#,@function
767 .global  __libm_cos_large#