OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [machine/] [spu/] [headers/] [scalbnf4.h] - Blame information for rev 207

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

Line No. Rev Author Line
1 207 jeremybenn
/* --------------------------------------------------------------  */
2
/* (C)Copyright 2006,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
#ifndef _SCALBNF4_H_
43
#define _SCALBNF4_H_    1
44
 
45
#include <spu_intrinsics.h>
46
 
47
/*
48
 * FUNCTION
49
 *      vector float _scalbnf4(vector float x, vector signed int exp)
50
 *
51
 * DESCRIPTION
52
 *      The _scalbnf4 function returns a vector containing each element of x
53
 *      multiplied by 2^n computed efficiently.  This function is computed
54
 *      without the assistance of any floating point operations and as such
55
 *      does not set any floating point exceptions.
56
 *
57
 *      Special Cases:
58
 *        - if the exponent is 0, then x is either 0 or a subnormal, and the
59
 *          result will be returned as 0.
60
 *        - if the result if underflows, it will be returned as 0.
61
 *        - if the result overflows, it will be returned as FLT_MAX.
62
 *
63
 */
64
static __inline vector float _scalbnf4(vector float x, vector signed int exp)
65
{
66
  vec_int4 x_exp;
67
  vec_uint4 zero;
68
  vec_uint4 overflow;
69
  vec_uint4 exp_mask = (vec_uint4)spu_splats(0x7F800000);
70
  vec_float4 out;
71
 
72
  /* Extract exponent from x. If the exponent is 0, then
73
   * x is either 0 or a denorm and x*2^exp is a zero.
74
   */
75
  x_exp = spu_and(spu_rlmask((vec_int4)x, -23), 0xFF);
76
  zero = spu_cmpeq(x_exp, 0);
77
 
78
  /* Compute the expected exponent and determine if the
79
   * result is within range.
80
   */
81
  x_exp = spu_add(exp, x_exp);
82
 
83
  /* Check for zero or overflow of result.
84
   * Note: set high bit of flags = 0, since we have to
85
   * return -0 when x = -0
86
   */
87
  zero     = spu_rlmask(spu_orc(zero, spu_cmpgt(x_exp, 0)), -1);
88
  overflow = spu_rlmask(spu_cmpgt(x_exp, 255), -1);
89
 
90
  /* Merge the expect exponent with x's mantissa. Zero the
91
   * result if underflow and force to max if overflow.
92
   */
93
  out = spu_sel(x, (vec_float4)spu_rl(x_exp, 23), exp_mask);
94
  out = spu_andc(out, (vec_float4)zero);
95
  out = spu_or(out, (vec_float4)overflow);
96
 
97
  return out;
98
}
99
 
100
#endif /* _SCALBNF4_H_ */
101
#endif /* __SPU__ */

powered by: WebSVN 2.1.0

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