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