18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Linux/PA-RISC Project (http://www.parisc-linux.org/)
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Floating-point emulation code
68c2ecf20Sopenharmony_ci *  Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifdef __NO_PA_HDRS
108c2ecf20Sopenharmony_ci    PA header file -- do not include this header file for non-PA builds.
118c2ecf20Sopenharmony_ci#endif
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * Some more constants
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci#define SGL_FX_MAX_EXP 30
178c2ecf20Sopenharmony_ci#define DBL_FX_MAX_EXP 62
188c2ecf20Sopenharmony_ci#define QUAD_FX_MAX_EXP 126
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define Dintp1(object) (object)
218c2ecf20Sopenharmony_ci#define Dintp2(object) (object)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define Duintp1(object) (object)
248c2ecf20Sopenharmony_ci#define Duintp2(object) (object)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define Qintp0(object) (object)
278c2ecf20Sopenharmony_ci#define Qintp1(object) (object)
288c2ecf20Sopenharmony_ci#define Qintp2(object) (object)
298c2ecf20Sopenharmony_ci#define Qintp3(object) (object)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/*
338c2ecf20Sopenharmony_ci * These macros will be used specifically by the convert instructions.
348c2ecf20Sopenharmony_ci *
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * Single format macros
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define Sgl_to_dbl_exponent(src_exponent,dest)			\
408c2ecf20Sopenharmony_ci    Deposit_dexponent(dest,src_exponent+(DBL_BIAS-SGL_BIAS))
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define Sgl_to_dbl_mantissa(src_mantissa,destA,destB)	\
438c2ecf20Sopenharmony_ci    Deposit_dmantissap1(destA,src_mantissa>>3);		\
448c2ecf20Sopenharmony_ci    Dmantissap2(destB) = src_mantissa << 29
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define Sgl_isinexact_to_fix(sgl_value,exponent)	\
478c2ecf20Sopenharmony_ci    ((exponent < (SGL_P - 1)) ?				\
488c2ecf20Sopenharmony_ci     (Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) : FALSE)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define Int_isinexact_to_sgl(int_value)	((int_value << 33 - SGL_EXP_LENGTH) != 0)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define Sgl_roundnearest_from_int(int_value,sgl_value)			\
538c2ecf20Sopenharmony_ci    if (int_value & 1<<(SGL_EXP_LENGTH - 2))   /* round bit */		\
548c2ecf20Sopenharmony_ci	if (((int_value << 34 - SGL_EXP_LENGTH) != 0) || Slow(sgl_value)) \
558c2ecf20Sopenharmony_ci		Sall(sgl_value)++
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define Dint_isinexact_to_sgl(dint_valueA,dint_valueB)		\
588c2ecf20Sopenharmony_ci    (((Dintp1(dint_valueA) << 33 - SGL_EXP_LENGTH) != 0) || Dintp2(dint_valueB))
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define Sgl_roundnearest_from_dint(dint_valueA,dint_valueB,sgl_value)	\
618c2ecf20Sopenharmony_ci    if (Dintp1(dint_valueA) & 1<<(SGL_EXP_LENGTH - 2)) 			\
628c2ecf20Sopenharmony_ci	if (((Dintp1(dint_valueA) << 34 - SGL_EXP_LENGTH) != 0) ||	\
638c2ecf20Sopenharmony_ci    	Dintp2(dint_valueB) || Slow(sgl_value)) Sall(sgl_value)++
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define Dint_isinexact_to_dbl(dint_value) 	\
668c2ecf20Sopenharmony_ci    (Dintp2(dint_value) << 33 - DBL_EXP_LENGTH)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define Dbl_roundnearest_from_dint(dint_opndB,dbl_opndA,dbl_opndB) 	\
698c2ecf20Sopenharmony_ci    if (Dintp2(dint_opndB) & 1<<(DBL_EXP_LENGTH - 2))			\
708c2ecf20Sopenharmony_ci       if ((Dintp2(dint_opndB) << 34 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB))  \
718c2ecf20Sopenharmony_ci          if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define Sgl_isone_roundbit(sgl_value,exponent)			\
748c2ecf20Sopenharmony_ci    ((Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) >> 31)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define Sgl_isone_stickybit(sgl_value,exponent)		\
778c2ecf20Sopenharmony_ci    (exponent < (SGL_P - 2) ?				\
788c2ecf20Sopenharmony_ci     Sall(sgl_value) << (SGL_EXP_LENGTH + 2 + exponent) : FALSE)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/*
828c2ecf20Sopenharmony_ci * Double format macros
838c2ecf20Sopenharmony_ci */
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#define Dbl_to_sgl_exponent(src_exponent,dest)			\
868c2ecf20Sopenharmony_ci    dest = src_exponent + (SGL_BIAS - DBL_BIAS)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define Dbl_to_sgl_mantissa(srcA,srcB,dest,inexact,guard,sticky,odd)	\
898c2ecf20Sopenharmony_ci    Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); 	\
908c2ecf20Sopenharmony_ci    guard = Dbit3p2(srcB);					\
918c2ecf20Sopenharmony_ci    sticky = Dallp2(srcB)<<4;					\
928c2ecf20Sopenharmony_ci    inexact = guard | sticky;					\
938c2ecf20Sopenharmony_ci    odd = Dbit2p2(srcB)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define Dbl_to_sgl_denormalized(srcA,srcB,exp,dest,inexact,guard,sticky,odd,tiny) \
968c2ecf20Sopenharmony_ci    Deposit_dexponent(srcA,1);						\
978c2ecf20Sopenharmony_ci    tiny = TRUE;							\
988c2ecf20Sopenharmony_ci    if (exp >= -2) {							\
998c2ecf20Sopenharmony_ci	if (exp == 0) {							\
1008c2ecf20Sopenharmony_ci	    inexact = Dallp2(srcB) << 3;				\
1018c2ecf20Sopenharmony_ci	    guard = inexact >> 31;					\
1028c2ecf20Sopenharmony_ci	    sticky = inexact << 1;					\
1038c2ecf20Sopenharmony_ci	    Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest);	\
1048c2ecf20Sopenharmony_ci	    odd = dest << 31;						\
1058c2ecf20Sopenharmony_ci	    if (inexact) {						\
1068c2ecf20Sopenharmony_ci		switch(Rounding_mode()) {				\
1078c2ecf20Sopenharmony_ci		    case ROUNDPLUS:					\
1088c2ecf20Sopenharmony_ci			if (Dbl_iszero_sign(srcA)) {			\
1098c2ecf20Sopenharmony_ci			    dest++;					\
1108c2ecf20Sopenharmony_ci			    if (Sgl_isone_hidden(dest))	\
1118c2ecf20Sopenharmony_ci				tiny = FALSE;				\
1128c2ecf20Sopenharmony_ci			    dest--;					\
1138c2ecf20Sopenharmony_ci			}						\
1148c2ecf20Sopenharmony_ci			break;						\
1158c2ecf20Sopenharmony_ci		    case ROUNDMINUS:					\
1168c2ecf20Sopenharmony_ci			if (Dbl_isone_sign(srcA)) {			\
1178c2ecf20Sopenharmony_ci			    dest++;					\
1188c2ecf20Sopenharmony_ci			    if (Sgl_isone_hidden(dest))	\
1198c2ecf20Sopenharmony_ci				tiny = FALSE;				\
1208c2ecf20Sopenharmony_ci			    dest--;					\
1218c2ecf20Sopenharmony_ci			}						\
1228c2ecf20Sopenharmony_ci			break;						\
1238c2ecf20Sopenharmony_ci		    case ROUNDNEAREST:					\
1248c2ecf20Sopenharmony_ci			if (guard && (sticky || odd)) {			\
1258c2ecf20Sopenharmony_ci			    dest++;					\
1268c2ecf20Sopenharmony_ci			    if (Sgl_isone_hidden(dest))	\
1278c2ecf20Sopenharmony_ci				tiny = FALSE;				\
1288c2ecf20Sopenharmony_ci			    dest--;					\
1298c2ecf20Sopenharmony_ci			}						\
1308c2ecf20Sopenharmony_ci			break;						\
1318c2ecf20Sopenharmony_ci		}							\
1328c2ecf20Sopenharmony_ci	    }								\
1338c2ecf20Sopenharmony_ci		/* shift right by one to get correct result */		\
1348c2ecf20Sopenharmony_ci		guard = odd;						\
1358c2ecf20Sopenharmony_ci		sticky = inexact;					\
1368c2ecf20Sopenharmony_ci		inexact |= guard;					\
1378c2ecf20Sopenharmony_ci		dest >>= 1;						\
1388c2ecf20Sopenharmony_ci    		Deposit_dsign(srcA,0);					\
1398c2ecf20Sopenharmony_ci    	        Shiftdouble(Dallp1(srcA),Dallp2(srcB),30,dest);		\
1408c2ecf20Sopenharmony_ci	        odd = dest << 31;					\
1418c2ecf20Sopenharmony_ci	}								\
1428c2ecf20Sopenharmony_ci	else {								\
1438c2ecf20Sopenharmony_ci    	    inexact = Dallp2(srcB) << (2 + exp);			\
1448c2ecf20Sopenharmony_ci    	    guard = inexact >> 31;					\
1458c2ecf20Sopenharmony_ci    	    sticky = inexact << 1; 					\
1468c2ecf20Sopenharmony_ci    	    Deposit_dsign(srcA,0);					\
1478c2ecf20Sopenharmony_ci    	    if (exp == -2) dest = Dallp1(srcA);				\
1488c2ecf20Sopenharmony_ci    	    else Variable_shift_double(Dallp1(srcA),Dallp2(srcB),30-exp,dest); \
1498c2ecf20Sopenharmony_ci    	    odd = dest << 31;						\
1508c2ecf20Sopenharmony_ci	}								\
1518c2ecf20Sopenharmony_ci    }									\
1528c2ecf20Sopenharmony_ci    else {								\
1538c2ecf20Sopenharmony_ci    	Deposit_dsign(srcA,0);						\
1548c2ecf20Sopenharmony_ci    	if (exp > (1 - SGL_P)) {					\
1558c2ecf20Sopenharmony_ci    	    dest = Dallp1(srcA) >> (- 2 - exp);				\
1568c2ecf20Sopenharmony_ci    	    inexact = Dallp1(srcA) << (34 + exp);			\
1578c2ecf20Sopenharmony_ci    	    guard = inexact >> 31;					\
1588c2ecf20Sopenharmony_ci    	    sticky = (inexact << 1) | Dallp2(srcB);			\
1598c2ecf20Sopenharmony_ci    	    inexact |= Dallp2(srcB); 					\
1608c2ecf20Sopenharmony_ci    	    odd = dest << 31;						\
1618c2ecf20Sopenharmony_ci    	}								\
1628c2ecf20Sopenharmony_ci    	else {								\
1638c2ecf20Sopenharmony_ci    	    dest = 0;							\
1648c2ecf20Sopenharmony_ci    	    inexact = Dallp1(srcA) | Dallp2(srcB);			\
1658c2ecf20Sopenharmony_ci    	    if (exp == (1 - SGL_P)) {					\
1668c2ecf20Sopenharmony_ci    	    	guard = Dhidden(srcA);					\
1678c2ecf20Sopenharmony_ci    	    	sticky = Dmantissap1(srcA) | Dallp2(srcB); 		\
1688c2ecf20Sopenharmony_ci    	    }								\
1698c2ecf20Sopenharmony_ci    	    else {							\
1708c2ecf20Sopenharmony_ci    	    	guard = 0;						\
1718c2ecf20Sopenharmony_ci    	    	sticky = inexact;					\
1728c2ecf20Sopenharmony_ci    	    }								\
1738c2ecf20Sopenharmony_ci    	    odd = 0;							\
1748c2ecf20Sopenharmony_ci    	}								\
1758c2ecf20Sopenharmony_ci    }									\
1768c2ecf20Sopenharmony_ci    exp = 0
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#define Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent)		\
1798c2ecf20Sopenharmony_ci    (exponent < (DBL_P-33) ? 						\
1808c2ecf20Sopenharmony_ci     Dallp2(dbl_valueB) || Dallp1(dbl_valueA) << (DBL_EXP_LENGTH+1+exponent) : \
1818c2ecf20Sopenharmony_ci     (exponent < (DBL_P-1) ? Dallp2(dbl_valueB) << (exponent + (33-DBL_P)) :   \
1828c2ecf20Sopenharmony_ci      FALSE))
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#define Dbl_isoverflow_to_int(exponent,dbl_valueA,dbl_valueB)		\
1858c2ecf20Sopenharmony_ci    ((exponent > SGL_FX_MAX_EXP + 1) || Dsign(dbl_valueA)==0 ||		\
1868c2ecf20Sopenharmony_ci     Dmantissap1(dbl_valueA)!=0 || (Dallp2(dbl_valueB)>>21)!=0 )
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define Dbl_isone_roundbit(dbl_valueA,dbl_valueB,exponent)              \
1898c2ecf20Sopenharmony_ci    ((exponent < (DBL_P - 33) ?						\
1908c2ecf20Sopenharmony_ci      Dallp1(dbl_valueA) >> ((30 - DBL_EXP_LENGTH) - exponent) :	\
1918c2ecf20Sopenharmony_ci      Dallp2(dbl_valueB) >> ((DBL_P - 2) - exponent)) & 1)
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#define Dbl_isone_stickybit(dbl_valueA,dbl_valueB,exponent)		\
1948c2ecf20Sopenharmony_ci    (exponent < (DBL_P-34) ? 						\
1958c2ecf20Sopenharmony_ci     (Dallp2(dbl_valueB) || Dallp1(dbl_valueA)<<(DBL_EXP_LENGTH+2+exponent)) : \
1968c2ecf20Sopenharmony_ci     (exponent<(DBL_P-2) ? (Dallp2(dbl_valueB) << (exponent + (34-DBL_P))) : \
1978c2ecf20Sopenharmony_ci      FALSE))
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci/* Int macros */
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci#define Int_from_sgl_mantissa(sgl_value,exponent)	\
2038c2ecf20Sopenharmony_ci    Sall(sgl_value) = 				\
2048c2ecf20Sopenharmony_ci    	(unsigned)(Sall(sgl_value) << SGL_EXP_LENGTH)>>(31 - exponent)
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci#define Int_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent)	\
2078c2ecf20Sopenharmony_ci    Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),22,Dallp1(dbl_valueA)); \
2088c2ecf20Sopenharmony_ci    if (exponent < 31) Dallp1(dbl_valueA) >>= 30 - exponent;	\
2098c2ecf20Sopenharmony_ci    else Dallp1(dbl_valueA) <<= 1
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci#define Int_negate(int_value) int_value = -int_value
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/* Dint macros */
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci#define Dint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB)	\
2178c2ecf20Sopenharmony_ci    {Sall(sgl_value) <<= SGL_EXP_LENGTH;  /*  left-justify  */		\
2188c2ecf20Sopenharmony_ci    if (exponent <= 31) {						\
2198c2ecf20Sopenharmony_ci    	Dintp1(dresultA) = 0;						\
2208c2ecf20Sopenharmony_ci    	Dintp2(dresultB) = (unsigned)Sall(sgl_value) >> (31 - exponent); \
2218c2ecf20Sopenharmony_ci    }									\
2228c2ecf20Sopenharmony_ci    else {								\
2238c2ecf20Sopenharmony_ci    	Dintp1(dresultA) = Sall(sgl_value) >> (63 - exponent);		\
2248c2ecf20Sopenharmony_ci    	Dintp2(dresultB) = Sall(sgl_value) << (exponent - 31);		\
2258c2ecf20Sopenharmony_ci    }}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci#define Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \
2298c2ecf20Sopenharmony_ci    {if (exponent < 32) {						\
2308c2ecf20Sopenharmony_ci    	Dintp1(destA) = 0;						\
2318c2ecf20Sopenharmony_ci    	if (exponent <= 20)						\
2328c2ecf20Sopenharmony_ci    	    Dintp2(destB) = Dallp1(dbl_valueA) >> 20-exponent;		\
2338c2ecf20Sopenharmony_ci    	else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
2348c2ecf20Sopenharmony_ci	     52-exponent,Dintp2(destB));					\
2358c2ecf20Sopenharmony_ci    }									\
2368c2ecf20Sopenharmony_ci    else {								\
2378c2ecf20Sopenharmony_ci    	if (exponent <= 52) {						\
2388c2ecf20Sopenharmony_ci    	    Dintp1(destA) = Dallp1(dbl_valueA) >> 52-exponent;		\
2398c2ecf20Sopenharmony_ci	    if (exponent == 52) Dintp2(destB) = Dallp2(dbl_valueB);	\
2408c2ecf20Sopenharmony_ci	    else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
2418c2ecf20Sopenharmony_ci	    52-exponent,Dintp2(destB));					\
2428c2ecf20Sopenharmony_ci        }								\
2438c2ecf20Sopenharmony_ci    	else {								\
2448c2ecf20Sopenharmony_ci    	    Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \
2458c2ecf20Sopenharmony_ci	    84-exponent,Dintp1(destA));					\
2468c2ecf20Sopenharmony_ci    	    Dintp2(destB) = Dallp2(dbl_valueB) << exponent-52;		\
2478c2ecf20Sopenharmony_ci    	}								\
2488c2ecf20Sopenharmony_ci    }}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci#define Dint_setzero(dresultA,dresultB) 	\
2518c2ecf20Sopenharmony_ci    Dintp1(dresultA) = 0; 	\
2528c2ecf20Sopenharmony_ci    Dintp2(dresultB) = 0
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci#define Dint_setone_sign(dresultA,dresultB)		\
2558c2ecf20Sopenharmony_ci    Dintp1(dresultA) = ~Dintp1(dresultA);		\
2568c2ecf20Sopenharmony_ci    if ((Dintp2(dresultB) = -Dintp2(dresultB)) == 0) Dintp1(dresultA)++
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci#define Dint_set_minint(dresultA,dresultB)		\
2598c2ecf20Sopenharmony_ci    Dintp1(dresultA) = (unsigned int)1<<31;		\
2608c2ecf20Sopenharmony_ci    Dintp2(dresultB) = 0
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci#define Dint_isone_lowp2(dresultB)  (Dintp2(dresultB) & 01)
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci#define Dint_increment(dresultA,dresultB) 		\
2658c2ecf20Sopenharmony_ci    if ((++Dintp2(dresultB))==0) Dintp1(dresultA)++
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci#define Dint_decrement(dresultA,dresultB) 		\
2688c2ecf20Sopenharmony_ci    if ((Dintp2(dresultB)--)==0) Dintp1(dresultA)--
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci#define Dint_negate(dresultA,dresultB)			\
2718c2ecf20Sopenharmony_ci    Dintp1(dresultA) = ~Dintp1(dresultA);		\
2728c2ecf20Sopenharmony_ci    if ((Dintp2(dresultB) = -Dintp2(dresultB))==0) Dintp1(dresultA)++
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci#define Dint_copyfromptr(src,destA,destB) \
2758c2ecf20Sopenharmony_ci     Dintp1(destA) = src->wd0;		\
2768c2ecf20Sopenharmony_ci     Dintp2(destB) = src->wd1
2778c2ecf20Sopenharmony_ci#define Dint_copytoptr(srcA,srcB,dest)	\
2788c2ecf20Sopenharmony_ci    dest->wd0 = Dintp1(srcA);		\
2798c2ecf20Sopenharmony_ci    dest->wd1 = Dintp2(srcB)
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci/* other macros  */
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci#define Find_ms_one_bit(value, position)	\
2858c2ecf20Sopenharmony_ci    {						\
2868c2ecf20Sopenharmony_ci	int var;				\
2878c2ecf20Sopenharmony_ci	for (var=8; var >=1; var >>= 1) {	\
2888c2ecf20Sopenharmony_ci	    if (value >> 32 - position)		\
2898c2ecf20Sopenharmony_ci		position -= var;		\
2908c2ecf20Sopenharmony_ci		else position += var;		\
2918c2ecf20Sopenharmony_ci	}					\
2928c2ecf20Sopenharmony_ci	if ((value >> 32 - position) == 0)	\
2938c2ecf20Sopenharmony_ci	    position--;				\
2948c2ecf20Sopenharmony_ci	else position -= 2;			\
2958c2ecf20Sopenharmony_ci    }
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci/*
2998c2ecf20Sopenharmony_ci * Unsigned int macros
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_ci#define Duint_copyfromptr(src,destA,destB) \
3028c2ecf20Sopenharmony_ci    Dint_copyfromptr(src,destA,destB)
3038c2ecf20Sopenharmony_ci#define Duint_copytoptr(srcA,srcB,dest)	\
3048c2ecf20Sopenharmony_ci    Dint_copytoptr(srcA,srcB,dest)
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci#define Suint_isinexact_to_sgl(int_value) \
3078c2ecf20Sopenharmony_ci    (int_value << 32 - SGL_EXP_LENGTH)
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci#define Sgl_roundnearest_from_suint(suint_value,sgl_value)		\
3108c2ecf20Sopenharmony_ci    if (suint_value & 1<<(SGL_EXP_LENGTH - 1))   /* round bit */	\
3118c2ecf20Sopenharmony_ci    	if ((suint_value << 33 - SGL_EXP_LENGTH) || Slow(sgl_value))	\
3128c2ecf20Sopenharmony_ci		Sall(sgl_value)++
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci#define Duint_isinexact_to_sgl(duint_valueA,duint_valueB)	\
3158c2ecf20Sopenharmony_ci    ((Duintp1(duint_valueA) << 32 - SGL_EXP_LENGTH) || Duintp2(duint_valueB))
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci#define Sgl_roundnearest_from_duint(duint_valueA,duint_valueB,sgl_value) \
3188c2ecf20Sopenharmony_ci    if (Duintp1(duint_valueA) & 1<<(SGL_EXP_LENGTH - 1))		\
3198c2ecf20Sopenharmony_ci    	if ((Duintp1(duint_valueA) << 33 - SGL_EXP_LENGTH) ||		\
3208c2ecf20Sopenharmony_ci    	Duintp2(duint_valueB) || Slow(sgl_value)) Sall(sgl_value)++
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci#define Duint_isinexact_to_dbl(duint_value) 	\
3238c2ecf20Sopenharmony_ci    (Duintp2(duint_value) << 32 - DBL_EXP_LENGTH)
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci#define Dbl_roundnearest_from_duint(duint_opndB,dbl_opndA,dbl_opndB) 	\
3268c2ecf20Sopenharmony_ci    if (Duintp2(duint_opndB) & 1<<(DBL_EXP_LENGTH - 1))			\
3278c2ecf20Sopenharmony_ci       if ((Duintp2(duint_opndB) << 33 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \
3288c2ecf20Sopenharmony_ci          if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci#define Suint_from_sgl_mantissa(src,exponent,result)	\
3318c2ecf20Sopenharmony_ci    Sall(result) = (unsigned)(Sall(src) << SGL_EXP_LENGTH)>>(31 - exponent)
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci#define Sgl_isinexact_to_unsigned(sgl_value,exponent)	\
3348c2ecf20Sopenharmony_ci    Sgl_isinexact_to_fix(sgl_value,exponent)
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci#define Duint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB)	\
3378c2ecf20Sopenharmony_ci  {unsigned int val = Sall(sgl_value) << SGL_EXP_LENGTH;		\
3388c2ecf20Sopenharmony_ci    if (exponent <= 31) {						\
3398c2ecf20Sopenharmony_ci	Dintp1(dresultA) = 0;						\
3408c2ecf20Sopenharmony_ci	Dintp2(dresultB) = val >> (31 - exponent);			\
3418c2ecf20Sopenharmony_ci    }									\
3428c2ecf20Sopenharmony_ci    else {								\
3438c2ecf20Sopenharmony_ci	Dintp1(dresultA) = val >> (63 - exponent);			\
3448c2ecf20Sopenharmony_ci	Dintp2(dresultB) = exponent <= 62 ? val << (exponent - 31) : 0;	\
3458c2ecf20Sopenharmony_ci    }									\
3468c2ecf20Sopenharmony_ci  }
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci#define Duint_setzero(dresultA,dresultB) 	\
3498c2ecf20Sopenharmony_ci    Dint_setzero(dresultA,dresultB)
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci#define Duint_increment(dresultA,dresultB) Dint_increment(dresultA,dresultB)
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci#define Duint_isone_lowp2(dresultB)  Dint_isone_lowp2(dresultB)
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci#define Suint_from_dbl_mantissa(srcA,srcB,exponent,dest) \
3568c2ecf20Sopenharmony_ci    Shiftdouble(Dallp1(srcA),Dallp2(srcB),21,dest); \
3578c2ecf20Sopenharmony_ci    dest = (unsigned)dest >> 31 - exponent
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci#define Dbl_isinexact_to_unsigned(dbl_valueA,dbl_valueB,exponent) \
3608c2ecf20Sopenharmony_ci    Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent)
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci#define Duint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \
3638c2ecf20Sopenharmony_ci    Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB)
364