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/] [logbf4.h] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* --------------------------------------------------------------  */
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
 
40
#ifndef _LOGBF4_H_
41
#define _LOGBF4_H_      1
42
 
43
#include <spu_intrinsics.h>
44
#include <vec_types.h>
45
 
46
/*
47
 * FUNCTION
48
 *      vector float _logbf4(vector float x)
49
 *
50
 * DESCRIPTION
51
 *  The _logbf4 function returns a vector float that contains the exponent
52
 *  of the corresponding elements of the input vector x. The exponent is
53
 *  defined by:
54
 *    x = frac * FLT_RADIX^exp, with frac in [1, FLT_RADIX).
55
 *
56
 *  Special Cases:
57
 *    x = 0,  result is undefined.
58
 *    x = NaN, result is NaN.
59
 *    x = infinity, +infinity is returned.
60
 *
61
 */
62
static __inline vector float _logbf4(vector float x)
63
{
64
  vec_uint4 lzero     = (vector unsigned int) {0, 0, 0, 0};
65
  vec_uint4 exp_mask  = (vector unsigned int) {0xFF, 0xFF, 0xFF, 0xFF};
66
  vec_int4  exp_shift = (vector signed int) { -23,  -23,  -23,  -23};
67
  vec_int4  exp_bias  = (vector signed int) {-127, -127, -127, -127};
68
  vec_uint4 sign_mask = (vector unsigned int) {0x80000000, 0x80000000,
69
                                                       0x80000000, 0x80000000};
70
  vec_uint4 linf      = (vector unsigned int) {0x7F800000, 0x7F800000,
71
                                                       0x7F800000, 0x7F800000};
72
  vec_uint4 lminf     = (vector unsigned int) {0xFF800000, 0xFF800000,
73
                                                       0xFF800000, 0xFF800000};
74
  vec_uint4 exp;
75
  vec_uint4 xabs;
76
  vec_float4 exp_unbias;
77
 
78
 
79
  xabs = spu_andc((vec_uint4)x, sign_mask);
80
 
81
  exp  = spu_and(spu_rlmask((vec_uint4)x, exp_shift), exp_mask);
82
  exp_unbias = spu_convtf(spu_add((vec_int4)exp, exp_bias), 0);
83
 
84
  /* Zero */
85
  exp_unbias = spu_sel(exp_unbias, (vec_float4)lminf, (vec_uint4)spu_cmpeq(xabs, lzero));
86
 
87
  /* NaN */
88
  exp_unbias = spu_sel(exp_unbias, x, (vec_uint4)spu_cmpgt(xabs, linf));
89
 
90
  /* Infinite */
91
  exp_unbias = spu_sel(exp_unbias, (vec_float4)linf, (vec_uint4)spu_cmpeq(xabs, linf));
92
 
93
  return (exp_unbias);
94
}
95
 
96
#endif /* _LOGBF4_H_ */
97
 
98
#endif /* __SPU__ */

powered by: WebSVN 2.1.0

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