1*25c28e83SPiotr Jasiukajtis /*
2*25c28e83SPiotr Jasiukajtis * CDDL HEADER START
3*25c28e83SPiotr Jasiukajtis *
4*25c28e83SPiotr Jasiukajtis * The contents of this file are subject to the terms of the
5*25c28e83SPiotr Jasiukajtis * Common Development and Distribution License (the "License").
6*25c28e83SPiotr Jasiukajtis * You may not use this file except in compliance with the License.
7*25c28e83SPiotr Jasiukajtis *
8*25c28e83SPiotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25c28e83SPiotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
10*25c28e83SPiotr Jasiukajtis * See the License for the specific language governing permissions
11*25c28e83SPiotr Jasiukajtis * and limitations under the License.
12*25c28e83SPiotr Jasiukajtis *
13*25c28e83SPiotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
14*25c28e83SPiotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25c28e83SPiotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
16*25c28e83SPiotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
17*25c28e83SPiotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
18*25c28e83SPiotr Jasiukajtis *
19*25c28e83SPiotr Jasiukajtis * CDDL HEADER END
20*25c28e83SPiotr Jasiukajtis */
21*25c28e83SPiotr Jasiukajtis
22*25c28e83SPiotr Jasiukajtis /*
23*25c28e83SPiotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24*25c28e83SPiotr Jasiukajtis */
25*25c28e83SPiotr Jasiukajtis /*
26*25c28e83SPiotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27*25c28e83SPiotr Jasiukajtis * Use is subject to license terms.
28*25c28e83SPiotr Jasiukajtis */
29*25c28e83SPiotr Jasiukajtis
30*25c28e83SPiotr Jasiukajtis #include <sys/isa_defs.h>
31*25c28e83SPiotr Jasiukajtis #include "libm_inlines.h"
32*25c28e83SPiotr Jasiukajtis
33*25c28e83SPiotr Jasiukajtis #ifdef _LITTLE_ENDIAN
34*25c28e83SPiotr Jasiukajtis #define HI(x) *(1+(int*)x)
35*25c28e83SPiotr Jasiukajtis #define LO(x) *(unsigned*)x
36*25c28e83SPiotr Jasiukajtis #else
37*25c28e83SPiotr Jasiukajtis #define HI(x) *(int*)x
38*25c28e83SPiotr Jasiukajtis #define LO(x) *(1+(unsigned*)x)
39*25c28e83SPiotr Jasiukajtis #endif
40*25c28e83SPiotr Jasiukajtis
41*25c28e83SPiotr Jasiukajtis #ifdef __RESTRICT
42*25c28e83SPiotr Jasiukajtis #define restrict _Restrict
43*25c28e83SPiotr Jasiukajtis #else
44*25c28e83SPiotr Jasiukajtis #define restrict
45*25c28e83SPiotr Jasiukajtis #endif
46*25c28e83SPiotr Jasiukajtis
47*25c28e83SPiotr Jasiukajtis extern const double __vlibm_TBL_atan2[];
48*25c28e83SPiotr Jasiukajtis
49*25c28e83SPiotr Jasiukajtis static const double
50*25c28e83SPiotr Jasiukajtis zero = 0.0,
51*25c28e83SPiotr Jasiukajtis twom3 = 0.125,
52*25c28e83SPiotr Jasiukajtis one = 1.0,
53*25c28e83SPiotr Jasiukajtis two110 = 1.2980742146337069071e+33,
54*25c28e83SPiotr Jasiukajtis pio4 = 7.8539816339744827900e-01,
55*25c28e83SPiotr Jasiukajtis pio2 = 1.5707963267948965580e+00,
56*25c28e83SPiotr Jasiukajtis pio2_lo = 6.1232339957367658860e-17,
57*25c28e83SPiotr Jasiukajtis pi = 3.1415926535897931160e+00,
58*25c28e83SPiotr Jasiukajtis pi_lo = 1.2246467991473531772e-16,
59*25c28e83SPiotr Jasiukajtis p1 = -3.33333333333327571893331786354179101074860633009e-0001,
60*25c28e83SPiotr Jasiukajtis p2 = 1.99999999942671624230086497610394721817438631379e-0001,
61*25c28e83SPiotr Jasiukajtis p3 = -1.42856965565428636896183013324727205980484158356e-0001,
62*25c28e83SPiotr Jasiukajtis p4 = 1.10894981496317081405107718475040168084164825641e-0001;
63*25c28e83SPiotr Jasiukajtis
64*25c28e83SPiotr Jasiukajtis /* Don't __ the following; acomp will handle it */
65*25c28e83SPiotr Jasiukajtis extern double fabs(double);
66*25c28e83SPiotr Jasiukajtis
67*25c28e83SPiotr Jasiukajtis void
__vatan2(int n,double * restrict y,int stridey,double * restrict x,int stridex,double * restrict z,int stridez)68*25c28e83SPiotr Jasiukajtis __vatan2(int n, double * restrict y, int stridey, double * restrict x,
69*25c28e83SPiotr Jasiukajtis int stridex, double * restrict z, int stridez)
70*25c28e83SPiotr Jasiukajtis {
71*25c28e83SPiotr Jasiukajtis double x0, x1, x2, y0, y1, y2, *pz0, *pz1, *pz2;
72*25c28e83SPiotr Jasiukajtis double ah0, ah1, ah2, al0, al1, al2, t0, t1, t2;
73*25c28e83SPiotr Jasiukajtis double z0, z1, z2, sign0, sign1, sign2, xh;
74*25c28e83SPiotr Jasiukajtis int i, k, hx, hy, sx, sy;
75*25c28e83SPiotr Jasiukajtis
76*25c28e83SPiotr Jasiukajtis do
77*25c28e83SPiotr Jasiukajtis {
78*25c28e83SPiotr Jasiukajtis loop0:
79*25c28e83SPiotr Jasiukajtis hy = HI(y);
80*25c28e83SPiotr Jasiukajtis sy = hy & 0x80000000;
81*25c28e83SPiotr Jasiukajtis hy &= ~0x80000000;
82*25c28e83SPiotr Jasiukajtis sign0 = (sy)? -one : one;
83*25c28e83SPiotr Jasiukajtis
84*25c28e83SPiotr Jasiukajtis hx = HI(x);
85*25c28e83SPiotr Jasiukajtis sx = hx & 0x80000000;
86*25c28e83SPiotr Jasiukajtis hx &= ~0x80000000;
87*25c28e83SPiotr Jasiukajtis
88*25c28e83SPiotr Jasiukajtis if (hy > hx || (hy == hx && LO(y) > LO(x)))
89*25c28e83SPiotr Jasiukajtis {
90*25c28e83SPiotr Jasiukajtis i = hx;
91*25c28e83SPiotr Jasiukajtis hx = hy;
92*25c28e83SPiotr Jasiukajtis hy = i;
93*25c28e83SPiotr Jasiukajtis x0 = fabs(*y);
94*25c28e83SPiotr Jasiukajtis y0 = fabs(*x);
95*25c28e83SPiotr Jasiukajtis if (sx)
96*25c28e83SPiotr Jasiukajtis {
97*25c28e83SPiotr Jasiukajtis ah0 = pio2;
98*25c28e83SPiotr Jasiukajtis al0 = pio2_lo;
99*25c28e83SPiotr Jasiukajtis }
100*25c28e83SPiotr Jasiukajtis else
101*25c28e83SPiotr Jasiukajtis {
102*25c28e83SPiotr Jasiukajtis ah0 = -pio2;
103*25c28e83SPiotr Jasiukajtis al0 = -pio2_lo;
104*25c28e83SPiotr Jasiukajtis sign0 = -sign0;
105*25c28e83SPiotr Jasiukajtis }
106*25c28e83SPiotr Jasiukajtis }
107*25c28e83SPiotr Jasiukajtis else
108*25c28e83SPiotr Jasiukajtis {
109*25c28e83SPiotr Jasiukajtis x0 = fabs(*x);
110*25c28e83SPiotr Jasiukajtis y0 = fabs(*y);
111*25c28e83SPiotr Jasiukajtis if (sx)
112*25c28e83SPiotr Jasiukajtis {
113*25c28e83SPiotr Jasiukajtis ah0 = -pi;
114*25c28e83SPiotr Jasiukajtis al0 = -pi_lo;
115*25c28e83SPiotr Jasiukajtis sign0 = -sign0;
116*25c28e83SPiotr Jasiukajtis }
117*25c28e83SPiotr Jasiukajtis else
118*25c28e83SPiotr Jasiukajtis ah0 = al0 = zero;
119*25c28e83SPiotr Jasiukajtis }
120*25c28e83SPiotr Jasiukajtis
121*25c28e83SPiotr Jasiukajtis if (hx >= 0x7fe00000 || hx - hy >= 0x03600000)
122*25c28e83SPiotr Jasiukajtis {
123*25c28e83SPiotr Jasiukajtis if (hx >= 0x7ff00000)
124*25c28e83SPiotr Jasiukajtis {
125*25c28e83SPiotr Jasiukajtis if ((hx ^ 0x7ff00000) | LO(&x0)) /* nan */
126*25c28e83SPiotr Jasiukajtis ah0 = x0 + y0;
127*25c28e83SPiotr Jasiukajtis else if (hy >= 0x7ff00000)
128*25c28e83SPiotr Jasiukajtis ah0 += pio4;
129*25c28e83SPiotr Jasiukajtis *z = sign0 * ah0;
130*25c28e83SPiotr Jasiukajtis x += stridex;
131*25c28e83SPiotr Jasiukajtis y += stridey;
132*25c28e83SPiotr Jasiukajtis z += stridez;
133*25c28e83SPiotr Jasiukajtis i = 0;
134*25c28e83SPiotr Jasiukajtis if (--n <= 0)
135*25c28e83SPiotr Jasiukajtis break;
136*25c28e83SPiotr Jasiukajtis goto loop0;
137*25c28e83SPiotr Jasiukajtis }
138*25c28e83SPiotr Jasiukajtis if (hx - hy >= 0x03600000)
139*25c28e83SPiotr Jasiukajtis {
140*25c28e83SPiotr Jasiukajtis if ((int) ah0 == 0)
141*25c28e83SPiotr Jasiukajtis ah0 = y0 / x0;
142*25c28e83SPiotr Jasiukajtis *z = sign0 * ah0;
143*25c28e83SPiotr Jasiukajtis x += stridex;
144*25c28e83SPiotr Jasiukajtis y += stridey;
145*25c28e83SPiotr Jasiukajtis z += stridez;
146*25c28e83SPiotr Jasiukajtis i = 0;
147*25c28e83SPiotr Jasiukajtis if (--n <= 0)
148*25c28e83SPiotr Jasiukajtis break;
149*25c28e83SPiotr Jasiukajtis goto loop0;
150*25c28e83SPiotr Jasiukajtis }
151*25c28e83SPiotr Jasiukajtis y0 *= twom3;
152*25c28e83SPiotr Jasiukajtis x0 *= twom3;
153*25c28e83SPiotr Jasiukajtis hy -= 0x00300000;
154*25c28e83SPiotr Jasiukajtis hx -= 0x00300000;
155*25c28e83SPiotr Jasiukajtis }
156*25c28e83SPiotr Jasiukajtis else if (hy < 0x00100000)
157*25c28e83SPiotr Jasiukajtis {
158*25c28e83SPiotr Jasiukajtis if ((hy | LO(&y0)) == 0)
159*25c28e83SPiotr Jasiukajtis {
160*25c28e83SPiotr Jasiukajtis *z = sign0 * ah0;
161*25c28e83SPiotr Jasiukajtis x += stridex;
162*25c28e83SPiotr Jasiukajtis y += stridey;
163*25c28e83SPiotr Jasiukajtis z += stridez;
164*25c28e83SPiotr Jasiukajtis i = 0;
165*25c28e83SPiotr Jasiukajtis if (--n <= 0)
166*25c28e83SPiotr Jasiukajtis break;
167*25c28e83SPiotr Jasiukajtis goto loop0;
168*25c28e83SPiotr Jasiukajtis }
169*25c28e83SPiotr Jasiukajtis y0 *= two110;
170*25c28e83SPiotr Jasiukajtis x0 *= two110;
171*25c28e83SPiotr Jasiukajtis hy = HI(&y0);
172*25c28e83SPiotr Jasiukajtis hx = HI(&x0);
173*25c28e83SPiotr Jasiukajtis }
174*25c28e83SPiotr Jasiukajtis
175*25c28e83SPiotr Jasiukajtis k = (((hx - hy) + 0x00004000) >> 13) & ~0x3;
176*25c28e83SPiotr Jasiukajtis if (k > 644)
177*25c28e83SPiotr Jasiukajtis k = 644;
178*25c28e83SPiotr Jasiukajtis ah0 += __vlibm_TBL_atan2[k];
179*25c28e83SPiotr Jasiukajtis al0 += __vlibm_TBL_atan2[k+1];
180*25c28e83SPiotr Jasiukajtis t0 = __vlibm_TBL_atan2[k+2];
181*25c28e83SPiotr Jasiukajtis
182*25c28e83SPiotr Jasiukajtis xh = x0;
183*25c28e83SPiotr Jasiukajtis LO(&xh) = 0;
184*25c28e83SPiotr Jasiukajtis z0 = ((y0 - t0 * xh) - t0 * (x0 - xh)) / (x0 + y0 * t0);
185*25c28e83SPiotr Jasiukajtis pz0 = z;
186*25c28e83SPiotr Jasiukajtis x += stridex;
187*25c28e83SPiotr Jasiukajtis y += stridey;
188*25c28e83SPiotr Jasiukajtis z += stridez;
189*25c28e83SPiotr Jasiukajtis i = 1;
190*25c28e83SPiotr Jasiukajtis if (--n <= 0)
191*25c28e83SPiotr Jasiukajtis break;
192*25c28e83SPiotr Jasiukajtis
193*25c28e83SPiotr Jasiukajtis loop1:
194*25c28e83SPiotr Jasiukajtis hy = HI(y);
195*25c28e83SPiotr Jasiukajtis sy = hy & 0x80000000;
196*25c28e83SPiotr Jasiukajtis hy &= ~0x80000000;
197*25c28e83SPiotr Jasiukajtis sign1 = (sy)? -one : one;
198*25c28e83SPiotr Jasiukajtis
199*25c28e83SPiotr Jasiukajtis hx = HI(x);
200*25c28e83SPiotr Jasiukajtis sx = hx & 0x80000000;
201*25c28e83SPiotr Jasiukajtis hx &= ~0x80000000;
202*25c28e83SPiotr Jasiukajtis
203*25c28e83SPiotr Jasiukajtis if (hy > hx || (hy == hx && LO(y) > LO(x)))
204*25c28e83SPiotr Jasiukajtis {
205*25c28e83SPiotr Jasiukajtis i = hx;
206*25c28e83SPiotr Jasiukajtis hx = hy;
207*25c28e83SPiotr Jasiukajtis hy = i;
208*25c28e83SPiotr Jasiukajtis x1 = fabs(*y);
209*25c28e83SPiotr Jasiukajtis y1 = fabs(*x);
210*25c28e83SPiotr Jasiukajtis if (sx)
211*25c28e83SPiotr Jasiukajtis {
212*25c28e83SPiotr Jasiukajtis ah1 = pio2;
213*25c28e83SPiotr Jasiukajtis al1 = pio2_lo;
214*25c28e83SPiotr Jasiukajtis }
215*25c28e83SPiotr Jasiukajtis else
216*25c28e83SPiotr Jasiukajtis {
217*25c28e83SPiotr Jasiukajtis ah1 = -pio2;
218*25c28e83SPiotr Jasiukajtis al1 = -pio2_lo;
219*25c28e83SPiotr Jasiukajtis sign1 = -sign1;
220*25c28e83SPiotr Jasiukajtis }
221*25c28e83SPiotr Jasiukajtis }
222*25c28e83SPiotr Jasiukajtis else
223*25c28e83SPiotr Jasiukajtis {
224*25c28e83SPiotr Jasiukajtis x1 = fabs(*x);
225*25c28e83SPiotr Jasiukajtis y1 = fabs(*y);
226*25c28e83SPiotr Jasiukajtis if (sx)
227*25c28e83SPiotr Jasiukajtis {
228*25c28e83SPiotr Jasiukajtis ah1 = -pi;
229*25c28e83SPiotr Jasiukajtis al1 = -pi_lo;
230*25c28e83SPiotr Jasiukajtis sign1 = -sign1;
231*25c28e83SPiotr Jasiukajtis }
232*25c28e83SPiotr Jasiukajtis else
233*25c28e83SPiotr Jasiukajtis ah1 = al1 = zero;
234*25c28e83SPiotr Jasiukajtis }
235*25c28e83SPiotr Jasiukajtis
236*25c28e83SPiotr Jasiukajtis if (hx >= 0x7fe00000 || hx - hy >= 0x03600000)
237*25c28e83SPiotr Jasiukajtis {
238*25c28e83SPiotr Jasiukajtis if (hx >= 0x7ff00000)
239*25c28e83SPiotr Jasiukajtis {
240*25c28e83SPiotr Jasiukajtis if ((hx ^ 0x7ff00000) | LO(&x1)) /* nan */
241*25c28e83SPiotr Jasiukajtis ah1 = x1 + y1;
242*25c28e83SPiotr Jasiukajtis else if (hy >= 0x7ff00000)
243*25c28e83SPiotr Jasiukajtis ah1 += pio4;
244*25c28e83SPiotr Jasiukajtis *z = sign1 * ah1;
245*25c28e83SPiotr Jasiukajtis x += stridex;
246*25c28e83SPiotr Jasiukajtis y += stridey;
247*25c28e83SPiotr Jasiukajtis z += stridez;
248*25c28e83SPiotr Jasiukajtis i = 1;
249*25c28e83SPiotr Jasiukajtis if (--n <= 0)
250*25c28e83SPiotr Jasiukajtis break;
251*25c28e83SPiotr Jasiukajtis goto loop1;
252*25c28e83SPiotr Jasiukajtis }
253*25c28e83SPiotr Jasiukajtis if (hx - hy >= 0x03600000)
254*25c28e83SPiotr Jasiukajtis {
255*25c28e83SPiotr Jasiukajtis if ((int) ah1 == 0)
256*25c28e83SPiotr Jasiukajtis ah1 = y1 / x1;
257*25c28e83SPiotr Jasiukajtis *z = sign1 * ah1;
258*25c28e83SPiotr Jasiukajtis x += stridex;
259*25c28e83SPiotr Jasiukajtis y += stridey;
260*25c28e83SPiotr Jasiukajtis z += stridez;
261*25c28e83SPiotr Jasiukajtis i = 1;
262*25c28e83SPiotr Jasiukajtis if (--n <= 0)
263*25c28e83SPiotr Jasiukajtis break;
264*25c28e83SPiotr Jasiukajtis goto loop1;
265*25c28e83SPiotr Jasiukajtis }
266*25c28e83SPiotr Jasiukajtis y1 *= twom3;
267*25c28e83SPiotr Jasiukajtis x1 *= twom3;
268*25c28e83SPiotr Jasiukajtis hy -= 0x00300000;
269*25c28e83SPiotr Jasiukajtis hx -= 0x00300000;
270*25c28e83SPiotr Jasiukajtis }
271*25c28e83SPiotr Jasiukajtis else if (hy < 0x00100000)
272*25c28e83SPiotr Jasiukajtis {
273*25c28e83SPiotr Jasiukajtis if ((hy | LO(&y1)) == 0)
274*25c28e83SPiotr Jasiukajtis {
275*25c28e83SPiotr Jasiukajtis *z = sign1 * ah1;
276*25c28e83SPiotr Jasiukajtis x += stridex;
277*25c28e83SPiotr Jasiukajtis y += stridey;
278*25c28e83SPiotr Jasiukajtis z += stridez;
279*25c28e83SPiotr Jasiukajtis i = 1;
280*25c28e83SPiotr Jasiukajtis if (--n <= 0)
281*25c28e83SPiotr Jasiukajtis break;
282*25c28e83SPiotr Jasiukajtis goto loop1;
283*25c28e83SPiotr Jasiukajtis }
284*25c28e83SPiotr Jasiukajtis y1 *= two110;
285*25c28e83SPiotr Jasiukajtis x1 *= two110;
286*25c28e83SPiotr Jasiukajtis hy = HI(&y1);
287*25c28e83SPiotr Jasiukajtis hx = HI(&x1);
288*25c28e83SPiotr Jasiukajtis }
289*25c28e83SPiotr Jasiukajtis
290*25c28e83SPiotr Jasiukajtis k = (((hx - hy) + 0x00004000) >> 13) & ~0x3;
291*25c28e83SPiotr Jasiukajtis if (k > 644)
292*25c28e83SPiotr Jasiukajtis k = 644;
293*25c28e83SPiotr Jasiukajtis ah1 += __vlibm_TBL_atan2[k];
294*25c28e83SPiotr Jasiukajtis al1 += __vlibm_TBL_atan2[k+1];
295*25c28e83SPiotr Jasiukajtis t1 = __vlibm_TBL_atan2[k+2];
296*25c28e83SPiotr Jasiukajtis
297*25c28e83SPiotr Jasiukajtis xh = x1;
298*25c28e83SPiotr Jasiukajtis LO(&xh) = 0;
299*25c28e83SPiotr Jasiukajtis z1 = ((y1 - t1 * xh) - t1 * (x1 - xh)) / (x1 + y1 * t1);
300*25c28e83SPiotr Jasiukajtis pz1 = z;
301*25c28e83SPiotr Jasiukajtis x += stridex;
302*25c28e83SPiotr Jasiukajtis y += stridey;
303*25c28e83SPiotr Jasiukajtis z += stridez;
304*25c28e83SPiotr Jasiukajtis i = 2;
305*25c28e83SPiotr Jasiukajtis if (--n <= 0)
306*25c28e83SPiotr Jasiukajtis break;
307*25c28e83SPiotr Jasiukajtis
308*25c28e83SPiotr Jasiukajtis loop2:
309*25c28e83SPiotr Jasiukajtis hy = HI(y);
310*25c28e83SPiotr Jasiukajtis sy = hy & 0x80000000;
311*25c28e83SPiotr Jasiukajtis hy &= ~0x80000000;
312*25c28e83SPiotr Jasiukajtis sign2 = (sy)? -one : one;
313*25c28e83SPiotr Jasiukajtis
314*25c28e83SPiotr Jasiukajtis hx = HI(x);
315*25c28e83SPiotr Jasiukajtis sx = hx & 0x80000000;
316*25c28e83SPiotr Jasiukajtis hx &= ~0x80000000;
317*25c28e83SPiotr Jasiukajtis
318*25c28e83SPiotr Jasiukajtis if (hy > hx || (hy == hx && LO(y) > LO(x)))
319*25c28e83SPiotr Jasiukajtis {
320*25c28e83SPiotr Jasiukajtis i = hx;
321*25c28e83SPiotr Jasiukajtis hx = hy;
322*25c28e83SPiotr Jasiukajtis hy = i;
323*25c28e83SPiotr Jasiukajtis x2 = fabs(*y);
324*25c28e83SPiotr Jasiukajtis y2 = fabs(*x);
325*25c28e83SPiotr Jasiukajtis if (sx)
326*25c28e83SPiotr Jasiukajtis {
327*25c28e83SPiotr Jasiukajtis ah2 = pio2;
328*25c28e83SPiotr Jasiukajtis al2 = pio2_lo;
329*25c28e83SPiotr Jasiukajtis }
330*25c28e83SPiotr Jasiukajtis else
331*25c28e83SPiotr Jasiukajtis {
332*25c28e83SPiotr Jasiukajtis ah2 = -pio2;
333*25c28e83SPiotr Jasiukajtis al2 = -pio2_lo;
334*25c28e83SPiotr Jasiukajtis sign2 = -sign2;
335*25c28e83SPiotr Jasiukajtis }
336*25c28e83SPiotr Jasiukajtis }
337*25c28e83SPiotr Jasiukajtis else
338*25c28e83SPiotr Jasiukajtis {
339*25c28e83SPiotr Jasiukajtis x2 = fabs(*x);
340*25c28e83SPiotr Jasiukajtis y2 = fabs(*y);
341*25c28e83SPiotr Jasiukajtis if (sx)
342*25c28e83SPiotr Jasiukajtis {
343*25c28e83SPiotr Jasiukajtis ah2 = -pi;
344*25c28e83SPiotr Jasiukajtis al2 = -pi_lo;
345*25c28e83SPiotr Jasiukajtis sign2 = -sign2;
346*25c28e83SPiotr Jasiukajtis }
347*25c28e83SPiotr Jasiukajtis else
348*25c28e83SPiotr Jasiukajtis ah2 = al2 = zero;
349*25c28e83SPiotr Jasiukajtis }
350*25c28e83SPiotr Jasiukajtis
351*25c28e83SPiotr Jasiukajtis if (hx >= 0x7fe00000 || hx - hy >= 0x03600000)
352*25c28e83SPiotr Jasiukajtis {
353*25c28e83SPiotr Jasiukajtis if (hx >= 0x7ff00000)
354*25c28e83SPiotr Jasiukajtis {
355*25c28e83SPiotr Jasiukajtis if ((hx ^ 0x7ff00000) | LO(&x2)) /* nan */
356*25c28e83SPiotr Jasiukajtis ah2 = x2 + y2;
357*25c28e83SPiotr Jasiukajtis else if (hy >= 0x7ff00000)
358*25c28e83SPiotr Jasiukajtis ah2 += pio4;
359*25c28e83SPiotr Jasiukajtis *z = sign2 * ah2;
360*25c28e83SPiotr Jasiukajtis x += stridex;
361*25c28e83SPiotr Jasiukajtis y += stridey;
362*25c28e83SPiotr Jasiukajtis z += stridez;
363*25c28e83SPiotr Jasiukajtis i = 2;
364*25c28e83SPiotr Jasiukajtis if (--n <= 0)
365*25c28e83SPiotr Jasiukajtis break;
366*25c28e83SPiotr Jasiukajtis goto loop2;
367*25c28e83SPiotr Jasiukajtis }
368*25c28e83SPiotr Jasiukajtis if (hx - hy >= 0x03600000)
369*25c28e83SPiotr Jasiukajtis {
370*25c28e83SPiotr Jasiukajtis if ((int) ah2 == 0)
371*25c28e83SPiotr Jasiukajtis ah2 = y2 / x2;
372*25c28e83SPiotr Jasiukajtis *z = sign2 * ah2;
373*25c28e83SPiotr Jasiukajtis x += stridex;
374*25c28e83SPiotr Jasiukajtis y += stridey;
375*25c28e83SPiotr Jasiukajtis z += stridez;
376*25c28e83SPiotr Jasiukajtis i = 2;
377*25c28e83SPiotr Jasiukajtis if (--n <= 0)
378*25c28e83SPiotr Jasiukajtis break;
379*25c28e83SPiotr Jasiukajtis goto loop2;
380*25c28e83SPiotr Jasiukajtis }
381*25c28e83SPiotr Jasiukajtis y2 *= twom3;
382*25c28e83SPiotr Jasiukajtis x2 *= twom3;
383*25c28e83SPiotr Jasiukajtis hy -= 0x00300000;
384*25c28e83SPiotr Jasiukajtis hx -= 0x00300000;
385*25c28e83SPiotr Jasiukajtis }
386*25c28e83SPiotr Jasiukajtis else if (hy < 0x00100000)
387*25c28e83SPiotr Jasiukajtis {
388*25c28e83SPiotr Jasiukajtis if ((hy | LO(&y2)) == 0)
389*25c28e83SPiotr Jasiukajtis {
390*25c28e83SPiotr Jasiukajtis *z = sign2 * ah2;
391*25c28e83SPiotr Jasiukajtis x += stridex;
392*25c28e83SPiotr Jasiukajtis y += stridey;
393*25c28e83SPiotr Jasiukajtis z += stridez;
394*25c28e83SPiotr Jasiukajtis i = 2;
395*25c28e83SPiotr Jasiukajtis if (--n <= 0)
396*25c28e83SPiotr Jasiukajtis break;
397*25c28e83SPiotr Jasiukajtis goto loop2;
398*25c28e83SPiotr Jasiukajtis }
399*25c28e83SPiotr Jasiukajtis y2 *= two110;
400*25c28e83SPiotr Jasiukajtis x2 *= two110;
401*25c28e83SPiotr Jasiukajtis hy = HI(&y2);
402*25c28e83SPiotr Jasiukajtis hx = HI(&x2);
403*25c28e83SPiotr Jasiukajtis }
404*25c28e83SPiotr Jasiukajtis
405*25c28e83SPiotr Jasiukajtis k = (((hx - hy) + 0x00004000) >> 13) & ~0x3;
406*25c28e83SPiotr Jasiukajtis if (k > 644)
407*25c28e83SPiotr Jasiukajtis k = 644;
408*25c28e83SPiotr Jasiukajtis ah2 += __vlibm_TBL_atan2[k];
409*25c28e83SPiotr Jasiukajtis al2 += __vlibm_TBL_atan2[k+1];
410*25c28e83SPiotr Jasiukajtis t2 = __vlibm_TBL_atan2[k+2];
411*25c28e83SPiotr Jasiukajtis
412*25c28e83SPiotr Jasiukajtis xh = x2;
413*25c28e83SPiotr Jasiukajtis LO(&xh) = 0;
414*25c28e83SPiotr Jasiukajtis z2 = ((y2 - t2 * xh) - t2 * (x2 - xh)) / (x2 + y2 * t2);
415*25c28e83SPiotr Jasiukajtis pz2 = z;
416*25c28e83SPiotr Jasiukajtis
417*25c28e83SPiotr Jasiukajtis x0 = z0 * z0;
418*25c28e83SPiotr Jasiukajtis x1 = z1 * z1;
419*25c28e83SPiotr Jasiukajtis x2 = z2 * z2;
420*25c28e83SPiotr Jasiukajtis
421*25c28e83SPiotr Jasiukajtis t0 = ah0 + (z0 + (al0 + (z0 * x0) * (p1 + x0 *
422*25c28e83SPiotr Jasiukajtis (p2 + x0 * (p3 + x0 * p4)))));
423*25c28e83SPiotr Jasiukajtis t1 = ah1 + (z1 + (al1 + (z1 * x1) * (p1 + x1 *
424*25c28e83SPiotr Jasiukajtis (p2 + x1 * (p3 + x1 * p4)))));
425*25c28e83SPiotr Jasiukajtis t2 = ah2 + (z2 + (al2 + (z2 * x2) * (p1 + x2 *
426*25c28e83SPiotr Jasiukajtis (p2 + x2 * (p3 + x2 * p4)))));
427*25c28e83SPiotr Jasiukajtis
428*25c28e83SPiotr Jasiukajtis *pz0 = sign0 * t0;
429*25c28e83SPiotr Jasiukajtis *pz1 = sign1 * t1;
430*25c28e83SPiotr Jasiukajtis *pz2 = sign2 * t2;
431*25c28e83SPiotr Jasiukajtis
432*25c28e83SPiotr Jasiukajtis x += stridex;
433*25c28e83SPiotr Jasiukajtis y += stridey;
434*25c28e83SPiotr Jasiukajtis z += stridez;
435*25c28e83SPiotr Jasiukajtis i = 0;
436*25c28e83SPiotr Jasiukajtis } while (--n > 0);
437*25c28e83SPiotr Jasiukajtis
438*25c28e83SPiotr Jasiukajtis if (i > 0)
439*25c28e83SPiotr Jasiukajtis {
440*25c28e83SPiotr Jasiukajtis if (i > 1)
441*25c28e83SPiotr Jasiukajtis {
442*25c28e83SPiotr Jasiukajtis x1 = z1 * z1;
443*25c28e83SPiotr Jasiukajtis t1 = ah1 + (z1 + (al1 + (z1 * x1) * (p1 + x1 *
444*25c28e83SPiotr Jasiukajtis (p2 + x1 * (p3 + x1 * p4)))));
445*25c28e83SPiotr Jasiukajtis *pz1 = sign1 * t1;
446*25c28e83SPiotr Jasiukajtis }
447*25c28e83SPiotr Jasiukajtis
448*25c28e83SPiotr Jasiukajtis x0 = z0 * z0;
449*25c28e83SPiotr Jasiukajtis t0 = ah0 + (z0 + (al0 + (z0 * x0) * (p1 + x0 *
450*25c28e83SPiotr Jasiukajtis (p2 + x0 * (p3 + x0 * p4)))));
451*25c28e83SPiotr Jasiukajtis *pz0 = sign0 * t0;
452*25c28e83SPiotr Jasiukajtis }
453*25c28e83SPiotr Jasiukajtis }
454