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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [machine/] [spu/] [headers/] [atanf4.h] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* --------------------------------------------------------------  */
2
/* (C)Copyright 2001,2008,                                         */
3
/* International Business Machines Corporation,                    */
4
/* Sony Computer Entertainment, Incorporated,                      */
5
/* Toshiba Corporation,                                            */
6
/*                                                                 */
7
/* All Rights Reserved.                                            */
8
/*                                                                 */
9
/* Redistribution and use in source and binary forms, with or      */
10
/* without modification, are permitted provided that the           */
11
/* following conditions are met:                                   */
12
/*                                                                 */
13
/* - Redistributions of source code must retain the above copyright*/
14
/*   notice, this list of conditions and the following disclaimer. */
15
/*                                                                 */
16
/* - Redistributions in binary form must reproduce the above       */
17
/*   copyright notice, this list of conditions and the following   */
18
/*   disclaimer in the documentation and/or other materials        */
19
/*   provided with the distribution.                               */
20
/*                                                                 */
21
/* - Neither the name of IBM Corporation nor the names of its      */
22
/*   contributors may be used to endorse or promote products       */
23
/*   derived from this software without specific prior written     */
24
/*   permission.                                                   */
25
/*                                                                 */
26
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
27
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
28
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
29
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
30
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
31
/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
32
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
33
/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
34
/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
35
/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
36
/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
37
/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
38
/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
39
/* --------------------------------------------------------------  */
40
/* PROLOG END TAG zYx                                              */
41
#ifdef __SPU__
42
 
43
#ifndef _ATANF4_H_
44
#define _ATANF4_H_      1
45
 
46
#include <spu_intrinsics.h>
47
 
48
#include "simdmath.h"
49
#include "recipf4.h"
50
 
51
/*
52
 * FUNCTION
53
 *      vector float _atanf4(vector float x)
54
 *
55
 * DESCRIPTION
56
 *      The _atanf4 function computes the arc tangent of a vector of values x;
57
 *      that is the values whose tangent is x.
58
 *
59
 *      The _atanf4 function returns the arc tangents in radians and the value
60
 *      is mathematically defined to be in the range -PI/2 to PI/2.
61
 *
62
 *      The arc tangent function is computed using a polynomial approximation
63
 *      (B. Carlson, M. Goldstein, Los Alamos Scientific Laboratory, 1955).
64
 *                __8__
65
 *                \
66
 *                 \
67
 *      atan(x) =  /    Ci*x^(2*i+1)
68
 *                /____
69
 *                 i=0
70
 *
71
 *      for x in the range -1 to 1. The remaining regions are defined to be:
72
 *
73
 *      [1, infinity]   :  PI/2 + atanf(-1/x)
74
 *      [-infinity, -1] : -PI/2 + atanf(-1/x)
75
 *
76
 */
77
static __inline vector float _atanf4(vector float x)
78
{
79
  vector float bias;
80
  vector float x2, x3, x4, x8, x9;
81
  vector float hi, lo;
82
  vector float result;
83
  vector float inv_x;
84
  vector unsigned int sign;
85
  vector unsigned int select;
86
 
87
  sign = spu_sl(spu_rlmask((vector unsigned int)x, -31), 31);
88
  inv_x = _recipf4(x);
89
  inv_x = (vector float)spu_xor((vector unsigned int)inv_x, spu_splats(0x80000000));
90
 
91
  select = (vector unsigned int)spu_cmpabsgt(x, spu_splats(1.0f));
92
  bias = (vector float)spu_or(sign, (vector unsigned int)(spu_splats((float)SM_PI_2)));
93
  bias = (vector float)spu_and((vector unsigned int)bias, select);
94
 
95
  x = spu_sel(x, inv_x, select);
96
 
97
  /* Instruction counts can be reduced if the polynomial was
98
   * computed entirely from nested (dependent) fma's. However,
99
   * to reduce the number of pipeline stalls, the polygon is evaluated
100
   * in two halves(hi and lo).
101
   */
102
  bias = spu_add(bias, x);
103
  x2 = spu_mul(x, x);
104
  x3 = spu_mul(x2, x);
105
  x4 = spu_mul(x2, x2);
106
  x8 = spu_mul(x4, x4);
107
  x9 = spu_mul(x8, x);
108
  hi = spu_madd(spu_splats(0.0028662257f), x2, spu_splats(-0.0161657367f));
109
  hi = spu_madd(hi, x2, spu_splats(0.0429096138f));
110
  hi = spu_madd(hi, x2, spu_splats(-0.0752896400f));
111
  hi = spu_madd(hi, x2, spu_splats(0.1065626393f));
112
  lo = spu_madd(spu_splats(-0.1420889944f), x2, spu_splats(0.1999355085f));
113
  lo = spu_madd(lo, x2, spu_splats(-0.3333314528f));
114
  lo = spu_madd(lo, x3, bias);
115
 
116
  result = spu_madd(hi, x9, lo);
117
 
118
  return (result);
119
}
120
 
121
#endif /* _ATANF4_H_ */
122
#endif /* __SPU__ */
123
 
124
 

powered by: WebSVN 2.1.0

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