MIPS: math-emu: Cleanup definition of structs describe sp/dp floats.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
This commit is contained in:
Ralf Baechle 2014-04-25 15:48:40 +02:00
Родитель de2fc342b8
Коммит 49548b09e0
5 изменённых файлов: 73 добавлений и 86 удалений

Просмотреть файл

@ -110,13 +110,13 @@ union ieee754dp ieee754dp_sqrt(union ieee754dp x)
/* triple to almost 56 sig. bits: y ~= sqrt(x) to within 1 ulp */ /* triple to almost 56 sig. bits: y ~= sqrt(x) to within 1 ulp */
/* t=y*y; z=t; pt[n0]+=0x00100000; t+=z; z=(x-z)*y; */ /* t=y*y; z=t; pt[n0]+=0x00100000; t+=z; z=(x-z)*y; */
z = t = ieee754dp_mul(y, y); z = t = ieee754dp_mul(y, y);
t.parts.bexp += 0x001; t.bexp += 0x001;
t = ieee754dp_add(t, z); t = ieee754dp_add(t, z);
z = ieee754dp_mul(ieee754dp_sub(x, z), y); z = ieee754dp_mul(ieee754dp_sub(x, z), y);
/* t=z/(t+x) ; pt[n0]+=0x00100000; y+=t; */ /* t=z/(t+x) ; pt[n0]+=0x00100000; y+=t; */
t = ieee754dp_div(z, ieee754dp_add(t, x)); t = ieee754dp_div(z, ieee754dp_add(t, x));
t.parts.bexp += 0x001; t.bexp += 0x001;
y = ieee754dp_add(y, t); y = ieee754dp_add(y, t);
/* twiddle last bit to force y correctly rounded */ /* twiddle last bit to force y correctly rounded */
@ -155,7 +155,7 @@ union ieee754dp ieee754dp_sqrt(union ieee754dp x)
} }
/* py[n0]=py[n0]+scalx; ...scale back y */ /* py[n0]=py[n0]+scalx; ...scale back y */
y.parts.bexp += scalx; y.bexp += scalx;
/* restore rounding mode, possibly set inexact */ /* restore rounding mode, possibly set inexact */
ieee754_csr = oldcsr; ieee754_csr = oldcsr;

Просмотреть файл

