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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libm/] [machine/] [spu/] [headers/] [log1pd2.h] - Blame information for rev 148

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

Line No. Rev Author Line
1 148 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
 
39
#ifdef __SPU__
40
#ifndef _LOG1PD2_H_
41
#define _LOG1PD2_H_     1
42
 
43
#include <spu_intrinsics.h>
44
#include "simdmath.h"
45
 
46
#include "logd2.h"
47
#include "divd2.h"
48
 
49
 
50
 
51
#define LOG1PD2_P0 0.0000000000000000000000000e+00
52
#define LOG1PD2_P1 1.0000000000000000000000000e+00
53
#define LOG1PD2_P2 2.3771612265431403265836252e+00
54
#define LOG1PD2_P3 2.0034423569559494104908026e+00
55
#define LOG1PD2_P4 7.1309327316770110272159400e-01
56
#define LOG1PD2_P5 9.8219761968547217301228613e-02
57
#define LOG1PD2_P6 3.4385125174546914139650511e-03
58
 
59
#define LOG1PD2_Q0 1.0000000000000000000000000e+00
60
#define LOG1PD2_Q1 2.8771612265431403265836252e+00
61
#define LOG1PD2_Q2 3.1086896368941925317130881e+00
62
#define LOG1PD2_Q3 1.5583843494335058998956356e+00
63
#define LOG1PD2_Q4 3.6047236436186669283898709e-01
64
#define LOG1PD2_Q5 3.2620075387969869884496887e-02
65
#define LOG1PD2_Q6 6.8047193336239690346356479e-04
66
 
67
 
68
/*
69
 * FUNCTION
70
 *      vector double _log1pd2(vector double x)
71
 *
72
 * DESCRIPTION
73
 *      The function _log1pd2 computes the natural logarithm of x + 1
74
 *      for each of the double word elements of x.
75
 *
76
 */
77
 
78
static __inline vector double _log1pd2(vector double x)
79
{
80
  vector double oned  = spu_splats(1.0);
81
  vector double rangehi = spu_splats(0.35);
82
  vector double rangelo = spu_splats(0.0);
83
  vector unsigned long long use_log;
84
  vector double pr, qr;
85
  vector double eresult;
86
  vector double rresult;
87
  vector double result;
88
 
89
  /* Compiler Bug. Replace xbug with x when spu_cmp*() doesn't
90
   * modify it's arguments! */
91
  volatile vector double xbug = x;
92
  use_log = spu_or(spu_cmpgt(xbug, rangehi), spu_cmpgt(rangelo, xbug));
93
 
94
  /*
95
   * Calculate directly using log(x+1)
96
   */
97
  eresult = _logd2(spu_add(x, oned));
98
 
99
  /*
100
   * For x in [0.0,0.35], use a rational approximation.
101
   */
102
  pr = spu_madd(x, spu_splats(LOG1PD2_P6), spu_splats(LOG1PD2_P5));
103
  qr = spu_madd(x, spu_splats(LOG1PD2_Q6), spu_splats(LOG1PD2_Q5));
104
  pr = spu_madd(pr, x, spu_splats(LOG1PD2_P4));
105
  qr = spu_madd(qr, x, spu_splats(LOG1PD2_Q4));
106
  pr = spu_madd(pr, x, spu_splats(LOG1PD2_P3));
107
  qr = spu_madd(qr, x, spu_splats(LOG1PD2_Q3));
108
  pr = spu_madd(pr, x, spu_splats(LOG1PD2_P2));
109
  qr = spu_madd(qr, x, spu_splats(LOG1PD2_Q2));
110
  pr = spu_madd(pr, x, spu_splats(LOG1PD2_P1));
111
  qr = spu_madd(qr, x, spu_splats(LOG1PD2_Q1));
112
  pr = spu_madd(pr, x, spu_splats(LOG1PD2_P0));
113
  qr = spu_madd(qr, x, spu_splats(LOG1PD2_Q0));
114
  rresult = _divd2(pr, qr);
115
 
116
  /*
117
   * Select either direct calculation or rational approximation.
118
   */
119
  result = spu_sel(rresult, eresult, use_log);
120
 
121
  return result;
122
}
123
 
124
#endif /* _LOG1PD2_H_ */
125
#endif /* __SPU__ */

powered by: WebSVN 2.1.0

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