MIPS: math-emu: Replace DP_MBITS with DP_FBITS and SP_MBITS with SP_FBITS.
[firefly-linux-kernel-4.4.55.git] / arch / mips / math-emu / ieee754int.h
1 /*
2  * IEEE754 floating point
3  * common 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 #ifndef __IEEE754INT_H
27 #define __IEEE754INT_H
28
29 #include "ieee754.h"
30
31 #define DP_EBIAS        1023
32 #define DP_EMIN         (-1022)
33 #define DP_EMAX         1023
34 #define DP_FBITS        52
35
36 #define SP_EBIAS        127
37 #define SP_EMIN         (-126)
38 #define SP_EMAX         127
39 #define SP_FBITS        23
40
41 #define DP_MBIT(x)      ((u64)1 << (x))
42 #define DP_HIDDEN_BIT   DP_MBIT(DP_FBITS)
43 #define DP_SIGN_BIT     DP_MBIT(63)
44
45 #define SP_MBIT(x)      ((u32)1 << (x))
46 #define SP_HIDDEN_BIT   SP_MBIT(SP_FBITS)
47 #define SP_SIGN_BIT     SP_MBIT(31)
48
49
50 #define SPSIGN(sp)      (sp.parts.sign)
51 #define SPBEXP(sp)      (sp.parts.bexp)
52 #define SPMANT(sp)      (sp.parts.mant)
53
54 #define DPSIGN(dp)      (dp.parts.sign)
55 #define DPBEXP(dp)      (dp.parts.bexp)
56 #define DPMANT(dp)      (dp.parts.mant)
57
58 #define CLPAIR(x, y)    ((x)*6+(y))
59
60 static inline void ieee754_clearcx(void)
61 {
62         ieee754_csr.cx = 0;
63 }
64
65 static inline void ieee754_setcx(const unsigned int flags)
66 {
67         ieee754_csr.cx |= flags;
68         ieee754_csr.sx |= flags;
69 }
70
71 static inline int ieee754_setandtestcx(const unsigned int x)
72 {
73         ieee754_setcx(x);
74
75         return ieee754_csr.mx & x;
76 }
77
78 static inline int ieee754_tstx(void)
79 {
80         return ieee754_csr.cx & ieee754_csr.mx;
81 }
82
83 #define COMPXSP \
84         unsigned xm; int xe; int xs __maybe_unused; int xc
85
86 #define COMPYSP \
87         unsigned ym; int ye; int ys; int yc
88
89 #define EXPLODESP(v, vc, vs, ve, vm)                                    \
90 {                                                                       \
91         vs = SPSIGN(v);                                                 \
92         ve = SPBEXP(v);                                                 \
93         vm = SPMANT(v);                                                 \
94         if (ve == SP_EMAX+1+SP_EBIAS) {                                 \
95                 if (vm == 0)                                            \
96                         vc = IEEE754_CLASS_INF;                         \
97                 else if (vm & SP_MBIT(SP_FBITS-1))                      \
98                         vc = IEEE754_CLASS_SNAN;                        \
99         else                                                            \
100                 vc = IEEE754_CLASS_QNAN;                                \
101         } else if (ve == SP_EMIN-1+SP_EBIAS) {                          \
102                 if (vm) {                                               \
103                         ve = SP_EMIN;                                   \
104                         vc = IEEE754_CLASS_DNORM;                       \
105                 } else                                                  \
106                         vc = IEEE754_CLASS_ZERO;                        \
107         } else {                                                        \
108                 ve -= SP_EBIAS;                                         \
109                 vm |= SP_HIDDEN_BIT;                                    \
110                 vc = IEEE754_CLASS_NORM;                                \
111         }                                                               \
112 }
113 #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
114 #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
115
116
117 #define COMPXDP \
118         u64 xm; int xe; int xs __maybe_unused; int xc
119
120 #define COMPYDP \
121         u64 ym; int ye; int ys; int yc
122
123 #define EXPLODEDP(v, vc, vs, ve, vm)                                    \
124 {                                                                       \
125         vm = DPMANT(v);                                                 \
126         vs = DPSIGN(v);                                                 \
127         ve = DPBEXP(v);                                                 \
128         if (ve == DP_EMAX+1+DP_EBIAS) {                                 \
129                 if (vm == 0)                                            \
130                         vc = IEEE754_CLASS_INF;                         \
131                 else if (vm & DP_MBIT(DP_FBITS-1))                      \
132                         vc = IEEE754_CLASS_SNAN;                        \
133                 else                                                    \
134                         vc = IEEE754_CLASS_QNAN;                        \
135         } else if (ve == DP_EMIN-1+DP_EBIAS) {                          \
136                 if (vm) {                                               \
137                         ve = DP_EMIN;                                   \
138                         vc = IEEE754_CLASS_DNORM;                       \
139         } else                                                          \
140                 vc = IEEE754_CLASS_ZERO;                                \
141         } else {                                                        \
142                 ve -= DP_EBIAS;                                         \
143                 vm |= DP_HIDDEN_BIT;                                    \
144                 vc = IEEE754_CLASS_NORM;                                \
145         }                                                               \
146 }
147 #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
148 #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
149
150 #define FLUSHDP(v, vc, vs, ve, vm)                                      \
151         if (vc==IEEE754_CLASS_DNORM) {                                  \
152                 if (ieee754_csr.nod) {                                  \
153                         ieee754_setcx(IEEE754_INEXACT);                 \
154                         vc = IEEE754_CLASS_ZERO;                        \
155                         ve = DP_EMIN-1+DP_EBIAS;                        \
156                         vm = 0;                                         \
157                         v = ieee754dp_zero(vs);                         \
158                 }                                                       \
159         }
160
161 #define FLUSHSP(v, vc, vs, ve, vm)                                      \
162         if (vc==IEEE754_CLASS_DNORM) {                                  \
163                 if (ieee754_csr.nod) {                                  \
164                         ieee754_setcx(IEEE754_INEXACT);                 \
165                         vc = IEEE754_CLASS_ZERO;                        \
166                         ve = SP_EMIN-1+SP_EBIAS;                        \
167                         vm = 0;                                         \
168                         v = ieee754sp_zero(vs);                         \
169                 }                                                       \
170         }
171
172 #define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
173 #define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
174 #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
175 #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
176
177 #endif /* __IEEE754INT_H  */