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

📄 softfloat.java

📁 Java Op Processor java vhdl processor
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	aSign = a>>>31;	shiftCount = aExp - 0x96;	if ( 0 <= shiftCount ) {		if ( 0x9E <= aExp ) {			if ( a != 0xCF000000 ) {//				float_raise( float_flag_invalid );				// if ( ! aSign || ( ( aExp == 0xFF ) && aSig ) ) {				if ( aSign==0 || ( ( aExp == 0xFF ) && aSig!=0 ) ) {					return 0x7FFFFFFF;				}			}			return 0x80000000;		}		z = ( aSig | 0x00800000 )<<shiftCount;		if ( aSign!=0 ) z = - z;	}	else {		if ( aExp < 0x7E ) {			aSigExtra = aExp | aSig;			z = 0;		}		else {			aSig |= 0x00800000;			aSigExtra = aSig<<( shiftCount & 31 );			z = aSig>>>( -shiftCount );		}		// if ( aSigExtra ) float_exception_flags |= float_flag_inexact;		// roundingMode = float_rounding_mode;		// if ( roundingMode == float_round_nearest_even ) {			if ( aSigExtra < 0 ) {				++z;				// if ( (bits32) ( aSigExtra<<1 ) == 0 ) z &= ~1;				if ( ( aSigExtra<<1 ) == 0 ) z &= ~1;			}			if ( aSign!=0 ) z = - z;//		}//		else {//			aSigExtra = ( aSigExtra != 0 );//			if ( aSign ) {//				z += ( roundingMode == float_round_down ) & aSigExtra;//				z = - z;//			}//			else {//				z += ( roundingMode == float_round_up ) & aSigExtra;//			}//		}	}	return z;}*//*----------------------------------------------------------------------------| Returns the result of converting the single-precision floating-point value| `a' to the 32-bit two's complement integer format.  The conversion is| performed according to the IEC/IEEE Standard for Binary Floating-Point| Arithmetic, except that the conversion is always rounded toward zero.| If `a' is a NaN, the largest positive integer is returned.  Otherwise, if| the conversion overflows, the largest integer with the same sign as `a' is| returned.*----------------------------------------------------------------------------*/// int32 float32_to_int32_round_to_zero( float32 a )public static int float32_to_int32_round_to_zero(int a){	// flag aSign;	// int16 aExp, shiftCount;	// bits32 aSig;	// int32 z;	int aSign;	int aExp, shiftCount;	int aSig;	int z;	// aSig = extractFloat32Frac( a );	// aExp = extractFloat32Exp( a );	// aSign = extractFloat32Sign( a );	aSig = a & 0x007FFFFF;	aExp = ( a>>>23 ) & 0xFF;	aSign = a>>>31;	shiftCount = aExp - 0x9E;	if ( 0 <= shiftCount ) {		if ( a != 0xCF000000 ) {			// float_raise( float_flag_invalid );			// if ( ! aSign || ( ( aExp == 0xFF ) && aSig ) ) return 0x7FFFFFFF;			if (((aExp == 0xFF) && aSig!=0)) { // NaN				// NaN hase to return 0 in Java!				// That is different form IEEE 754				return 0;			} else if (aSign==0) {				// +INF				return 0x7FFFFFFF;			}		}		return 0x80000000;	}	else if ( aExp <= 0x7E ) {		// if ( aExp | aSig ) float_exception_flags |= float_flag_inexact;		return 0;	}	aSig = ( aSig | 0x00800000 )<<8;	z = aSig>>>( -shiftCount );/*	if ( (bits32) ( aSig<<( shiftCount & 31 ) ) ) {		float_exception_flags |= float_flag_inexact;	}*/	if (aSign!=0) z = - z;	return z;}///*----------------------------------------------------------------------------//| Rounds the single-precision floating-point value `a' to an integer,//| and returns the result as a single-precision floating-point value.  The//| operation is performed according to the IEC/IEEE Standard for Binary//| Floating-Point Arithmetic.//*----------------------------------------------------------------------------*/////float32 float32_round_to_int( float32 a )//{//	flag aSign;//	int16 aExp;//	bits32 lastBitMask, roundBitsMask;//	int8 roundingMode;//	float32 z;////	aExp = extractFloat32Exp( a );//	if ( 0x96 <= aExp ) {//		if ( ( aExp == 0xFF ) && extractFloat32Frac( a ) ) {//			return propagateFloat32NaN( a, a );//		}//		return a;//	}//	if ( aExp <= 0x7E ) {//		if ( (bits32) ( a<<1 ) == 0 ) return a;//		float_exception_flags |= float_flag_inexact;//		aSign = extractFloat32Sign( a );//		switch ( float_rounding_mode ) {//		 case float_round_nearest_even://			if ( ( aExp == 0x7E ) && extractFloat32Frac( a ) ) {//				return packFloat32( aSign, 0x7F, 0 );//			}//			break;//		 case float_round_down://			return aSign ? 0xBF800000 : 0;//		 case float_round_up://			return aSign ? 0x80000000 : 0x3F800000;//		}//		return packFloat32( aSign, 0, 0 );//	}//	lastBitMask = 1;//	lastBitMask <<= 0x96 - aExp;//	roundBitsMask = lastBitMask - 1;//	z = a;//	roundingMode = float_rounding_mode;//	if ( roundingMode == float_round_nearest_even ) {//		z += lastBitMask>>1;//		if ( ( z & roundBitsMask ) == 0 ) z &= ~ lastBitMask;//	}//	else if ( roundingMode != float_round_to_zero ) {//		if ( extractFloat32Sign( z ) ^ ( roundingMode == float_round_up ) ) {//			z += roundBitsMask;//		}//	}//	z &= ~ roundBitsMask;//	if ( z != a ) float_exception_flags |= float_flag_inexact;//	return z;////}///*----------------------------------------------------------------------------| Returns the result of adding the absolute values of the single-precision| floating-point values `a' and `b'.  If `zSign' is 1, the sum is negated| before being returned.  `zSign' is ignored if the result is a NaN.| The addition is performed according to the IEC/IEEE Standard for Binary| Floating-Point Arithmetic.*----------------------------------------------------------------------------*/// static float32 addFloat32Sigs( float32 a, float32 b, flag zSign )static int addFloat32Sigs( int a, int b, int zSign ){	// int16 aExp, bExp, zExp;	// bits32 aSig, bSig, zSig;	// int16 expDiff;	int aExp, bExp, zExp;	int aSig, bSig, zSig;	int expDiff;	// aSig = extractFloat32Frac( a );	// aExp = extractFloat32Exp( a );	// bSig = extractFloat32Frac( b );	// bExp = extractFloat32Exp( b );	aSig = a & 0x007FFFFF;	aExp = ( a>>>23 ) & 0xFF;	bSig = b & 0x007FFFFF;	bExp = ( b>>>23 ) & 0xFF;	expDiff = aExp - bExp;	aSig <<= 6;	bSig <<= 6;	if ( 0 < expDiff ) {		if ( aExp == 0xFF ) {			// if ( aSig!=0 ) return propagateFloat32NaN( a, b );			if ( aSig!=0 ) return 0x7fc00000;			return a;		}		if ( bExp == 0 ) {			--expDiff;		}		else {			bSig |= 0x20000000;		}		bSig = shift32RightJamming(bSig, expDiff);		zExp = aExp;	}	else if ( expDiff < 0 ) {		if ( bExp == 0xFF ) {			// if ( bSig!=0 ) return propagateFloat32NaN( a, b );			if ( bSig!=0 ) return 0x7fc00000;			// return packFloat32( zSign, 0xFF, 0 );			return (((zSign)<<31) + ((0xff)<<23));		}		if ( aExp == 0 ) {			++expDiff;		}		else {			aSig |= 0x20000000;		}		aSig = shift32RightJamming( aSig, -expDiff);		zExp = bExp;	}	else {		if ( aExp == 0xFF ) {			// if ( (aSig | bSig)!=0 ) return propagateFloat32NaN( a, b );			if ( (aSig | bSig)!=0 ) return 0x7fc00000;			return a;		}		// if ( aExp == 0 ) return packFloat32( zSign, 0, ( aSig + bSig )>>>6 );		if ( aExp == 0 ) return (((zSign)<<31) + ((aSig+bSig)>>>6));		zSig = 0x40000000 + aSig + bSig;		zExp = aExp;		return roundAndPackFloat32( zSign, zExp, zSig );	}	aSig |= 0x20000000;	zSig = ( aSig + bSig )<<1;	--zExp;	if ( zSig < 0 ) {		zSig = aSig + bSig;		++zExp;	}	return roundAndPackFloat32( zSign, zExp, zSig );}/*----------------------------------------------------------------------------| Returns the result of subtracting the absolute values of the single-| precision floating-point values `a' and `b'.  If `zSign' is 1, the| difference is negated before being returned.  `zSign' is ignored if the| result is a NaN.  The subtraction is performed according to the IEC/IEEE| Standard for Binary Floating-Point Arithmetic.*----------------------------------------------------------------------------*/// static float32 subFloat32Sigs( float32 a, float32 b, flag zSign )static int subFloat32Sigs( int a, int b, int zSign ){	// int16 aExp, bExp, zExp;	// bits32 aSig, bSig, zSig;	// int16 expDiff;	int aExp, bExp, zExp;	int aSig, bSig, zSig;	int expDiff;	// aSig = extractFloat32Frac( a );	// aExp = extractFloat32Exp( a );	// bSig = extractFloat32Frac( b );	// bExp = extractFloat32Exp( b );	aSig = a & 0x007FFFFF;	aExp = ( a>>>23 ) & 0xFF;	bSig = b & 0x007FFFFF;	bExp = ( b>>>23 ) & 0xFF;	expDiff = aExp - bExp;	aSig <<= 7;	bSig <<= 7;	if ( 0 < expDiff ) {		if ( aExp == 0xFF ) {			// if ( aSig!=0 ) return propagateFloat32NaN( a, b );			if ( aSig!=0 ) return 0x7fc00000;			return a;		}		if ( bExp == 0 ) {			--expDiff;		}		else {			bSig |= 0x40000000;		}		bSig = shift32RightJamming(bSig, expDiff);		aSig |= 0x40000000;		zSig = aSig - bSig;		zExp = aExp;		--zExp;		return normalizeRoundAndPackFloat32( zSign, zExp, zSig );	} else if ( expDiff < 0 ) {		if ( bExp == 0xFF ) {			// if ( bSig!=0 ) return propagateFloat32NaN( a, b );			if ( bSig!=0 ) return 0x7fc00000;			// return packFloat32( zSign ^ 1, 0xFF, 0 );			return (((zSign^1)<<31) + ((0xff)<<23));		}		if ( aExp == 0 ) {			++expDiff;		}		else {			aSig |= 0x40000000;		}		aSig = shift32RightJamming( aSig, -expDiff);		bSig |= 0x40000000;		zSig = bSig - aSig;		zExp = bExp;		zSign ^= 1;		--zExp;		return normalizeRoundAndPackFloat32( zSign, zExp, zSig );	}	if ( aExp == 0xFF ) {		// if ( aSig!=0 || bSig!=0 ) return propagateFloat32NaN( a, b );		if ( aSig!=0 || bSig!=0 ) return 0x7fc00000;		// float_raise( float_flag_invalid );		// return float32_default_nan;		// return 0x7FFFFFFF;return 0x7fc00000;	}	if ( aExp == 0 ) {		aExp = 1;		bExp = 1;	}	if ( bSig < aSig ) {		zSig = aSig - bSig;		zExp = aExp;		--zExp;		return normalizeRoundAndPackFloat32( zSign, zExp, zSig );	}	if ( aSig < bSig ) {		zSig = bSig - aSig;		zExp = bExp;		zSign ^= 1;		--zExp;		return normalizeRoundAndPackFloat32( zSign, zExp, zSig );	}	// return packFloat32( 0, 0, 0 );	return 0;}/*----------------------------------------------------------------------------| Returns the result of adding the single-precision floating-point values `a'| and `b'.  The operation is performed according to the IEC/IEEE Standard for| Binary Floating-Point Arithmetic.*----------------------------------------------------------------------------*/public static int float32_add( int a, int b ){	int aSign, bSign;	// aSign = extractFloat32Sign( a );	// bSign = extractFloat32Sign( b );	aSign = a>>>31;	bSign = b>>>31;	if ( aSign == bSign ) {		return addFloat32Sigs( a, b, aSign );	} else {		return subFloat32Sigs( a, b, aSign );	}}/*----------------------------------------------------------------------------| Returns the result of subtracting the single-precision floating-point values| `a' and `b'.  The operation is performed according to the IEC/IEEE Standard| for Binary Floating-Point Arithmetic.*----------------------------------------------------------------------------*/public static int float32_sub( int a, int b ){	int aSign, bSign;	// aSign = extractFloat32Sign( a );	// bSign = extractFloat32Sign( b );	aSign = a>>>31;	bSign = b>>>31;	if ( aSign == bSign ) {		return subFloat32Sigs( a, b, aSign );	}	else {		return addFloat32Sigs( a, b, aSign );	}}///*----------------------------------------------------------------------------//| Returns the result of multiplying the single-precision floating-point values//| `a' and `b'.  The operation is performed according to the IEC/IEEE Standard//| for Binary Floating-Point Arithmetic.//*----------------------------------------------------------------------------*/////float32 float32_mul( float32 a, float32 b )//{//	flag aSign, bSign, zSign;//	int16 aExp, bExp, zExp;//	bits32 aSig, bSig, zSig0, zSig1;////	aSig = extractFloat32Frac( a );//	aExp = extractFloat32Exp( a );//	aSign = extractFloat32Sign( a );//	bSig = extractFloat32Frac( b );//	bExp = extractFloat32Exp( b );//	bSign = extractFloat32Sign( b );//	zSign = aSign ^ bSign;//	if ( aExp == 0xFF ) {//		if ( aSig || ( ( bExp == 0xFF ) && bSig ) ) {//			return propagateFloat32NaN( a, b );//		}//		if ( ( bExp | bSig ) == 0 ) {//			float_raise( float_flag_invalid );//			return float32_default_nan;//		}//		return packFloat32( zSign, 0xFF, 0 );//	}//	if ( bExp == 0xFF ) {//		if ( bSig ) return propagateFloat32NaN( a, b );//		if ( ( aExp | aSig ) == 0 ) {//			float_raise( float_flag_invalid );//			return float32_default_nan;//		}//		return packFloat32( zSign, 0xFF, 0 );//	}//	if ( aExp == 0 ) {//		if ( aSig == 0 ) return packFloat32( zSign, 0, 0 );//		normalizeFloat32Subnormal( aSig, &aExp, &aSig );

⌨️ 快捷键说明

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