diff options
Diffstat (limited to 'arch/mips/math-emu/sp_sub.c')
-rw-r--r-- | arch/mips/math-emu/sp_sub.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/arch/mips/math-emu/sp_sub.c b/arch/mips/math-emu/sp_sub.c index e595c6f3d0bb..8592e49032b8 100644 --- a/arch/mips/math-emu/sp_sub.c +++ b/arch/mips/math-emu/sp_sub.c | |||
@@ -5,8 +5,6 @@ | |||
5 | * MIPS floating point support | 5 | * MIPS floating point support |
6 | * Copyright (C) 1994-2000 Algorithmics Ltd. | 6 | * Copyright (C) 1994-2000 Algorithmics Ltd. |
7 | * | 7 | * |
8 | * ######################################################################## | ||
9 | * | ||
10 | * This program is free software; you can distribute it and/or modify it | 8 | * This program is free software; you can distribute it and/or modify it |
11 | * under the terms of the GNU General Public License (Version 2) as | 9 | * under the terms of the GNU General Public License (Version 2) as |
12 | * published by the Free Software Foundation. | 10 | * published by the Free Software Foundation. |
@@ -18,23 +16,22 @@ | |||
18 | * | 16 | * |
19 | * You should have received a copy of the GNU General Public License along | 17 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | 19 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
22 | * | ||
23 | * ######################################################################## | ||
24 | */ | 20 | */ |
25 | 21 | ||
26 | |||
27 | #include "ieee754sp.h" | 22 | #include "ieee754sp.h" |
28 | 23 | ||
29 | ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | 24 | union ieee754sp ieee754sp_sub(union ieee754sp x, union ieee754sp y) |
30 | { | 25 | { |
26 | int s; | ||
27 | |||
31 | COMPXSP; | 28 | COMPXSP; |
32 | COMPYSP; | 29 | COMPYSP; |
33 | 30 | ||
34 | EXPLODEXSP; | 31 | EXPLODEXSP; |
35 | EXPLODEYSP; | 32 | EXPLODEYSP; |
36 | 33 | ||
37 | CLEARCX; | 34 | ieee754_clearcx(); |
38 | 35 | ||
39 | FLUSHXSP; | 36 | FLUSHXSP; |
40 | FLUSHYSP; | 37 | FLUSHYSP; |
@@ -51,8 +48,8 @@ ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | |||
51 | case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM): | 48 | case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM): |
52 | case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM): | 49 | case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM): |
53 | case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF): | 50 | case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF): |
54 | SETCX(IEEE754_INVALID_OPERATION); | 51 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
55 | return ieee754sp_nanxcpt(ieee754sp_indef(), "sub", x, y); | 52 | return ieee754sp_nanxcpt(ieee754sp_indef()); |
56 | 53 | ||
57 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN): | 54 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN): |
58 | case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN): | 55 | case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN): |
@@ -68,14 +65,14 @@ ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | |||
68 | return x; | 65 | return x; |
69 | 66 | ||
70 | 67 | ||
71 | /* Infinity handling | 68 | /* |
72 | */ | 69 | * Infinity handling |
73 | 70 | */ | |
74 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF): | 71 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF): |
75 | if (xs != ys) | 72 | if (xs != ys) |
76 | return x; | 73 | return x; |
77 | SETCX(IEEE754_INVALID_OPERATION); | 74 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
78 | return ieee754sp_xcpt(ieee754sp_indef(), "sub", x, y); | 75 | return ieee754sp_indef(); |
79 | 76 | ||
80 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF): | 77 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF): |
81 | case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF): | 78 | case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF): |
@@ -87,15 +84,14 @@ ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | |||
87 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM): | 84 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM): |
88 | return x; | 85 | return x; |
89 | 86 | ||
90 | /* Zero handling | 87 | /* |
91 | */ | 88 | * Zero handling |
92 | 89 | */ | |
93 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO): | 90 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO): |
94 | if (xs != ys) | 91 | if (xs != ys) |
95 | return x; | 92 | return x; |
96 | else | 93 | else |
97 | return ieee754sp_zero(ieee754_csr.rm == | 94 | return ieee754sp_zero(ieee754_csr.rm == FPU_CSR_RD); |
98 | IEEE754_RD); | ||
99 | 95 | ||
100 | case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO): | 96 | case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO): |
101 | case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO): | 97 | case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO): |
@@ -104,7 +100,7 @@ ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | |||
104 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM): | 100 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM): |
105 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM): | 101 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM): |
106 | /* quick fix up */ | 102 | /* quick fix up */ |
107 | DPSIGN(y) ^= 1; | 103 | SPSIGN(y) ^= 1; |
108 | return y; | 104 | return y; |
109 | 105 | ||
110 | case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM): | 106 | case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM): |
@@ -133,14 +129,16 @@ ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | |||
133 | ym <<= 3; | 129 | ym <<= 3; |
134 | 130 | ||
135 | if (xe > ye) { | 131 | if (xe > ye) { |
136 | /* have to shift y fraction right to align | 132 | /* |
133 | * have to shift y fraction right to align | ||
137 | */ | 134 | */ |
138 | int s = xe - ye; | 135 | s = xe - ye; |
139 | SPXSRSYn(s); | 136 | SPXSRSYn(s); |
140 | } else if (ye > xe) { | 137 | } else if (ye > xe) { |
141 | /* have to shift x fraction right to align | 138 | /* |
139 | * have to shift x fraction right to align | ||
142 | */ | 140 | */ |
143 | int s = ye - xe; | 141 | s = ye - xe; |
144 | SPXSRSXn(s); | 142 | SPXSRSXn(s); |
145 | } | 143 | } |
146 | assert(xe == ye); | 144 | assert(xe == ye); |
@@ -153,7 +151,7 @@ ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | |||
153 | xe = xe; | 151 | xe = xe; |
154 | xs = xs; | 152 | xs = xs; |
155 | 153 | ||
156 | if (xm >> (SP_MBITS + 1 + 3)) { /* carry out */ | 154 | if (xm >> (SP_FBITS + 1 + 3)) { /* carry out */ |
157 | SPXSRSX1(); /* shift preserving sticky */ | 155 | SPXSRSX1(); /* shift preserving sticky */ |
158 | } | 156 | } |
159 | } else { | 157 | } else { |
@@ -167,17 +165,18 @@ ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y) | |||
167 | xs = ys; | 165 | xs = ys; |
168 | } | 166 | } |
169 | if (xm == 0) { | 167 | if (xm == 0) { |
170 | if (ieee754_csr.rm == IEEE754_RD) | 168 | if (ieee754_csr.rm == FPU_CSR_RD) |
171 | return ieee754sp_zero(1); /* round negative inf. => sign = -1 */ | 169 | return ieee754sp_zero(1); /* round negative inf. => sign = -1 */ |
172 | else | 170 | else |
173 | return ieee754sp_zero(0); /* other round modes => sign = 1 */ | 171 | return ieee754sp_zero(0); /* other round modes => sign = 1 */ |
174 | } | 172 | } |
175 | /* normalize to rounding precision | 173 | /* normalize to rounding precision |
176 | */ | 174 | */ |
177 | while ((xm >> (SP_MBITS + 3)) == 0) { | 175 | while ((xm >> (SP_FBITS + 3)) == 0) { |
178 | xm <<= 1; | 176 | xm <<= 1; |
179 | xe--; | 177 | xe--; |
180 | } | 178 | } |
181 | } | 179 | } |
182 | SPNORMRET2(xs, xe, xm, "sub", x, y); | 180 | |
181 | return ieee754sp_format(xs, xe, xm); | ||
183 | } | 182 | } |