@ -30,64 +30,63 @@
#include <linux/compiler.h> #include <linux/compiler.h>
#include "ieee754int.h" #include "ieee754.h"
#include "ieee754sp.h" #include "ieee754sp.h"
#include "ieee754dp.h" #include "ieee754dp.h"
/* special constants /* special constants
*/ */
#define DPSTR(s, b, mh, ml) \ #define DPCNST(s, b, m) \
{ \ { \
.sign = (s), \ .sign = (s), \
.bexp = (b), \ .bexp = (b) + DP_EBIAS, \
.manthi = (mh), \
.mantlo = (ml) \
}
const struct ieee754dp_const __ieee754dp_spcvals[] = {
DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 0), /* + zero */
DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 0), /* - zero */
DPSTR(0, DP_EBIAS, 0, 0), /* + 1.0 */
DPSTR(1, DP_EBIAS, 0, 0), /* - 1.0 */
DPSTR(0, 3 + DP_EBIAS, 0x40000, 0), /* + 10.0 */
DPSTR(1, 3 + DP_EBIAS, 0x40000, 0), /* - 10.0 */
DPSTR(0, DP_EMAX + 1 + DP_EBIAS, 0, 0), /* + infinity */
DPSTR(1, DP_EMAX + 1 + DP_EBIAS, 0, 0), /* - infinity */
DPSTR(0, DP_EMAX+1+DP_EBIAS, 0x7FFFF, 0xFFFFFFFF), /* + indef quiet Nan */
DPSTR(0, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF), /* + max */
DPSTR(1, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF), /* - max */
DPSTR(0, DP_EMIN + DP_EBIAS, 0, 0), /* + min normal */
DPSTR(1, DP_EMIN + DP_EBIAS, 0, 0), /* - min normal */
DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 1), /* + min denormal */
DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 1), /* - min denormal */
DPSTR(0, 31 + DP_EBIAS, 0, 0), /* + 1.0e31 */
DPSTR(0, 63 + DP_EBIAS, 0, 0), /* + 1.0e63 */
};
#define SPSTR(s, b, m) \
{ \
.sign = (s), \
.bexp = (b), \
.mant = (m) \ .mant = (m) \
} }
const struct ieee754sp_const __ieee754sp_spcvals[] = { const union ieee754dp __ieee754dp_spcvals[] = {
SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 0), /* + zero */ DPCNST(0, DP_EMIN - 1, 0x0000000000000ULL), /* + zero */
SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 0), /* - zero */ DPCNST(1, DP_EMIN - 1, 0x0000000000000ULL), /* - zero */
SPSTR(0, SP_EBIAS, 0), /* + 1.0 */ DPCNST(0, 0, 0x0000000000000ULL), /* + 1.0 */
SPSTR(1, SP_EBIAS, 0), /* - 1.0 */ DPCNST(1, 0, 0x0000000000000ULL), /* - 1.0 */
SPSTR(0, 3 + SP_EBIAS, 0x200000), /* + 10.0 */ DPCNST(0, 3, 0x4000000000000ULL), /* + 10.0 */
SPSTR(1, 3 + SP_EBIAS, 0x200000), /* - 10.0 */ DPCNST(1, 3, 0x4000000000000ULL), /* - 10.0 */
SPSTR(0, SP_EMAX + 1 + SP_EBIAS, 0), /* + infinity */ DPCNST(0, DP_EMAX + 1, 0x0000000000000ULL), /* + infinity */
SPSTR(1, SP_EMAX + 1 + SP_EBIAS, 0), /* - infinity */ DPCNST(1, DP_EMAX + 1, 0x0000000000000ULL), /* - infinity */
SPSTR(0, SP_EMAX+1+SP_EBIAS, 0x3FFFFF), /* + indef quiet Nan */ DPCNST(0, DP_EMAX + 1, 0x7FFFFFFFFFFFFULL), /* + indef quiet Nan */
SPSTR(0, SP_EMAX + SP_EBIAS, 0x7FFFFF), /* + max normal */ DPCNST(0, DP_EMAX, 0xFFFFFFFFFFFFFULL), /* + max */
SPSTR(1, SP_EMAX + SP_EBIAS, 0x7FFFFF), /* - max normal */ DPCNST(1, DP_EMAX, 0xFFFFFFFFFFFFFULL), /* - max */
SPSTR(0, SP_EMIN + SP_EBIAS, 0), /* + min normal */ DPCNST(0, DP_EMIN, 0x0000000000000ULL), /* + min normal */
SPSTR(1, SP_EMIN + SP_EBIAS, 0), /* - min normal */ DPCNST(1, DP_EMIN, 0x0000000000000ULL), /* - min normal */
SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 1), /* + min denormal */ DPCNST(0, DP_EMIN - 1, 0x0000000000001ULL), /* + min denormal */
SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 1), /* - min denormal */ DPCNST(1, DP_EMIN - 1, 0x0000000000001ULL), /* - min denormal */
SPSTR(0, 31 + SP_EBIAS, 0), /* + 1.0e31 */ DPCNST(0, 31, 0x0000000000000ULL), /* + 1.0e31 */
SPSTR(0, 63 + SP_EBIAS, 0), /* + 1.0e63 */ DPCNST(0, 63, 0x0000000000000ULL), /* + 1.0e63 */
};
#define SPCNST(s, b, m) \
{ \
.sign = (s), \
.bexp = (b) + SP_EBIAS, \
.mant = (m) \
}
const union ieee754sp __ieee754sp_spcvals[] = {
SPCNST(0, SP_EMIN - 1, 0x000000), /* + zero */
SPCNST(1, SP_EMIN - 1, 0x000000), /* - zero */
SPCNST(0, 0, 0x000000), /* + 1.0 */
SPCNST(1, 0, 0x000000), /* - 1.0 */
SPCNST(0, 3, 0x200000), /* + 10.0 */
SPCNST(1, 3, 0x200000), /* - 10.0 */
SPCNST(0, SP_EMAX + 1, 0x000000), /* + infinity */
SPCNST(1, SP_EMAX + 1, 0x000000), /* - infinity */
SPCNST(0, SP_EMAX + 1, 0x3FFFFF), /* + indef quiet Nan */
SPCNST(0, SP_EMAX, 0x7FFFFF), /* + max normal */
SPCNST(1, SP_EMAX, 0x7FFFFF), /* - max normal */
SPCNST(0, SP_EMIN, 0x000000), /* + min normal */
SPCNST(1, SP_EMIN, 0x000000), /* - min normal */
SPCNST(0, SP_EMIN - 1, 0x000001), /* + min denormal */
SPCNST(1, SP_EMIN - 1, 0x000001), /* - min denormal */
SPCNST(0, 31, 0x000000), /* + 1.0e31 */
SPCNST(0, 63, 0x000000), /* + 1.0e63 */
}; };

Просмотреть файл

