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


/***********************************************************
 *                                                         *
 *  Module to convert 16-bit integer into 32-bit Single    *
 *          precision value                                *
 *                                                         *
 ***********************************************************/



module ConInt16ToSP(SinglePrecOut, Int16);

input  [15:0] Int16;
output [31:0] SinglePrecOut;

reg  [31:0] scanInRev;
reg  [31:0] SinglePrecOut;
reg  [31:0] tempInt16;
wire [4:0]  indexOutRev;
wire [15:0] complementIn, complementOut;
reg  [7:0]  index;


assign complementIn=Int16[15]? Int16 : 32'bz;


bitScanRev Bsr(indexOutRev, scanInRev);
twosComp16 TC16(complementOut,complementIn);

always @ ( Int16 or complementOut or indexOutRev )

begin
        if(Int16==16'b0)
                SinglePrecOut=32'b0;
        else
        begin
                if(Int16[15])
                begin
                        tempInt16=complementOut;
                        scanInRev= { 16'b0,complementOut };
                end
                else
                begin
                        tempInt16=Int16;
                        scanInRev={ 16'b0,Int16 };
                end

                //finding the biased exponent for the given 16-bit integer

                index=   { 3'd0, indexOutRev };
                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]}) ))))));



                case (indexOutRev)
                5'd15:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[14:0], 8'b0 };
                5'd14:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[13:0], 9'b0 };
                5'd13:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[12:0], 10'b0 };
                5'd12:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[11:0], 11'b0 };
                5'd11:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[10:0], 12'b0 };
                5'd10:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[9:0], 13'b0 };
                5'd9:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[8:0], 14'b0 };
                5'd8:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[7:0], 15'b0 };
                5'd7:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[6:0], 16'b0 };
                5'd6:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[5:0], 17'b0 };
                5'd5:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[4:0], 18'b0 };
                5'd4:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[3:0], 19'b0 };
                5'd3:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[2:0], 20'b0 };
                5'd2:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[1:0], 21'b0 };
                5'd1:
                          SinglePrecOut  = { Int16[15], index[7:0], tempInt16[0], 22'b0 };
                5'd0:
                          SinglePrecOut  = { Int16[15], index[7:0], 23'b0 };
                endcase
        end     //end else
end     // end always
endmodule