1 /*
2 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 #include <errno.h>
38 #include "headers/truncf4.h"
39 #include "headers/tgammaf4.h"
40 
_tgammaf(float x)41 static __inline float _tgammaf(float x)
42 {
43   float res;
44   vector float vx;
45   vector float truncx;
46   vector float vc = { 0.0, 0.0 };
47   vector unsigned int cmpres;
48   vector signed int verrno, ferrno;
49   vector signed int fail = { EDOM, EDOM, EDOM, EDOM };
50 
51   vx = spu_promote(x, 0);
52   res = spu_extract(_tgammaf4(vx), 0);
53 #ifndef _IEEE_LIBM
54   /*
55    * use vector truncf4 rather than splat x, and splat truncx.
56    */
57   truncx = _truncf4(vx);
58   cmpres = spu_cmpeq(truncx, vx);
59   verrno = spu_splats(errno);
60   ferrno = spu_sel(verrno, fail, (vector unsigned int) cmpres);
61   cmpres = spu_cmpgt(vc, vx);
62   errno = spu_extract(spu_sel(verrno, ferrno, (vector unsigned int) cmpres), 0);
63 #endif
64   return res;
65 }
66