OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [newlib/] [libm/] [machine/] [spu/] [headers/] [asinhd2.h] - Blame information for rev 829

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* --------------------------------------------------------------  */
2
/* (C)Copyright 2007,2008,                                         */
3
/* International Business Machines Corporation                     */
4
/* All Rights Reserved.                                            */
5
/*                                                                 */
6
/* Redistribution and use in source and binary forms, with or      */
7
/* without modification, are permitted provided that the           */
8
/* following conditions are met:                                   */
9
/*                                                                 */
10
/* - Redistributions of source code must retain the above copyright*/
11
/*   notice, this list of conditions and the following disclaimer. */
12
/*                                                                 */
13
/* - Redistributions in binary form must reproduce the above       */
14
/*   copyright notice, this list of conditions and the following   */
15
/*   disclaimer in the documentation and/or other materials        */
16
/*   provided with the distribution.                               */
17
/*                                                                 */
18
/* - Neither the name of IBM Corporation nor the names of its      */
19
/*   contributors may be used to endorse or promote products       */
20
/*   derived from this software without specific prior written     */
21
/*   permission.                                                   */
22
/*                                                                 */
23
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
24
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
25
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
26
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
27
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
28
/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
29
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
30
/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
31
/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
32
/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
33
/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
34
/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
35
/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
36
/* --------------------------------------------------------------  */
37
/* PROLOG END TAG zYx                                              */
38
#ifdef __SPU__
39
#ifndef _ASINHD2_H_
40
#define _ASINHD2_H_     1
41
 
42
#include <spu_intrinsics.h>
43
 
44
#include "logd2.h"
45
#include "sqrtd2.h"
46
 
47
/*
48
 * FUNCTION
49
 *  vector double _asinhd2(vector double x)
50
 *
51
 * DESCRIPTION
52
 *  The asinhd2 function returns a vector containing the hyperbolic
53
 *  arcsines of the corresponding elements of the input vector.
54
 *
55
 *  We are using the formula:
56
 *    asinh = ln(|x| + sqrt(x^2 + 1))
57
 *  and the anti-symmetry of asinh.
58
 *
59
 *  For x near zero, we use the Taylor series:
60
 *
61
 *                infinity
62
 *                 ------
63
 *                  -   '  P  (0)
64
 *                   -      k-1    k
65
 *    asinh x =       -    -----  x
66
 *                   -       k
67
 *                  -   ,
68
 *                 ------
69
 *                 k = 1
70
 *
71
 *  Special Cases:
72
 *    asinh(+0)        returns +0
73
 *    asinh(-0)        returns -0
74
 *    asinh(+infinity) returns +infinity
75
 *    asinh(-infinity) returns -infinity
76
 *    asinh(NaN)       returns NaN
77
 *
78
 */
79
 
80
/*
81
 * Maclaurin Series Coefficients
82
 * for x near 0.
83
 */
84
#define SDM_ASINHD2_MAC01     1.000000000000000000000000000000000000000000E0
85
#define SDM_ASINHD2_MAC03    -1.666666666666666666666666666666666666666667E-1
86
#define SDM_ASINHD2_MAC05     7.500000000000000000000000000000000000000000E-2
87
#define SDM_ASINHD2_MAC07    -4.464285714285714285714285714285714285714286E-2
88
#define SDM_ASINHD2_MAC09     3.038194444444444444444444444444444444444444E-2
89
#define SDM_ASINHD2_MAC11    -2.237215909090909090909090909090909090909091E-2
90
#define SDM_ASINHD2_MAC13     1.735276442307692307692307692307692307692308E-2
91
#define SDM_ASINHD2_MAC15    -1.396484375000000000000000000000000000000000E-2
92
#define SDM_ASINHD2_MAC17     1.155180089613970588235294117647058823529412E-2
93
 
94
 
95
static __inline vector double _asinhd2(vector double x)
96
{
97
    vec_double2 sign_mask = spu_splats(-0.0);
98
    vec_double2 oned      = spu_splats(1.0);
99
    vec_uchar16 dup_even  = ((vec_uchar16) { 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 });
100
    vec_uint4   infminus1 = spu_splats(0x7FEFFFFFU);
101
    vec_uint4   isinfnan;
102
    vec_double2 xabs, xsqu;
103
    vec_uint4   xabshigh;
104
    vec_float4  switch_approx = spu_splats(0.165f);  /* Where we switch from maclaurin to formula */
105
    vec_uint4   use_form;
106
    vec_float4  xf;
107
    vec_double2 result, fresult, mresult;
108
 
109
 
110
    xabs = spu_andc(x, sign_mask);
111
    xsqu = spu_mul(x, x);
112
 
113
    xf = spu_roundtf(xabs);
114
    xf = spu_shuffle(xf, xf, dup_even);
115
 
116
    /*
117
     * Formula:
118
     *   asinh = ln(|x| + sqrt(x^2 + 1))
119
     */
120
    fresult = _sqrtd2(spu_add(xsqu, oned));
121
    fresult = spu_add(xabs, fresult);
122
    fresult = _logd2(fresult);
123
 
124
 
125
    /*
126
     * Maclaurin Series approximation
127
     */
128
 
129
    mresult = spu_splats(SDM_ASINHD2_MAC17);
130
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC15));
131
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC13));
132
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC11));
133
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC09));
134
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC07));
135
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC05));
136
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC03));
137
    mresult = spu_madd(xsqu, mresult, spu_splats(SDM_ASINHD2_MAC01));
138
    mresult = spu_mul(xabs, mresult);
139
 
140
 
141
    /*
142
     * Choose between series and formula
143
     */
144
    use_form = spu_cmpgt(xf, switch_approx);
145
    result = spu_sel(mresult, fresult, (vec_ullong2)use_form);
146
 
147
 
148
    /* Special Cases */
149
 
150
    /* Infinity and NaN */
151
    xabshigh = (vec_uint4)spu_shuffle(xabs, xabs, dup_even);
152
    isinfnan = spu_cmpgt(xabshigh, infminus1);
153
    result = spu_sel(result, x, (vec_ullong2)isinfnan);
154
 
155
 
156
    /* Restore sign - asinh is an anti-symmetric */
157
    result = spu_sel(result, x, (vec_ullong2)sign_mask);
158
 
159
    return result;
160
}
161
 
162
#endif /* _ASINHD2_H_ */
163
#endif /* __SPU__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.