@ -31,36 +31,23 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <asm/bitfield.h> #include <asm/bitfield.h>
struct ieee754dp_const {
__BITFIELD_FIELD(unsigned sign:1,
__BITFIELD_FIELD(unsigned bexp:11,
__BITFIELD_FIELD(unsigned manthi:20,
__BITFIELD_FIELD(unsigned mantlo:32,
;))))
};
union ieee754dp { union ieee754dp {
struct ieee754dp_const oparts;
struct { struct {
__BITFIELD_FIELD(unsigned int sign:1, __BITFIELD_FIELD(unsigned int sign:1,
__BITFIELD_FIELD(unsigned int bexp:11, __BITFIELD_FIELD(unsigned int bexp:11,
__BITFIELD_FIELD(u64 mant:52, __BITFIELD_FIELD(u64 mant:52,
;))) ;)))
} parts; };
double d;
u64 bits; u64 bits;
}; };
struct ieee754sp_const {
__BITFIELD_FIELD(unsigned sign:1,
__BITFIELD_FIELD(unsigned bexp:8,
__BITFIELD_FIELD(unsigned mant:23,
;)))
};
union ieee754sp { union ieee754sp {
struct ieee754sp_const parts; struct {
float f; __BITFIELD_FIELD(unsigned sign:1,
__BITFIELD_FIELD(unsigned bexp:8,
__BITFIELD_FIELD(unsigned mant:23,
;)))
};
u32 bits; u32 bits;
}; };
@ -299,8 +286,8 @@ union ieee754dp ieee754dp_dump(char *s, union ieee754dp x);
#define IEEE754_SPCVAL_P1E31 15 /* + 1.0e31 */ #define IEEE754_SPCVAL_P1E31 15 /* + 1.0e31 */
#define IEEE754_SPCVAL_P1E63 16 /* + 1.0e63 */ #define IEEE754_SPCVAL_P1E63 16 /* + 1.0e63 */
extern const struct ieee754dp_const __ieee754dp_spcvals[]; extern const union ieee754dp __ieee754dp_spcvals[];
extern const struct ieee754sp_const __ieee754sp_spcvals[]; extern const union ieee754sp __ieee754sp_spcvals[];
#define ieee754dp_spcvals ((const union ieee754dp *)__ieee754dp_spcvals) #define ieee754dp_spcvals ((const union ieee754dp *)__ieee754dp_spcvals)
#define ieee754sp_spcvals ((const union ieee754sp *)__ieee754sp_spcvals) #define ieee754sp_spcvals ((const union ieee754sp *)__ieee754sp_spcvals)

Просмотреть файл

@ -40,9 +40,9 @@
#define DP_HIDDEN_BIT DP_MBIT(DP_FBITS) #define DP_HIDDEN_BIT DP_MBIT(DP_FBITS)
#define DP_SIGN_BIT DP_MBIT(63) #define DP_SIGN_BIT DP_MBIT(63)
#define DPSIGN(dp) (dp.parts.sign) #define DPSIGN(dp) (dp.sign)
#define DPBEXP(dp) (dp.parts.bexp) #define DPBEXP(dp) (dp.bexp)
#define DPMANT(dp) (dp.parts.mant) #define DPMANT(dp) (dp.mant)
static inline int ieee754dp_finite(union ieee754dp x) static inline int ieee754dp_finite(union ieee754dp x)
{ {
@ -74,9 +74,10 @@ static inline union ieee754dp builddp(int s, int bx, u64 m)
&& (bx) <= DP_EMAX + 1 + DP_EBIAS); && (bx) <= DP_EMAX + 1 + DP_EBIAS);
assert(((m) >> DP_FBITS) == 0); assert(((m) >> DP_FBITS) == 0);
r.parts.sign = s; r.sign = s;
r.parts.bexp = bx; r.bexp = bx;
r.parts.mant = m; r.mant = m;
return r; return r;
} }

Просмотреть файл

@ -40,9 +40,9 @@
#define SP_HIDDEN_BIT SP_MBIT(SP_FBITS) #define SP_HIDDEN_BIT SP_MBIT(SP_FBITS)
#define SP_SIGN_BIT SP_MBIT(31) #define SP_SIGN_BIT SP_MBIT(31)
#define SPSIGN(sp) (sp.parts.sign) #define SPSIGN(sp) (sp.sign)
#define SPBEXP(sp) (sp.parts.bexp) #define SPBEXP(sp) (sp.bexp)
#define SPMANT(sp) (sp.parts.mant) #define SPMANT(sp) (sp.mant)
static inline int ieee754sp_finite(union ieee754sp x) static inline int ieee754sp_finite(union ieee754sp x)
{ {
@ -79,9 +79,9 @@ static inline union ieee754sp buildsp(int s, int bx, unsigned m)
&& (bx) <= SP_EMAX + 1 + SP_EBIAS); && (bx) <= SP_EMAX + 1 + SP_EBIAS);
assert(((m) >> SP_FBITS) == 0); assert(((m) >> SP_FBITS) == 0);
r.parts.sign = s; r.sign = s;
r.parts.bexp = bx; r.bexp = bx;
r.parts.mant = m; r.mant = m;
return r; return r;
} }