Linux Audio

Check our new training course

Loading...
v4.17
  1/*
  2 * IEEE754 floating point
  3 * common internal header file
  4 */
  5/*
  6 * MIPS floating point support
  7 * Copyright (C) 1994-2000 Algorithmics Ltd.
  8 *
 
 
  9 *  This program is free software; you can distribute it and/or modify it
 10 *  under the terms of the GNU General Public License (Version 2) as
 11 *  published by the Free Software Foundation.
 12 *
 13 *  This program is distributed in the hope it will be useful, but WITHOUT
 14 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 15 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 16 *  for more details.
 17 *
 18 *  You should have received a copy of the GNU General Public License along
 19 *  with this program; if not, write to the Free Software Foundation, Inc.,
 20 *  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 
 
 21 */
 22#ifndef __IEEE754INT_H
 23#define __IEEE754INT_H
 24
 25#include "ieee754.h"
 26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 27#define CLPAIR(x, y)	((x)*6+(y))
 28
 29enum maddf_flags {
 30	MADDF_NEGATE_PRODUCT	= 1 << 0,
 31};
 32
 33static inline void ieee754_clearcx(void)
 34{
 35	ieee754_csr.cx = 0;
 36}
 37
 38static inline void ieee754_setcx(const unsigned int flags)
 39{
 40	ieee754_csr.cx |= flags;
 41	ieee754_csr.sx |= flags;
 42}
 43
 44static inline int ieee754_setandtestcx(const unsigned int x)
 45{
 46	ieee754_setcx(x);
 47
 48	return ieee754_csr.mx & x;
 49}
 50
 51static inline int ieee754_class_nan(int xc)
 52{
 53	return xc >= IEEE754_CLASS_SNAN;
 54}
 55
 56#define COMPXSP \
 57	unsigned int xm; int xe; int xs __maybe_unused; int xc
 58
 59#define COMPYSP \
 60	unsigned int ym; int ye; int ys; int yc
 61
 62#define COMPZSP \
 63	unsigned int zm; int ze; int zs; int zc
 64
 65#define EXPLODESP(v, vc, vs, ve, vm)					\
 66{									\
 67	vs = SPSIGN(v);							\
 68	ve = SPBEXP(v);							\
 69	vm = SPMANT(v);							\
 70	if (ve == SP_EMAX+1+SP_EBIAS) {					\
 71		if (vm == 0)						\
 72			vc = IEEE754_CLASS_INF;				\
 73		else if (ieee754_csr.nan2008 ^ !(vm & SP_MBIT(SP_FBITS - 1))) \
 74			vc = IEEE754_CLASS_QNAN;			\
 75		else							\
 76			vc = IEEE754_CLASS_SNAN;			\
 77	} else if (ve == SP_EMIN-1+SP_EBIAS) {				\
 78		if (vm) {						\
 79			ve = SP_EMIN;					\
 80			vc = IEEE754_CLASS_DNORM;			\
 81		} else							\
 82			vc = IEEE754_CLASS_ZERO;			\
 83	} else {							\
 84		ve -= SP_EBIAS;						\
 85		vm |= SP_HIDDEN_BIT;					\
 86		vc = IEEE754_CLASS_NORM;				\
 87	}								\
 88}
 89#define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
 90#define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
 91#define EXPLODEZSP EXPLODESP(z, zc, zs, ze, zm)
 92
 93
 94#define COMPXDP \
 95	u64 xm; int xe; int xs __maybe_unused; int xc
 96
 97#define COMPYDP \
 98	u64 ym; int ye; int ys; int yc
 99
