hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/mips/math-emu/dp_maddf.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * IEEE754 floating point arithmetic
34 * double precision: MADDF.f (Fused Multiply Add)
....@@ -6,10 +7,6 @@
67 * MIPS floating point support
78 * Copyright (C) 2015 Imagination Technologies, Ltd.
89 * Author: Markos Chandras <markos.chandras@imgtec.com>
9
- *
10
- * This program is free software; you can distribute it and/or modify it
11
- * under the terms of the GNU General Public License as published by the
12
- * Free Software Foundation; version 2 of the License.
1310 */
1411
1512 #include "ieee754dp.h"
....@@ -71,6 +68,12 @@
7168
7269 ieee754_clearcx();
7370
71
+ rs = xs ^ ys;
72
+ if (flags & MADDF_NEGATE_PRODUCT)
73
+ rs ^= 1;
74
+ if (flags & MADDF_NEGATE_ADDITION)
75
+ zs ^= 1;
76
+
7477 /*
7578 * Handle the cases when at least one of x, y or z is a NaN.
7679 * Order of precedence is sNaN, qNaN and z, x, y.
....@@ -107,9 +110,7 @@
107110 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
108111 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
109112 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
110
- if ((zc == IEEE754_CLASS_INF) &&
111
- ((!(flags & MADDF_NEGATE_PRODUCT) && (zs != (xs ^ ys))) ||
112
- ((flags & MADDF_NEGATE_PRODUCT) && (zs == (xs ^ ys))))) {
113
+ if ((zc == IEEE754_CLASS_INF) && (zs != rs)) {
113114 /*
114115 * Cases of addition of infinities with opposite signs
115116 * or subtraction of infinities with same signs.
....@@ -119,15 +120,10 @@
119120 }
120121 /*
121122 * z is here either not an infinity, or an infinity having the
122
- * same sign as product (x*y) (in case of MADDF.D instruction)
123
- * or product -(x*y) (in MSUBF.D case). The result must be an
124
- * infinity, and its sign is determined only by the value of
125
- * (flags & MADDF_NEGATE_PRODUCT) and the signs of x and y.
123
+ * same sign as product (x*y). The result must be an infinity,
124
+ * and its sign is determined only by the sign of product (x*y).
126125 */
127
- if (flags & MADDF_NEGATE_PRODUCT)
128
- return ieee754dp_inf(1 ^ (xs ^ ys));
129
- else
130
- return ieee754dp_inf(xs ^ ys);
126
+ return ieee754dp_inf(rs);
131127
132128 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
133129 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
....@@ -138,10 +134,7 @@
138134 return ieee754dp_inf(zs);
139135 if (zc == IEEE754_CLASS_ZERO) {
140136 /* Handle cases +0 + (-0) and similar ones. */
141
- if ((!(flags & MADDF_NEGATE_PRODUCT)
142
- && (zs == (xs ^ ys))) ||
143
- ((flags & MADDF_NEGATE_PRODUCT)
144
- && (zs != (xs ^ ys))))
137
+ if (zs == rs)
145138 /*
146139 * Cases of addition of zeros of equal signs
147140 * or subtraction of zeroes of opposite signs.
....@@ -157,8 +150,7 @@
157150
158151 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
159152 DPDNORMX;
160
- /* fall through */
161
-
153
+ fallthrough;
162154 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
163155 if (zc == IEEE754_CLASS_INF)
164156 return ieee754dp_inf(zs);
....@@ -190,9 +182,6 @@
190182 assert(ym & DP_HIDDEN_BIT);
191183
192184 re = xe + ye;
193
- rs = xs ^ ys;
194
- if (flags & MADDF_NEGATE_PRODUCT)
195
- rs ^= 1;
196185
197186 /* shunt to top of word */
198187 xm <<= 64 - (DP_FBITS + 1);
....@@ -343,3 +332,27 @@
343332 {
344333 return _dp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
345334 }
335
+
336
+union ieee754dp ieee754dp_madd(union ieee754dp z, union ieee754dp x,
337
+ union ieee754dp y)
338
+{
339
+ return _dp_maddf(z, x, y, 0);
340
+}
341
+
342
+union ieee754dp ieee754dp_msub(union ieee754dp z, union ieee754dp x,
343
+ union ieee754dp y)
344
+{
345
+ return _dp_maddf(z, x, y, MADDF_NEGATE_ADDITION);
346
+}
347
+
348
+union ieee754dp ieee754dp_nmadd(union ieee754dp z, union ieee754dp x,
349
+ union ieee754dp y)
350
+{
351
+ return _dp_maddf(z, x, y, MADDF_NEGATE_PRODUCT|MADDF_NEGATE_ADDITION);
352
+}
353
+
354
+union ieee754dp ieee754dp_nmsub(union ieee754dp z, union ieee754dp x,
355
+ union ieee754dp y)
356
+{
357
+ return _dp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
358
+}