xref: /linux/arch/parisc/math-emu/cnv_float.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*660662f8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * Linux/PA-RISC Project (http://www.parisc-linux.org/)
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Floating-point emulation code
61da177e4SLinus Torvalds  *  Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds #ifdef __NO_PA_HDRS
101da177e4SLinus Torvalds     PA header file -- do not include this header file for non-PA builds.
111da177e4SLinus Torvalds #endif
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds /*
141da177e4SLinus Torvalds  * Some more constants
151da177e4SLinus Torvalds  */
161da177e4SLinus Torvalds #define SGL_FX_MAX_EXP 30
171da177e4SLinus Torvalds #define DBL_FX_MAX_EXP 62
181da177e4SLinus Torvalds #define QUAD_FX_MAX_EXP 126
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds #define Dintp1(object) (object)
211da177e4SLinus Torvalds #define Dintp2(object) (object)
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #define Duintp1(object) (object)
241da177e4SLinus Torvalds #define Duintp2(object) (object)
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #define Qintp0(object) (object)
271da177e4SLinus Torvalds #define Qintp1(object) (object)
281da177e4SLinus Torvalds #define Qintp2(object) (object)
291da177e4SLinus Torvalds #define Qintp3(object) (object)
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds /*
331da177e4SLinus Torvalds  * These macros will be used specifically by the convert instructions.
341da177e4SLinus Torvalds  *
351da177e4SLinus Torvalds  *
361da177e4SLinus Torvalds  * Single format macros
371da177e4SLinus Torvalds  */
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds #define Sgl_to_dbl_exponent(src_exponent,dest)			\
401da177e4SLinus Torvalds     Deposit_dexponent(dest,src_exponent+(DBL_BIAS-SGL_BIAS))
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds #define Sgl_to_dbl_mantissa(src_mantissa,destA,destB)	\
431da177e4SLinus Torvalds     Deposit_dmantissap1(destA,src_mantissa>>3);		\
441da177e4SLinus Torvalds     Dmantissap2(destB) = src_mantissa << 29
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds #define Sgl_isinexact_to_fix(sgl_value,exponent)	\
471da177e4SLinus Torvalds     ((exponent < (SGL_P - 1)) ?				\
481da177e4SLinus Torvalds      (Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) : FALSE)
491da177e4SLinus Torvalds 
506b98d913SHelge Deller #define Int_isinexact_to_sgl(int_value)	((int_value << 33 - SGL_EXP_LENGTH) != 0)
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds #define Sgl_roundnearest_from_int(int_value,sgl_value)			\
531da177e4SLinus Torvalds     if (int_value & 1<<(SGL_EXP_LENGTH - 2))   /* round bit */		\
546b98d913SHelge Deller 	if (((int_value << 34 - SGL_EXP_LENGTH) != 0) || Slow(sgl_value)) \
551da177e4SLinus Torvalds 		Sall(sgl_value)++
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds #define Dint_isinexact_to_sgl(dint_valueA,dint_valueB)		\
586b98d913SHelge Deller     (((Dintp1(dint_valueA) << 33 - SGL_EXP_LENGTH) != 0) || Dintp2(dint_valueB))
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds #define Sgl_roundnearest_from_dint(dint_valueA,dint_valueB,sgl_value)	\
611da177e4SLinus Torvalds     if (Dintp1(dint_valueA) & 1<<(SGL_EXP_LENGTH - 2)) 			\
626b98d913SHelge Deller 	if (((Dintp1(dint_valueA) << 34 - SGL_EXP_LENGTH) != 0) ||	\
631da177e4SLinus Torvalds     	Dintp2(dint_valueB) || Slow(sgl_value)) Sall(sgl_value)++
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds #define Dint_isinexact_to_dbl(dint_value) 	\
661da177e4SLinus Torvalds     (Dintp2(dint_value) << 33 - DBL_EXP_LENGTH)
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #define Dbl_roundnearest_from_dint(dint_opndB,dbl_opndA,dbl_opndB) 	\
691da177e4SLinus Torvalds     if (Dintp2(dint_opndB) & 1<<(DBL_EXP_LENGTH - 2))			\
701da177e4SLinus Torvalds        if ((Dintp2(dint_opndB) << 34 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB))  \
711da177e4SLinus Torvalds           if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds #define Sgl_isone_roundbit(sgl_value,exponent)			\
741da177e4SLinus Torvalds     ((Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) >> 31)
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds #define Sgl_isone_stickybit(sgl_value,exponent)		\
771da177e4SLinus Torvalds     (exponent < (SGL_P - 2) ?				\
781da177e4SLinus Torvalds      Sall(sgl_value) << (SGL_EXP_LENGTH + 2 + exponent) : FALSE)
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds /*
821da177e4SLinus Torvalds  * Double format macros
831da177e4SLinus Torvalds  */
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds #define Dbl_to_sgl_exponent(src_exponent,dest)			\
861da177e4SLinus Torvalds     dest = src_exponent + (SGL_BIAS - DBL_BIAS)
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds #define Dbl_to_sgl_mantissa(srcA,srcB,dest,inexact,guard,sticky,odd)	\
891da177e4SLinus Torvalds     Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); 	\
901da177e4SLinus Torvalds     guard = Dbit3p2(srcB);					\
911da177e4SLinus Torvalds     sticky = Dallp2(srcB)<<4;					\
921da177e4SLinus Torvalds     inexact = guard | sticky;					\
931da177e4SLinus Torvalds     odd = Dbit2p2(srcB)
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds #define Dbl_to_sgl_denormalized(srcA,srcB,exp,dest,inexact,guard,sticky,odd,tiny) \
961da177e4SLinus Torvalds     Deposit_dexponent(srcA,1);						\
971da177e4SLinus Torvalds     tiny = TRUE;							\
981da177e4SLinus Torvalds     if (exp >= -2) {							\
991da177e4SLinus Torvalds 	if (exp == 0) {							\
1001da177e4SLinus Torvalds 	    inexact = Dallp2(srcB) << 3;				\
1011da177e4SLinus Torvalds 	    guard = inexact >> 31;					\
1021da177e4SLinus Torvalds 	    sticky = inexact << 1;					\
1031da177e4SLinus Torvalds 	    Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest);	\
1041da177e4SLinus Torvalds 	    odd = dest << 31;						\
1051da177e4SLinus Torvalds 	    if (inexact) {						\
1061da177e4SLinus Torvalds 		switch(Rounding_mode()) {				\
1071da177e4SLinus Torvalds 		    case ROUNDPLUS:					\
1081da177e4SLinus Torvalds 			if (Dbl_iszero_sign(srcA)) {			\
1091da177e4SLinus Torvalds 			    dest++;					\
1101da177e4SLinus Torvalds 			    if (Sgl_isone_hidden(dest))	\
1111da177e4SLinus Torvalds 				tiny = FALSE;				\
1121da177e4SLinus Torvalds 			    dest--;					\
1131da177e4SLinus Torvalds 			}						\
1141da177e4SLinus Torvalds 			break;						\
1151da177e4SLinus Torvalds 		    case ROUNDMINUS:					\
1161da177e4SLinus Torvalds 			if (Dbl_isone_sign(srcA)) {			\
1171da177e4SLinus Torvalds 			    dest++;					\
1181da177e4SLinus Torvalds 			    if (Sgl_isone_hidden(dest))	\
1191da177e4SLinus Torvalds 				tiny = FALSE;				\
1201da177e4SLinus Torvalds 			    dest--;					\
1211da177e4SLinus Torvalds 			}						\
1221da177e4SLinus Torvalds 			break;						\
1231da177e4SLinus Torvalds 		    case ROUNDNEAREST:					\
1241da177e4SLinus Torvalds 			if (guard && (sticky || odd)) {			\
1251da177e4SLinus Torvalds 			    dest++;					\
1261da177e4SLinus Torvalds 			    if (Sgl_isone_hidden(dest))	\
1271da177e4SLinus Torvalds 				tiny = FALSE;				\
1281da177e4SLinus Torvalds 			    dest--;					\
1291da177e4SLinus Torvalds 			}						\
1301da177e4SLinus Torvalds 			break;						\
1311da177e4SLinus Torvalds 		}							\
1321da177e4SLinus Torvalds 	    }								\
1331da177e4SLinus Torvalds 		/* shift right by one to get correct result */		\
1341da177e4SLinus Torvalds 		guard = odd;						\
1351da177e4SLinus Torvalds 		sticky = inexact;					\
1361da177e4SLinus Torvalds 		inexact |= guard;					\
1371da177e4SLinus Torvalds 		dest >>= 1;						\
1381da177e4SLinus Torvalds     		Deposit_dsign(srcA,0);					\
1391da177e4SLinus Torvalds     	        Shiftdouble(Dallp1(srcA),Dallp2(srcB),30,dest);		\
1401da177e4SLinus Torvalds 	        odd = dest << 31;					\
1411da177e4SLinus Torvalds 	}								\
1421da177e4SLinus Torvalds 	else {								\
1431da177e4SLinus Torvalds     	    inexact = Dallp2(srcB) << (2 + exp);			\
1441da177e4SLinus Torvalds     	    guard = inexact >> 31;					\
1451da177e4SLinus Torvalds     	    sticky = inexact << 1; 					\
1461da177e4SLinus Torvalds     	    Deposit_dsign(srcA,0);					\
1471da177e4SLinus Torvalds     	    if (exp == -2) dest = Dallp1(srcA);				\
1481da177e4SLinus Torvalds     	    else Variable_shift_double(Dallp1(srcA),Dallp2(srcB),30-exp,dest); \
1491da177e4SLinus Torvalds     	    odd = dest << 31;						\
1501da177e4SLinus Torvalds 	}								\
1511da177e4SLinus Torvalds     }									\
1521da177e4SLinus Torvalds     else {								\
1531da177e4SLinus Torvalds     	Deposit_dsign(srcA,0);						\
1541da177e4SLinus Torvalds     	if (exp > (1 - SGL_P)) {					\
1551da177e4SLinus Torvalds     	    dest = Dallp1(srcA) >> (- 2 - exp);				\
1561da177e4SLinus Torvalds     	    inexact = Dallp1(srcA) << (34 + exp);			\
1571da177e4SLinus Torvalds     	    guard = inexact >> 31;					\
1581da177e4SLinus Torvalds     	    sticky = (inexact << 1) | Dallp2(srcB);			\
1591da177e4SLinus Torvalds     	    inexact |= Dallp2(srcB); 					\
1601da177e4SLinus Torvalds     	    odd = dest << 31;						\
1611da177e4SLinus Torvalds     	}								\
1621da177e4SLinus Torvalds     	else {								\
1631da177e4SLinus Torvalds     	    dest = 0;							\
1641da177e4SLinus Torvalds     	    inexact = Dallp1(srcA) | Dallp2(srcB);			\
1651da177e4SLinus Torvalds     	    if (exp == (1 - SGL_P)) {					\
1661da177e4SLinus Torvalds     	    	guard = Dhidden(srcA);					\
1671da177e4SLinus Torvalds     	    	sticky = Dmantissap1(srcA) | Dallp2(srcB); 		\
1681da177e4SLinus Torvalds     	    }								\
1691da177e4SLinus Torvalds     	    else {							\
1701da177e4SLinus Torvalds     	    	guard = 0;						\
1711da177e4SLinus Torvalds     	    	sticky = inexact;					\
1721da177e4SLinus Torvalds     	    }								\
1731da177e4SLinus Torvalds     	    odd = 0;							\
1741da177e4SLinus Torvalds     	}								\
1751da177e4SLinus Torvalds     }									\
1761da177e4SLinus Torvalds     exp = 0
1771da177e4SLinus Torvalds 
1781da177e4SLinus Torvalds #define Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent)		\
1791da177e4SLinus Torvalds     (exponent < (DBL_P-33) ? 						\
1801da177e4SLinus Torvalds      Dallp2(dbl_valueB) || Dallp1(dbl_valueA) << (DBL_EXP_LENGTH+1+exponent) : \
1811da177e4SLinus Torvalds      (exponent < (DBL_P-1) ? Dallp2(dbl_valueB) << (exponent + (33-DBL_P)) :   \
1821da177e4SLinus Torvalds       FALSE))
1831da177e4SLinus Torvalds 
1841da177e4SLinus Torvalds #define Dbl_isoverflow_to_int(exponent,dbl_valueA,dbl_valueB)		\
1851da177e4SLinus Torvalds     ((exponent > SGL_FX_MAX_EXP + 1) || Dsign(dbl_valueA)==0 ||		\
1861da177e4SLinus Torvalds      Dmantissap1(dbl_valueA)!=0 || (Dallp2(dbl_valueB)>>21)!=0 )
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds #define Dbl_isone_roundbit(dbl_valueA,dbl_valueB,exponent)              \
1891da177e4SLinus Torvalds     ((exponent < (DBL_P - 33) ?						\
1901da177e4SLinus Torvalds       Dallp1(dbl_valueA) >> ((30 - DBL_EXP_LENGTH) - exponent) :	\
1911da177e4SLinus Torvalds       Dallp2(dbl_valueB) >> ((DBL_P - 2) - exponent)) & 1)
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds #define Dbl_isone_stickybit(dbl_valueA,dbl_valueB,exponent)		\
1941da177e4SLinus Torvalds     (exponent < (DBL_P-34) ? 						\
1951da177e4SLinus Torvalds      (Dallp2(dbl_valueB) || Dallp1(dbl_valueA)<<(DBL_EXP_LENGTH+2+exponent)) : \
1961da177e4SLinus Torvalds      (exponent<(DBL_P-2) ? (Dallp2(dbl_valueB) << (exponent + (34-DBL_P))) : \
1971da177e4SLinus Torvalds       FALSE))
1981da177e4SLinus Torvalds 
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds /* Int macros */
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds #define Int_from_sgl_mantissa(sgl_value,exponent)	\
2031da177e4SLinus Torvalds     Sall(sgl_value) = 				\
2041da177e4SLinus Torvalds     	(unsigned)(Sall(sgl_value) << SGL_EXP_LENGTH)>>(31 - exponent)
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds #define Int_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent)	\
2071da177e4SLinus Torvalds     Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),22,Dallp1(dbl_valueA)); \
2081da177e4SLinus Torvalds     if (exponent < 31) Dallp1(dbl_valueA) >>= 30 - exponent;	\
2091da177e4SLinus Torvalds     else Dallp1(dbl_valueA) <<= 1
2101da177e4SLinus Torvalds 
2111da177e4SLinus Torvalds #define Int_negate(int_value) int_value = -int_value
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds /* Dint macros */
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds #define Dint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB)	\
2171da177e4SLinus Torvalds     {Sall(sgl_value) <<= SGL_EXP_LENGTH;  /*  left-justify  */		\
2181da177e4SLinus Torvalds     if (exponent <= 31) {						\
2191da177e4SLinus Torvalds     	Dintp1(dresultA) = 0;						\
2201da177e4SLinus Torvalds     	Dintp2(dresultB) = (unsigned)Sall(sgl_value) >> (31 - exponent); \
2211da177e4SLinus Torvalds     }									\
2221da177e4SLinus Torvalds     else {								\
2231da177e4SLinus Torvalds     	Dintp1(dresultA) = Sall(sgl_value) >> (63 - exponent);		\
2241da177e4SLinus Torvalds     	Dintp2(dresultB) = Sall(sgl_value) << (exponent - 31);		\
2251da177e4SLinus Torvalds     }}
2261da177e4SLinus Torvalds 
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds #define Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \
2291da177e4SLinus Torvalds     {if (exponent < 32) {						\
2301da177e4SLinus Torvalds     	Dintp1(destA) = 0;						\
2311da177e4SLinus Torvalds     	if (exponent <= 20)						\
2321da177e4SLinus Torvalds     	    Dintp2(destB) = Dallp1(dbl_valueA) >> 20-exponent;		\
2331da177e4SLinus Torvalds     	else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
2341da177e4SLinus Torvalds 	     52-exponent,Dintp2(destB));					\
2351da177e4SLinus Torvalds     }									\
2361da177e4SLinus Torvalds     else {								\
2371da177e4SLinus Torvalds     	if (exponent <= 52) {						\
2381da177e4SLinus Torvalds     	    Dintp1(destA) = Dallp1(dbl_valueA) >> 52-exponent;		\
2391da177e4SLinus Torvalds 	    if (exponent == 52) Dintp2(destB) = Dallp2(dbl_valueB);	\
2401da177e4SLinus Torvalds 	    else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
2411da177e4SLinus Torvalds 	    52-exponent,Dintp2(destB));					\
2421da177e4SLinus Torvalds         }								\
2431da177e4SLinus Torvalds     	else {								\
2441da177e4SLinus Torvalds     	    Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
2451da177e4SLinus Torvalds 	    84-exponent,Dintp1(destA));					\
2461da177e4SLinus Torvalds     	    Dintp2(destB) = Dallp2(dbl_valueB) << exponent-52;		\
2471da177e4SLinus Torvalds     	}								\
2481da177e4SLinus Torvalds     }}
2491da177e4SLinus Torvalds 
2501da177e4SLinus Torvalds #define Dint_setzero(dresultA,dresultB) 	\
2511da177e4SLinus Torvalds     Dintp1(dresultA) = 0; 	\
2521da177e4SLinus Torvalds     Dintp2(dresultB) = 0
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds #define Dint_setone_sign(dresultA,dresultB)		\
2551da177e4SLinus Torvalds     Dintp1(dresultA) = ~Dintp1(dresultA);		\
2561da177e4SLinus Torvalds     if ((Dintp2(dresultB) = -Dintp2(dresultB)) == 0) Dintp1(dresultA)++
2571da177e4SLinus Torvalds 
2581da177e4SLinus Torvalds #define Dint_set_minint(dresultA,dresultB)		\
2591da177e4SLinus Torvalds     Dintp1(dresultA) = (unsigned int)1<<31;		\
2601da177e4SLinus Torvalds     Dintp2(dresultB) = 0
2611da177e4SLinus Torvalds 
2621da177e4SLinus Torvalds #define Dint_isone_lowp2(dresultB)  (Dintp2(dresultB) & 01)
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds #define Dint_increment(dresultA,dresultB) 		\
2651da177e4SLinus Torvalds     if ((++Dintp2(dresultB))==0) Dintp1(dresultA)++
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds #define Dint_decrement(dresultA,dresultB) 		\
2681da177e4SLinus Torvalds     if ((Dintp2(dresultB)--)==0) Dintp1(dresultA)--
2691da177e4SLinus Torvalds 
2701da177e4SLinus Torvalds #define Dint_negate(dresultA,dresultB)			\
2711da177e4SLinus Torvalds     Dintp1(dresultA) = ~Dintp1(dresultA);		\
2721da177e4SLinus Torvalds     if ((Dintp2(dresultB) = -Dintp2(dresultB))==0) Dintp1(dresultA)++
2731da177e4SLinus Torvalds 
2741da177e4SLinus Torvalds #define Dint_copyfromptr(src,destA,destB) \
2751da177e4SLinus Torvalds      Dintp1(destA) = src->wd0;		\
2761da177e4SLinus Torvalds      Dintp2(destB) = src->wd1
2771da177e4SLinus Torvalds #define Dint_copytoptr(srcA,srcB,dest)	\
2781da177e4SLinus Torvalds     dest->wd0 = Dintp1(srcA);		\
2791da177e4SLinus Torvalds     dest->wd1 = Dintp2(srcB)
2801da177e4SLinus Torvalds 
2811da177e4SLinus Torvalds 
2821da177e4SLinus Torvalds /* other macros  */
2831da177e4SLinus Torvalds 
2841da177e4SLinus Torvalds #define Find_ms_one_bit(value, position)	\
2851da177e4SLinus Torvalds     {						\
2861da177e4SLinus Torvalds 	int var;				\
2871da177e4SLinus Torvalds 	for (var=8; var >=1; var >>= 1) {	\
2881da177e4SLinus Torvalds 	    if (value >> 32 - position)		\
2891da177e4SLinus Torvalds 		position -= var;		\
2901da177e4SLinus Torvalds 		else position += var;		\
2911da177e4SLinus Torvalds 	}					\
2921da177e4SLinus Torvalds 	if ((value >> 32 - position) == 0)	\
2931da177e4SLinus Torvalds 	    position--;				\
2941da177e4SLinus Torvalds 	else position -= 2;			\
2951da177e4SLinus Torvalds     }
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds /*
2991da177e4SLinus Torvalds  * Unsigned int macros
3001da177e4SLinus Torvalds  */
3011da177e4SLinus Torvalds #define Duint_copyfromptr(src,destA,destB) \
3021da177e4SLinus Torvalds     Dint_copyfromptr(src,destA,destB)
3031da177e4SLinus Torvalds #define Duint_copytoptr(srcA,srcB,dest)	\
3041da177e4SLinus Torvalds     Dint_copytoptr(srcA,srcB,dest)
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds #define Suint_isinexact_to_sgl(int_value) \
3071da177e4SLinus Torvalds     (int_value << 32 - SGL_EXP_LENGTH)
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds #define Sgl_roundnearest_from_suint(suint_value,sgl_value)		\
3101da177e4SLinus Torvalds     if (suint_value & 1<<(SGL_EXP_LENGTH - 1))   /* round bit */	\
3111da177e4SLinus Torvalds     	if ((suint_value << 33 - SGL_EXP_LENGTH) || Slow(sgl_value))	\
3121da177e4SLinus Torvalds 		Sall(sgl_value)++
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds #define Duint_isinexact_to_sgl(duint_valueA,duint_valueB)	\
3151da177e4SLinus Torvalds     ((Duintp1(duint_valueA) << 32 - SGL_EXP_LENGTH) || Duintp2(duint_valueB))
3161da177e4SLinus Torvalds 
3171da177e4SLinus Torvalds #define Sgl_roundnearest_from_duint(duint_valueA,duint_valueB,sgl_value) \
3181da177e4SLinus Torvalds     if (Duintp1(duint_valueA) & 1<<(SGL_EXP_LENGTH - 1))		\
3191da177e4SLinus Torvalds     	if ((Duintp1(duint_valueA) << 33 - SGL_EXP_LENGTH) ||		\
3201da177e4SLinus Torvalds     	Duintp2(duint_valueB) || Slow(sgl_value)) Sall(sgl_value)++
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds #define Duint_isinexact_to_dbl(duint_value) 	\
3231da177e4SLinus Torvalds     (Duintp2(duint_value) << 32 - DBL_EXP_LENGTH)
3241da177e4SLinus Torvalds 
3251da177e4SLinus Torvalds #define Dbl_roundnearest_from_duint(duint_opndB,dbl_opndA,dbl_opndB) 	\
3261da177e4SLinus Torvalds     if (Duintp2(duint_opndB) & 1<<(DBL_EXP_LENGTH - 1))			\
3271da177e4SLinus Torvalds        if ((Duintp2(duint_opndB) << 33 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \
3281da177e4SLinus Torvalds           if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds #define Suint_from_sgl_mantissa(src,exponent,result)	\
3311da177e4SLinus Torvalds     Sall(result) = (unsigned)(Sall(src) << SGL_EXP_LENGTH)>>(31 - exponent)
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds #define Sgl_isinexact_to_unsigned(sgl_value,exponent)	\
3341da177e4SLinus Torvalds     Sgl_isinexact_to_fix(sgl_value,exponent)
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds #define Duint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB)	\
337cabd91c3SJohn David Anglin   {unsigned int val = Sall(sgl_value) << SGL_EXP_LENGTH;		\
3381da177e4SLinus Torvalds     if (exponent <= 31) {						\
3391da177e4SLinus Torvalds 	Dintp1(dresultA) = 0;						\
340cabd91c3SJohn David Anglin 	Dintp2(dresultB) = val >> (31 - exponent);			\
3411da177e4SLinus Torvalds     }									\
3421da177e4SLinus Torvalds     else {								\
343cabd91c3SJohn David Anglin 	Dintp1(dresultA) = val >> (63 - exponent);			\
344cabd91c3SJohn David Anglin 	Dintp2(dresultB) = exponent <= 62 ? val << (exponent - 31) : 0;	\
3451da177e4SLinus Torvalds     }									\
3461da177e4SLinus Torvalds   }
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds #define Duint_setzero(dresultA,dresultB) 	\
3491da177e4SLinus Torvalds     Dint_setzero(dresultA,dresultB)
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds #define Duint_increment(dresultA,dresultB) Dint_increment(dresultA,dresultB)
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds #define Duint_isone_lowp2(dresultB)  Dint_isone_lowp2(dresultB)
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds #define Suint_from_dbl_mantissa(srcA,srcB,exponent,dest) \
3561da177e4SLinus Torvalds     Shiftdouble(Dallp1(srcA),Dallp2(srcB),21,dest); \
3571da177e4SLinus Torvalds     dest = (unsigned)dest >> 31 - exponent
3581da177e4SLinus Torvalds 
3591da177e4SLinus Torvalds #define Dbl_isinexact_to_unsigned(dbl_valueA,dbl_valueB,exponent) \
3601da177e4SLinus Torvalds     Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent)
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds #define Duint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \
3631da177e4SLinus Torvalds     Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB)
364