xref: /titanic_50/usr/src/lib/libmvec/common/__vexpf.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 #ifdef __RESTRICT
31*25c28e83SPiotr Jasiukajtis #define restrict _Restrict
32*25c28e83SPiotr Jasiukajtis #else
33*25c28e83SPiotr Jasiukajtis #define restrict
34*25c28e83SPiotr Jasiukajtis #endif
35*25c28e83SPiotr Jasiukajtis 
36*25c28e83SPiotr Jasiukajtis /* float expf(float x)
37*25c28e83SPiotr Jasiukajtis  *
38*25c28e83SPiotr Jasiukajtis  * Method :
39*25c28e83SPiotr Jasiukajtis  *	1. Special cases:
40*25c28e83SPiotr Jasiukajtis  *		for x > 88.722839355...(0x42B17218) => Inf + overflow;
41*25c28e83SPiotr Jasiukajtis  *		for x < -103.97207642..(0xc2CFF1B4) => 0 + underflow;
42*25c28e83SPiotr Jasiukajtis  *		for x = Inf			    => Inf;
43*25c28e83SPiotr Jasiukajtis  *		for x = -Inf			    => 0;
44*25c28e83SPiotr Jasiukajtis  *		for x = +-NaN			    => QNaN.
45*25c28e83SPiotr Jasiukajtis  *	2. Computes exponential from:
46*25c28e83SPiotr Jasiukajtis  *		exp(x) = 2**a  *  2**(k/256)  *  2**(y/256)
47*25c28e83SPiotr Jasiukajtis  *	Where:
48*25c28e83SPiotr Jasiukajtis  *		a    =    int  ( 256 * log2(e) * x ) >> 8;
49*25c28e83SPiotr Jasiukajtis  *		k    =    int  ( 256 * log2(e) * x ) & 0xFF;
50*25c28e83SPiotr Jasiukajtis  *		y    =    frac ( 256 * x * log2(e)).
51*25c28e83SPiotr Jasiukajtis  *	Note that:
52*25c28e83SPiotr Jasiukajtis  *		k = 0, 1, ..., 255;
53*25c28e83SPiotr Jasiukajtis  *		y = (-1, 1).
54*25c28e83SPiotr Jasiukajtis  *	Then:
55*25c28e83SPiotr Jasiukajtis  *		2**(k/256) is looked up in a table of 2**0, 2**1/256, ...
56*25c28e83SPiotr Jasiukajtis  *		2**(y/256) is computed using approximation:
57*25c28e83SPiotr Jasiukajtis  *			2**(y/256) =  a0 + a1 * y + a2 * y**2
58*25c28e83SPiotr Jasiukajtis  *		Multiplication by 2**a is done by adding "a" to
59*25c28e83SPiotr Jasiukajtis  *		the biased exponent.
60*25c28e83SPiotr Jasiukajtis  * Accuracy:
61*25c28e83SPiotr Jasiukajtis  *	The maximum relative error for the approximating
62*25c28e83SPiotr Jasiukajtis  *	polynomial is 2**(-29.18).  All calculations are of
63*25c28e83SPiotr Jasiukajtis  *	double precision.
64*25c28e83SPiotr Jasiukajtis  *	Maximum error observed: less than 0.528 ulp for the whole
65*25c28e83SPiotr Jasiukajtis  *	float type range.
66*25c28e83SPiotr Jasiukajtis  *
67*25c28e83SPiotr Jasiukajtis  * NOTE: This implementation has been modified for SPARC to deliver
68*25c28e83SPiotr Jasiukajtis  * zero instead of a subnormal result whenever the argument is less
69*25c28e83SPiotr Jasiukajtis  * than log(2^-126).  Therefore the worst case relative error is 1.
70*25c28e83SPiotr Jasiukajtis  */
71*25c28e83SPiotr Jasiukajtis 
72*25c28e83SPiotr Jasiukajtis static const double __TBL_exp2f[] = {
73*25c28e83SPiotr Jasiukajtis 	/* 2^(i/256) - (((i & 0xff) << 44), i = [0, 255] */
74*25c28e83SPiotr Jasiukajtis 1.000000000000000000e+00, 9.994025125251012609e-01, 9.988087005564013632e-01,
75*25c28e83SPiotr Jasiukajtis 9.982185740592087742e-01, 9.976321430258502376e-01, 9.970494174757447148e-01,
76*25c28e83SPiotr Jasiukajtis 9.964704074554765478e-01, 9.958951230388689568e-01, 9.953235743270583136e-01,
77*25c28e83SPiotr Jasiukajtis 9.947557714485678604e-01, 9.941917245593818730e-01, 9.936314438430204898e-01,
78*25c28e83SPiotr Jasiukajtis 9.930749395106142074e-01, 9.925222218009785990e-01, 9.919733009806893653e-01,
79*25c28e83SPiotr Jasiukajtis 9.914281873441580517e-01, 9.908868912137068774e-01, 9.903494229396448967e-01,
80*25c28e83SPiotr Jasiukajtis 9.898157929003436051e-01, 9.892860115023132117e-01, 9.887600891802785785e-01,
81*25c28e83SPiotr Jasiukajtis 9.882380363972563808e-01, 9.877198636446310465e-01, 9.872055814422322495e-01,
82*25c28e83SPiotr Jasiukajtis 9.866952003384118486e-01, 9.861887309101209365e-01, 9.856861837629877776e-01,
83*25c28e83SPiotr Jasiukajtis 9.851875695313955239e-01, 9.846928988785599302e-01, 9.842021824966076249e-01,
84*25c28e83SPiotr Jasiukajtis 9.837154311066546031e-01, 9.832326554588848300e-01, 9.827538663326288448e-01,
85*25c28e83SPiotr Jasiukajtis 9.822790745364429199e-01, 9.818082909081884413e-01, 9.813415263151109569e-01,
86*25c28e83SPiotr Jasiukajtis 9.808787916539204454e-01, 9.804200978508705866e-01, 9.799654558618393629e-01,
87*25c28e83SPiotr Jasiukajtis 9.795148766724087741e-01, 9.790683712979462161e-01, 9.786259507836846394e-01,
88*25c28e83SPiotr Jasiukajtis 9.781876262048033732e-01, 9.777534086665099489e-01, 9.773233093041209241e-01,
89*25c28e83SPiotr Jasiukajtis 9.768973392831440394e-01, 9.764755097993595978e-01, 9.760578320789027318e-01,
90*25c28e83SPiotr Jasiukajtis 9.756443173783457823e-01, 9.752349769847807881e-01, 9.748298222159020865e-01,
91*25c28e83SPiotr Jasiukajtis 9.744288644200894689e-01, 9.740321149764913367e-01, 9.736395852951079677e-01,
92*25c28e83SPiotr Jasiukajtis 9.732512868168755604e-01, 9.728672310137493895e-01, 9.724874293887887378e-01,
93*25c28e83SPiotr Jasiukajtis 9.721118934762408292e-01, 9.717406348416250950e-01, 9.713736650818186602e-01,
94*25c28e83SPiotr Jasiukajtis 9.710109958251406104e-01, 9.706526387314379223e-01, 9.702986054921705072e-01,
95*25c28e83SPiotr Jasiukajtis 9.699489078304969203e-01, 9.696035575013605134e-01, 9.692625662915755891e-01,
96*25c28e83SPiotr Jasiukajtis 9.689259460199136642e-01, 9.685937085371902899e-01, 9.682658657263515378e-01,
97*25c28e83SPiotr Jasiukajtis 9.679424295025619296e-01, 9.676234118132908124e-01, 9.673088246384006217e-01,
98*25c28e83SPiotr Jasiukajtis 9.669986799902344776e-01, 9.666929899137042259e-01, 9.663917664863788115e-01,
99*25c28e83SPiotr Jasiukajtis 9.660950218185727634e-01, 9.658027680534350123e-01, 9.655150173670379310e-01,
100*25c28e83SPiotr Jasiukajtis 9.652317819684667066e-01, 9.649530740999082701e-01, 9.646789060367420010e-01,
101*25c28e83SPiotr Jasiukajtis 9.644092900876289898e-01, 9.641442385946024096e-01, 9.638837639331581109e-01,
102*25c28e83SPiotr Jasiukajtis 9.636278785123455481e-01, 9.633765947748582636e-01, 9.631299251971253694e-01,
103*25c28e83SPiotr Jasiukajtis 9.628878822894031408e-01, 9.626504785958666099e-01, 9.624177266947013809e-01,
104*25c28e83SPiotr Jasiukajtis 9.621896391981960006e-01, 9.619662287528346623e-01, 9.617475080393891318e-01,
105*25c28e83SPiotr Jasiukajtis 9.615334897730127839e-01, 9.613241867033328614e-01, 9.611196116145447332e-01,
106*25c28e83SPiotr Jasiukajtis 9.609197773255048203e-01, 9.607246966898252971e-01, 9.605343825959679060e-01,
107*25c28e83SPiotr Jasiukajtis 9.603488479673386591e-01, 9.601681057623822069e-01, 9.599921689746773179e-01,
108*25c28e83SPiotr Jasiukajtis 9.598210506330320246e-01, 9.596547638015787696e-01, 9.594933215798706616e-01,
109*25c28e83SPiotr Jasiukajtis 9.593367371029771773e-01, 9.591850235415807502e-01, 9.590381941020729162e-01,
110*25c28e83SPiotr Jasiukajtis 9.588962620266514580e-01, 9.587592405934176609e-01, 9.586271431164729018e-01,
111*25c28e83SPiotr Jasiukajtis 9.584999829460172371e-01, 9.583777734684463256e-01, 9.582605281064505709e-01,
112*25c28e83SPiotr Jasiukajtis 9.581482603191123770e-01, 9.580409836020059577e-01, 9.579387114872952580e-01,
113*25c28e83SPiotr Jasiukajtis 9.578414575438342071e-01, 9.577492353772650846e-01, 9.576620586301189952e-01,
114*25c28e83SPiotr Jasiukajtis 9.575799409819160113e-01, 9.575028961492645374e-01, 9.574309378859631181e-01,
115*25c28e83SPiotr Jasiukajtis 9.573640799831001358e-01, 9.573023362691556182e-01, 9.572457206101023797e-01,
116*25c28e83SPiotr Jasiukajtis 9.571942469095077177e-01, 9.571479291086353314e-01, 9.571067811865475727e-01,
117*25c28e83SPiotr Jasiukajtis 9.570708171602075875e-01, 9.570400510845827879e-01, 9.570144970527471040e-01,
118*25c28e83SPiotr Jasiukajtis 9.569941691959850116e-01, 9.569790816838944503e-01, 9.569692487244911838e-01,
119*25c28e83SPiotr Jasiukajtis 9.569646845643128286e-01, 9.569654034885233251e-01, 9.569714198210175216e-01,
120*25c28e83SPiotr Jasiukajtis 9.569827479245263113e-01, 9.569994022007218826e-01, 9.570213970903235223e-01,
121*25c28e83SPiotr Jasiukajtis 9.570487470732028656e-01, 9.570814666684909211e-01, 9.571195704346837640e-01,
122*25c28e83SPiotr Jasiukajtis 9.571630729697496731e-01, 9.572119889112359337e-01, 9.572663329363761964e-01,
123*25c28e83SPiotr Jasiukajtis 9.573261197621985019e-01, 9.573913641456324175e-01, 9.574620808836177277e-01,
124*25c28e83SPiotr Jasiukajtis 9.575382848132127922e-01, 9.576199908117032367e-01, 9.577072137967114207e-01,
125*25c28e83SPiotr Jasiukajtis 9.577999687263049067e-01, 9.578982705991073709e-01, 9.580021344544072948e-01,
126*25c28e83SPiotr Jasiukajtis 9.581115753722692086e-01, 9.582266084736434930e-01, 9.583472489204779565e-01,
127*25c28e83SPiotr Jasiukajtis 9.584735119158284133e-01, 9.586054127039703721e-01, 9.587429665705107240e-01,
128*25c28e83SPiotr Jasiukajtis 9.588861888424999869e-01, 9.590350948885443261e-01, 9.591897001189184646e-01,
129*25c28e83SPiotr Jasiukajtis 9.593500199856788146e-01, 9.595160699827764983e-01, 9.596878656461707013e-01,
130*25c28e83SPiotr Jasiukajtis 9.598654225539432483e-01, 9.600487563264122892e-01, 9.602378826262468747e-01,
131*25c28e83SPiotr Jasiukajtis 9.604328171585819751e-01, 9.606335756711334994e-01, 9.608401739543135367e-01,
132*25c28e83SPiotr Jasiukajtis 9.610526278413467072e-01, 9.612709532083855146e-01, 9.614951659746271417e-01,
133*25c28e83SPiotr Jasiukajtis 9.617252821024303566e-01, 9.619613175974318642e-01, 9.622032885086644338e-01,
134*25c28e83SPiotr Jasiukajtis 9.624512109286739170e-01, 9.627051009936374859e-01, 9.629649748834822054e-01,
135*25c28e83SPiotr Jasiukajtis 9.632308488220031606e-01, 9.635027390769824729e-01, 9.637806619603088709e-01,
136*25c28e83SPiotr Jasiukajtis 9.640646338280971506e-01, 9.643546710808080791e-01, 9.646507901633681881e-01,
137*25c28e83SPiotr Jasiukajtis 9.649530075652912320e-01, 9.652613398207983142e-01, 9.655758035089392344e-01,
138*25c28e83SPiotr Jasiukajtis 9.658964152537145020e-01, 9.662231917241966839e-01, 9.665561496346526393e-01,
139*25c28e83SPiotr Jasiukajtis 9.668953057446663113e-01, 9.672406768592617388e-01, 9.675922798290256255e-01,
140*25c28e83SPiotr Jasiukajtis 9.679501315502314629e-01, 9.683142489649629869e-01, 9.686846490612389671e-01,
141*25c28e83SPiotr Jasiukajtis 9.690613488731369962e-01, 9.694443654809188349e-01, 9.698337160111555333e-01,
142*25c28e83SPiotr Jasiukajtis 9.702294176368531087e-01, 9.706314875775782225e-01, 9.710399430995845238e-01,
143*25c28e83SPiotr Jasiukajtis 9.714548015159391037e-01, 9.718760801866497268e-01, 9.723037965187919518e-01,
144*25c28e83SPiotr Jasiukajtis 9.727379679666363632e-01, 9.731786120317773570e-01, 9.736257462632605941e-01,
145*25c28e83SPiotr Jasiukajtis 9.740793882577122309e-01, 9.745395556594674824e-01, 9.750062661607005188e-01,
146*25c28e83SPiotr Jasiukajtis 9.754795375015535841e-01, 9.759593874702675587e-01, 9.764458339033119660e-01,
147*25c28e83SPiotr Jasiukajtis 9.769388946855159794e-01, 9.774385877501994280e-01, 9.779449310793042471e-01,
148*25c28e83SPiotr Jasiukajtis 9.784579427035267063e-01, 9.789776407024486371e-01, 9.795040432046712153e-01,
149*25c28e83SPiotr Jasiukajtis 9.800371683879468554e-01, 9.805770344793129922e-01, 9.811236597552254191e-01,
150*25c28e83SPiotr Jasiukajtis 9.816770625416927354e-01, 9.822372612144102400e-01, 9.828042741988944897e-01,
151*25c28e83SPiotr Jasiukajtis 9.833781199706193021e-01, 9.839588170551499813e-01, 9.845463840282800971e-01,
152*25c28e83SPiotr Jasiukajtis 9.851408395161672660e-01, 9.857422021954695968e-01, 9.863504907934828037e-01,
153*25c28e83SPiotr Jasiukajtis 9.869657240882776517e-01, 9.875879209088370692e-01, 9.882171001351949258e-01,
154*25c28e83SPiotr Jasiukajtis 9.888532806985737000e-01, 9.894964815815237014e-01, 9.901467218180625141e-01,
155*25c28e83SPiotr Jasiukajtis 9.908040204938135531e-01, 9.914683967461471736e-01, 9.921398697643202258e-01,
156*25c28e83SPiotr Jasiukajtis 9.928184587896166091e-01, 9.935041831154891590e-01, 9.941970620877000897e-01,
157*25c28e83SPiotr Jasiukajtis 9.948971151044636585e-01, 9.956043616165879406e-01, 9.963188211276171602e-01,
158*25c28e83SPiotr Jasiukajtis 9.970405131939754639e-01, 9.977694574251096959e-01, 9.985056734836331715e-01,
159*25c28e83SPiotr Jasiukajtis 9.992491810854701173e-01
160*25c28e83SPiotr Jasiukajtis };
161*25c28e83SPiotr Jasiukajtis 
162*25c28e83SPiotr Jasiukajtis static const double
163*25c28e83SPiotr Jasiukajtis 	K256ONLN2 = 369.3299304675746271,
164*25c28e83SPiotr Jasiukajtis 	KA2 = 3.66556671660783833261e-06,
165*25c28e83SPiotr Jasiukajtis 	KA1 = 2.70760782821392980564e-03,
166*25c28e83SPiotr Jasiukajtis 	KA0 = 1.0;
167*25c28e83SPiotr Jasiukajtis 
168*25c28e83SPiotr Jasiukajtis static const float extreme[2] = { 1.0e30f, 1.0e-30f };
169*25c28e83SPiotr Jasiukajtis 
170*25c28e83SPiotr Jasiukajtis #define PROCESS(N)						\
171*25c28e83SPiotr Jasiukajtis 	x##N *= K256ONLN2;					\
172*25c28e83SPiotr Jasiukajtis 	k##N = (int) x##N;					\
173*25c28e83SPiotr Jasiukajtis 	x##N -= (double) k##N;					\
174*25c28e83SPiotr Jasiukajtis 	x##N = (KA2 * x##N + KA1) * x##N + KA0;			\
175*25c28e83SPiotr Jasiukajtis 	lres##N = ((long long *)__TBL_exp2f)[k##N & 0xff];	\
176*25c28e83SPiotr Jasiukajtis 	lres##N += (long long)k##N << 44;			\
177*25c28e83SPiotr Jasiukajtis 	*y = (float) (x##N * *(double *)&lres##N);		\
178*25c28e83SPiotr Jasiukajtis 	y += stridey
179*25c28e83SPiotr Jasiukajtis 
180*25c28e83SPiotr Jasiukajtis #ifdef __sparc
181*25c28e83SPiotr Jasiukajtis 
182*25c28e83SPiotr Jasiukajtis #define PREPROCESS(N, index, label)				\
183*25c28e83SPiotr Jasiukajtis 	xi = *(int *)x;						\
184*25c28e83SPiotr Jasiukajtis 	ax = xi & ~0x80000000;					\
185*25c28e83SPiotr Jasiukajtis 	fx = *x;						\
186*25c28e83SPiotr Jasiukajtis 	x += stridex;						\
187*25c28e83SPiotr Jasiukajtis 	if (ax >= 0x42aeac50)	/* log(2^126) = 87.3365... */	\
188*25c28e83SPiotr Jasiukajtis 	{							\
189*25c28e83SPiotr Jasiukajtis 		sign = (unsigned)xi >> 31;			\
190*25c28e83SPiotr Jasiukajtis 		if (ax >= 0x7f800000)	/* |x| = inf or nan */	\
191*25c28e83SPiotr Jasiukajtis 		{						\
192*25c28e83SPiotr Jasiukajtis 			if (ax > 0x7f800000)	/* nan */	\
193*25c28e83SPiotr Jasiukajtis 			{					\
194*25c28e83SPiotr Jasiukajtis 				y[index] = fx * fx;		\
195*25c28e83SPiotr Jasiukajtis 				goto label;			\
196*25c28e83SPiotr Jasiukajtis 			}					\
197*25c28e83SPiotr Jasiukajtis 			y[index] = (sign) ? 0.0f : fx;		\
198*25c28e83SPiotr Jasiukajtis 			goto label;				\
199*25c28e83SPiotr Jasiukajtis 		}						\
200*25c28e83SPiotr Jasiukajtis 		if (sign || ax > 0x42b17218) {		\
201*25c28e83SPiotr Jasiukajtis 			fx = extreme[sign];			\
202*25c28e83SPiotr Jasiukajtis 			y[index] = fx * fx;			\
203*25c28e83SPiotr Jasiukajtis 			goto label;				\
204*25c28e83SPiotr Jasiukajtis 		}						\
205*25c28e83SPiotr Jasiukajtis 	}							\
206*25c28e83SPiotr Jasiukajtis 	x##N = fx
207*25c28e83SPiotr Jasiukajtis 
208*25c28e83SPiotr Jasiukajtis #else
209*25c28e83SPiotr Jasiukajtis 
210*25c28e83SPiotr Jasiukajtis #define PREPROCESS(N, index, label)				\
211*25c28e83SPiotr Jasiukajtis 	xi = *(int *)x;						\
212*25c28e83SPiotr Jasiukajtis 	ax = xi & ~0x80000000;					\
213*25c28e83SPiotr Jasiukajtis 	fx = *x;						\
214*25c28e83SPiotr Jasiukajtis 	x += stridex;						\
215*25c28e83SPiotr Jasiukajtis 	if (ax > 0x42cff1b4)	/* 103.972076f */		\
216*25c28e83SPiotr Jasiukajtis 	{							\
217*25c28e83SPiotr Jasiukajtis 		sign = (unsigned)xi >> 31;			\
218*25c28e83SPiotr Jasiukajtis 		if (ax >= 0x7f800000)	/* |x| = inf or nan */	\
219*25c28e83SPiotr Jasiukajtis 		{						\
220*25c28e83SPiotr Jasiukajtis 			if (ax > 0x7f800000)	/* nan */	\
221*25c28e83SPiotr Jasiukajtis 			{					\
222*25c28e83SPiotr Jasiukajtis 				y[index] = fx * fx;		\
223*25c28e83SPiotr Jasiukajtis 				goto label;			\
224*25c28e83SPiotr Jasiukajtis 			}					\
225*25c28e83SPiotr Jasiukajtis 			y[index] = (sign) ? 0.0f : fx;		\
226*25c28e83SPiotr Jasiukajtis 			goto label;				\
227*25c28e83SPiotr Jasiukajtis 		}						\
228*25c28e83SPiotr Jasiukajtis 		fx = extreme[sign];				\
229*25c28e83SPiotr Jasiukajtis 		y[index] = fx * fx;				\
230*25c28e83SPiotr Jasiukajtis 		goto label;					\
231*25c28e83SPiotr Jasiukajtis 	}							\
232*25c28e83SPiotr Jasiukajtis 	x##N = fx
233*25c28e83SPiotr Jasiukajtis 
234*25c28e83SPiotr Jasiukajtis #endif
235*25c28e83SPiotr Jasiukajtis 
236*25c28e83SPiotr Jasiukajtis void
__vexpf(int n,float * restrict x,int stridex,float * restrict y,int stridey)237*25c28e83SPiotr Jasiukajtis __vexpf(int n, float * restrict x, int stridex, float * restrict y,
238*25c28e83SPiotr Jasiukajtis 	int stridey)
239*25c28e83SPiotr Jasiukajtis {
240*25c28e83SPiotr Jasiukajtis 	double		x0, x1, x2, x3, x4;
241*25c28e83SPiotr Jasiukajtis 	double		res0, res1, res2, res3, res4;
242*25c28e83SPiotr Jasiukajtis 	float		fx;
243*25c28e83SPiotr Jasiukajtis 	long long	lres0, lres1, lres2, lres3, lres4;
244*25c28e83SPiotr Jasiukajtis 	int		k0, k1, k2, k3, k4;
245*25c28e83SPiotr Jasiukajtis 	int		xi, ax, sign;
246*25c28e83SPiotr Jasiukajtis 
247*25c28e83SPiotr Jasiukajtis 	y -= stridey;
248*25c28e83SPiotr Jasiukajtis 
249*25c28e83SPiotr Jasiukajtis 	for (; ;)
250*25c28e83SPiotr Jasiukajtis 	{
251*25c28e83SPiotr Jasiukajtis begin:
252*25c28e83SPiotr Jasiukajtis 		if (--n < 0)
253*25c28e83SPiotr Jasiukajtis 			break;
254*25c28e83SPiotr Jasiukajtis 		y += stridey;
255*25c28e83SPiotr Jasiukajtis 
256*25c28e83SPiotr Jasiukajtis 		PREPROCESS(0, 0, begin);
257*25c28e83SPiotr Jasiukajtis 
258*25c28e83SPiotr Jasiukajtis 		if (--n < 0)
259*25c28e83SPiotr Jasiukajtis 			goto process1;
260*25c28e83SPiotr Jasiukajtis 
261*25c28e83SPiotr Jasiukajtis 		PREPROCESS(1, stridey, process1);
262*25c28e83SPiotr Jasiukajtis 
263*25c28e83SPiotr Jasiukajtis 		if (--n < 0)
264*25c28e83SPiotr Jasiukajtis 			goto process2;
265*25c28e83SPiotr Jasiukajtis 
266*25c28e83SPiotr Jasiukajtis 		PREPROCESS(2, stridey << 1, process2);
267*25c28e83SPiotr Jasiukajtis 
268*25c28e83SPiotr Jasiukajtis 		if (--n < 0)
269*25c28e83SPiotr Jasiukajtis 			goto process3;
270*25c28e83SPiotr Jasiukajtis 
271*25c28e83SPiotr Jasiukajtis 		PREPROCESS(3, (stridey << 1) + stridey, process3);
272*25c28e83SPiotr Jasiukajtis 
273*25c28e83SPiotr Jasiukajtis 		if (--n < 0)
274*25c28e83SPiotr Jasiukajtis 			goto process4;
275*25c28e83SPiotr Jasiukajtis 
276*25c28e83SPiotr Jasiukajtis 		PREPROCESS(4, (stridey << 2), process4);
277*25c28e83SPiotr Jasiukajtis 
278*25c28e83SPiotr Jasiukajtis 		x0 *= K256ONLN2;
279*25c28e83SPiotr Jasiukajtis 		x1 *= K256ONLN2;
280*25c28e83SPiotr Jasiukajtis 		x2 *= K256ONLN2;
281*25c28e83SPiotr Jasiukajtis 		x3 *= K256ONLN2;
282*25c28e83SPiotr Jasiukajtis 		x4 *= K256ONLN2;
283*25c28e83SPiotr Jasiukajtis 
284*25c28e83SPiotr Jasiukajtis 		k0 = (int)x0;
285*25c28e83SPiotr Jasiukajtis 		k1 = (int)x1;
286*25c28e83SPiotr Jasiukajtis 		k2 = (int)x2;
287*25c28e83SPiotr Jasiukajtis 		k3 = (int)x3;
288*25c28e83SPiotr Jasiukajtis 		k4 = (int)x4;
289*25c28e83SPiotr Jasiukajtis 
290*25c28e83SPiotr Jasiukajtis 		x0 -= (double)k0;
291*25c28e83SPiotr Jasiukajtis 		x1 -= (double)k1;
292*25c28e83SPiotr Jasiukajtis 		x2 -= (double)k2;
293*25c28e83SPiotr Jasiukajtis 		x3 -= (double)k3;
294*25c28e83SPiotr Jasiukajtis 		x4 -= (double)k4;
295*25c28e83SPiotr Jasiukajtis 
296*25c28e83SPiotr Jasiukajtis 		x0 = (KA2 * x0 + KA1) * x0 + KA0;
297*25c28e83SPiotr Jasiukajtis 		x1 = (KA2 * x1 + KA1) * x1 + KA0;
298*25c28e83SPiotr Jasiukajtis 		x2 = (KA2 * x2 + KA1) * x2 + KA0;
299*25c28e83SPiotr Jasiukajtis 		x3 = (KA2 * x3 + KA1) * x3 + KA0;
300*25c28e83SPiotr Jasiukajtis 		x4 = (KA2 * x4 + KA1) * x4 + KA0;
301*25c28e83SPiotr Jasiukajtis 
302*25c28e83SPiotr Jasiukajtis 		lres0 = ((long long *)__TBL_exp2f)[k0 & 255];
303*25c28e83SPiotr Jasiukajtis 		lres1 = ((long long *)__TBL_exp2f)[k1 & 255];
304*25c28e83SPiotr Jasiukajtis 		lres2 = ((long long *)__TBL_exp2f)[k2 & 255];
305*25c28e83SPiotr Jasiukajtis 		lres3 = ((long long *)__TBL_exp2f)[k3 & 255];
306*25c28e83SPiotr Jasiukajtis 		lres4 = ((long long *)__TBL_exp2f)[k4 & 255];
307*25c28e83SPiotr Jasiukajtis 
308*25c28e83SPiotr Jasiukajtis 		lres0 += (long long)k0 << 44;
309*25c28e83SPiotr Jasiukajtis 		res0 = *(double *)&lres0;
310*25c28e83SPiotr Jasiukajtis 		lres1 += (long long)k1 << 44;
311*25c28e83SPiotr Jasiukajtis 		res1 = *(double *)&lres1;
312*25c28e83SPiotr Jasiukajtis 		lres2 += (long long)k2 << 44;
313*25c28e83SPiotr Jasiukajtis 		res2 = *(double *)&lres2;
314*25c28e83SPiotr Jasiukajtis 		lres3 += (long long)k3 << 44;
315*25c28e83SPiotr Jasiukajtis 		res3 = *(double *)&lres3;
316*25c28e83SPiotr Jasiukajtis 		lres4 += (long long)k4 << 44;
317*25c28e83SPiotr Jasiukajtis 		res4 = *(double *)&lres4;
318*25c28e83SPiotr Jasiukajtis 
319*25c28e83SPiotr Jasiukajtis 		*y = (float)(res0 * x0);
320*25c28e83SPiotr Jasiukajtis 		y += stridey;
321*25c28e83SPiotr Jasiukajtis 		*y = (float)(res1 * x1);
322*25c28e83SPiotr Jasiukajtis 		y += stridey;
323*25c28e83SPiotr Jasiukajtis 		*y = (float)(res2 * x2);
324*25c28e83SPiotr Jasiukajtis 		y += stridey;
325*25c28e83SPiotr Jasiukajtis 		*y = (float)(res3 * x3);
326*25c28e83SPiotr Jasiukajtis 		y += stridey;
327*25c28e83SPiotr Jasiukajtis 		*y = (float)(res4 * x4);
328*25c28e83SPiotr Jasiukajtis 		continue;
329*25c28e83SPiotr Jasiukajtis 
330*25c28e83SPiotr Jasiukajtis process1:
331*25c28e83SPiotr Jasiukajtis 		PROCESS(0);
332*25c28e83SPiotr Jasiukajtis 		continue;
333*25c28e83SPiotr Jasiukajtis 
334*25c28e83SPiotr Jasiukajtis process2:
335*25c28e83SPiotr Jasiukajtis 		PROCESS(0);
336*25c28e83SPiotr Jasiukajtis 		PROCESS(1);
337*25c28e83SPiotr Jasiukajtis 		continue;
338*25c28e83SPiotr Jasiukajtis 
339*25c28e83SPiotr Jasiukajtis process3:
340*25c28e83SPiotr Jasiukajtis 		PROCESS(0);
341*25c28e83SPiotr Jasiukajtis 		PROCESS(1);
342*25c28e83SPiotr Jasiukajtis 		PROCESS(2);
343*25c28e83SPiotr Jasiukajtis 		continue;
344*25c28e83SPiotr Jasiukajtis 
345*25c28e83SPiotr Jasiukajtis process4:
346*25c28e83SPiotr Jasiukajtis 		PROCESS(0);
347*25c28e83SPiotr Jasiukajtis 		PROCESS(1);
348*25c28e83SPiotr Jasiukajtis 		PROCESS(2);
349*25c28e83SPiotr Jasiukajtis 		PROCESS(3);
350*25c28e83SPiotr Jasiukajtis 	}
351*25c28e83SPiotr Jasiukajtis }
352