2019-05-31 16:09:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 06:20:36 +08:00
|
|
|
/* IEEE754 floating point arithmetic
|
|
|
|
* single precision
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* MIPS floating point support
|
|
|
|
* Copyright (C) 1994-2000 Algorithmics Ltd.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ieee754sp.h"
|
2014-04-22 22:33:07 +08:00
|
|
|
#include "ieee754dp.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-04-04 06:25:23 +08: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 07:31:11 +08:00
|
|
|
union ieee754sp ieee754sp_fdp(union ieee754dp x)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-04-04 06:25:52 +08:00
|
|
|
union ieee754sp y;
|
2014-04-26 07:49:14 +08:00
|
|
|
u32 rm;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
COMPXDP;
|
2015-04-04 06:25:52 +08:00
|
|
|
COMPYSP;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
EXPLODEXDP;
|
|
|
|
|
2014-04-19 06:36:32 +08:00
|
|
|
ieee754_clearcx();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
FLUSHXDP;
|
|
|
|
|
|
|
|
switch (xc) {
|
|
|
|
case IEEE754_CLASS_SNAN:
|
2015-11-13 08:47:28 +08:00
|
|
|
x = ieee754dp_nanxcpt(x);
|
|
|
|
EXPLODEXDP;
|
2020-05-04 16:51:29 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08:00
|
|
|
case IEEE754_CLASS_QNAN:
|
2015-04-04 06:25:52 +08:00
|
|
|
y = ieee754sp_nan_fdp(xs, xm);
|
2015-11-13 08:47:28 +08:00
|
|
|
if (!ieee754_csr.nan2008) {
|
|
|
|
EXPLODEYSP;
|
|
|
|
if (!ieee754_class_nan(yc))
|
|
|
|
y = ieee754sp_indef();
|
|
|
|
}
|
2015-04-04 06:25:52 +08:00
|
|
|
return y;
|
2014-04-26 07:49:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case IEEE754_CLASS_INF:
|
|
|
|
return ieee754sp_inf(xs);
|
2014-04-26 07:49:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case IEEE754_CLASS_ZERO:
|
|
|
|
return ieee754sp_zero(xs);
|
2014-04-26 07:49:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case IEEE754_CLASS_DNORM:
|
|
|
|
/* can't possibly be sp representable */
|
2014-04-19 06:36:32 +08:00
|
|
|
ieee754_setcx(IEEE754_UNDERFLOW);
|
|
|
|
ieee754_setcx(IEEE754_INEXACT);
|
2014-04-30 17:21:55 +08:00
|
|
|
if ((ieee754_csr.rm == FPU_CSR_RU && !xs) ||
|
|
|
|
(ieee754_csr.rm == FPU_CSR_RD && xs))
|
2014-04-25 09:19:57 +08:00
|
|
|
return ieee754sp_mind(xs);
|
|
|
|
return ieee754sp_zero(xs);
|
2014-04-26 07:49:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case IEEE754_CLASS_NORM:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-26 07:49:14 +08: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 06:20:36 +08:00
|
|
|
|
2014-04-26 07:49:14 +08:00
|
|
|
return ieee754sp_format(xs, xe, rm);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|