Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * IEEE754 floating point | |
3 | * common internal header file | |
4 | */ | |
5 | /* | |
6 | * MIPS floating point support | |
7 | * Copyright (C) 1994-2000 Algorithmics Ltd. | |
1da177e4 | 8 | * |
1da177e4 LT |
9 | * This program is free software; you can distribute it and/or modify it |
10 | * under the terms of the GNU General Public License (Version 2) as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope it will be useful, but WITHOUT | |
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | * for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License along | |
19 | * with this program; if not, write to the Free Software Foundation, Inc., | |
3f7cac41 | 20 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1da177e4 | 21 | */ |
bee16535 RB |
22 | #ifndef __IEEE754INT_H |
23 | #define __IEEE754INT_H | |
1da177e4 LT |
24 | |
25 | #include "ieee754.h" | |
26 | ||
21a151d8 | 27 | #define CLPAIR(x, y) ((x)*6+(y)) |
1da177e4 | 28 | |
9e8bad1f RB |
29 | static inline void ieee754_clearcx(void) |
30 | { | |
31 | ieee754_csr.cx = 0; | |
32 | } | |
1da177e4 | 33 | |
9e8bad1f RB |
34 | static inline void ieee754_setcx(const unsigned int flags) |
35 | { | |
36 | ieee754_csr.cx |= flags; | |
37 | ieee754_csr.sx |= flags; | |
38 | } | |
1da177e4 | 39 | |
9e8bad1f RB |
40 | static inline int ieee754_setandtestcx(const unsigned int x) |
41 | { | |
42 | ieee754_setcx(x); | |
1da177e4 | 43 | |
9e8bad1f RB |
44 | return ieee754_csr.mx & x; |
45 | } | |
1da177e4 | 46 | |
c9a10845 MR |
47 | static inline int ieee754_class_nan(int xc) |
48 | { | |
49 | return xc >= IEEE754_CLASS_SNAN; | |
50 | } | |
51 | ||
1da177e4 | 52 | #define COMPXSP \ |
47fa0c02 | 53 | unsigned xm; int xe; int xs __maybe_unused; int xc |
1da177e4 LT |
54 | |
55 | #define COMPYSP \ | |
47fa0c02 RB |
56 | unsigned ym; int ye; int ys; int yc |
57 | ||
e2d11e1a PB |
58 | #define COMPZSP \ |
59 | unsigned zm; int ze; int zs; int zc | |
60 | ||
47fa0c02 RB |
61 | #define EXPLODESP(v, vc, vs, ve, vm) \ |
62 | { \ | |
63 | vs = SPSIGN(v); \ | |
64 | ve = SPBEXP(v); \ | |
65 | vm = SPMANT(v); \ | |
66 | if (ve == SP_EMAX+1+SP_EBIAS) { \ | |
67 | if (vm == 0) \ | |
68 | vc = IEEE754_CLASS_INF; \ | |
90d53a91 | 69 | else if (ieee754_csr.nan2008 ^ !(vm & SP_MBIT(SP_FBITS - 1))) \ |
16645743 | 70 | vc = IEEE754_CLASS_QNAN; \ |
90d53a91 MR |
71 | else \ |
72 | vc = IEEE754_CLASS_SNAN; \ | |
47fa0c02 RB |
73 | } else if (ve == SP_EMIN-1+SP_EBIAS) { \ |
74 | if (vm) { \ | |
75 | ve = SP_EMIN; \ | |
76 | vc = IEEE754_CLASS_DNORM; \ | |
77 | } else \ | |
78 | vc = IEEE754_CLASS_ZERO; \ | |
79 | } else { \ | |
80 | ve -= SP_EBIAS; \ | |
81 | vm |= SP_HIDDEN_BIT; \ | |
82 | vc = IEEE754_CLASS_NORM; \ | |
83 | } \ | |
1da177e4 | 84 | } |
21a151d8 RB |
85 | #define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm) |
86 | #define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym) | |
e2d11e1a | 87 | #define EXPLODEZSP EXPLODESP(z, zc, zs, ze, zm) |
1da177e4 LT |
88 | |
89 | ||
90 | #define COMPXDP \ | |
47fa0c02 | 91 | u64 xm; int xe; int xs __maybe_unused; int xc |
1da177e4 LT |
92 | |
93 | #define COMPYDP \ | |
47fa0c02 RB |
94 | u64 ym; int ye; int ys; int yc |
95 | ||
e2d11e1a PB |
96 | #define COMPZDP \ |
97 | u64 zm; int ze; int zs; int zc | |
98 | ||
47fa0c02 RB |
99 | #define EXPLODEDP(v, vc, vs, ve, vm) \ |
100 | { \ | |
101 | vm = DPMANT(v); \ | |
102 | vs = DPSIGN(v); \ | |
103 | ve = DPBEXP(v); \ | |
104 | if (ve == DP_EMAX+1+DP_EBIAS) { \ | |
105 | if (vm == 0) \ | |
106 | vc = IEEE754_CLASS_INF; \ | |
90d53a91 | 107 | else if (ieee754_csr.nan2008 ^ !(vm & DP_MBIT(DP_FBITS - 1))) \ |
47fa0c02 | 108 | vc = IEEE754_CLASS_QNAN; \ |
90d53a91 MR |
109 | else \ |
110 | vc = IEEE754_CLASS_SNAN; \ | |
47fa0c02 RB |
111 | } else if (ve == DP_EMIN-1+DP_EBIAS) { \ |
112 | if (vm) { \ | |
113 | ve = DP_EMIN; \ | |
114 | vc = IEEE754_CLASS_DNORM; \ | |
16645743 MC |
115 | } else \ |
116 | vc = IEEE754_CLASS_ZERO; \ | |
47fa0c02 RB |
117 | } else { \ |
118 | ve -= DP_EBIAS; \ | |
119 | vm |= DP_HIDDEN_BIT; \ | |
120 | vc = IEEE754_CLASS_NORM; \ | |
121 | } \ | |
1da177e4 | 122 | } |
21a151d8 RB |
123 | #define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm) |
124 | #define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym) | |
e2d11e1a | 125 | #define EXPLODEZDP EXPLODEDP(z, zc, zs, ze, zm) |
1da177e4 | 126 | |
47fa0c02 RB |
127 | #define FLUSHDP(v, vc, vs, ve, vm) \ |
128 | if (vc==IEEE754_CLASS_DNORM) { \ | |
129 | if (ieee754_csr.nod) { \ | |
9e8bad1f | 130 | ieee754_setcx(IEEE754_INEXACT); \ |
47fa0c02 RB |
131 | vc = IEEE754_CLASS_ZERO; \ |
132 | ve = DP_EMIN-1+DP_EBIAS; \ | |
133 | vm = 0; \ | |
134 | v = ieee754dp_zero(vs); \ | |
135 | } \ | |
1da177e4 LT |
136 | } |
137 | ||
47fa0c02 RB |
138 | #define FLUSHSP(v, vc, vs, ve, vm) \ |
139 | if (vc==IEEE754_CLASS_DNORM) { \ | |
140 | if (ieee754_csr.nod) { \ | |
9e8bad1f | 141 | ieee754_setcx(IEEE754_INEXACT); \ |
47fa0c02 RB |
142 | vc = IEEE754_CLASS_ZERO; \ |
143 | ve = SP_EMIN-1+SP_EBIAS; \ | |
144 | vm = 0; \ | |
145 | v = ieee754sp_zero(vs); \ | |
146 | } \ | |
1da177e4 LT |
147 | } |
148 | ||
21a151d8 RB |
149 | #define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm) |
150 | #define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym) | |
e2d11e1a | 151 | #define FLUSHZDP FLUSHDP(z, zc, zs, ze, zm) |
21a151d8 RB |
152 | #define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm) |
153 | #define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym) | |
e2d11e1a | 154 | #define FLUSHZSP FLUSHSP(z, zc, zs, ze, zm) |
bee16535 RB |
155 | |
156 | #endif /* __IEEE754INT_H */ |