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


//  Module to Convert Single precision value into 16-bit integer 
 
 
 
module ConvertSPTo16Int(Int16Out, SinglePrecIn); 
 
output [15:0] Int16Out; 
 
input  [31:0] SinglePrecIn; 
 
wire [31:0] SinglePrecIn; 
wire [15:0] complementIn, complementOut; 
reg  [15:0] Int16; 
reg  [7:0]  index; 
 
assign Int16Out = (SinglePrecIn[31]) ? complementOut : Int16; 
assign complementIn = SinglePrecIn[31] ? Int16 :16'bz; 
 
twosComp16 TC16(complementOut,complementIn); 
 
always @ ( SinglePrecIn ) 
 
begin 
 
	index=	 SinglePrecIn[30:23]; 
	index[7]=~index[7] ; 
	index= 	(~index[0] ? ( {index [7:1], ~index[0]}): 
		(~index[1] ? ( {index [7:2], ~index[1:0]}): 
		(~index[2] ? ( {index [7:3], ~index[2:0]}): 
		(~index[3] ? ( {index [7:4], ~index[3:0]}): 
		(~index[4] ? ( {index [7:5], ~index[4:0]}): 
		(~index[5] ? ( {index [7:6], ~index[5:0]}): 
		({index[7], ~index[6:0]}) )))))); 
 
 
	begin 
 
		case (index)				// Whenever the output of 16 bit adder changes 
 
		5'd14: 
			  Int16  = { 1'b0, 1'b1 , SinglePrecIn[22:9] }; 
		5'd13: 
			  Int16  = { 1'b0, {1{1'b0}}, 1'b1 , SinglePrecIn[22:10] }; 
		5'd12: 
			  Int16  = { 1'b0, {2{1'b0}}, 1'b1 , SinglePrecIn[22:11] }; 
		5'd11: 
			  Int16  = { 1'b0, {3{1'b0}}, 1'b1 , SinglePrecIn[22:12] }; 
		5'd10: 
			  Int16  = { 1'b0, {4{1'b0}}, 1'b1 , SinglePrecIn[22:13] }; 
		5'd9: 
			  Int16  = { 1'b0, {5{1'b0}}, 1'b1 , SinglePrecIn[22:14] }; 
		5'd8: 
			  Int16  = { 1'b0, {6{1'b0}}, 1'b1 , SinglePrecIn[22:15] }; 
		5'd7: 
			  Int16  = { 1'b0, {7{1'b0}}, 1'b1 , SinglePrecIn[22:16] }; 
		5'd6: 
			  Int16  = { 1'b0, {8{1'b0}}, 1'b1 , SinglePrecIn[22:17] }; 
		5'd5: 
			  Int16  = { 1'b0, {9{1'b0}}, 1'b1 , SinglePrecIn[22:18] }; 
		5'd4: 
			  Int16  = { 1'b0, {10{1'b0}}, 1'b1 , SinglePrecIn[22:19] }; 
		5'd3: 
			  Int16  = { 1'b0, {11{1'b0}}, 1'b1 , SinglePrecIn[22:20] }; 
		5'd2: 
			  Int16  = { 1'b0, {12{1'b0}}, 1'b1 , SinglePrecIn[22:21] }; 
		5'd1: 
			  Int16  = { 1'b0, {13{1'b0}}, 1'b1 , SinglePrecIn[22] }; 
		5'd0: 
			  Int16  = { 1'b0, {14{1'b0}}, 1'b1 }; 
		default: 
			  Int16  = 16'b0; 
 
		endcase 
	end 
end 
endmodule