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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-newlib/] [newlib-1.17.0/] [newlib/] [libm/] [machine/] [spu/] [headers/] [coshf4.h] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 jlechner
/* --------------------------------------------------------------  */
2
/* (C)Copyright 2006,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 _COSHF4_H_
40
#define _COSHF4_H_ 1
41
 
42
#include <spu_intrinsics.h>
43
 
44
#include "expf4.h"
45
#include "recipf4.h"
46
 
47
 
48
/*
49
 * FUNCTION
50
 *      vector float _coshf4(vector float x)
51
 *
52
 * DESCRIPTION
53
 *      The _coshf4 function computes the hyperbolic cosines of a vector of
54
 *      angles (expressed in radians) to an accuracy of a single precision
55
 *      floating point.
56
 *
57
 */
58
static __inline vector float _coshf4(vector float x)
59
{
60
  //  1.0000  (above this number, use sinh(x) = 0.5 * (e^x - e^-x)
61
  vec_uint4 threshold = (vec_uint4)spu_splats(0x3F800000);
62
 
63
  vec_uint4 sign_mask = (vec_uint4)spu_splats(0x80000000);
64
 
65
  // Coefficents for the Taylor series
66
  vec_float4 f02 = spu_splats(5.0000000000000000E-1f);  // 1/2!
67
  vec_float4 f04 = spu_splats(4.1666666666666667E-2f);  // 1/4!
68
  vec_float4 f06 = spu_splats(1.3888888888888889E-3f);  // 1/6!
69
  vec_float4 f08 = spu_splats(2.4801587301587302E-5f);  // 1/8!
70
  vec_float4 f10 = spu_splats(2.7557319223985891E-7f);  // 1/10!
71
  vec_float4 f12 = spu_splats(2.0876756987868099E-9f);  // 1/12!
72
 
73
  // Perform the calculation as a Taylor series
74
  vec_float4 result;
75
  vector float x2 = spu_mul(x,x);
76
  result = spu_madd(x2,f12,f10);
77
  result = spu_madd(x2,result,f08);
78
  result = spu_madd(x2,result,f06);
79
  result = spu_madd(x2,result,f04);
80
  result = spu_madd(x2,result,f02);
81
  result = spu_madd(x2,result,spu_splats(1.0f));
82
 
83
 
84
  //  Perform calculation as a function of 0.5 * (e^x - e^-x)
85
  vec_float4 ex = _expf4(x);
86
  vec_float4 ex_inv = _recipf4(ex);
87
 
88
  vec_float4 r2= spu_add(ex,ex_inv);
89
  r2 = spu_mul(r2,f02);  // we can reused f02 here
90
 
91
  vec_uint4 xabs = spu_andc((vec_uint4)x,sign_mask);
92
  vec_uint4 use_exp = spu_cmpgt(xabs,threshold);
93
 
94
  //  Select either the Taylor or exp version
95
  result = spu_sel(result,r2,use_exp);
96
 
97
  return result;
98
}
99
#endif /* _COSHF4_H_ */
100
#endif /* __SPU__ */

powered by: WebSVN 2.1.0

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