100#define COMPZDP \
101	u64 zm; int ze; int zs; int zc
102
103#define EXPLODEDP(v, vc, vs, ve, vm)					\
104{									\
105	vm = DPMANT(v);							\
106	vs = DPSIGN(v);							\
107	ve = DPBEXP(v);							\
108	if (ve == DP_EMAX+1+DP_EBIAS) {					\
109		if (vm == 0)						\
110			vc = IEEE754_CLASS_INF;				\
111		else if (ieee754_csr.nan2008 ^ !(vm & DP_MBIT(DP_FBITS - 1))) \
112			vc = IEEE754_CLASS_QNAN;			\
113		else							\
114			vc = IEEE754_CLASS_SNAN;			\
115	} else if (ve == DP_EMIN-1+DP_EBIAS) {				\
116		if (vm) {						\
117			ve = DP_EMIN;					\
118			vc = IEEE754_CLASS_DNORM;			\
119		} else							\
120			vc = IEEE754_CLASS_ZERO;			\
121	} else {							\
122		ve -= DP_EBIAS;						\
123		vm |= DP_HIDDEN_BIT;					\
124		vc = IEEE754_CLASS_NORM;				\
125	}								\
126}
127#define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
128#define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
129#define EXPLODEZDP EXPLODEDP(z, zc, zs, ze, zm)
130
131#define FLUSHDP(v, vc, vs, ve, vm)					\
132	if (vc==IEEE754_CLASS_DNORM) {					\
133		if (ieee754_csr.nod) {					\
134			ieee754_setcx(IEEE754_INEXACT);			\
135			vc = IEEE754_CLASS_ZERO;			\
136			ve = DP_EMIN-1+DP_EBIAS;			\
137			vm = 0;						\
138			v = ieee754dp_zero(vs);				\
139		}							\
140	}
141
142#define FLUSHSP(v, vc, vs, ve, vm)					\
143	if (vc==IEEE754_CLASS_DNORM) {					\
144		if (ieee754_csr.nod) {					\
145			ieee754_setcx(IEEE754_INEXACT);			\
146			vc = IEEE754_CLASS_ZERO;			\
147			ve = SP_EMIN-1+SP_EBIAS;			\
148			vm = 0;						\
149			v = ieee754sp_zero(vs);				\
150		}							\
151	}
152
153#define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
154#define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
155#define FLUSHZDP FLUSHDP(z, zc, zs, ze, zm)
156#define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
157#define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
158#define FLUSHZSP FLUSHSP(z, zc, zs, ze, zm)
159
160#endif /* __IEEE754INT_H  */
v3.1
  1/*
  2 * IEEE754 floating point
  3 * common internal header file
  4 */
  5/*
  6 * MIPS floating point support
  7 * Copyright (C) 1994-2000 Algorithmics Ltd.
  8 *
  9 * ########################################################################
 10 *
 11 *  This program is free software; you can distribute it and/or modify it
 12 *  under the terms of the GNU General Public License (Version 2) as
 13 *  published by the Free Software Foundation.
 14 *
 15 *  This program is distributed in the hope it will be useful, but WITHOUT
 16 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 17 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 18 *  for more details.
 19 *
 20 *  You should have received a copy of the GNU General Public License along
 21 *  with this program; if not, write to the Free Software Foundation, Inc.,
 22 *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 23 *
 24 * ########################################################################
 25 */
 26
 
 27
 28#include "ieee754.h"
 29
 30#define DP_EBIAS	1023
 31#define DP_EMIN		(-1022)
 32#define DP_EMAX		1023
 33#define DP_MBITS	52
 34
 35#define SP_EBIAS	127
 36#define SP_EMIN		(-126)
 37#define SP_EMAX		127
 38#define SP_MBITS	23
 39
 40#define DP_MBIT(x)	((u64)1 << (x))
 41#define DP_HIDDEN_BIT	DP_MBIT(DP_MBITS)
 42#define DP_SIGN_BIT	DP_MBIT(63)
 43
 44#define SP_MBIT(x)	((u32)1 << (x))
 45#define SP_HIDDEN_BIT	SP_MBIT(SP_MBITS)
 46#define SP_SIGN_BIT	SP_MBIT(31)
 47
 48
 49#define SPSIGN(sp)	(sp.parts.sign)
 50#define SPBEXP(sp)	(sp.parts.bexp)
 51#define SPMANT(sp)	(sp.parts.mant)
 52
 53#define DPSIGN(dp)	(dp.parts.sign)
 54#define DPBEXP(dp)	(dp.parts.bexp)
 55#define DPMANT(dp)	(dp.parts.mant)
 56
 57#define CLPAIR(x, y)	((x)*6+(y))
 58
 59#define CLEARCX	\
 60  (ieee754_csr.cx = 0)
 
 
 
 
 
 
 61
 62#define SETCX(x) \
 63  (ieee754_csr.cx |= (x), ieee754_csr.sx |= (x))
 
 
 
 64
 65#define SETANDTESTCX(x) \
 66  (SETCX(x), ieee754_csr.mx & (x))
 
 67
 68#define TSTX()	\
 69	(ieee754_csr.cx & ieee754_csr.mx)
 70
 
 
 
 
 71
 72#define COMPXSP \
 73  unsigned xm; int xe; int xs __maybe_unused; int xc
 74
 75#define COMPYSP \
 76  unsigned ym; int ye; int ys; int yc
 
 
 
 77
 78#define EXPLODESP(v, vc, vs, ve, vm) \
 79{\
 80    vs = SPSIGN(v);\
 81    ve = SPBEXP(v);\
 82    vm = SPMANT(v);\
 83    if(ve == SP_EMAX+1+SP_EBIAS){\
 84	if(vm == 0)\
 85	  vc = IEEE754_CLASS_INF;\
 86	else if(vm & SP_MBIT(SP_MBITS-1)) \
 87	  vc = IEEE754_CLASS_SNAN;\
 88	else \
 89	  vc = IEEE754_CLASS_QNAN;\
 90    } else if(ve == SP_EMIN-1+SP_EBIAS) {\
 91	if(vm) {\
 92	    ve = SP_EMIN;\
 93	    vc = IEEE754_CLASS_DNORM;\
 94	} else\
 95	  vc = IEEE754_CLASS_ZERO;\
 96    } else {\
 97	ve -= SP_EBIAS;\
 98	vm |= SP_HIDDEN_BIT;\
 99	vc = IEEE754_CLASS_NORM;\
100    }\
101}
102#define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
103#define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
 
