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


/************************************************* 
 
This module is used to compare two 80-bit values and 
gives the following output 
 
	0 - Operand1 is greater 
	1 - Operand2 is greater 
	2 - Operand3 is greater 
 
 
***************************************************/ 
 
 
module compare80(compOp1, compOp2, compRes); 
 
input [79:0] compOp1, compOp2;		//	Module inputs declaration 
 
output [1:0] compRes;			//	Module output declaration 
reg    [1:0] compRes; 
 
reg [15:0] comp1In1,comp1In2; 
reg [31:0] comp2In1,comp2In2; 
reg [31:0] comp3In1,comp3In2; 
 
wire [2:0] comp1Out,comp2Out,comp3Out,comp4Out,comp5Out; 
 
//	Instances of 16-bit comparators 
 
compare16 CompIns1(comp1Out, comp1In1, comp1In2); 
compare32 CompIns2(comp2Out, comp2In1, comp2In2); 
compare32 CompIns3(comp3Out, comp3In1, comp3In2); 
 
always @ (compOp1 or compOp2 or compRes or comp1Out or comp2Out or comp3Out or comp4Out or comp5Out) 
begin 
   	if(|(compOp1[78:0] == 0) && |(compOp2[78:0] == 0))	//	If both operands are zero then 
		compRes = 2'd2;					//	  both operands are equal 
	else 
	begin 
	   	if(compOp1[79] == 0 && compOp2[79] == 1)	//	If Op1 is positive. & Op2 is negative 
			compRes = 2'd0;				//	      Op1 is greater 
		else 
  		if(compOp1[79] == 1 && compOp2[79] == 0)	//	If Op1 is negative & Op2 is positive 
			compRes = 2'd1;				//	      Op2 is greater 
		else 
		begin 
		   	if((compOp1[79] == 0 && compOp2[79] == 0) || (compOp1[79] == 1 && compOp2[79] == 1))	 
			//	if the signs of Op1 & Op2 are equal then enter into this block 
			begin 
				 
				comp1In1 = { 1'b0, compOp1[78:64] };	//	give the most significant 16-bits of Op1 & 
				comp1In2 = { 1'b0, compOp2[78:64] };	//	 Op2 to 16-bit comparator & assign the 
				 
				if(comp1Out[2] == 1)			//	result according to that. 
					 
                                       compRes = 2'd0;   
				else 
				if(comp1Out[0] == 1) 
					compRes = 2'd1; 
				else 
				if(comp1Out[1] == 1)			//	If the most significant 16-bits are equal 
				begin					//	 then give the next 16-bits to 16-bit 
					comp2In1 = compOp1[63:32];	//	   comparator. 
					comp2In2 = compOp2[63:32]; 
					if(comp2Out[2] == 1) 
						compRes = 2'd0; 
					else 
					if(comp2Out[0] == 1) 
						compRes = 2'd1; 
					else 
					if(comp2Out[1] == 1)		//	If again all the bits are equal give next 
					begin				//	 16-bits to 16-bit comparator 
						comp3In1 = compOp1[32:0]; 
						comp3In2 = compOp2[32:0]; 
						if(comp3Out[2] == 1) 
							compRes = 2'd0; 
						else 
						if(comp3Out[0] == 1) 
							compRes = 2'd1; 
						else 
						if(comp2Out[1] == 1)		//	If again all the bits are equal give 
						begin				//	 16-bits to 16-bit comparator 
							compRes = 2'd2;	// If all bits are equal 
						end 
					end 
				end 
			end 
			if(compOp1[79] == 1'b1)		//	If the operands are negative 
		  	begin				//        make greater as smaller & vice versa 
		    		if(compRes == 2'd0) 
		      			compRes = 2'd1; 
		    		else 
				if(compRes == 2'd1) 
		      			compRes = 2'd0; 
			end 
		end 
		 
       	end 
end 
endmodule