diff options
Diffstat (limited to 'arch/mips/math-emu/ieee754int.h')
-rw-r--r-- | arch/mips/math-emu/ieee754int.h | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/arch/mips/math-emu/ieee754int.h b/arch/mips/math-emu/ieee754int.h new file mode 100644 index 000000000000..4a5a81d6b893 --- /dev/null +++ b/arch/mips/math-emu/ieee754int.h | |||
@@ -0,0 +1,165 @@ | |||
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 | * http://www.algor.co.uk | ||
9 | * | ||
10 | * ######################################################################## | ||
11 | * | ||
12 | * This program is free software; you can distribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License (Version 2) as | ||
14 | * published by the Free Software Foundation. | ||
15 | * | ||
16 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
19 | * for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License along | ||
22 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
24 | * | ||
25 | * ######################################################################## | ||
26 | */ | ||
27 | |||
28 | |||
29 | #include "ieee754.h" | ||
30 | |||
31 | #define DP_EBIAS 1023 | ||
32 | #define DP_EMIN (-1022) | ||
33 | #define DP_EMAX 1023 | ||
34 | #define DP_MBITS 52 | ||
35 | |||
36 | #define SP_EBIAS 127 | ||
37 | #define SP_EMIN (-126) | ||
38 | #define SP_EMAX 127 | ||
39 | #define SP_MBITS 23 | ||
40 | |||
41 | #define DP_MBIT(x) ((u64)1 << (x)) | ||
42 | #define DP_HIDDEN_BIT DP_MBIT(DP_MBITS) | ||
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_MBITS) | ||
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 | #define CLEARCX \ | ||
61 | (ieee754_csr.cx = 0) | ||
62 | |||
63 | #define SETCX(x) \ | ||
64 | (ieee754_csr.cx |= (x),ieee754_csr.sx |= (x)) | ||
65 | |||
66 | #define SETANDTESTCX(x) \ | ||
67 | (SETCX(x),ieee754_csr.mx & (x)) | ||
68 | |||
69 | #define TSTX() \ | ||
70 | (ieee754_csr.cx & ieee754_csr.mx) | ||
71 | |||
72 | |||
73 | #define COMPXSP \ | ||
74 | unsigned xm; int xe; int xs; int xc | ||
75 | |||
76 | #define COMPYSP \ | ||
77 | unsigned ym; int ye; int ys; int yc | ||
78 | |||
79 | #define EXPLODESP(v,vc,vs,ve,vm) \ | ||
80 | {\ | ||
81 | vs = SPSIGN(v);\ | ||
82 | ve = SPBEXP(v);\ | ||
83 | vm = SPMANT(v);\ | ||
84 | if(ve == SP_EMAX+1+SP_EBIAS){\ | ||
85 | if(vm == 0)\ | ||
86 | vc = IEEE754_CLASS_INF;\ | ||
87 | else if(vm & SP_MBIT(SP_MBITS-1)) \ | ||
88 | vc = IEEE754_CLASS_SNAN;\ | ||
89 | else \ | ||
90 | vc = IEEE754_CLASS_QNAN;\ | ||
91 | } else if(ve == SP_EMIN-1+SP_EBIAS) {\ | ||
92 | if(vm) {\ | ||
93 | ve = SP_EMIN;\ | ||
94 | vc = IEEE754_CLASS_DNORM;\ | ||
95 | } else\ | ||
96 | vc = IEEE754_CLASS_ZERO;\ | ||
97 | } else {\ | ||
98 | ve -= SP_EBIAS;\ | ||
99 | vm |= SP_HIDDEN_BIT;\ | ||
100 | vc = IEEE754_CLASS_NORM;\ | ||
101 | }\ | ||
102 | } | ||
103 | #define EXPLODEXSP EXPLODESP(x,xc,xs,xe,xm) | ||
104 | #define EXPLODEYSP EXPLODESP(y,yc,ys,ye,ym) | ||
105 | |||
106 | |||
107 | #define COMPXDP \ | ||
108 | u64 xm; int xe; int xs; int xc | ||
109 | |||
110 | #define COMPYDP \ | ||
111 | u64 ym; int ye; int ys; int yc | ||
112 | |||
113 | #define EXPLODEDP(v,vc,vs,ve,vm) \ | ||
114 | {\ | ||
115 | vm = DPMANT(v);\ | ||
116 | vs = DPSIGN(v);\ | ||
117 | ve = DPBEXP(v);\ | ||
118 | if(ve == DP_EMAX+1+DP_EBIAS){\ | ||
119 | if(vm == 0)\ | ||
120 | vc = IEEE754_CLASS_INF;\ | ||
121 | else if(vm & DP_MBIT(DP_MBITS-1)) \ | ||
122 | vc = IEEE754_CLASS_SNAN;\ | ||
123 | else \ | ||
124 | vc = IEEE754_CLASS_QNAN;\ | ||
125 | } else if(ve == DP_EMIN-1+DP_EBIAS) {\ | ||
126 | if(vm) {\ | ||
127 | ve = DP_EMIN;\ | ||
128 | vc = IEEE754_CLASS_DNORM;\ | ||
129 | } else\ | ||
130 | vc = IEEE754_CLASS_ZERO;\ | ||
131 | } else {\ | ||
132 | ve -= DP_EBIAS;\ | ||
133 | vm |= DP_HIDDEN_BIT;\ | ||
134 | vc = IEEE754_CLASS_NORM;\ | ||
135 | }\ | ||
136 | } | ||
137 | #define EXPLODEXDP EXPLODEDP(x,xc,xs,xe,xm) | ||
138 | #define EXPLODEYDP EXPLODEDP(y,yc,ys,ye,ym) | ||
139 | |||
140 | #define FLUSHDP(v,vc,vs,ve,vm) \ | ||
141 | if(vc==IEEE754_CLASS_DNORM) {\ | ||
142 | if(ieee754_csr.nod) {\ | ||
143 | SETCX(IEEE754_INEXACT);\ | ||
144 | vc = IEEE754_CLASS_ZERO;\ | ||
145 | ve = DP_EMIN-1+DP_EBIAS;\ | ||
146 | vm = 0;\ | ||
147 | v = ieee754dp_zero(vs);\ | ||
148 | }\ | ||
149 | } | ||
150 | |||
151 | #define FLUSHSP(v,vc,vs,ve,vm) \ | ||
152 | if(vc==IEEE754_CLASS_DNORM) {\ | ||
153 | if(ieee754_csr.nod) {\ | ||
154 | SETCX(IEEE754_INEXACT);\ | ||
155 | vc = IEEE754_CLASS_ZERO;\ | ||
156 | ve = SP_EMIN-1+SP_EBIAS;\ | ||
157 | vm = 0;\ | ||
158 | v = ieee754sp_zero(vs);\ | ||
159 | }\ | ||
160 | } | ||
161 | |||
162 | #define FLUSHXDP FLUSHDP(x,xc,xs,xe,xm) | ||
163 | #define FLUSHYDP FLUSHDP(y,yc,ys,ye,ym) | ||
164 | #define FLUSHXSP FLUSHSP(x,xc,xs,xe,xm) | ||
165 | #define FLUSHYSP FLUSHSP(y,yc,ys,ye,ym) | ||