2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* IEEE754 floating point
|
|
|
|
* double precision internal header file
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* 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-25 23:49:14 +00:00
|
|
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2014-04-15 22:47:59 +00:00
|
|
|
#include <linux/compiler.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "ieee754int.h"
|
|
|
|
|
|
|
|
#define assert(expr) ((void)0)
|
|
|
|
|
2014-04-22 14:33:07 +00:00
|
|
|
#define SP_EBIAS 127
|
|
|
|
#define SP_EMIN (-126)
|
|
|
|
#define SP_EMAX 127
|
|
|
|
#define SP_FBITS 23
|
|
|
|
#define SP_MBITS 23
|
|
|
|
|
|
|
|
#define SP_MBIT(x) ((u32)1 << (x))
|
|
|
|
#define SP_HIDDEN_BIT SP_MBIT(SP_FBITS)
|
|
|
|
#define SP_SIGN_BIT SP_MBIT(31)
|
|
|
|
|
2014-04-25 13:48:40 +00:00
|
|
|
#define SPSIGN(sp) (sp.sign)
|
|
|
|
#define SPBEXP(sp) (sp.bexp)
|
|
|
|
#define SPMANT(sp) (sp.mant)
|
2014-04-22 14:33:07 +00:00
|
|
|
|
2014-04-22 14:52:01 +00:00
|
|
|
static inline int ieee754sp_finite(union ieee754sp x)
|
|
|
|
{
|
|
|
|
return SPBEXP(x) != SP_EMAX + 1 + SP_EBIAS;
|
|
|
|
}
|
|
|
|
|
2017-07-27 16:08:58 +00:00
|
|
|
/* 64 bit right shift with rounding */
|
|
|
|
#define XSPSRS64(v, rs) \
|
|
|
|
(((rs) >= 64) ? ((v) != 0) : ((v) >> (rs)) | ((v) << (64-(rs)) != 0))
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* 3bit extended single precision sticky right shift */
|
2016-04-21 13:04:54 +00:00
|
|
|
#define XSPSRS(v, rs) \
|
|
|
|
((rs > (SP_FBITS+3))?1:((v) >> (rs)) | ((v) << (32-(rs)) != 0))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-04-21 13:04:54 +00:00
|
|
|
#define XSPSRS1(m) \
|
|
|
|
((m >> 1) | (m & 1))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-04-21 13:04:54 +00:00
|
|
|
#define SPXSRSX1() \
|
|
|
|
(xe++, (xm = XSPSRS1(xm)))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define SPXSRSY1() \
|
2016-04-21 13:04:54 +00:00
|
|
|
(ye++, (ym = XSPSRS1(ym)))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* convert denormal to normalized with extended exponent */
|
|
|
|
#define SPDNORMx(m,e) \
|
2014-04-22 13:51:55 +00:00
|
|
|
while ((m >> SP_FBITS) == 0) { m <<= 1; e--; }
|
2007-10-11 22:46:15 +00:00
|
|
|
#define SPDNORMX SPDNORMx(xm, xe)
|
|
|
|
#define SPDNORMY SPDNORMx(ym, ye)
|
2016-04-21 13:04:51 +00:00
|
|
|
#define SPDNORMZ SPDNORMx(zm, ze)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-04-15 23:31:11 +00:00
|
|
|
static inline union ieee754sp buildsp(int s, int bx, unsigned m)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-04-15 23:31:11 +00:00
|
|
|
union ieee754sp r;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
assert((s) == 0 || (s) == 1);
|
|
|
|
assert((bx) >= SP_EMIN - 1 + SP_EBIAS
|
|
|
|
&& (bx) <= SP_EMAX + 1 + SP_EBIAS);
|
2014-04-22 13:51:55 +00:00
|
|
|
assert(((m) >> SP_FBITS) == 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-04-25 13:48:40 +00:00
|
|
|
r.sign = s;
|
|
|
|
r.bexp = bx;
|
|
|
|
r.mant = m;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-04-25 01:19:57 +00:00
|
|
|
extern union ieee754sp __cold ieee754sp_nanxcpt(union ieee754sp);
|
2014-04-15 23:31:11 +00:00
|
|
|
extern union ieee754sp ieee754sp_format(int, int, unsigned);
|