diff options
Diffstat (limited to 'arch/mips/math-emu/dp_div.c')
-rw-r--r-- | arch/mips/math-emu/dp_div.c | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/arch/mips/math-emu/dp_div.c b/arch/mips/math-emu/dp_div.c index 377e11470e3f..bef0e55e5938 100644 --- a/arch/mips/math-emu/dp_div.c +++ b/arch/mips/math-emu/dp_div.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,16 +16,17 @@ | |||
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 "ieee754dp.h" | 22 | #include "ieee754dp.h" |
28 | 23 | ||
29 | union ieee754dp ieee754dp_div(union ieee754dp x, union ieee754dp y) | 24 | union ieee754dp ieee754dp_div(union ieee754dp x, union ieee754dp y) |
30 | { | 25 | { |
26 | u64 rm; | ||
27 | int re; | ||
28 | u64 bm; | ||
29 | |||
31 | COMPXDP; | 30 | COMPXDP; |
32 | COMPYDP; | 31 | COMPYDP; |
33 | 32 | ||
@@ -68,9 +67,9 @@ union ieee754dp ieee754dp_div(union ieee754dp x, union ieee754dp y) | |||
68 | return x; | 67 | return x; |
69 | 68 | ||
70 | 69 | ||
71 | /* Infinity handling | 70 | /* |
72 | */ | 71 | * Infinity handling |
73 | 72 | */ | |
74 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF): | 73 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF): |
75 | ieee754_setcx(IEEE754_INVALID_OPERATION); | 74 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
76 | return ieee754dp_indef(); | 75 | return ieee754dp_indef(); |
@@ -85,9 +84,9 @@ union ieee754dp ieee754dp_div(union ieee754dp x, union ieee754dp y) | |||
85 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM): | 84 | case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM): |
86 | return ieee754dp_inf(xs ^ ys); | 85 | return ieee754dp_inf(xs ^ ys); |
87 | 86 | ||
88 | /* Zero handling | 87 | /* |
89 | */ | 88 | * Zero handling |
90 | 89 | */ | |
91 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO): | 90 | case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO): |
92 | ieee754_setcx(IEEE754_INVALID_OPERATION); | 91 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
93 | return ieee754dp_indef(); | 92 | return ieee754dp_indef(); |
@@ -122,35 +121,34 @@ union ieee754dp ieee754dp_div(union ieee754dp x, union ieee754dp y) | |||
122 | xm <<= 3; | 121 | xm <<= 3; |
123 | ym <<= 3; | 122 | ym <<= 3; |
124 | 123 | ||
125 | { | 124 | /* now the dirty work */ |
126 | /* now the dirty work */ | ||
127 | |||
128 | u64 rm = 0; | ||
129 | int re = xe - ye; | ||
130 | u64 bm; | ||
131 | |||
132 | for (bm = DP_MBIT(DP_FBITS + 2); bm; bm >>= 1) { | ||
133 | if (xm >= ym) { | ||
134 | xm -= ym; | ||
135 | rm |= bm; | ||
136 | if (xm == 0) | ||
137 | break; | ||
138 | } | ||
139 | xm <<= 1; | ||
140 | } | ||
141 | rm <<= 1; | ||
142 | if (xm) | ||
143 | rm |= 1; /* have remainder, set sticky */ | ||
144 | 125 | ||
145 | assert(rm); | 126 | rm = 0; |
127 | re = xe - ye; | ||
146 | 128 | ||
147 | /* normalise rm to rounding precision ? | 129 | for (bm = DP_MBIT(DP_FBITS + 2); bm; bm >>= 1) { |
148 | */ | 130 | if (xm >= ym) { |
149 | while ((rm >> (DP_FBITS + 3)) == 0) { | 131 | xm -= ym; |
150 | rm <<= 1; | 132 | rm |= bm; |
151 | re--; | 133 | if (xm == 0) |
134 | break; | ||
152 | } | 135 | } |
136 | xm <<= 1; | ||
137 | } | ||
138 | |||
139 | rm <<= 1; | ||
140 | if (xm) | ||
141 | rm |= 1; /* have remainder, set sticky */ | ||
153 | 142 | ||
154 | return ieee754dp_format(xs == ys ? 0 : 1, re, rm); | 143 | assert(rm); |
144 | |||
145 | /* | ||
146 | * Normalise rm to rounding precision ? | ||
147 | */ | ||
148 | while ((rm >> (DP_FBITS + 3)) == 0) { | ||
149 | rm <<= 1; | ||
150 | re--; | ||
155 | } | 151 | } |
152 | |||
153 | return ieee754dp_format(xs == ys ? 0 : 1, re, rm); | ||
156 | } | 154 | } |