2019-06-04 16:10:48 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-08-13 15:56:31 +08:00
|
|
|
/*
|
|
|
|
* IEEE754 floating point arithmetic
|
|
|
|
* single precision: MADDF.f (Fused Multiply Add)
|
|
|
|
* MADDF.fmt: FPR[fd] = FPR[fd] + (FPR[fs] x FPR[ft])
|
|
|
|
*
|
|
|
|
* MIPS floating point support
|
|
|
|
* Copyright (C) 2015 Imagination Technologies, Ltd.
|
|
|
|
* Author: Markos Chandras <markos.chandras@imgtec.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ieee754sp.h"
|
|
|
|
|
2016-04-21 21:04:49 +08:00
|
|
|
|
|
|
|
static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
|
|
|
|
union ieee754sp y, enum maddf_flags flags)
|
2015-08-13 15:56:31 +08:00
|
|
|
{
|
|
|
|
int re;
|
|
|
|
int rs;
|
2017-11-02 19:13:59 +08:00
|
|
|
unsigned int rm;
|
|
|
|
u64 rm64;
|
|
|
|
u64 zm64;
|
2015-08-13 15:56:31 +08:00
|
|
|
int s;
|
|
|
|
|
|
|
|
COMPXSP;
|
|
|
|
COMPYSP;
|
2016-04-21 21:04:51 +08:00
|
|
|
COMPZSP;
|
2015-08-13 15:56:31 +08:00
|
|
|
|
|
|
|
EXPLODEXSP;
|
|
|
|
EXPLODEYSP;
|
2016-04-21 21:04:51 +08:00
|
|
|
EXPLODEZSP;
|
2015-08-13 15:56:31 +08:00
|
|
|
|
|
|
|
FLUSHXSP;
|
|
|
|
FLUSHYSP;
|
2016-04-21 21:04:51 +08:00
|
|
|
FLUSHZSP;
|
2015-08-13 15:56:31 +08:00
|
|
|
|
|
|
|
ieee754_clearcx();
|
|
|
|
|
2020-01-13 18:16:11 +08:00
|
|
|
rs = xs ^ ys;
|
|
|
|
if (flags & MADDF_NEGATE_PRODUCT)
|
|
|
|
rs ^= 1;
|
|
|
|
if (flags & MADDF_NEGATE_ADDITION)
|
|
|
|
zs ^= 1;
|
|
|
|
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
/*
|
|
|
|
* Handle the cases when at least one of x, y or z is a NaN.
|
|
|
|
* Order of precedence is sNaN, qNaN and z, x, y.
|
|
|
|
*/
|
|
|
|
if (zc == IEEE754_CLASS_SNAN)
|
2015-08-13 15:56:31 +08:00
|
|
|
return ieee754sp_nanxcpt(z);
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
if (xc == IEEE754_CLASS_SNAN)
|
|
|
|
return ieee754sp_nanxcpt(x);
|
|
|
|
if (yc == IEEE754_CLASS_SNAN)
|
2015-08-13 15:56:31 +08:00
|
|
|
return ieee754sp_nanxcpt(y);
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
if (zc == IEEE754_CLASS_QNAN)
|
|
|
|
return z;
|
|
|
|
if (xc == IEEE754_CLASS_QNAN)
|
|
|
|
return x;
|
|
|
|
if (yc == IEEE754_CLASS_QNAN)
|
|
|
|
return y;
|
2015-08-13 15:56:31 +08:00
|
|
|
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
if (zc == IEEE754_CLASS_DNORM)
|
|
|
|
SPDNORMZ;
|
|
|
|
/* ZERO z cases are handled separately below */
|
2015-08-13 15:56:31 +08:00
|
|
|
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
switch (CLPAIR(xc, yc)) {
|
2015-08-13 15:56:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Infinity handling
|
|
|
|
*/
|
|
|
|
case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
|
|
|
|
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
|
|
|
|
ieee754_setcx(IEEE754_INVALID_OPERATION);
|
|
|
|
return ieee754sp_indef();
|
|
|
|
|
|
|
|
case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
|
|
|
|
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
|
|
|
|
case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
|
|
|
|
case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
|
|
|
|
case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
|
2020-01-13 18:16:11 +08:00
|
|
|
if ((zc == IEEE754_CLASS_INF) && (zs != rs)) {
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix some cases of infinite inputs
Fix the cases of <MADDF|MSUBF>.<D|S> when any of two multiplicands is
infinity. The correct behavior in such cases is affected by the nature
of third input. Cases of addition of infinities with opposite signs
and subtraction of infinities with same signs may arise and must be
handles separately. Also, the value od flags argument (that determines
whether the instruction is MADDF or MSUBF) affects the outcome.
Relevant examples:
MADDF.S fd,fs,ft:
If fs contains +inf, ft contains +inf, and fd contains -inf, fd is
going to contain indef (without this patch, it used to contain
-inf).
MSUBF.S fd,fs,ft:
If fs contains +inf, ft contains 1.0, and fd contains +0.0, fd is
going to contain -inf (without this patch, it used to contain +inf).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Douglas Leung <douglas.leung@imgtec.com>
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16887/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:55 +08:00
|
|
|
/*
|
|
|
|
* Cases of addition of infinities with opposite signs
|
|
|
|
* or subtraction of infinities with same signs.
|
|
|
|
*/
|
|
|
|
ieee754_setcx(IEEE754_INVALID_OPERATION);
|
|
|
|
return ieee754sp_indef();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* z is here either not an infinity, or an infinity having the
|
2020-01-13 18:16:11 +08:00
|
|
|
* same sign as product (x*y). The result must be an infinity,
|
|
|
|
* and its sign is determined only by the sign of product (x*y).
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix some cases of infinite inputs
Fix the cases of <MADDF|MSUBF>.<D|S> when any of two multiplicands is
infinity. The correct behavior in such cases is affected by the nature
of third input. Cases of addition of infinities with opposite signs
and subtraction of infinities with same signs may arise and must be
handles separately. Also, the value od flags argument (that determines
whether the instruction is MADDF or MSUBF) affects the outcome.
Relevant examples:
MADDF.S fd,fs,ft:
If fs contains +inf, ft contains +inf, and fd contains -inf, fd is
going to contain indef (without this patch, it used to contain
-inf).
MSUBF.S fd,fs,ft:
If fs contains +inf, ft contains 1.0, and fd contains +0.0, fd is
going to contain -inf (without this patch, it used to contain +inf).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Douglas Leung <douglas.leung@imgtec.com>
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16887/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:55 +08:00
|
|
|
*/
|
2020-01-13 18:16:11 +08:00
|
|
|
return ieee754sp_inf(rs);
|
2015-08-13 15:56:31 +08:00
|
|
|
|
|
|
|
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
|
|
|
|
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
|
|
|
|
case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
|
|
|
|
case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
|
|
|
|
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
|
|
|
|
if (zc == IEEE754_CLASS_INF)
|
|
|
|
return ieee754sp_inf(zs);
|
2017-07-28 00:08:56 +08:00
|
|
|
if (zc == IEEE754_CLASS_ZERO) {
|
|
|
|
/* Handle cases +0 + (-0) and similar ones. */
|
2020-01-13 18:16:11 +08:00
|
|
|
if (zs == rs)
|
2017-07-28 00:08:56 +08:00
|
|
|
/*
|
|
|
|
* Cases of addition of zeros of equal signs
|
|
|
|
* or subtraction of zeroes of opposite signs.
|
|
|
|
* The sign of the resulting zero is in any
|
|
|
|
* such case determined only by the sign of z.
|
|
|
|
*/
|
|
|
|
return z;
|
|
|
|
|
|
|
|
return ieee754sp_zero(ieee754_csr.rm == FPU_CSR_RD);
|
|
|
|
}
|
|
|
|
/* x*y is here 0, and z is not 0, so just return z */
|
2015-08-13 15:56:31 +08:00
|
|
|
return z;
|
|
|
|
|
|
|
|
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
|
|
|
|
SPDNORMX;
|
2020-05-04 16:51:29 +08:00
|
|
|
fallthrough;
|
2015-08-13 15:56:31 +08:00
|
|
|
case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
if (zc == IEEE754_CLASS_INF)
|
2015-08-13 15:56:31 +08:00
|
|
|
return ieee754sp_inf(zs);
|
|
|
|
SPDNORMY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
if (zc == IEEE754_CLASS_INF)
|
2015-08-13 15:56:31 +08:00
|
|
|
return ieee754sp_inf(zs);
|
|
|
|
SPDNORMX;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
|
MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
Fix the cases of <MADDF|MSUBF>.<D|S> when any of three inputs is any
NaN. Correct behavior of <MADDF|MSUBF>.<D|S> fd, fs, ft is following:
- if any of inputs is sNaN, return a sNaN using following rules: if
only one input is sNaN, return that one; if more than one input is
sNaN, order of precedence for return value is fd, fs, ft
- if no input is sNaN, but at least one of inputs is qNaN, return a
qNaN using following rules: if only one input is qNaN, return that
one; if more than one input is qNaN, order of precedence for
return value is fd, fs, ft
The previous code contained correct handling of some above cases, but
not all. Also, such handling was scattered into various cases of
"switch (CLPAIR(xc, yc))" statement, and elsewhere. With this patch,
this logic is placed in one place, and "switch (CLPAIR(xc, yc))" is
significantly simplified.
A relevant example:
MADDF.S fd,fs,ft:
If fs contains qNaN1, ft contains qNaN2, and fd contains qNaN3, fd
is going to contain qNaN3 (without this patch, it used to contain
qNaN1).
Fixes: e24c3bec3e8e ("MIPS: math-emu: Add support for the MIPS R6 MADDF FPU instruction")
Fixes: 83d43305a1df ("MIPS: math-emu: Add support for the MIPS R6 MSUBF FPU instruction")
Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Bo Hu <bohu@google.com>
Cc: Douglas Leung <douglas.leung@imgtec.com>
Cc: Jin Qian <jinqian@google.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
Cc: Raghu Gandham <raghu.gandham@imgtec.com>
Cc: <stable@vger.kernel.org> # 4.7+
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16886/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-07-28 00:08:54 +08:00
|
|
|
if (zc == IEEE754_CLASS_INF)
|
2015-08-13 15:56:31 +08:00
|
|
|
return ieee754sp_inf(zs);
|
MIPS: math-emu: Mark fall throughs in switch statements with a comment
Mark intentional fall throughs in switch statements with a consistent
comment.
In most of the cases, a new comment line containing text "fall through"
is inserted. In some of the cases, existing comment contained a variation
of the text "fall through" (for example, "FALL THROUGH" or "drop through").
In such cases, the existing comment is modified to contain "fall through".
Lastly, in two cases, code segments were described in comments as "fall
througs", but were in reality "breaks out" of switch statement. In such
cases, existing comments are accordingly modified.
Apart from making code easier to follow and debug, this change enables
some static code analysers to interpret newly inserted comments as their
annotations (and, therefore, not issue warnings of type "fall through in
switch statement", which is desireable, since marked fallthroughs are
intentional).
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@mips.com>
Cc: Douglas Leung <douglas.leung@mips.com>
Cc: Goran Ferenc <goran.ferenc@mips.com>
Cc: James Hogan <james.hogan@mips.com>
Cc: Maciej W. Rozycki <macro@mips.com>
Cc: Manuel Lauss <manuel.lauss@gmail.com>
Cc: Miodrag Dinic <miodrag.dinic@mips.com>
Cc: Paul Burton <paul.burton@mips.com>
Cc: Petar Jovanovic <petar.jovanovic@mips.com>
Cc: Raghu Gandham <raghu.gandham@mips.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/17588/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-11-02 19:14:05 +08:00
|
|
|
/* continue to real computations */
|
2015-08-13 15:56:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally get to do some computation */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the multiplication bit first
|
|
|
|
*
|
|
|
|
* rm = xm * ym, re = xe + ye basically
|
|
|
|
*
|
|
|
|
* At this point xm and ym should have been normalized.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* rm = xm * ym, re = xe+ye basically */
|
|
|
|
assert(xm & SP_HIDDEN_BIT);
|
|
|
|
assert(ym & SP_HIDDEN_BIT);
|
|
|
|
|
|
|
|
re = xe + ye;
|
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
/* Multiple 24 bit xm and ym to give 48 bit results */
|
|
|
|
rm64 = (uint64_t)xm * ym;
|
2015-08-13 15:56:31 +08:00
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
/* Shunt to top of word */
|
|
|
|
rm64 = rm64 << 16;
|
2015-08-13 15:56:31 +08:00
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
/* Put explicit bit at bit 62 if necessary */
|
|
|
|
if ((int64_t) rm64 < 0) {
|
|
|
|
rm64 = rm64 >> 1;
|
2015-08-13 15:56:31 +08:00
|
|
|
re++;
|
|
|
|
}
|
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
assert(rm64 & (1 << 62));
|
2015-08-13 15:56:31 +08:00
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
if (zc == IEEE754_CLASS_ZERO) {
|
|
|
|
/*
|
|
|
|
* Move explicit bit from bit 62 to bit 26 since the
|
|
|
|
* ieee754sp_format code expects the mantissa to be
|
|
|
|
* 27 bits wide (24 + 3 rounding bits).
|
|
|
|
*/
|
|
|
|
rm = XSPSRS64(rm64, (62 - 26));
|
|
|
|
return ieee754sp_format(rs, re, rm);
|
|
|
|
}
|
2015-08-13 15:56:31 +08:00
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
/* Move explicit bit from bit 23 to bit 62 */
|
|
|
|
zm64 = (uint64_t)zm << (62 - 23);
|
|
|
|
assert(zm64 & (1 << 62));
|
2015-08-13 15:56:31 +08:00
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
/* Make the exponents the same */
|
2015-08-13 15:56:31 +08:00
|
|
|
if (ze > re) {
|
|
|
|
/*
|
2016-04-21 21:04:54 +08:00
|
|
|
* Have to shift r fraction right to align.
|
2015-08-13 15:56:31 +08:00
|
|
|
*/
|
|
|
|
s = ze - re;
|
2017-07-28 00:08:58 +08:00
|
|
|
rm64 = XSPSRS64(rm64, s);
|
2016-04-21 21:04:54 +08:00
|
|
|
re += s;
|
2015-08-13 15:56:31 +08:00
|
|
|
} else if (re > ze) {
|
|
|
|
/*
|
2016-04-21 21:04:54 +08:00
|
|
|
* Have to shift z fraction right to align.
|
2015-08-13 15:56:31 +08:00
|
|
|
*/
|
|
|
|
s = re - ze;
|
2017-07-28 00:08:58 +08:00
|
|
|
zm64 = XSPSRS64(zm64, s);
|
2016-04-21 21:04:54 +08:00
|
|
|
ze += s;
|
2015-08-13 15:56:31 +08:00
|
|
|
}
|
|
|
|
assert(ze == re);
|
|
|
|
assert(ze <= SP_EMAX);
|
|
|
|
|
2017-07-28 00:08:58 +08:00
|
|
|
/* Do the addition */
|
2015-08-13 15:56:31 +08:00
|
|
|
if (zs == rs) {
|
|
|
|
/*
|
2017-07-28 00:08:58 +08:00
|
|
|
* Generate 64 bit result by adding two 63 bit numbers
|
|
|
|
* leaving result in zm64, zs and ze.
|
2015-08-13 15:56:31 +08:00
|
|
|
*/
|
2017-07-28 00:08:58 +08:00
|
|
|
zm64 = zm64 + rm64;
|
|
|
|
if ((int64_t)zm64 < 0) { /* carry out */
|
|
|
|
zm64 = XSPSRS1(zm64);
|
2016-04-21 21:04:54 +08:00
|
|
|
ze++;
|
2015-08-13 15:56:31 +08:00
|
|
|
}
|
|
|
|
} else {
|
2017-07-28 00:08:58 +08:00
|
|
|
if (zm64 >= rm64) {
|
|
|
|
zm64 = zm64 - rm64;
|
2015-08-13 15:56:31 +08:00
|
|
|
} else {
|
2017-07-28 00:08:58 +08:00
|
|
|
zm64 = rm64 - zm64;
|
2015-08-13 15:56:31 +08:00
|
|
|
zs = rs;
|
|
|
|
}
|
2017-07-28 00:08:58 +08:00
|
|
|
if (zm64 == 0)
|
2015-08-13 15:56:31 +08:00
|
|
|
return ieee754sp_zero(ieee754_csr.rm == FPU_CSR_RD);
|
|
|
|
|
|
|
|
/*
|
2017-07-28 00:08:58 +08:00
|
|
|
* Put explicit bit at bit 62 if necessary.
|
2015-08-13 15:56:31 +08:00
|
|
|
*/
|
2017-07-28 00:08:58 +08:00
|
|
|
while ((zm64 >> 62) == 0) {
|
|
|
|
zm64 <<= 1;
|
2015-08-13 15:56:31 +08:00
|
|
|
ze--;
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 00:08:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Move explicit bit from bit 62 to bit 26 since the
|
|
|
|
* ieee754sp_format code expects the mantissa to be
|
|
|
|
* 27 bits wide (24 + 3 rounding bits).
|
|
|
|
*/
|
|
|
|
zm = XSPSRS64(zm64, (62 - 26));
|
|
|
|
|
2015-08-13 15:56:31 +08:00
|
|
|
return ieee754sp_format(zs, ze, zm);
|
|
|
|
}
|
2016-04-21 21:04:49 +08:00
|
|
|
|
|
|
|
union ieee754sp ieee754sp_maddf(union ieee754sp z, union ieee754sp x,
|
|
|
|
union ieee754sp y)
|
|
|
|
{
|
|
|
|
return _sp_maddf(z, x, y, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
union ieee754sp ieee754sp_msubf(union ieee754sp z, union ieee754sp x,
|
|
|
|
union ieee754sp y)
|
|
|
|
{
|
2017-07-28 00:08:57 +08:00
|
|
|
return _sp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
|
2016-04-21 21:04:49 +08:00
|
|
|
}
|
2020-01-13 18:16:11 +08:00
|
|
|
|
|
|
|
union ieee754sp ieee754sp_madd(union ieee754sp z, union ieee754sp x,
|
|
|
|
union ieee754sp y)
|
|
|
|
{
|
|
|
|
return _sp_maddf(z, x, y, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
union ieee754sp ieee754sp_msub(union ieee754sp z, union ieee754sp x,
|
|
|
|
union ieee754sp y)
|
|
|
|
{
|
|
|
|
return _sp_maddf(z, x, y, MADDF_NEGATE_ADDITION);
|
|
|
|
}
|
|
|
|
|
|
|
|
union ieee754sp ieee754sp_nmadd(union ieee754sp z, union ieee754sp x,
|
|
|
|
union ieee754sp y)
|
|
|
|
{
|
|
|
|
return _sp_maddf(z, x, y, MADDF_NEGATE_PRODUCT|MADDF_NEGATE_ADDITION);
|
|
|
|
}
|
|
|
|
|
|
|
|
union ieee754sp ieee754sp_nmsub(union ieee754sp z, union ieee754sp x,
|
|
|
|
union ieee754sp y)
|
|
|
|
{
|
|
|
|
return _sp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
|
|
|
|
}
|