ieee754sp.h 2.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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.,
20
 *  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
L
Linus Torvalds 已提交
21 22
 */

23
#include <linux/compiler.h>
L
Linus Torvalds 已提交
24 25 26 27 28

#include "ieee754int.h"

#define assert(expr) ((void)0)

29 30 31 32 33 34 35 36 37 38
#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)

39 40 41
#define SPSIGN(sp)	(sp.sign)
#define SPBEXP(sp)	(sp.bexp)
#define SPMANT(sp)	(sp.mant)
42

43 44 45 46 47
static inline int ieee754sp_finite(union ieee754sp x)
{
	return SPBEXP(x) != SP_EMAX + 1 + SP_EBIAS;
}

48 49 50 51
/* 64 bit right shift with rounding */
#define XSPSRS64(v, rs)						\
	(((rs) >= 64) ? ((v) != 0) : ((v) >> (rs)) | ((v) << (64-(rs)) != 0))

L
Linus Torvalds 已提交
52
/* 3bit extended single precision sticky right shift */
53 54
#define XSPSRS(v, rs)						\
	((rs > (SP_FBITS+3))?1:((v) >> (rs)) | ((v) << (32-(rs)) != 0))
L
Linus Torvalds 已提交
55

56 57
#define XSPSRS1(m) \
	((m >> 1) | (m & 1))
L
Linus Torvalds 已提交
58

59 60
#define SPXSRSX1() \
	(xe++, (xm = XSPSRS1(xm)))
L
Linus Torvalds 已提交
61 62

#define SPXSRSY1() \
63
	(ye++, (ym = XSPSRS1(ym)))
L
Linus Torvalds 已提交
64 65 66

/* convert denormal to normalized with extended exponent */
#define SPDNORMx(m,e) \
67
	while ((m >> SP_FBITS) == 0) { m <<= 1; e--; }
68 69
#define SPDNORMX	SPDNORMx(xm, xe)
#define SPDNORMY	SPDNORMx(ym, ye)
70
#define SPDNORMZ	SPDNORMx(zm, ze)
L
Linus Torvalds 已提交
71

72
static inline union ieee754sp buildsp(int s, int bx, unsigned m)
L
Linus Torvalds 已提交
73
{
74
	union ieee754sp r;
L
Linus Torvalds 已提交
75 76 77 78

	assert((s) == 0 || (s) == 1);
	assert((bx) >= SP_EMIN - 1 + SP_EBIAS
	       && (bx) <= SP_EMAX + 1 + SP_EBIAS);
79
	assert(((m) >> SP_FBITS) == 0);
L
Linus Torvalds 已提交
80

81 82 83
	r.sign = s;
	r.bexp = bx;
	r.mant = m;
L
Linus Torvalds 已提交
84 85 86 87

	return r;
}

88
extern union ieee754sp __cold ieee754sp_nanxcpt(union ieee754sp);
89
extern union ieee754sp ieee754sp_format(int, int, unsigned);