aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/math-emu/sp_add.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/math-emu/sp_add.c')
-rw-r--r--arch/mips/math-emu/sp_add.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/arch/mips/math-emu/sp_add.c b/arch/mips/math-emu/sp_add.c
index db4d89beada6..a0bc95cea1cc 100644
--- a/arch/mips/math-emu/sp_add.c
+++ b/arch/mips/math-emu/sp_add.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,15 @@
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
29union ieee754sp ieee754sp_add(union ieee754sp x, union ieee754sp y) 24union ieee754sp ieee754sp_add(union ieee754sp x, union ieee754sp y)
30{ 25{
26 int s;
27
31 COMPXSP; 28 COMPXSP;
32 COMPYSP; 29 COMPYSP;
33 30
@@ -68,9 +65,9 @@ union ieee754sp ieee754sp_add(union ieee754sp x, union 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;
@@ -87,15 +84,14 @@ union ieee754sp ieee754sp_add(union ieee754sp x, union 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 == IEEE754_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):
@@ -108,6 +104,8 @@ union ieee754sp ieee754sp_add(union ieee754sp x, union ieee754sp y)
108 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM): 104 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
109 SPDNORMX; 105 SPDNORMX;
110 106
107 /* FALL THROUGH */
108
111 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM): 109 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
112 SPDNORMY; 110 SPDNORMY;
113 break; 111 break;
@@ -122,27 +120,32 @@ union ieee754sp ieee754sp_add(union ieee754sp x, union ieee754sp y)
122 assert(xm & SP_HIDDEN_BIT); 120 assert(xm & SP_HIDDEN_BIT);
123 assert(ym & SP_HIDDEN_BIT); 121 assert(ym & SP_HIDDEN_BIT);
124 122
125 /* provide guard,round and stick bit space */ 123 /*
124 * Provide guard, round and stick bit space.
125 */
126 xm <<= 3; 126 xm <<= 3;
127 ym <<= 3; 127 ym <<= 3;
128 128
129 if (xe > ye) { 129 if (xe > ye) {
130 /* have to shift y fraction right to align 130 /*
131 * Have to shift y fraction right to align.
131 */ 132 */
132 int s = xe - ye; 133 s = xe - ye;
133 SPXSRSYn(s); 134 SPXSRSYn(s);
134 } else if (ye > xe) { 135 } else if (ye > xe) {
135 /* have to shift x fraction right to align 136 /*
137 * Have to shift x fraction right to align.
136 */ 138 */
137 int s = ye - xe; 139 s = ye - xe;
138 SPXSRSXn(s); 140 SPXSRSXn(s);
139 } 141 }
140 assert(xe == ye); 142 assert(xe == ye);
141 assert(xe <= SP_EMAX); 143 assert(xe <= SP_EMAX);
142 144
143 if (xs == ys) { 145 if (xs == ys) {
144 /* generate 28 bit result of adding two 27 bit numbers 146 /*
145 * leaving result in xm,xs,xe 147 * Generate 28 bit result of adding two 27 bit numbers
148 * leaving result in xm, xs and xe.
146 */ 149 */
147 xm = xm + ym; 150 xm = xm + ym;
148 xe = xe; 151 xe = xe;
@@ -162,15 +165,15 @@ union ieee754sp ieee754sp_add(union ieee754sp x, union ieee754sp y)
162 xs = ys; 165 xs = ys;
163 } 166 }
164 if (xm == 0) 167 if (xm == 0)
165 return ieee754sp_zero(ieee754_csr.rm == 168 return ieee754sp_zero(ieee754_csr.rm == IEEE754_RD);
166 IEEE754_RD);
167 169
168 /* normalize in extended single precision */ 170 /*
171 * Normalize in extended single precision
172 */
169 while ((xm >> (SP_FBITS + 3)) == 0) { 173 while ((xm >> (SP_FBITS + 3)) == 0) {
170 xm <<= 1; 174 xm <<= 1;
171 xe--; 175 xe--;
172 } 176 }
173
174 } 177 }
175 178
176 return ieee754sp_format(xs, xe, xm); 179 return ieee754sp_format(xs, xe, xm);