104
105
106#define COMPXDP \
107u64 xm; int xe; int xs __maybe_unused; int xc
108
109#define COMPYDP \
110u64 ym; int ye; int ys; int yc
111
112#define EXPLODEDP(v, vc, vs, ve, vm) \
113{\
114    vm = DPMANT(v);\
115    vs = DPSIGN(v);\
116    ve = DPBEXP(v);\
117    if(ve == DP_EMAX+1+DP_EBIAS){\
118	if(vm == 0)\
119	  vc = IEEE754_CLASS_INF;\
120	else if(vm & DP_MBIT(DP_MBITS-1)) \
121	  vc = IEEE754_CLASS_SNAN;\
122	else \
123	  vc = IEEE754_CLASS_QNAN;\
124    } else if(ve == DP_EMIN-1+DP_EBIAS) {\
125	if(vm) {\
126	    ve = DP_EMIN;\
127	    vc = IEEE754_CLASS_DNORM;\
128	} else\
129	  vc = IEEE754_CLASS_ZERO;\
130    } else {\
131	ve -= DP_EBIAS;\
132	vm |= DP_HIDDEN_BIT;\
133	vc = IEEE754_CLASS_NORM;\
134    }\
 
 
 
135}
136#define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
137#define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
 
138
139#define FLUSHDP(v, vc, vs, ve, vm) \
140	if(vc==IEEE754_CLASS_DNORM) {\
141	    if(ieee754_csr.nod) {\
142		SETCX(IEEE754_INEXACT);\
143		vc = IEEE754_CLASS_ZERO;\
144		ve = DP_EMIN-1+DP_EBIAS;\
145		vm = 0;\
146		v = ieee754dp_zero(vs);\
147	    }\
148	}
149
150#define FLUSHSP(v, vc, vs, ve, vm) \
151	if(vc==IEEE754_CLASS_DNORM) {\
152	    if(ieee754_csr.nod) {\
153		SETCX(IEEE754_INEXACT);\
154		vc = IEEE754_CLASS_ZERO;\
155		ve = SP_EMIN-1+SP_EBIAS;\
156		vm = 0;\
157		v = ieee754sp_zero(vs);\
158	    }\
159	}
160
161#define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
162#define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
 
163#define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
164#define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)