25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER START
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The contents of this file are subject to the terms of the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Common Development and Distribution License (the "License").
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You may not use this file except in compliance with the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * See the License for the specific language governing permissions
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * and limitations under the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER END
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Use is subject to license terms.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define restrict _Restrict
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define restrict
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis__vatanf(int n, float * restrict x, int stridex, float * restrict y, int stridey)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis extern const double __vlibm_TBL_atan1[];
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* Power series atan(x) = x + p1*x**3 + p2*x**5 + p3*x**7
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Error = -3.08254E-18 On the interval |x| < 1/64 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis static const float p1 = -0.33329644f /* -3.333333333329292858E-01f */ ;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (n <= 0) return; /* if no. of elements is 0 or neg, do nothing */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = *(int *) x; /* upper half of x, as integer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = intf & ~0x80000000; /* abs(upper argument) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if ((intf > 0x5B000000) || (intf < 0x31800000)) /* filter out special cases */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf < 0x31800000) /* avoid underflow for small arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf > 0x5B000000) /* avoid underflow for big arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis ansf = __vlibm_TBL_atan1[index0];/* pi/2 up */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *y = sign0*ansf; /* store answer, with sign bit */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (--n <=0) break; /* we are done */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto LOOP0; /* otherwise, examine next arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index0 = 2; /* point to pi/2 upper, lower */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf >= 0x3C800000) /* if |x| >= (1/64)... */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intz = (intf + 0x00040000) & 0x7ff80000;/* round arg, keep upper */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index0 = (intz - 0x3C800000) >> 18; /* (index >> 19) << 1) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index0 = index0+ 4; /* skip over 0,0,pi/2,pi/2 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else /* |x| < 1/64 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis yaddr0 = y; /* address to store this answer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis argcount = 1; /* we now have 1 good argument */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto UNROLL; /* finish up with 1 good arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = *(int *) x; /* upper half of x, as integer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = intf & ~0x80000000; /* abs(upper argument) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if ((intf > 0x5B000000) || (intf < 0x31800000)) /* filter out special cases */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf < 0x31800000) /* avoid underflow for small arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf > 0x5B000000) /* avoid underflow for big arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis ansf = __vlibm_TBL_atan1[index1] ;/* pi/2 up */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *y = sign1 * ansf; /* store answer, with sign bit */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis argcount = 1; /* we still have 1 good arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto UNROLL; /* finish up with 1 good arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto LOOP1; /* otherwise, examine next arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index1 = 2; /* point to pi/2 upper, lower */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf >= 0x3C800000) /* if |x| >= (1/64)... */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intz = (intf + 0x00040000) & 0x7ff80000;/* round arg, keep upper */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index1 = (intz - 0x3C800000) >> 18; /* (index >> 19) << 1) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index1 = index1 + 4; /* skip over 0,0,pi/2,pi/2 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis yaddr1 = y; /* address to store this answer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis argcount = 2; /* we now have 2 good arguments */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto UNROLL; /* finish up with 2 good args */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = *(int *) x; /* upper half of x, as integer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = intf & ~0x80000000; /* abs(upper argument) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if ((intf > 0x5B000000) || (intf < 0x31800000)) /* filter out special cases */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf < 0x31800000) /* avoid underflow for small arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf > 0x5B000000) /* avoid underflow for big arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis ansf = __vlibm_TBL_atan1[index2] ;/* pi/2 up */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *y = sign2 * ansf; /* store answer, with sign bit */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis argcount = 2; /* we still have 2 good args */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto UNROLL; /* finish up with 2 good args */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto LOOP2; /* otherwise, examine next arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index2 = 2; /* point to pi/2 upper, lower */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf >= 0x3C800000) /* if |x| >= (1/64)... */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intz = (intf + 0x00040000) & 0x7ff80000;/* round arg, keep upper */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index2 = (intz - 0x3C800000) >> 18; /* (index >> 19) << 1) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index2 = index2 + 4; /* skip over 0,0,pi/2,pi/2 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis yaddr2 = y; /* address to store this answer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis argcount = 3; /* we now have 3 good arguments */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto UNROLL; /* finish up with 2 good args */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /*--------------------------------------------------------------------------*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = *(int *) x; /* upper half of x, as integer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intf = intf & ~0x80000000; /* abs(upper argument) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if ((intf > 0x5B000000) || (intf < 0x31800000)) /* filter out special cases */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf < 0x31800000) /* avoid underflow for small arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf > 0x5B000000) /* avoid underflow for big arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis ansf = __vlibm_TBL_atan1[index3] ;/* pi/2 up */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis *y = sign3 * ansf; /* store answer, with sign bit */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis argcount = 3; /* we still have 3 good args */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto UNROLL; /* finish up with 3 good args */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto LOOP3; /* otherwise, examine next arg */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index3 = 2; /* point to pi/2 upper, lower */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (intf >= 0x3C800000) /* if |x| >= (1/64)... */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis intz = (intf + 0x00040000) & 0x7ff80000;/* round arg, keep upper */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis d3 = (pone + f3*z); /* get reduced argument */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index3 = (intz - 0x3C800000) >> 18; /* (index >> 19) << 1) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis index3 = index3 + 4; /* skip over 0,0,pi/2,pi/2 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis yaddr3 = y; /* address to store this answer */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis argcount = 4; /* we now have 4 good arguments */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis goto UNROLL; /* finish up with 3 good args */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#endif /* UNROLL4 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* here is the n-way unrolled section,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis but we may actually have less than n
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis arguments at this point
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } while (n > 0);