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
32*25c28e83SPiotr Jasiukajtis #ifdef _LITTLE_ENDIAN
33*25c28e83SPiotr Jasiukajtis #define HI(x) *(1+(int*)x)
34*25c28e83SPiotr Jasiukajtis #define LO(x) *(unsigned*)x
35*25c28e83SPiotr Jasiukajtis #else
36*25c28e83SPiotr Jasiukajtis #define HI(x) *(int*)x
37*25c28e83SPiotr Jasiukajtis #define LO(x) *(1+(unsigned*)x)
38*25c28e83SPiotr Jasiukajtis #endif
39*25c28e83SPiotr Jasiukajtis
40*25c28e83SPiotr Jasiukajtis #ifdef __RESTRICT
41*25c28e83SPiotr Jasiukajtis #define restrict _Restrict
42*25c28e83SPiotr Jasiukajtis #else
43*25c28e83SPiotr Jasiukajtis #define restrict
44*25c28e83SPiotr Jasiukajtis #endif
45*25c28e83SPiotr Jasiukajtis
46*25c28e83SPiotr Jasiukajtis extern const double __vlibm_TBL_sincos_hi[], __vlibm_TBL_sincos_lo[];
47*25c28e83SPiotr Jasiukajtis extern int __vlibm_rem_pio2m(double *, double *, int, int, int);
48*25c28e83SPiotr Jasiukajtis
49*25c28e83SPiotr Jasiukajtis static const double
50*25c28e83SPiotr Jasiukajtis zero = 0.0,
51*25c28e83SPiotr Jasiukajtis one = 1.0,
52*25c28e83SPiotr Jasiukajtis two24 = 16777216.0,
53*25c28e83SPiotr Jasiukajtis pp1 = -1.666666666605760465276263943134982554676e-0001,
54*25c28e83SPiotr Jasiukajtis pp2 = 8.333261209690963126718376566146180944442e-0003,
55*25c28e83SPiotr Jasiukajtis p1 = -1.666666666666629669805215138920301589656e-0001,
56*25c28e83SPiotr Jasiukajtis p2 = 8.333333332390951295683993455280336376663e-0003,
57*25c28e83SPiotr Jasiukajtis p3 = -1.984126237997976692791551778230098403960e-0004,
58*25c28e83SPiotr Jasiukajtis p4 = 2.753403624854277237649987622848330351110e-0006,
59*25c28e83SPiotr Jasiukajtis qq1 = -4.999999999977710986407023955908711557870e-0001,
60*25c28e83SPiotr Jasiukajtis qq2 = 4.166654863857219350645055881018842089580e-0002,
61*25c28e83SPiotr Jasiukajtis q1 = -4.999999999999931701464060878888294524481e-0001,
62*25c28e83SPiotr Jasiukajtis q2 = 4.166666666394861917535640593963708222319e-0002,
63*25c28e83SPiotr Jasiukajtis q3 = -1.388888552656142867832756687736851681462e-0003,
64*25c28e83SPiotr Jasiukajtis q4 = 2.478519423681460796618128289454530524759e-0005;
65*25c28e83SPiotr Jasiukajtis
66*25c28e83SPiotr Jasiukajtis void
__vlibm_vsin_big(int n,double * restrict x,int stridex,double * restrict y,int stridey,int thresh)67*25c28e83SPiotr Jasiukajtis __vlibm_vsin_big(int n, double * restrict x, int stridex, double * restrict y,
68*25c28e83SPiotr Jasiukajtis int stridey, int thresh)
69*25c28e83SPiotr Jasiukajtis {
70*25c28e83SPiotr Jasiukajtis for (; n--; x += stridex, y += stridey)
71*25c28e83SPiotr Jasiukajtis {
72*25c28e83SPiotr Jasiukajtis double tx, tt[3], ty[2], t, w, z, a;
73*25c28e83SPiotr Jasiukajtis unsigned hx, xsb;
74*25c28e83SPiotr Jasiukajtis int e0, nx, j;
75*25c28e83SPiotr Jasiukajtis
76*25c28e83SPiotr Jasiukajtis hx = HI(x);
77*25c28e83SPiotr Jasiukajtis xsb = hx & 0x80000000;
78*25c28e83SPiotr Jasiukajtis hx &= ~0x80000000;
79*25c28e83SPiotr Jasiukajtis if (hx <= thresh || hx >= 0x7ff00000)
80*25c28e83SPiotr Jasiukajtis continue;
81*25c28e83SPiotr Jasiukajtis e0 = (hx >> 20) - 1046;
82*25c28e83SPiotr Jasiukajtis HI(&tx) = 0x41600000 | (hx & 0xfffff);
83*25c28e83SPiotr Jasiukajtis LO(&tx) = LO(x);
84*25c28e83SPiotr Jasiukajtis tt[0] = (double)((int) tx);
85*25c28e83SPiotr Jasiukajtis tx = (tx - tt[0]) * two24;
86*25c28e83SPiotr Jasiukajtis if (tx != zero)
87*25c28e83SPiotr Jasiukajtis {
88*25c28e83SPiotr Jasiukajtis nx = 2;
89*25c28e83SPiotr Jasiukajtis tt[1] = (double)((int) tx);
90*25c28e83SPiotr Jasiukajtis tt[2] = (tx - tt[1]) * two24;
91*25c28e83SPiotr Jasiukajtis if (tt[2] != zero)
92*25c28e83SPiotr Jasiukajtis nx = 3;
93*25c28e83SPiotr Jasiukajtis }
94*25c28e83SPiotr Jasiukajtis else
95*25c28e83SPiotr Jasiukajtis {
96*25c28e83SPiotr Jasiukajtis nx = 1;
97*25c28e83SPiotr Jasiukajtis tt[1] = tt[2] = zero;
98*25c28e83SPiotr Jasiukajtis }
99*25c28e83SPiotr Jasiukajtis nx = __vlibm_rem_pio2m(tt, ty, e0, nx, 2);
100*25c28e83SPiotr Jasiukajtis if (xsb)
101*25c28e83SPiotr Jasiukajtis {
102*25c28e83SPiotr Jasiukajtis nx = -nx;
103*25c28e83SPiotr Jasiukajtis ty[0] = -ty[0];
104*25c28e83SPiotr Jasiukajtis ty[1] = -ty[1];
105*25c28e83SPiotr Jasiukajtis }
106*25c28e83SPiotr Jasiukajtis
107*25c28e83SPiotr Jasiukajtis /* now nx and ty[*] are the quadrant and reduced arg */
108*25c28e83SPiotr Jasiukajtis xsb = (nx & 2) << 30;
109*25c28e83SPiotr Jasiukajtis hx = HI(&ty[0]);
110*25c28e83SPiotr Jasiukajtis if (nx & 1)
111*25c28e83SPiotr Jasiukajtis {
112*25c28e83SPiotr Jasiukajtis if (hx & 0x80000000)
113*25c28e83SPiotr Jasiukajtis {
114*25c28e83SPiotr Jasiukajtis ty[0] = -ty[0];
115*25c28e83SPiotr Jasiukajtis ty[1] = -ty[1];
116*25c28e83SPiotr Jasiukajtis hx &= ~0x80000000;
117*25c28e83SPiotr Jasiukajtis }
118*25c28e83SPiotr Jasiukajtis if (hx < 0x3fc40000)
119*25c28e83SPiotr Jasiukajtis {
120*25c28e83SPiotr Jasiukajtis z = ty[0] * ty[0];
121*25c28e83SPiotr Jasiukajtis t = z * (q1 + z * (q2 + z * (q3 + z * q4)));
122*25c28e83SPiotr Jasiukajtis a = one + t;
123*25c28e83SPiotr Jasiukajtis }
124*25c28e83SPiotr Jasiukajtis else
125*25c28e83SPiotr Jasiukajtis {
126*25c28e83SPiotr Jasiukajtis j = (hx + 0x4000) & 0x7fff8000;
127*25c28e83SPiotr Jasiukajtis HI(&t) = j;
128*25c28e83SPiotr Jasiukajtis LO(&t) = 0;
129*25c28e83SPiotr Jasiukajtis ty[0] = (ty[0] - t) + ty[1];
130*25c28e83SPiotr Jasiukajtis z = ty[0] * ty[0];
131*25c28e83SPiotr Jasiukajtis t = z * (qq1 + z * qq2);
132*25c28e83SPiotr Jasiukajtis w = ty[0] * (one + z * (pp1 + z * pp2));
133*25c28e83SPiotr Jasiukajtis j = ((j - 0x3fc40000) >> 13) & ~3;
134*25c28e83SPiotr Jasiukajtis a = __vlibm_TBL_sincos_hi[j+1];
135*25c28e83SPiotr Jasiukajtis t = __vlibm_TBL_sincos_lo[j+1] - (__vlibm_TBL_sincos_hi[j] * w - a * t);
136*25c28e83SPiotr Jasiukajtis a += t;
137*25c28e83SPiotr Jasiukajtis }
138*25c28e83SPiotr Jasiukajtis }
139*25c28e83SPiotr Jasiukajtis else
140*25c28e83SPiotr Jasiukajtis {
141*25c28e83SPiotr Jasiukajtis if (hx & 0x80000000)
142*25c28e83SPiotr Jasiukajtis {
143*25c28e83SPiotr Jasiukajtis ty[0] = -ty[0];
144*25c28e83SPiotr Jasiukajtis ty[1] = -ty[1];
145*25c28e83SPiotr Jasiukajtis hx &= ~0x80000000;
146*25c28e83SPiotr Jasiukajtis xsb ^= 0x80000000;
147*25c28e83SPiotr Jasiukajtis }
148*25c28e83SPiotr Jasiukajtis if (hx < 0x3fc90000)
149*25c28e83SPiotr Jasiukajtis {
150*25c28e83SPiotr Jasiukajtis z = ty[0] * ty[0];
151*25c28e83SPiotr Jasiukajtis t = z * (p1 + z * (p2 + z * (p3 + z * p4)));
152*25c28e83SPiotr Jasiukajtis a = ty[0] + (ty[1] + ty[0] * t);
153*25c28e83SPiotr Jasiukajtis }
154*25c28e83SPiotr Jasiukajtis else
155*25c28e83SPiotr Jasiukajtis {
156*25c28e83SPiotr Jasiukajtis j = (hx + 0x4000) & 0x7fff8000;
157*25c28e83SPiotr Jasiukajtis HI(&t) = j;
158*25c28e83SPiotr Jasiukajtis LO(&t) = 0;
159*25c28e83SPiotr Jasiukajtis ty[0] = (ty[0] - t) + ty[1];
160*25c28e83SPiotr Jasiukajtis z = ty[0] * ty[0];
161*25c28e83SPiotr Jasiukajtis t = z * (qq1 + z * qq2);
162*25c28e83SPiotr Jasiukajtis w = ty[0] * (one + z * (pp1 + z * pp2));
163*25c28e83SPiotr Jasiukajtis j = ((j - 0x3fc40000) >> 13) & ~3;
164*25c28e83SPiotr Jasiukajtis a = __vlibm_TBL_sincos_hi[j];
165*25c28e83SPiotr Jasiukajtis t = (__vlibm_TBL_sincos_hi[j+1] * w + a * t) + __vlibm_TBL_sincos_lo[j];
166*25c28e83SPiotr Jasiukajtis a += t;
167*25c28e83SPiotr Jasiukajtis }
168*25c28e83SPiotr Jasiukajtis }
169*25c28e83SPiotr Jasiukajtis if (xsb) a = -a;
170*25c28e83SPiotr Jasiukajtis *y = a;
171*25c28e83SPiotr Jasiukajtis }
172*25c28e83SPiotr Jasiukajtis }
173