www.pudn.com > x86.rar > Check4Nans.v, change:2007-12-05,size:5824b


/********************************************************** 
 * This module is used to check the Operand is +0 or -0,  * 
 * or + Normal or  - Normal or or + Denormal or - Denormal* 
 * or + Infinity or - Infinity or NaN or SNaN or QNaN or  * 
 * QNaN FPI						  * 
 **********************************************************/ 
 
 
`define SP_Exponent     30:23 
`define SP_Significant  22:0 
`define SP_Sign         31 
 
`define DP_Exponent     62:52 
`define DP_Significant  51:0 
`define DP_Sign         63 
 
`define DEP_Exponent     78:64 
`define DEP_Significant  62:0 
`define DEP_Sign         79 
 
/* Output values to represent various types of numbers. 
 
+ zero	   	0 
- zero	   	1 
+ Normal   	2 
- Normal   	3 
+ Denormal 	4 
- Denormal 	5 
+ Infinity 	6 
- Infinity 	7 
 
NaNs 
---- 
SNaN     	8 
QNaN	   	9 
QNaN FPI 	10 
 
*/ 
 
 
module Check4Nans(ResOut, Operand, Opsize); 
 
input [79:0] Operand; 
input [1:0]  Opsize; 
output[3:0]  ResOut; 
 
reg[3:0] ResOut; 
 
 
always@( Operand or Opsize ) 
begin 
 
// If the Operand is Single Precision value 
if(Opsize == 2'd0) 
begin 
	if (&(Operand[`SP_Exponent]) == 1) 		// If all bits of Exponent are 1s 
	begin 
		if (&(Operand[`SP_Significant]) == 0)	// If all bits of Significant are 0s 
			begin 
			if (Operand[`SP_Sign] == 0) 	// If Sign is positive 
				ResOut = 4'd6; 		// This + infinity 
			else				// If Sign is negative 
				ResOut = 4'd7;		// This - infinity 
			end 
		else 
		begin						// If all exponents are 1s and not all significants are 0s 
			if(Operand[22] == 0)			// If bit 22 is 0 
				ResOut = 4'd8;			// This is SNaN 
			else 
				begin				// If bit 22 is 1 
				if(|(Operand[21:0]) == 0) 	// If bits 21 thro' 0 are 0s 
					ResOut = 4'd10;		// This is QNaN Floating-Point indefinite 
				else 
					ResOut = 4'd9;		// This is QNaN 
				end 
		end 
	end 
	else 
	begin 
		if( |(Operand[`SP_Exponent] == 0))			// If all exponents are 0s 
			begin 
				if( |(Operand[`SP_Significant] == 0))	// If all significants are 1s 
				begin 
					if( Operand[`SP_Sign] == 0)	// If sign is positive 
						ResOut = 4'd0;		// This is + 0 
					else				// If sign is negative 
						ResOut = 4'd1;		// This is - zero 
				end 
				else 
				begin					// If exponent is 0 but significant is non 0 
					if( Operand[`SP_Sign] == 0 )	// If sign is positive 
						ResOut = 4'd4;		// This is + denormal 
					else 
						ResOut = 4'd5;		// This is - denormal 
				end 
			end 
		else 
		begin 
			if( Operand[`SP_Sign] == 0) 
				ResOut = 4'd2;		// This is + Normal 
			else 
				ResOut = 4'd3;		// This is - Normal 
		end 
	end 
end 
 
// If the Operand is Double Precision value 
else 
if(Opsize == 2'd1) 
begin 
	if (&(Operand[`DP_Exponent]) == 1) 		// If all bits of Exponent are 1s 
	begin 
		if (&(Operand[`DP_Significant]) == 0)	// If all bits of Significant are 0s 
			begin 
			if (Operand[`DP_Sign] == 0) 	// If Sign is positive 
				ResOut = 4'd6; 		// This + infinity 
			else				// If Sign is negative 
				ResOut = 4'd7;		// This - infinity 
			end 
		else 
		begin					// If all exponents are 1s and not all significants are 0s 
			if(Operand[22] == 0)		// If bit 22 is 0 
				ResOut = 4'd8;		// This is SNaN 
			else 
				begin				// If bit 22 is 1 
				if(|(Operand[21:0]) == 0) 	// If bits 21 thro' 0 are 0s 
					ResOut = 4'd10;		// This is QNaN Floating-Point indefinite 
				else 
					ResOut = 4'd9;		// This is QNaN 
				end 
		end 
	end 
	else 
	begin 
		if( |(Operand[`DP_Exponent] == 0))		// If all exponents are 0s 
			begin 
				if( |(Operand[`DP_Significant] == 0))	// If all significants are 1s 
				begin 
					if( Operand[`DP_Sign] == 0)	// If sign is positive 
						ResOut = 4'd0;		// This is + 0 
					else				// If sign is negative 
						ResOut = 4'd1;		// This is - zero 
				end 
				else 
				begin			// If exponent is 0 but significant is non 0 
					if( Operand[`DP_Sign] == 0 )		// If sign is positive 
						ResOut = 4'd4;		// This is + denormal 
					else 
						ResOut = 4'd5;		// This is - denormal 
				end 
			end 
		else 
		begin 
			if( Operand[`DP_Sign] == 0) 
				ResOut = 4'd2;		// This is + Normal 
			else 
				ResOut = 4'd3;		// This is - Normal 
		end 
	end 
end 
 
// If the Operand is Double Extended Precision value 
else 
if(Opsize == 2'd2) 
begin 
	if (&(Operand[`DEP_Exponent]) == 1) 		// If all bits of Exponent are 1s 
	begin 
		if (&(Operand[`DEP_Significant]) == 0)	// If all bits of Significant are 0s 
			begin 
			if (Operand[`DEP_Sign] == 0) 	// If Sign is positive 
				ResOut = 4'd6; 		// This + infinity 
			else				// If Sign is negative 
				ResOut = 4'd7;		// This - infinity 
			end 
		else 
		begin					// If all exponents are 1s and not all significants are 0s 
			if(Operand[22] == 0)		// If bit 22 is 0 
				ResOut = 4'd8;		// This is SNaN 
			else 
				begin				// If bit 22 is 1 
				if(|(Operand[21:0]) == 0) 	// If bits 21 thro' 0 are 0s 
					ResOut = 4'd10;		// This is QNaN Floating-Point indefinite 
				else 
					ResOut = 4'd9;		// This is QNaN 
				end 
		end 
	end 
	else 
	begin 
		if( |(Operand[`DEP_Exponent] == 0))		// If all exponents are 0s 
			begin 
				if( |(Operand[`DEP_Significant] == 0))	// If all significants are 1s 
				begin 
					if( Operand[`DEP_Sign] == 0)	// If sign is positive 
						ResOut = 4'd0;		// This is + 0 
					else				// If sign is negative 
						ResOut = 4'd1;		// This is - zero 
				end 
				else 
				begin			// If exponent is 0 but significant is non 0 
					if( Operand[`DEP_Sign] == 0 )		// If sign is positive 
						ResOut = 4'd4;		// This is + denormal 
					else 
						ResOut = 4'd5;		// This is - denormal 
				end 
			end 
		else 
		begin 
			if( Operand[`DEP_Sign] == 0) 
				ResOut = 4'd2;		// This is + Normal 
			else 
				ResOut = 4'd3;		// This is - Normal 
		end 
	end 
end 
 
 
end 
endmodule