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