2.9
[glibc/nacl-glibc.git] / sysdeps / ia64 / fpu / e_atan2.S
blob7a17fbfed4a412ba82f4b7535ab4be151792cc19
1 .file "atan2.s"
4 // Copyright (c) 2000 - 2003, 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/04/00  Unwind support added
44 // 08/15/00  Bundle added after call to __libm_error_support to properly
45 //           set [the previously overwritten] GR_Parameter_RESULT.
46 // 08/17/00  Changed predicate register macro-usage to direct predicate
47 //           names due to an assembler bug.
48 // 09/28/00  Updated to set invalid on SNaN inputs
49 // 01/19/01  Fixed flags for small results
50 // 04/13/01  Rescheduled to make all paths faster
51 // 05/20/02  Cleaned up namespace and sf0 syntax
52 // 08/20/02  Corrected inexact flag and directed rounding symmetry bugs
53 // 02/06/03  Reordered header: .section, .global, .proc, .align
54 // 04/17/03  Added missing mutex directive
55 // 12/23/03  atan2(NaN1,NaN2) now QNaN1, for consistency with atan2f, atan2l
57 // API
58 //==============================================================
59 // double atan2(double Y, double X)
61 // Overview of operation
62 //==============================================================
64 // The atan2 function returns values in the interval [-pi,+pi].
66 // There are two basic paths: swap true and swap false.
67 // atan2(Y,X) ==> atan2(V/U) where U >= V. If Y > X, we must swap.
69 // p6  swap True    |Y| > |X|
70 // p7  swap False   |Y| <= |X|
71 // p8  X+   (If swap=True p8=p9=0)
72 // p9  X-
74 // all the other predicates p10 thru p15 are false for the main path
76 // Simple trigonometric identities show
77 //   Region 1 (-45 to +45 degrees):
78 //         X>0, |Y|<=X, V=Y, U=X     atan2(Y,X) = sgnY * (0 + atan(V/U))
80 //   Region 2 (-90 to -45 degrees, and +45 to +90 degrees):
81 //         X>0, |Y|>X, V=X, U=Y      atan2(Y,X) = sgnY * (pi/2 - atan(V/U))
83 //   Region 3 (-135 to -90 degrees, and +90 to +135 degrees):
84 //         X<0, |Y|>X, V=X, U=Y      atan2(Y,X) = sgnY * (pi/2 + atan(V/U))
86 //   Region 4 (-180 to -135 degrees, and +135 to +180 degrees):
87 //         X<0, |Y|<=X, V=Y, U=X      atan2(Y,X) = sgnY * (pi - atan(V/U))
89 // So the result is always of the form atan2(Y,X) = P + sgnXY * atan(V/U)
91 // We compute atan(V/U) from the identity
92 //      atan(z) + atan([(V/U)-z] / [1+(V/U)z])
93 //      where z is a limited precision approximation (16 bits) to V/U
95 // z is calculated with the assistance of the frcpa instruction.
97 // atan(z) is calculated by a polynomial z + z^3 * p(w),  w=z^2
98 // where p(w) = P0+P1*w+...+P22*w^22
100 // Let d = [(V/U)-z] / [1+(V/U)z]) = (V-U*z)/(U+V*z)
102 // Approximate atan(d) by d + P0*d^3
103 // Let F = 1/(U+V*z) * (1-a), where |a|< 2^-8.8.
104 // Compute q(a) = 1 + a + ... + a^5.
105 // Then F*q(a) approximates the reciprocal to more than 50 bits.
107 // Special values
108 //==============================================================
109 //              Y                 x          Result
110 //             +number           +inf        +0
111 //             -number           +inf        -0
112 //             +number           -inf        +pi
113 //             -number           -inf        -pi
115 //             +inf              +number     +pi/2
116 //             -inf              +number     -pi/2
117 //             +inf              -number     +pi/2
118 //             -inf              -number     -pi/2
120 //             +inf              +inf        +pi/4
121 //             -inf              +inf        -pi/4
122 //             +inf              -inf        +3pi/4
123 //             -inf              -inf        -3pi/4
125 //             +1                +1          +pi/4
126 //             -1                +1          -pi/4
127 //             +1                -1          +3pi/4
128 //             -1                -1          -3pi/4
130 //             +number           +0          +pi/2
131 //             -number           +0          -pi/2
132 //             +number           -0          +pi/2
133 //             -number           -0          -pi/2
135 //             +0                +number     +0
136 //             -0                +number     -0
137 //             +0                -number     +pi
138 //             -0                -number     -pi
140 //             +0                +0          +0
141 //             -0                +0          -0
142 //             +0                -0          +pi
143 //             -0                -0          -pi
145 //            Nan             anything      quiet Y
146 //            Not NaN         NaN           quiet X
148 // atan2(+-0/+-0) sets double error tag to 37
150 // Registers used
151 //==============================================================
153 // predicate registers used:
154 // p6 -> p15
156 // floating-point registers used:
157 // f8, f9 input
158 // f32 -> f119
160 // general registers used
161 // r32 -> r41
163 // Assembly macros
164 //==============================================================
166 EXP_AD_P1                    = r33
167 EXP_AD_P2                    = r34
168 rsig_near_one                = r35
171 GR_SAVE_B0                   = r35
172 GR_SAVE_GP                   = r36
173 GR_SAVE_PFS                  = r37
175 GR_Parameter_X               = r38
176 GR_Parameter_Y               = r39
177 GR_Parameter_RESULT          = r40
178 atan2_GR_tag                 = r41
180 atan2_Y                      = f8
181 atan2_X                      = f9
183 atan2_u1_X                   = f32
184 atan2_u1_Y                   = f33
185 atan2_z2_X                   = f34
186 atan2_z2_Y                   = f35
188 atan2_two                    = f36
189 atan2_B1sq_Y                 = f37
190 atan2_z1_X                   = f38
191 atan2_z1_Y                   = f39
192 atan2_B1X                    = f40
194 atan2_B1Y                    = f41
195 atan2_wp_X                   = f42
196 atan2_B1sq_X                 = f43
197 atan2_z                      = f44
198 atan2_w                      = f45
200 atan2_P0                     = f46
201 atan2_P1                     = f47
202 atan2_P2                     = f48
203 atan2_P3                     = f49
204 atan2_P4                     = f50
206 atan2_P5                     = f51
207 atan2_P6                     = f52
208 atan2_P7                     = f53
209 atan2_P8                     = f54
210 atan2_P9                     = f55
212 atan2_P10                    = f56
213 atan2_P11                    = f57
214 atan2_P12                    = f58
215 atan2_P13                    = f59
216 atan2_P14                    = f60
218 atan2_P15                    = f61
219 atan2_P16                    = f62
220 atan2_P17                    = f63
221 atan2_P18                    = f64
222 atan2_P19                    = f65
224 atan2_P20                    = f66
225 atan2_P21                    = f67
226 atan2_P22                    = f68
227 atan2_tmp                    = f68
228 atan2_pi_by_2                = f69
229 atan2_sgn_pi_by_2            = f69
230 atan2_V13                    = f70
232 atan2_W11                    = f71
233 atan2_E                      = f72
234 atan2_wp_Y                   = f73
235 atan2_V11                    = f74
236 atan2_V12                    = f75
238 atan2_V7                     = f76
239 atan2_V8                     = f77
240 atan2_W7                     = f78
241 atan2_W8                     = f79
242 atan2_W3                     = f80
244 atan2_W4                     = f81
245 atan2_V3                     = f82
246 atan2_V4                     = f83
247 atan2_F                      = f84
248 atan2_gV                     = f85
250 atan2_V10                    = f86
251 atan2_zcub                   = f87
252 atan2_V6                     = f88
253 atan2_V9                     = f89
254 atan2_W10                    = f90
256 atan2_W6                     = f91
257 atan2_W2                     = f92
258 atan2_V2                     = f93
259 atan2_alpha                  = f94
260 atan2_alpha_1                = f95
262 atan2_gVF                    = f96
263 atan2_V5                     = f97
264 atan2_W12                    = f98
265 atan2_W5                     = f99
266 atan2_alpha_sq               = f100
268 atan2_Cp                     = f101
269 atan2_V1                     = f102
270 atan2_ysq                    = f103
271 atan2_W1                     = f104
272 atan2_alpha_cub              = f105
274 atan2_C                      = f106
275 atan2_xsq                    = f107
276 atan2_d                      = f108
277 atan2_A_hi                   = f109
278 atan2_dsq                    = f110
280 atan2_pd                     = f111
281 atan2_A_lo                   = f112
282 atan2_A                      = f113
283 atan2_Pp                     = f114
284 atan2_sgnY                   = f115
286 atan2_sig_near_one           = f116
287 atan2_near_one               = f116
288 atan2_pi                     = f117
289 atan2_sgn_pi                 = f117
290 atan2_3pi_by_4               = f118
291 atan2_pi_by_4                = f119
294 /////////////////////////////////////////////////////////////
297 RODATA
299 .align 16
301 LOCAL_OBJECT_START(atan2_tb1)
302 data8 0xA21922DC45605EA1 ,  0x00003FFA // P11
303 data8 0xB199DD6D2675C40F ,  0x0000BFFA // P10
304 data8 0xC2F01E5DDD100DBE ,  0x00003FFA // P9
305 data8 0xD78F28FC2A592781 ,  0x0000BFFA // P8
306 data8 0xF0F03ADB3FC930D3 ,  0x00003FFA // P7
307 data8 0x88887EBB209E3543 ,  0x0000BFFB // P6
308 data8 0x9D89D7D55C3287A5 ,  0x00003FFB // P5
309 data8 0xBA2E8B9793955C77 ,  0x0000BFFB // P4
310 data8 0xE38E38E320A8A098 ,  0x00003FFB // P3
311 data8 0x9249249247E37913 ,  0x0000BFFC // P2
312 data8 0xCCCCCCCCCCC906CD ,  0x00003FFC // P1
313 data8 0xAAAAAAAAAAAAA8A9 ,  0x0000BFFD // P0
314 data8 0xC90FDAA22168C235 ,  0x00004000 // pi
315 LOCAL_OBJECT_END(atan2_tb1)
317 LOCAL_OBJECT_START(atan2_tb2)
318 data8 0xCE585A259BD8374C ,  0x00003FF0 // P21
319 data8 0x9F90FB984D8E39D0 ,  0x0000BFF3 // P20
320 data8 0x9D3436AABE218776 ,  0x00003FF5 // P19
321 data8 0xDEC343E068A6D2A8 ,  0x0000BFF6 // P18
322 data8 0xF396268151CFB11C ,  0x00003FF7 // P17
323 data8 0xD818B4BB43D84BF2 ,  0x0000BFF8 // P16
324 data8 0xA2270D30A90AA220 ,  0x00003FF9 // P15
325 data8 0xD5F4F2182E7A8725 ,  0x0000BFF9 // P14
326 data8 0x80D601879218B53A ,  0x00003FFA // P13
327 data8 0x9297B23CCFFB291F ,  0x0000BFFA // P12
328 data8 0xFE7E52D2A89995B3 ,  0x0000BFEC // P22
329 data8 0xC90FDAA22168C235 ,  0x00003FFF // pi/2
330 data8 0xC90FDAA22168C235 ,  0x00003FFE // pi/4
331 data8 0x96cbe3f9990e91a8 ,  0x00004000 // 3pi/4
332 LOCAL_OBJECT_END(atan2_tb2)
337 .section .text
338 GLOBAL_IEEE754_ENTRY(atan2)
340 { .mfi
341            alloc        r32           = ar.pfs,1,5,4,0
342            frcpa.s1     atan2_u1_X,p6 = f1,atan2_X
343            nop.i 999
345 { .mfi
346            addl         EXP_AD_P1   = @ltoff(atan2_tb1), gp
347            fma.s1       atan2_two  = f1,f1,f1
348            nop.i 999
352 { .mfi
353            ld8  EXP_AD_P1 = [EXP_AD_P1]
354            frcpa.s1     atan2_u1_Y,p7 = f1,atan2_Y
355            nop.i 999
357 { .mfi
358            nop.m 999
359            fma.s1       atan2_xsq  = atan2_X,atan2_X,f0
360            nop.i 999
364 { .mfi
365            nop.m 999
366            fclass.m p10,p0 = atan2_Y, 0xc3     // Test for y=nan
367            nop.i 999
369 { .mfi
370            nop.m 999
371            fma.s1       atan2_ysq  = atan2_Y,atan2_Y,f0
372            nop.i 999
376 { .mfi
377            add  EXP_AD_P2 = 0xd0,EXP_AD_P1
378            fclass.m p12,p0 = atan2_X, 0xc3     // Test for x nan
379            nop.i 999
384 // p10 Y NAN, quiet and return
385 { .mfi
386            ldfe         atan2_P11  = [EXP_AD_P1],16
387            fmerge.s     atan2_sgnY = atan2_Y,f1
388            nop.i 999
390 { .mfb
391            ldfe         atan2_P21  = [EXP_AD_P2],16
392 (p10)      fma.d.s0 f8 = atan2_X,atan2_Y,f0   // If y=nan, result quietized y
393 (p10)      br.ret.spnt b0        // Exit if y=nan
398 { .mfi
399            ldfe         atan2_P10  = [EXP_AD_P1],16
400            fma.s1       atan2_z1_X = atan2_u1_X, atan2_Y, f0
401            nop.i 999
403 { .mfi
404            ldfe         atan2_P20  = [EXP_AD_P2],16
405            fnma.s1      atan2_B1X  = atan2_u1_X, atan2_X, atan2_two
406            nop.i 999
410 { .mfi
411            ldfe         atan2_P9   = [EXP_AD_P1],16
412            fma.s1       atan2_z1_Y = atan2_u1_Y, atan2_X, f0
413            nop.i 999
415 { .mfi
416            ldfe         atan2_P19  = [EXP_AD_P2],16
417            fnma.s1      atan2_B1Y  = atan2_u1_Y, atan2_Y, atan2_two
418            nop.i 999
422 { .mfi
423            ldfe         atan2_P8   = [EXP_AD_P1],16
424            fma.s1       atan2_z2_X = atan2_u1_X, atan2_ysq, f0
425            nop.i 999
427 { .mfi
428            ldfe         atan2_P18  = [EXP_AD_P2],16
429            fma.s1       atan2_z2_Y = atan2_u1_Y, atan2_xsq, f0
430            nop.i 999
434 // p10 ==> x  inf     y ?
435 // p11 ==> x !inf     y ?
436 { .mfi
437            ldfe         atan2_P7   = [EXP_AD_P1],16
438            fclass.m p10,p11 = atan2_X, 0x23    // test for x inf
439            nop.i 999
441 { .mfb
442            ldfe         atan2_P17  = [EXP_AD_P2],16
443 (p12)      fma.d.s0        f8 = atan2_X,atan2_Y,f0     // If x nan, result quiet x
444 (p12)      br.ret.spnt b0                 // Exit for x nan
448 // p6 true if swap,    means |y| >  |x|    or ysq > xsq
449 // p7 true if no swap, means |x| >= |y|    or xsq >= ysq
450 { .mmf
451            ldfe         atan2_P6   = [EXP_AD_P1],16
452            ldfe         atan2_P16  = [EXP_AD_P2],16
453            fcmp.ge.s1 p7,p6    = atan2_xsq, atan2_ysq
457 { .mfi
458            ldfe         atan2_P5   = [EXP_AD_P1],16
459            fma.s1       atan2_wp_X   = atan2_z1_X, atan2_z1_X, f0
460            nop.i 999
462 { .mfi
463            ldfe         atan2_P15       = [EXP_AD_P2],16
464            fma.s1       atan2_B1sq_X = atan2_B1X, atan2_B1X, f0
465            nop.i 999
469 { .mfi
470            ldfe         atan2_P4   = [EXP_AD_P1],16
471 (p6)       fma.s1       atan2_wp_Y   = atan2_z1_Y, atan2_z1_Y, f0
472            nop.i 999
474 { .mfi
475            ldfe         atan2_P14  = [EXP_AD_P2],16
476 (p6)       fma.s1       atan2_B1sq_Y = atan2_B1Y, atan2_B1Y, f0
477            nop.i 999
481 { .mfi
482            ldfe         atan2_P3        = [EXP_AD_P1],16
483 (p6)       fma.s1       atan2_E         = atan2_z2_Y, atan2_B1Y, atan2_Y
484            nop.i 999
486 { .mfi
487            ldfe         atan2_P13  = [EXP_AD_P2],16
488 (p7)       fma.s1       atan2_E         = atan2_z2_X, atan2_B1X, atan2_X
489            nop.i 999
494 { .mfi
495            ldfe         atan2_P2        = [EXP_AD_P1],16
496 (p6)       fma.s1       atan2_z         = atan2_z1_Y, atan2_B1Y, f0
497            nop.i 999
499 { .mfi
500            ldfe         atan2_P12  = [EXP_AD_P2],16
501 (p7)       fma.s1       atan2_z         = atan2_z1_X, atan2_B1X, f0
502            nop.i 999
507 { .mfi
508            ldfe         atan2_P1        = [EXP_AD_P1],16
509            fcmp.eq.s0  p14,p15=atan2_X,atan2_Y  // Dummy for denorm and invalid
510            nop.i 999
512 { .mlx
513            ldfe         atan2_P22       = [EXP_AD_P2],16
514            movl         rsig_near_one = 0x8000000000000001 // signif near 1.0
519 // p12 ==> x  inf     y inf
520 // p13 ==> x  inf     y !inf
521 { .mmf
522            ldfe         atan2_P0        = [EXP_AD_P1],16
523            ldfe         atan2_pi_by_2   = [EXP_AD_P2],16
524 (p10)      fclass.m.unc p12,p13 = atan2_Y, 0x23  // x inf, test if y inf
528 { .mfi
529            ldfe         atan2_pi        = [EXP_AD_P1],16
530 (p6)       fma.s1       atan2_w         = atan2_wp_Y, atan2_B1sq_Y,f0
531            nop.i 999
533 { .mfi
534            ldfe         atan2_pi_by_4       = [EXP_AD_P2],16
535 (p7)       fma.s1       atan2_w         = atan2_wp_X, atan2_B1sq_X,f0
536            nop.i 999
540 { .mfi
541            ldfe         atan2_3pi_by_4       = [EXP_AD_P2],16
542 (p11)      fclass.m.unc p9,p0 = atan2_Y, 0x23  // x not inf, test if y inf
543            nop.i 999
547 { .mfi
548            setf.sig      atan2_sig_near_one = rsig_near_one
549 (p12)      fcmp.gt.unc.s1 p10,p11 = atan2_X,f0 // x inf, y inf, test if x +inf
550            nop.i 999
552 { .mfi
553            nop.m 999
554 (p6)       fnma.s1       atan2_gV        = atan2_Y, atan2_z, atan2_X
555            nop.i 999
559 { .mfi
560            nop.m 999
561            frcpa.s1     atan2_F,p0     = f1, atan2_E
562            nop.i 999
564 { .mfi
565            nop.m 999
566 (p7)       fnma.s1       atan2_gV        = atan2_X, atan2_z, atan2_Y
567            nop.i 999
571 // p13 ==> x  inf     y !inf
572 { .mfi
573            nop.m 999
574 (p13)      fcmp.gt.unc.s1 p14,p15 = atan2_X,f0 // x inf, y !inf, test if x +inf
575            nop.i 999
577 { .mfb
578            nop.m 999
579 (p9)       fma.d.s0  f8 = atan2_sgnY, atan2_pi_by_2, f0  // +-pi/2 if x !inf, y inf
580 (p9)       br.ret.spnt b0      // exit if x not inf, y inf, result is +-pi/2
584 { .mfi
585            nop.m 999
586            fma.s1       atan2_V13       = atan2_w, atan2_P11, atan2_P10
587            nop.i 999
589 { .mfi
590            nop.m 999
591            fma.s1       atan2_W11       = atan2_w, atan2_P21, atan2_P20
592            nop.i 999
596 { .mfi
597            nop.m 999
598            fma.s1       atan2_V11       = atan2_w, atan2_P9, atan2_P8
599            nop.i 999
601 { .mfi
602            nop.m 999
603            fma.s1       atan2_V12       = atan2_w, atan2_w, f0
604            nop.i 999
608 { .mfi
609            nop.m 999
610            fma.s1       atan2_V8        = atan2_w, atan2_P7 , atan2_P6
611            nop.i 999
613 { .mfi
614            nop.m 999
615            fma.s1       atan2_W8        = atan2_w, atan2_P19, atan2_P18
616            nop.i 999
620 { .mfi
621            nop.m 999
622            fnma.s1      atan2_alpha     = atan2_E, atan2_F, f1
623            nop.i 999
625 { .mfi
626            nop.m 999
627            fnma.s1      atan2_alpha_1   = atan2_E, atan2_F, atan2_two
628            nop.i 999
633 { .mfi
634            nop.m 999
635            fma.s1       atan2_V7        = atan2_w, atan2_P5 , atan2_P4
636            nop.i 999
638 { .mfi
639            nop.m 999
640            fma.s1       atan2_W7        = atan2_w, atan2_P17, atan2_P16
641            nop.i 999
645 { .mfi
646            nop.m 999
647            fma.s1       atan2_V4        = atan2_w, atan2_P3 , atan2_P2
648            nop.i 999
650 { .mfi
651            nop.m 999
652            fma.s1       atan2_W4        = atan2_w, atan2_P15, atan2_P14
653            nop.i 999
657 { .mfi
658            nop.m 999
659            fma.s1       atan2_V3        = atan2_w, atan2_P1 , atan2_P0
660            nop.i 999
662 { .mfi
663            nop.m 999
664            fma.s1       atan2_W3        = atan2_w, atan2_P13, atan2_P12
665            nop.i 999
669 { .mfi
670            nop.m 999
671            fma.s1       atan2_V10       = atan2_V12, atan2_V13, atan2_V11
672            nop.i 999
674 { .mfi
675            nop.m 999
676            fma.s1       atan2_gVF       = atan2_gV, atan2_F, f0
677            nop.i 999
681 { .mfi
682            nop.m 999
683            fma.s1       atan2_alpha_sq  = atan2_alpha, atan2_alpha, f0
684            nop.i 999
686 { .mfi
687            nop.m 999
688            fma.s1       atan2_Cp        = atan2_alpha, atan2_alpha_1, f1
689            nop.i 999
693 { .mfi
694            nop.m 999
695            fma.s1       atan2_V9        = atan2_V12, atan2_V12, f0
696            nop.i 999
698 { .mfi
699            nop.m 999
700            fma.s1       atan2_W10       = atan2_V12, atan2_P22 , atan2_W11
701            nop.i 999
705 { .mfi
706            nop.m 999
707            fma.s1       atan2_V6        = atan2_V12, atan2_V8 , atan2_V7
708            nop.i 999
710 { .mfi
711            nop.m 999
712            fma.s1       atan2_W6        = atan2_V12, atan2_W8 , atan2_W7
713            nop.i 999
717 { .mfi
718            nop.m 999
719            fma.s1       atan2_V2        = atan2_V12, atan2_V4 , atan2_V3
720            nop.i 999
722 { .mfi
723            nop.m 999
724            fma.s1       atan2_W2        = atan2_V12, atan2_W4  , atan2_W3
725            nop.i 999
729 // p8 ==> y   0     x?
730 // p9 ==> y  !0     x?
731 { .mfi
732            nop.m 999
733            fclass.m p8,p9 = atan2_Y, 0x07  // Test for y=0
734            nop.i 999
736 { .mfi
737            nop.m 999
738            fma.s1       atan2_zcub      = atan2_z, atan2_w, f0
739            nop.i 999
743 { .mfi
744            nop.m 999
745            fma.s1       atan2_alpha_cub = atan2_alpha, atan2_alpha_sq, f0
746            nop.i 999
748 { .mfi
749            nop.m 999
750            fma.s1       atan2_C         = atan2_gVF, atan2_Cp, f0
751            nop.i 999
755 // p12 ==>  y0     x0
756 // p13 ==>  y0     x!0
757 { .mfi
758            nop.m 999
759 (p8)       fclass.m.unc p12,p13 = atan2_X, 0x07  // y=0, test if x is 0
760            nop.i 999
762 { .mfi
763            nop.m 999
764            fma.s1       atan2_W12       = atan2_V9, atan2_V9, f0
765            nop.i 999
769 { .mfi
770            nop.m 999
771            fma.s1       atan2_V5        = atan2_V9, atan2_V10, atan2_V6
772            nop.i 999
774 { .mfi
775            nop.m 999
776            fma.s1       atan2_W5        = atan2_V9, atan2_W10, atan2_W6
777            nop.i 999
782 // p9 ==>  y!0    x0
783 { .mfi
784            nop.m 999
785 (p9)       fclass.m.unc p9,p0 = atan2_X, 0x07  // y not 0, test if x is 0
786            nop.i 999
788 // p10 ==> X +INF, Y +-INF
789 { .mfb
790            nop.m 999
791 (p10)      fma.d.s0       f8 = atan2_sgnY, atan2_pi_by_4, f0 // x=+inf, y=inf
792 (p10)      br.ret.spnt b0          // Exit for x=+inf, y=inf, result is +-pi/4
796 .pred.rel "mutex",p11,p14
797 { .mfi
798            nop.m 999
799 (p14)      fmerge.s    f8 = atan2_sgnY, f0 // x=+inf, y !inf, result +-0
800            nop.i 999
802 // p11 ==> X -INF, Y +-INF
803 { .mfb
804            nop.m 999
805 (p11)      fma.d.s0       f8 = atan2_sgnY, atan2_3pi_by_4, f0 // x=-inf, y=inf
806 (p11)      br.ret.spnt b0          // Exit for x=-inf, y=inf, result is +-3pi/4
810 { .mfi
811            nop.m 999
812 (p13)      fcmp.gt.unc.s1 p10,p11 = atan2_X,f0 // x not 0, y=0, test if x>0
813            nop.i 999
815 { .mfb
816            nop.m 999
817            fma.s1       atan2_d         = atan2_alpha_cub, atan2_C, atan2_C
818 (p14)      br.ret.spnt b0         // Exit if x=+inf, y !inf, result +-0
822 { .mfi
823            nop.m 999
824            fma.s1       atan2_W12       = atan2_V9, atan2_W12, f0
825            nop.i 999
827 { .mfb
828            nop.m 999
829 (p9)       fma.d.s0       f8 = atan2_sgnY, atan2_pi_by_2, f0 // x=0, y not 0
830 (p9)       br.ret.spnt b0      // Exit if x=0 and y not 0, result is +-pi/2
834 { .mfi
835            nop.m 999
836            fma.s1       atan2_V1        = atan2_V9, atan2_V5, atan2_V2
837            nop.i 999
839 { .mfb
840            nop.m 999
841            fma.s1       atan2_W1        = atan2_V9, atan2_W5, atan2_W2
842 (p12)      br.spnt ATAN2_ERROR            // Branch if x=0 and y=0
846 { .mfi
847            nop.m 999
848 (p10)      fmerge.s     f8              = atan2_sgnY, f0  // +-0 if x>0, y=0
849            nop.i 999
851 { .mfb
852            nop.m 999
853 (p11)      fma.d.s0        f8 = atan2_sgnY, atan2_pi, f0 // +-pi if x<0, y=0
854 (p13)      br.ret.spnt b0      // Exit if x!0 and y=0
859 { .mfi
860            nop.m 999
861            fma.s1       atan2_pd        = atan2_P0, atan2_d, f0
862            nop.i 999
864 { .mfi
865            nop.m 999
866            fma.s1       atan2_dsq       = atan2_d, atan2_d, f0
867            nop.i 999
872 { .mfi
873            nop.m 999
874            fmerge.se    atan2_near_one = f1, atan2_sig_near_one // Const ~1.0
875            nop.i 999
877 { .mfi
878            nop.m 999
879            fma.s1       atan2_Pp        = atan2_W12, atan2_W1, atan2_V1
880            nop.i 999
884 // p8 true if no swap and X positive
885 // p9 true if no swap and X negative
886 // both are false is swap is true
887 { .mfi
888            nop.m 999
889 (p7)       fcmp.ge.unc.s1 p8,p9    = atan2_X,f0
890            nop.i 999
892 { .mfb
893            nop.m 999
894 (p15)      fma.d.s0        f8              = atan2_sgnY, atan2_pi, f0
895 (p15)      br.ret.spnt b0         // Exit if x=-inf, y !inf, result +-pi
899 { .mfi
900            nop.m 999
901            fma.s1       atan2_sgn_pi_by_2 = atan2_pi_by_2, atan2_sgnY, f0
902            nop.i 999
904 { .mfi
905            nop.m 999
906            fma.s1       atan2_A_lo      = atan2_pd, atan2_dsq, atan2_d
907            nop.i 999
912 { .mfi
913            nop.m 999
914            fma.s1       atan2_sgn_pi = atan2_pi, atan2_sgnY, f0
915            nop.i 999
917 { .mfi
918            nop.m 999
919            fma.s1       atan2_A_hi      = atan2_zcub, atan2_Pp, atan2_z
920            nop.i 999
925 // For |Y| <= |X| and X > 0, force inexact in case A_lo is zero
926 { .mfi
927            nop.m 999
928 (p8)       fmpy.s0      atan2_tmp       = atan2_P22, atan2_P22
929            nop.i 999
933 { .mfi
934            nop.m 999
935            fma.s1       atan2_A         = atan2_A_hi, f1, atan2_A_lo
936            nop.i 999
938 // For |Y| <= |X| and X > 0, result is A_hi + A_lo
939 { .mfi
940            nop.m 999
941 (p8)       fma.d.s0       f8         = atan2_A_hi, f1, atan2_A_lo
942            nop.i 999
946 .pred.rel "mutex",p6,p9
947 // We perturb A by multiplying by 1.0+1ulp as we produce the result
948 // in order to get symmetrically rounded results in directed rounding modes.
949 // If we don't do this, there are a few cases where the trailing 11 bits of
950 // the significand of the result, before converting to double, are zero.  These
951 // cases do not round symmetrically in round to +infinity or round to -infinity.
952 // The perturbation also insures that the inexact flag is set.
953 // For |Y| > |X|, result is  +- pi/2 - (A_hi + A_lo)
954 { .mfi
955            nop.m 999
956 (p6)       fnma.d.s0      f8        = atan2_A, atan2_near_one, atan2_sgn_pi_by_2
957            nop.i 999
959 // For |Y| <= |X|, and X < 0, result is  +- pi + (A_hi + A_lo)
960 { .mfb
961            nop.m 999
962 (p9)       fma.d.s0        f8        = atan2_A, atan2_near_one, atan2_sgn_pi
963            br.ret.sptk  b0
967 ATAN2_ERROR:
968 // Here if x=0 and y=0
969 { .mfi
970           nop.m 999
971           fclass.m p10,p11       = atan2_X,0x05  // Test if x=+0
972           nop.i 999
976 { .mfi
977           mov        atan2_GR_tag     = 37
978 (p10)     fmerge.s     f10             = atan2_sgnY, f0 // x=+0, y=0
979           nop.i 999
981 { .mfi
982           nop.m 999
983 (p11)     fma.d.s0        f10            = atan2_sgnY, atan2_pi, f0 // x=-0, y=0
984           nop.i 999
987 GLOBAL_IEEE754_END(atan2)
990 LOCAL_LIBM_ENTRY(__libm_error_region)
991 .prologue
992 // (1)
993 { .mfi
994         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
995         nop.f 999
996 .save   ar.pfs,GR_SAVE_PFS
997         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
999 { .mfi
1000 .fframe 64
1001         add sp=-64,sp                          // Create new stack
1002         nop.f 0
1003         mov GR_SAVE_GP=gp                      // Save gp
1007 // (2)
1008 { .mmi
1009         stfd [GR_Parameter_Y] = f8,16         // STORE Parameter 2 on stack
1010         add GR_Parameter_X = 16,sp            // Parameter 1 address
1011 .save   b0, GR_SAVE_B0
1012         mov GR_SAVE_B0=b0                     // Save b0
1015 .body
1016 // (3)
1017 { .mib
1018         stfd [GR_Parameter_X] = f9            // STORE Parameter 1 on stack
1019         add   GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
1020         nop.b 0
1022 { .mib
1023         stfd [GR_Parameter_Y] = f10           // STORE Parameter 3 on stack
1024         add   GR_Parameter_Y = -16,GR_Parameter_Y
1025         br.call.sptk b0=__libm_error_support# // Call error handling function
1027 { .mmi
1028         add   GR_Parameter_RESULT = 48,sp
1029         nop.m 0
1030         nop.i 0
1033 // (4)
1034 { .mmi
1035         ldfd  f8 = [GR_Parameter_RESULT]       // Get return result off stack
1036 .restore sp
1037         add   sp = 64,sp                       // Restore stack pointer
1038         mov   b0 = GR_SAVE_B0                  // Restore return address
1040 { .mib
1041         mov   gp = GR_SAVE_GP                  // Restore gp
1042         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
1043         br.ret.sptk     b0                     // Return
1046 LOCAL_LIBM_END(__libm_error_region)
1048 .type   __libm_error_support#,@function
1049 .global __libm_error_support#