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