]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/mips/math-emu/ieee754sp.h
MIPS: math-emu: Inline ieee754sp_issnan and ieee754dp_issnan.
[karo-tx-linux.git] / arch / mips / math-emu / ieee754sp.h
1 /*
2  * IEEE754 floating point
3  * double precision internal header file
4  */
5 /*
6  * MIPS floating point support
7  * Copyright (C) 1994-2000 Algorithmics Ltd.
8  *
9  * ########################################################################
10  *
11  *  This program is free software; you can distribute it and/or modify it
12  *  under the terms of the GNU General Public License (Version 2) as
13  *  published by the Free Software Foundation.
14  *
15  *  This program is distributed in the hope it will be useful, but WITHOUT
16  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18  *  for more details.
19  *
20  *  You should have received a copy of the GNU General Public License along
21  *  with this program; if not, write to the Free Software Foundation, Inc.,
22  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
23  *
24  * ########################################################################
25  */
26
27 #include <linux/compiler.h>
28
29 #include "ieee754int.h"
30
31 #define assert(expr) ((void)0)
32
33 #define SP_EBIAS        127
34 #define SP_EMIN         (-126)
35 #define SP_EMAX         127
36 #define SP_FBITS        23
37 #define SP_MBITS        23
38
39 #define SP_MBIT(x)      ((u32)1 << (x))
40 #define SP_HIDDEN_BIT   SP_MBIT(SP_FBITS)
41 #define SP_SIGN_BIT     SP_MBIT(31)
42
43 #define SPSIGN(sp)      (sp.parts.sign)
44 #define SPBEXP(sp)      (sp.parts.bexp)
45 #define SPMANT(sp)      (sp.parts.mant)
46
47 static inline int ieee754sp_finite(union ieee754sp x)
48 {
49         return SPBEXP(x) != SP_EMAX + 1 + SP_EBIAS;
50 }
51
52 /* 3bit extended single precision sticky right shift */
53 #define SPXSRSXn(rs)                                                    \
54         (xe += rs,                                                      \
55          xm = (rs > (SP_FBITS+3))?1:((xm) >> (rs)) | ((xm) << (32-(rs)) != 0))
56
57 #define SPXSRSX1() \
58         (xe++, (xm = (xm >> 1) | (xm & 1)))
59
60 #define SPXSRSYn(rs)                                                            \
61         (ye+=rs,                                                                \
62          ym = (rs > (SP_FBITS+3))?1:((ym) >> (rs)) | ((ym) << (32-(rs)) != 0))
63
64 #define SPXSRSY1() \
65         (ye++, (ym = (ym >> 1) | (ym & 1)))
66
67 /* convert denormal to normalized with extended exponent */
68 #define SPDNORMx(m,e) \
69         while ((m >> SP_FBITS) == 0) { m <<= 1; e--; }
70 #define SPDNORMX        SPDNORMx(xm, xe)
71 #define SPDNORMY        SPDNORMx(ym, ye)
72
73 static inline union ieee754sp buildsp(int s, int bx, unsigned m)
74 {
75         union ieee754sp r;
76
77         assert((s) == 0 || (s) == 1);
78         assert((bx) >= SP_EMIN - 1 + SP_EBIAS
79                && (bx) <= SP_EMAX + 1 + SP_EBIAS);
80         assert(((m) >> SP_FBITS) == 0);
81
82         r.parts.sign = s;
83         r.parts.bexp = bx;
84         r.parts.mant = m;
85
86         return r;
87 }
88
89 extern int ieee754sp_isnan(union ieee754sp);
90 extern int __cold ieee754si_xcpt(int, const char *, ...);
91 extern s64 __cold ieee754di_xcpt(s64, const char *, ...);
92 extern union ieee754sp __cold ieee754sp_xcpt(union ieee754sp, const char *, ...);
93 extern union ieee754sp __cold ieee754sp_nanxcpt(union ieee754sp, const char *, ...);
94 extern union ieee754sp ieee754sp_format(int, int, unsigned);
95
96
97 #define SPNORMRET2(s, e, m, name, a0, a1)                               \
98 {                                                                       \
99         union ieee754sp V = ieee754sp_format(s, e, m);                  \
100                                                                         \
101         if (ieee754_tstx())                                             \
102                 return ieee754sp_xcpt(V, name, a0, a1);                 \
103         else                                                            \
104                 return V;                                               \
105 }
106
107 #define SPNORMRET1(s, e, m, name, a0)  SPNORMRET2(s, e, m, name, a0, a0)