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