⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmpyfadd.c

📁 这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自测试~但就算用来做参考资料也是非常好的
💻 C
📖 第 1 页 / 共 5 页
字号:
					/* either exactly half way and odd or					 * more than 1/2ulp */					Dbl_increment(resultp1,resultp2);				}			}	    		break;		case ROUNDPLUS:	    		if (Dbl_iszero_sign(resultp1)) {				/* Round up positive results */				Dbl_increment(resultp1,resultp2);			}			break;	    		case ROUNDMINUS:	    		if (Dbl_isone_sign(resultp1)) {				/* Round down negative results */				Dbl_increment(resultp1,resultp2);			}	    		case ROUNDZERO:;			/* truncate is simple */		} /* end switch... */		if (Dbl_isone_hiddenoverflow(resultp1)) result_exponent++;	}	if (result_exponent >= DBL_INFINITY_EXPONENT) {		/* Overflow */		if (Is_overflowtrap_enabled()) {                        /*                         * Adjust bias of result                         */                        Dbl_setwrapped_exponent(resultp1,result_exponent,ovfl);                        Dbl_copytoptr(resultp1,resultp2,dstptr);                        if (inexact)                            if (Is_inexacttrap_enabled())                                return (OPC_2E_OVERFLOWEXCEPTION |					OPC_2E_INEXACTEXCEPTION);                            else Set_inexactflag();                        return (OPC_2E_OVERFLOWEXCEPTION);		}		inexact = TRUE;		Set_overflowflag();		Dbl_setoverflow(resultp1,resultp2);	} else if (result_exponent <= 0) {	/* underflow case */		if (Is_underflowtrap_enabled()) {                        /*                         * Adjust bias of result                         */                	Dbl_setwrapped_exponent(resultp1,result_exponent,unfl);			Dbl_copytoptr(resultp1,resultp2,dstptr);                        if (inexact)                            if (Is_inexacttrap_enabled())                                return (OPC_2E_UNDERFLOWEXCEPTION |					OPC_2E_INEXACTEXCEPTION);                            else Set_inexactflag();	    		return(OPC_2E_UNDERFLOWEXCEPTION);		}		else if (inexact && is_tiny) Set_underflowflag();	}	else Dbl_set_exponent(resultp1,result_exponent);	Dbl_copytoptr(resultp1,resultp2,dstptr);	if (inexact) 		if (Is_inexacttrap_enabled()) return(OPC_2E_INEXACTEXCEPTION);		else Set_inexactflag();    	return(NOEXCEPTION);}/* *  Single Floating-point Multiply Fused Add */sgl_fmpyfadd(src1ptr,src2ptr,src3ptr,status,dstptr)sgl_floating_point *src1ptr, *src2ptr, *src3ptr, *dstptr;unsigned int *status;{	unsigned int opnd1, opnd2, opnd3;	register unsigned int tmpresp1, tmpresp2;	unsigned int rightp1, rightp2;	unsigned int resultp1, resultp2 = 0;	register int mpy_exponent, add_exponent, count;	boolean inexact = FALSE, is_tiny = FALSE;	unsigned int signlessleft1, signlessright1, save;	register int result_exponent, diff_exponent;	int sign_save, jumpsize;		Sgl_copyfromptr(src1ptr,opnd1);	Sgl_copyfromptr(src2ptr,opnd2);	Sgl_copyfromptr(src3ptr,opnd3);	/* 	 * set sign bit of result of multiply	 */	if (Sgl_sign(opnd1) ^ Sgl_sign(opnd2)) 		Sgl_setnegativezero(resultp1); 	else Sgl_setzero(resultp1);	/*	 * Generate multiply exponent 	 */	mpy_exponent = Sgl_exponent(opnd1) + Sgl_exponent(opnd2) - SGL_BIAS;	/*	 * check first operand for NaN's or infinity	 */	if (Sgl_isinfinity_exponent(opnd1)) {		if (Sgl_iszero_mantissa(opnd1)) {			if (Sgl_isnotnan(opnd2) && Sgl_isnotnan(opnd3)) {				if (Sgl_iszero_exponentmantissa(opnd2)) {					/* 					 * invalid since operands are infinity 					 * and zero 					 */					if (Is_invalidtrap_enabled())						return(OPC_2E_INVALIDEXCEPTION);					Set_invalidflag();					Sgl_makequietnan(resultp1);					Sgl_copytoptr(resultp1,dstptr);					return(NOEXCEPTION);				}				/*				 * Check third operand for infinity with a				 *  sign opposite of the multiply result				 */				if (Sgl_isinfinity(opnd3) &&				    (Sgl_sign(resultp1) ^ Sgl_sign(opnd3))) {					/* 					 * invalid since attempting a magnitude					 * subtraction of infinities					 */					if (Is_invalidtrap_enabled())						return(OPC_2E_INVALIDEXCEPTION);					Set_invalidflag();					Sgl_makequietnan(resultp1);					Sgl_copytoptr(resultp1,dstptr);					return(NOEXCEPTION);				}				/*			 	 * return infinity			 	 */				Sgl_setinfinity_exponentmantissa(resultp1);				Sgl_copytoptr(resultp1,dstptr);				return(NOEXCEPTION);			}		}		else {			/*		 	 * is NaN; signaling or quiet?		 	 */			if (Sgl_isone_signaling(opnd1)) {				/* trap if INVALIDTRAP enabled */				if (Is_invalidtrap_enabled()) 			    		return(OPC_2E_INVALIDEXCEPTION);				/* make NaN quiet */				Set_invalidflag();				Sgl_set_quiet(opnd1);			}			/* 			 * is second operand a signaling NaN? 			 */			else if (Sgl_is_signalingnan(opnd2)) {				/* trap if INVALIDTRAP enabled */				if (Is_invalidtrap_enabled())			    		return(OPC_2E_INVALIDEXCEPTION);				/* make NaN quiet */				Set_invalidflag();				Sgl_set_quiet(opnd2);				Sgl_copytoptr(opnd2,dstptr);				return(NOEXCEPTION);			}			/* 			 * is third operand a signaling NaN? 			 */			else if (Sgl_is_signalingnan(opnd3)) {				/* trap if INVALIDTRAP enabled */				if (Is_invalidtrap_enabled())			    		return(OPC_2E_INVALIDEXCEPTION);				/* make NaN quiet */				Set_invalidflag();				Sgl_set_quiet(opnd3);				Sgl_copytoptr(opnd3,dstptr);				return(NOEXCEPTION);			}			/*		 	 * return quiet NaN		 	 */			Sgl_copytoptr(opnd1,dstptr);			return(NOEXCEPTION);		}	}	/*	 * check second operand for NaN's or infinity	 */	if (Sgl_isinfinity_exponent(opnd2)) {		if (Sgl_iszero_mantissa(opnd2)) {			if (Sgl_isnotnan(opnd3)) {				if (Sgl_iszero_exponentmantissa(opnd1)) {					/* 					 * invalid since multiply operands are					 * zero & infinity					 */					if (Is_invalidtrap_enabled())						return(OPC_2E_INVALIDEXCEPTION);					Set_invalidflag();					Sgl_makequietnan(opnd2);					Sgl_copytoptr(opnd2,dstptr);					return(NOEXCEPTION);				}				/*				 * Check third operand for infinity with a				 *  sign opposite of the multiply result				 */				if (Sgl_isinfinity(opnd3) &&				    (Sgl_sign(resultp1) ^ Sgl_sign(opnd3))) {					/* 					 * invalid since attempting a magnitude					 * subtraction of infinities					 */					if (Is_invalidtrap_enabled())				       		return(OPC_2E_INVALIDEXCEPTION);				       	Set_invalidflag();				       	Sgl_makequietnan(resultp1);					Sgl_copytoptr(resultp1,dstptr);					return(NOEXCEPTION);				}				/*				 * return infinity				 */				Sgl_setinfinity_exponentmantissa(resultp1);				Sgl_copytoptr(resultp1,dstptr);				return(NOEXCEPTION);			}		}		else {			/*			 * is NaN; signaling or quiet?			 */			if (Sgl_isone_signaling(opnd2)) {				/* trap if INVALIDTRAP enabled */				if (Is_invalidtrap_enabled())					return(OPC_2E_INVALIDEXCEPTION);				/* make NaN quiet */				Set_invalidflag();				Sgl_set_quiet(opnd2);			}			/* 			 * is third operand a signaling NaN? 			 */			else if (Sgl_is_signalingnan(opnd3)) {			       	/* trap if INVALIDTRAP enabled */			       	if (Is_invalidtrap_enabled())				   		return(OPC_2E_INVALIDEXCEPTION);			       	/* make NaN quiet */			       	Set_invalidflag();			       	Sgl_set_quiet(opnd3);				Sgl_copytoptr(opnd3,dstptr);		       		return(NOEXCEPTION);			}			/*			 * return quiet NaN			 */			Sgl_copytoptr(opnd2,dstptr);			return(NOEXCEPTION);		}	}	/*	 * check third operand for NaN's or infinity	 */	if (Sgl_isinfinity_exponent(opnd3)) {		if (Sgl_iszero_mantissa(opnd3)) {			/* return infinity */			Sgl_copytoptr(opnd3,dstptr);			return(NOEXCEPTION);		} else {			/*			 * is NaN; signaling or quiet?			 */			if (Sgl_isone_signaling(opnd3)) {				/* trap if INVALIDTRAP enabled */				if (Is_invalidtrap_enabled())					return(OPC_2E_INVALIDEXCEPTION);				/* make NaN quiet */				Set_invalidflag();				Sgl_set_quiet(opnd3);			}			/*			 * return quiet NaN 			 */			Sgl_copytoptr(opnd3,dstptr);			return(NOEXCEPTION);		}    	}	/*	 * Generate multiply mantissa	 */	if (Sgl_isnotzero_exponent(opnd1)) {		/* set hidden bit */		Sgl_clear_signexponent_set_hidden(opnd1);	}	else {		/* check for zero */		if (Sgl_iszero_mantissa(opnd1)) {			/*			 * Perform the add opnd3 with zero here.			 */			if (Sgl_iszero_exponentmantissa(opnd3)) {				if (Is_rounding_mode(ROUNDMINUS)) {					Sgl_or_signs(opnd3,resultp1);				} else {					Sgl_and_signs(opnd3,resultp1);				}			}			/*			 * Now let's check for trapped underflow case.			 */			else if (Sgl_iszero_exponent(opnd3) &&			         Is_underflowtrap_enabled()) {                    		/* need to normalize results mantissa */                    		sign_save = Sgl_signextendedsign(opnd3);				result_exponent = 0;                    		Sgl_leftshiftby1(opnd3);                    		Sgl_normalize(opnd3,result_exponent);                    		Sgl_set_sign(opnd3,/*using*/sign_save);                    		Sgl_setwrapped_exponent(opnd3,result_exponent,							unfl);                    		Sgl_copytoptr(opnd3,dstptr);                    		/* inexact = FALSE */                    		return(OPC_2E_UNDERFLOWEXCEPTION);			}			Sgl_copytoptr(opnd3,dstptr);			return(NOEXCEPTION);		}		/* is denormalized, adjust exponent */		Sgl_clear_signexponent(opnd1);		Sgl_leftshiftby1(opnd1);		Sgl_normalize(opnd1,mpy_exponent);	}	/* opnd2 needs to have hidden bit set with msb in hidden bit */	if (Sgl_isnotzero_exponent(opnd2)) {		Sgl_clear_signexponent_set_hidden(opnd2);	}	else {		/* check for zero */		if (Sgl_iszero_mantissa(opnd2)) {			/*			 * Perform the add opnd3 with zero here.			 */			if (Sgl_iszero_exponentmantissa(opnd3)) {				if (Is_rounding_mode(ROUNDMINUS)) {					Sgl_or_signs(opnd3,resultp1);				} else {					Sgl_and_signs(opnd3,resultp1);				}			}			/*			 * Now let's check for trapped underflow case.			 */			else if (Sgl_iszero_exponent(opnd3) &&			    Is_underflowtrap_enabled()) {                    		/* need to normalize results mantissa */                    		sign_save = Sgl_signextendedsign(opnd3);				result_exponent = 0;                    		Sgl_leftshiftby1(opnd3);                    		Sgl_normalize(opnd3,result_exponent);                    		Sgl_set_sign(opnd3,/*using*/sign_save);                    		Sgl_setwrapped_exponent(opnd3,result_exponent,							unfl);                    		Sgl_copytoptr(opnd3,dstptr);                    		/* inexact = FALSE */                    		return(OPC_2E_UNDERFLOWEXCEPTION);			}			Sgl_copytoptr(opnd3,dstptr);			return(NOEXCEPTION);		}		/* is denormalized; want to normalize */		Sgl_clear_signexponent(opnd2);		Sgl_leftshiftby1(opnd2);		Sgl_normalize(opnd2,mpy_exponent);	}	/* Multiply the first two source mantissas together */	/* 	 * The intermediate result will be kept in tmpres,	 * which needs enough room for 106 bits of mantissa,	 * so lets call it a Double extended.	 */	Sglext_setzero(tmpresp1,tmpresp2);	/* 	 * Four bits at a time are inspected in each loop, and a 	 * simple shift and add multiply algorithm is used. 	 */ 	for (count = SGL_P-1; count >= 0; count -= 4) {		Sglext_rightshiftby4(tmpresp1,tmpresp2);		if (Sbit28(opnd1)) {	 		/* Twoword_add should be an ADD followed by 2 ADDC's */			Twoword_add(tmpresp1, tmpresp2, opnd2<<3, 0);		}		if (Sbit29(opnd1)) {			Twoword_add(tmpresp1, tmpresp2, opnd2<<2, 0);		}		if (Sbit30(opnd1)) {			Twoword_add(tmpresp1, tmpresp2, opnd2<<1, 0);		}		if (Sbit31(opnd1)) {			Twoword_add(tmpresp1, tmpresp2, opnd2, 0);		}		Sgl_rightshiftby4(opnd1);	}	if (Is_sexthiddenoverflow(tmpresp1)) {		/* result mantissa >= 2 (mantissa overflow) */		mpy_exponent++;		Sglext_rightshiftby4(tmpresp1,tmpresp2);	} else {		Sglext_rightshiftby3(tmpresp1,tmpresp2);	}	/*	 * Restore the sign of the mpy result which was saved in resultp1.	 * The exponent will continue to be kept in mpy_exponent.	 */	Sglext_set_sign(tmpresp1,Sgl_sign(resultp1));	/* 	 * No rounding is required, since the result of the multiply	 * is exact in the extended format.	 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -