__vcosbig.c revision 25c28e83beb90e7c80452a7c818c5e6f73a07dc8
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * CDDL HEADER START
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * The contents of this file are subject to the terms of the
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Common Development and Distribution License (the "License").
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * You may not use this file except in compliance with the License.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * or http://www.opensolaris.org/os/licensing.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * See the License for the specific language governing permissions
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * and limitations under the License.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * When distributing Covered Code, include this CDDL HEADER in each
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * If applicable, add the following below this CDDL HEADER, with the
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * fields enclosed by brackets "[]" replaced with your own identifying
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * information: Portions Copyright [yyyy] [name of copyright owner]
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * CDDL HEADER END
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0c45178b5714d692c44817c2235320c3f2b030abwl/*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs/*
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs * Use is subject to license terms.
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#include <sys/isa_defs.h>
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#ifdef _LITTLE_ENDIAN
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#define HI(x) *(1+(int*)x)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#define LO(x) *(unsigned*)x
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#else
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#define HI(x) *(int*)x
b1a03ab1e63a57c5b968c229e2f36c79d2fdd222Victor Li#define LO(x) *(1+(unsigned*)x)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#endif
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#ifdef __RESTRICT
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#define restrict _Restrict
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#else
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#define restrict
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs#endif
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsextern const double __vlibm_TBL_sincos_hi[], __vlibm_TBL_sincos_lo[];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsextern int __vlibm_rem_pio2m(double *, double *, int, int, int);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsstatic const double
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs zero = 0.0,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs one = 1.0,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs two24 = 16777216.0,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pp1 = -1.666666666605760465276263943134982554676e-0001,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs pp2 = 8.333261209690963126718376566146180944442e-0003,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs p1 = -1.666666666666629669805215138920301589656e-0001,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs p2 = 8.333333332390951295683993455280336376663e-0003,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs p3 = -1.984126237997976692791551778230098403960e-0004,
0c45178b5714d692c44817c2235320c3f2b030abwl p4 = 2.753403624854277237649987622848330351110e-0006,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs qq1 = -4.999999999977710986407023955908711557870e-0001,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs qq2 = 4.166654863857219350645055881018842089580e-0002,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs q1 = -4.999999999999931701464060878888294524481e-0001,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs q2 = 4.166666666394861917535640593963708222319e-0002,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs q3 = -1.388888552656142867832756687736851681462e-0003,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs q4 = 2.478519423681460796618128289454530524759e-0005;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphsvoid
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs__vlibm_vcos_big(int n, double * restrict x, int stridex, double * restrict y,
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int stridey, int thresh)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs{
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs for (; n--; x += stridex, y += stridey)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs double tx, tt[3], ty[2], t, w, z, a;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs unsigned hx, xsb;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs int e0, nx, j;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs hx = HI(x);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs xsb = hx & 0x80000000;
cc25db92ff252ca1b7f63bd54f087f4ddf0dda4eChris Liu hx &= ~0x80000000;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (hx <= thresh || hx >= 0x7ff00000)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs continue;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs e0 = (hx >> 20) - 1046;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs HI(&tx) = 0x41600000 | (hx & 0xfffff);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs LO(&tx) = LO(x);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tt[0] = (double)((int) tx);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tx = (tx - tt[0]) * two24;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (tx != zero)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs nx = 2;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tt[1] = (double)((int) tx);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tt[2] = (tx - tt[1]) * two24;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (tt[2] != zero)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs nx = 3;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs else
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs nx = 1;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs tt[1] = tt[2] = zero;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs nx = __vlibm_rem_pio2m(tt, ty, e0, nx, 2);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (xsb)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs nx = -nx;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ty[0] = -ty[0];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ty[1] = -ty[1];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs nx = (nx + 1) & 3; /* Add 1 to turn sin into cos */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs /* now nx and ty[*] are the quadrant and reduced arg */
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs xsb = (nx & 2) << 30;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs hx = HI(&ty[0]);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (nx & 1)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (hx & 0x80000000)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ty[0] = -ty[0];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ty[1] = -ty[1];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs hx &= ~0x80000000;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (hx < 0x3fc40000)
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs z = ty[0] * ty[0];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs t = z * (q1 + z * (q2 + z * (q3 + z * q4)));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs a = one + t;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs else
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0c45178b5714d692c44817c2235320c3f2b030abwl j = (hx + 0x4000) & 0x7fff8000;
0c45178b5714d692c44817c2235320c3f2b030abwl HI(&t) = j;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs LO(&t) = 0;
0c45178b5714d692c44817c2235320c3f2b030abwl ty[0] = (ty[0] - t) + ty[1];
0c45178b5714d692c44817c2235320c3f2b030abwl z = ty[0] * ty[0];
0c45178b5714d692c44817c2235320c3f2b030abwl t = z * (qq1 + z * qq2);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs w = ty[0] * (one + z * (pp1 + z * pp2));
0c45178b5714d692c44817c2235320c3f2b030abwl j = ((j - 0x3fc40000) >> 13) & ~3;
0c45178b5714d692c44817c2235320c3f2b030abwl a = __vlibm_TBL_sincos_hi[j+1];
0c45178b5714d692c44817c2235320c3f2b030abwl t = __vlibm_TBL_sincos_lo[j+1] - (__vlibm_TBL_sincos_hi[j] * w - a * t);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs a += t;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs else
0c45178b5714d692c44817c2235320c3f2b030abwl {
0c45178b5714d692c44817c2235320c3f2b030abwl if (hx & 0x80000000)
0c45178b5714d692c44817c2235320c3f2b030abwl {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ty[0] = -ty[0];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ty[1] = -ty[1];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs hx &= ~0x80000000;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs xsb ^= 0x80000000;
0c45178b5714d692c44817c2235320c3f2b030abwl }
0c45178b5714d692c44817c2235320c3f2b030abwl if (hx < 0x3fc90000)
0c45178b5714d692c44817c2235320c3f2b030abwl {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs z = ty[0] * ty[0];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs t = z * (p1 + z * (p2 + z * (p3 + z * p4)));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs a = ty[0] + (ty[1] + ty[0] * t);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0c45178b5714d692c44817c2235320c3f2b030abwl else
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs {
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs j = (hx + 0x4000) & 0x7fff8000;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs HI(&t) = j;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs LO(&t) = 0;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs ty[0] = (ty[0] - t) + ty[1];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs z = ty[0] * ty[0];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs t = z * (qq1 + z * qq2);
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs w = ty[0] * (one + z * (pp1 + z * pp2));
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs j = ((j - 0x3fc40000) >> 13) & ~3;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs a = __vlibm_TBL_sincos_hi[j];
0c45178b5714d692c44817c2235320c3f2b030abwl t = (__vlibm_TBL_sincos_hi[j+1] * w + a * t) + __vlibm_TBL_sincos_lo[j];
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs a += t;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs if (xsb) a = -a;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs *y = a;
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs }
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs}
0205780bc43902d17f94f07ceacb0cd8d5eab20frralphs