2005-04-17 05:20:36 +07:00
|
|
|
/* IEEE754 floating point arithmetic
|
|
|
|
* single precision
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* MIPS floating point support
|
|
|
|
* Copyright (C) 1994-2000 Algorithmics Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can distribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License (Version 2) as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2014-04-26 06:49:14 +07:00
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ieee754sp.h"
|
2014-04-22 21:33:07 +07:00
|
|
|
#include "ieee754dp.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-04-04 05:25:23 +07:00
|
|
|
static inline union ieee754sp ieee754sp_nan_fdp(int xs, u64 xm)
|
|
|
|
{
|
|
|
|
return buildsp(xs, SP_EMAX + 1 + SP_EBIAS,
|
|
|
|
xm >> (DP_FBITS - SP_FBITS));
|
|
|
|
}
|
|
|
|
|
2014-04-16 06:31:11 +07:00
|
|
|
union ieee754sp ieee754sp_fdp(union ieee754dp x)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2015-04-04 05:25:52 +07:00
|
|
|
union ieee754sp y;
|
2014-04-26 06:49:14 +07:00
|
|
|
u32 rm;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
COMPXDP;
|
2015-04-04 05:25:52 +07:00
|
|
|
COMPYSP;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
EXPLODEXDP;
|
|
|
|
|
2014-04-19 05:36:32 +07:00
|
|
|
ieee754_clearcx();
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
FLUSHXDP;
|
|
|
|
|
|
|
|
switch (xc) {
|
|
|
|
case IEEE754_CLASS_SNAN:
|
2015-11-13 07:47:28 +07:00
|
|
|
x = ieee754dp_nanxcpt(x);
|
|
|
|
EXPLODEXDP;
|
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 18:14:05 +07:00
|
|
|
/* fall through */
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
case IEEE754_CLASS_QNAN:
|
2015-04-04 05:25:52 +07:00
|
|
|
y = ieee754sp_nan_fdp(xs, xm);
|
2015-11-13 07:47:28 +07:00
|
|
|
if (!ieee754_csr.nan2008) {
|
|
|
|
EXPLODEYSP;
|
|
|
|
if (!ieee754_class_nan(yc))
|
|
|
|
y = ieee754sp_indef();
|
|
|
|
}
|
2015-04-04 05:25:52 +07:00
|
|
|
return y;
|
2014-04-26 06:49:14 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
case IEEE754_CLASS_INF:
|
|
|
|
return ieee754sp_inf(xs);
|
2014-04-26 06:49:14 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
case IEEE754_CLASS_ZERO:
|
|
|
|
return ieee754sp_zero(xs);
|
2014-04-26 06:49:14 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
case IEEE754_CLASS_DNORM:
|
|
|
|
/* can't possibly be sp representable */
|
2014-04-19 05:36:32 +07:00
|
|
|
ieee754_setcx(IEEE754_UNDERFLOW);
|
|
|
|
ieee754_setcx(IEEE754_INEXACT);
|
2014-04-30 16:21:55 +07:00
|
|
|
if ((ieee754_csr.rm == FPU_CSR_RU && !xs) ||
|
|
|
|
(ieee754_csr.rm == FPU_CSR_RD && xs))
|
2014-04-25 08:19:57 +07:00
|
|
|
return ieee754sp_mind(xs);
|
|
|
|
return ieee754sp_zero(xs);
|
2014-04-26 06:49:14 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
case IEEE754_CLASS_NORM:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-26 06:49:14 +07:00
|
|
|
/*
|
|
|
|
* Convert from DP_FBITS to SP_FBITS+3 with sticky right shift.
|
|
|
|
*/
|
|
|
|
rm = (xm >> (DP_FBITS - (SP_FBITS + 3))) |
|
|
|
|
((xm << (64 - (DP_FBITS - (SP_FBITS + 3)))) != 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-04-26 06:49:14 +07:00
|
|
|
return ieee754sp_format(xs, xe, rm);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|