xref: /titanic_50/usr/src/lib/libmvec/common/__vsincosbig.c (revision 25c28e83beb90e7c80452a7c818c5e6f73a07dc8)
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_vsincos_big(int n,double * restrict x,int stridex,double * restrict ss,int stridess,double * restrict cc,int stridecc,int thresh)67*25c28e83SPiotr Jasiukajtis __vlibm_vsincos_big(int n, double * restrict x, int stridex,
68*25c28e83SPiotr Jasiukajtis 	double * restrict ss, int stridess,
69*25c28e83SPiotr Jasiukajtis 	double * restrict cc, int stridecc, int thresh)
70*25c28e83SPiotr Jasiukajtis {
71*25c28e83SPiotr Jasiukajtis 	for (; n--; x += stridex, ss += stridess, cc += stridecc)
72*25c28e83SPiotr Jasiukajtis 	{
73*25c28e83SPiotr Jasiukajtis 		double		ts, tc, tx, tt[3], ty[2], t, w, z, c, s;
74*25c28e83SPiotr Jasiukajtis 		unsigned	hx, xsb;
75*25c28e83SPiotr Jasiukajtis 		int			e0, nx, j;
76*25c28e83SPiotr Jasiukajtis 
77*25c28e83SPiotr Jasiukajtis 		hx = HI(x);
78*25c28e83SPiotr Jasiukajtis 		xsb = hx & 0x80000000;
79*25c28e83SPiotr Jasiukajtis 		hx &= ~0x80000000;
80*25c28e83SPiotr Jasiukajtis 		if (hx <= thresh || hx >= 0x7ff00000)
81*25c28e83SPiotr Jasiukajtis 			continue;
82*25c28e83SPiotr Jasiukajtis 
83*25c28e83SPiotr Jasiukajtis 		/*
84*25c28e83SPiotr Jasiukajtis 		 * Argument reduction part.
85*25c28e83SPiotr Jasiukajtis 		 */
86*25c28e83SPiotr Jasiukajtis 		e0 = (hx >> 20) - 1046;
87*25c28e83SPiotr Jasiukajtis 		HI(&tx) = 0x41600000 | (hx & 0xfffff);
88*25c28e83SPiotr Jasiukajtis 		LO(&tx) = LO(x);
89*25c28e83SPiotr Jasiukajtis 		tt[0] = (double)((int) tx);
90*25c28e83SPiotr Jasiukajtis 		tx = (tx - tt[0]) * two24;
91*25c28e83SPiotr Jasiukajtis 		if (tx != zero)
92*25c28e83SPiotr Jasiukajtis 		{
93*25c28e83SPiotr Jasiukajtis 			nx = 2;
94*25c28e83SPiotr Jasiukajtis 			tt[1] = (double)((int) tx);
95*25c28e83SPiotr Jasiukajtis 			tt[2] = (tx - tt[1]) * two24;
96*25c28e83SPiotr Jasiukajtis 			if (tt[2] != zero)
97*25c28e83SPiotr Jasiukajtis 				nx = 3;
98*25c28e83SPiotr Jasiukajtis 		}
99*25c28e83SPiotr Jasiukajtis 		else
100*25c28e83SPiotr Jasiukajtis 		{
101*25c28e83SPiotr Jasiukajtis 			nx = 1;
102*25c28e83SPiotr Jasiukajtis 			tt[1] = tt[2] = zero;
103*25c28e83SPiotr Jasiukajtis 		}
104*25c28e83SPiotr Jasiukajtis 		nx = __vlibm_rem_pio2m(tt, ty, e0, nx, 2);
105*25c28e83SPiotr Jasiukajtis 		if (xsb)
106*25c28e83SPiotr Jasiukajtis 		{
107*25c28e83SPiotr Jasiukajtis 			nx = -nx;
108*25c28e83SPiotr Jasiukajtis 			ty[0] = -ty[0];
109*25c28e83SPiotr Jasiukajtis 			ty[1] = -ty[1];
110*25c28e83SPiotr Jasiukajtis 		}
111*25c28e83SPiotr Jasiukajtis 
112*25c28e83SPiotr Jasiukajtis 		/* now nx and ty[*] are the quadrant and reduced arg */
113*25c28e83SPiotr Jasiukajtis 		hx = HI(&ty[0]);
114*25c28e83SPiotr Jasiukajtis 		xsb = 0;
115*25c28e83SPiotr Jasiukajtis 		if (hx & 0x80000000)
116*25c28e83SPiotr Jasiukajtis 		{
117*25c28e83SPiotr Jasiukajtis 			ty[0] = -ty[0];
118*25c28e83SPiotr Jasiukajtis 			ty[1] = -ty[1];
119*25c28e83SPiotr Jasiukajtis 			hx &= ~0x80000000;
120*25c28e83SPiotr Jasiukajtis 			xsb = 1;
121*25c28e83SPiotr Jasiukajtis 		}
122*25c28e83SPiotr Jasiukajtis 		if (hx < 0x3fc40000)
123*25c28e83SPiotr Jasiukajtis 		{
124*25c28e83SPiotr Jasiukajtis 			z = ty[0] * ty[0];
125*25c28e83SPiotr Jasiukajtis 			t = z * (q1 + z * (q2 + z * (q3 + z * q4)));
126*25c28e83SPiotr Jasiukajtis 			c = one + t;
127*25c28e83SPiotr Jasiukajtis 			t = z * (p1 + z * (p2 + z * (p3 + z * p4)));
128*25c28e83SPiotr Jasiukajtis 			s = ty[0] + (ty[1] + ty[0] * t);
129*25c28e83SPiotr Jasiukajtis 		}
130*25c28e83SPiotr Jasiukajtis 		else {
131*25c28e83SPiotr Jasiukajtis 			j = (hx + 0x4000) & 0x7fff8000;
132*25c28e83SPiotr Jasiukajtis 			HI(&t) = j;
133*25c28e83SPiotr Jasiukajtis 			LO(&t) = 0;
134*25c28e83SPiotr Jasiukajtis 			ty[0] = (ty[0] - t) + ty[1];
135*25c28e83SPiotr Jasiukajtis 			z = ty[0] * ty[0];
136*25c28e83SPiotr Jasiukajtis 			t = z * (qq1 + z * qq2);
137*25c28e83SPiotr Jasiukajtis 			w = ty[0] * (one + z * (pp1 + z * pp2));
138*25c28e83SPiotr Jasiukajtis 			j = ((j - 0x3fc40000) >> 13) & ~3;
139*25c28e83SPiotr Jasiukajtis 
140*25c28e83SPiotr Jasiukajtis 			c = __vlibm_TBL_sincos_hi[j+1];
141*25c28e83SPiotr Jasiukajtis 			tc = __vlibm_TBL_sincos_lo[j+1] - (__vlibm_TBL_sincos_hi[j] * w - c * t);
142*25c28e83SPiotr Jasiukajtis 			c += tc;
143*25c28e83SPiotr Jasiukajtis 
144*25c28e83SPiotr Jasiukajtis 			s = __vlibm_TBL_sincos_hi[j];
145*25c28e83SPiotr Jasiukajtis 			ts = (__vlibm_TBL_sincos_hi[j+1] * w + s * t) + __vlibm_TBL_sincos_lo[j];
146*25c28e83SPiotr Jasiukajtis 			s += ts;
147*25c28e83SPiotr Jasiukajtis 		}
148*25c28e83SPiotr Jasiukajtis 		if (xsb) {
149*25c28e83SPiotr Jasiukajtis 			s = -s;
150*25c28e83SPiotr Jasiukajtis 		}
151*25c28e83SPiotr Jasiukajtis 
152*25c28e83SPiotr Jasiukajtis 		switch (nx & 3) {
153*25c28e83SPiotr Jasiukajtis 		case 0:
154*25c28e83SPiotr Jasiukajtis 			*ss = s;
155*25c28e83SPiotr Jasiukajtis 			*cc = c;
156*25c28e83SPiotr Jasiukajtis 			break;
157*25c28e83SPiotr Jasiukajtis 
158*25c28e83SPiotr Jasiukajtis 		case 1:
159*25c28e83SPiotr Jasiukajtis 			*ss = c;
160*25c28e83SPiotr Jasiukajtis 			*cc = -s;
161*25c28e83SPiotr Jasiukajtis 			break;
162*25c28e83SPiotr Jasiukajtis 
163*25c28e83SPiotr Jasiukajtis 		case 2:
164*25c28e83SPiotr Jasiukajtis 			*ss = -s;
165*25c28e83SPiotr Jasiukajtis 			*cc = -c;
166*25c28e83SPiotr Jasiukajtis 			break;
167*25c28e83SPiotr Jasiukajtis 
168*25c28e83SPiotr Jasiukajtis 		case 3:
169*25c28e83SPiotr Jasiukajtis 			*ss = -c;
170*25c28e83SPiotr Jasiukajtis 			*cc = s;
171*25c28e83SPiotr Jasiukajtis 			break;
172*25c28e83SPiotr Jasiukajtis 		}
173*25c28e83SPiotr Jasiukajtis 	}
174*25c28e83SPiotr Jasiukajtis }
175