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


`define SIZE32 63
`define SIZE64 127

//******************************************************************************************
// The following module implements the carrylookahead adder functionality
// It takes two 32 bit integer values and results a 32 bit output along with carry if any
// Inputs to the module are input1,input2
// Outputs to the module are output1
// cout stores the value of carry out when ever there is a carry
//******************************************************************************************

// This module is used to add two 64-bit values.





//**********************************************************************************************
// module carrySaveAdder implements the carrysaveadder function which takes three 64 bit
// values as inputs and results two 64 bit values
// Inputs to the module are input1,input2,input3
// Outputs to the module are output1,output2
//**********************************************************************************************


module carrySaveAdder(output1,output2,input1,input2,input3);

        input  [`SIZE64:0]input1;
        input  [`SIZE64:0]input2;
        input  [`SIZE64:0]input3;

        output [`SIZE64:0]output1;
        output [`SIZE64:0]output2;

        reg [`SIZE64:0]output1;
        reg [`SIZE64:0]output2;

        always @(input1 or input2 or input3)
        begin
                output1 = input1 ^ input2 ^ input3;
                output2 = ( (input1 & input2) | (input3 & input2) | (input1 & input3) ) << 1;
        end

endmodule

//**********************************************************************************************
// module wallaceTreeMultiplier is used to perform multiplication by invoking the
// carryLookAhead adder module and carrySaveAdder module
// Inputs to the module are operand1,operand2
// Outputs to the module are result1,result2
// carry out of the multiplier is stored in cout when ever there is a carry
//**********************************************************************************************


module mul64(  product, operand1, operand2);

        input  [63:0] operand1;
        input  [63:0] operand2;


        output [127:0] product;



        wire [63:0] result1;
        wire [63:0] result2;

        wire [`SIZE64:0] output1, output2;
        reg [127:0] product;

        wire carry;

        integer count;
        integer count1;

        wire [128:1] carriesout;
        reg  [`SIZE64:0] m[`SIZE64:0];
        reg  [`SIZE64:0] leftOutValue11, leftOutValue12, leftOutValue21, leftOutValue41, leftOutValue51, leftOutValue61, leftOutValue62, leftOutValue71;

        wire [`SIZE64:0] iRes10,iRes11,iRes12,iRes13,iRes14,iRes15,iRes16,iRes17,iRes18,iRes19,iRes110 ;
        wire [`SIZE64:0] iRes111,iRes112,iRes113,iRes114,iRes115,iRes116,iRes117,iRes118,iRes119,iRes120;
        wire [`SIZE64:0] iRes121,iRes122,iRes123,iRes124,iRes125,iRes126,iRes127,iRes128,iRes129,iRes130;
        wire [`SIZE64:0] iRes131,iRes132,iRes133,iRes134,iRes135,iRes136,iRes137,iRes138,iRes139,iRes140,iRes141;
        wire [`SIZE64:0] iRes20,iRes21,iRes22,iRes23,iRes24,iRes25,iRes26,iRes27,iRes28,iRes29,iRes210 ;
        wire [`SIZE64:0] iRes211,iRes212,iRes213,iRes214,iRes215,iRes216,iRes217,iRes218,iRes219,iRes220,iRes221,iRes222,iRes223,iRes224,iRes225,iRes226,iRes227;
        wire [`SIZE64:0] iRes30,iRes31,iRes32,iRes33,iRes34,iRes35,iRes36,iRes37,iRes38,iRes39,iRes310,iRes311,iRes312,iRes313,iRes314,iRes315,iRes316,iRes317;
        wire [`SIZE64:0] iRes40,iRes41,iRes42,iRes43,iRes44,iRes45,iRes46,iRes47,iRes48,iRes49,iRes410,iRes411 ;
        wire [`SIZE64:0] iRes50,iRes51,iRes52,iRes53,iRes54,iRes55,iRes56,iRes57;
        wire [`SIZE64:0] iRes60,iRes61,iRes62,iRes63,iRes64,iRes65;
        wire [`SIZE64:0] iRes70,iRes71,iRes72,iRes73;
        wire [`SIZE64:0] iRes80,iRes81;
        wire [`SIZE64:0] iRes90,iRes91;

//*********************************************************************************************
// Invoking carrySaveAdder module
//*********************************************************************************************
        //Initial input values-----level1
//*********************************************************************************************

        carrySaveAdder csa1 (iRes10,  iRes11,  m[0],  m[1],  m[2] );
        carrySaveAdder csa2 (iRes12,  iRes13 , m[3],  m[4],  m[5]);
        carrySaveAdder csa3 (iRes14,  iRes15 , m[6],  m[7],  m[8]);
        carrySaveAdder csa4 (iRes16,  iRes17 , m[9],  m[10], m[11]);
        carrySaveAdder csa5 (iRes18,  iRes19 , m[12], m[13], m[14]);
        carrySaveAdder csa6 (iRes110, iRes111, m[15], m[16], m[17]);
        carrySaveAdder csa7 (iRes112, iRes113, m[18], m[19], m[20]);
        carrySaveAdder csa8 (iRes114, iRes115, m[21], m[22], m[23]);
        carrySaveAdder csa9 (iRes116, iRes117, m[24], m[25], m[26]);
        carrySaveAdder csa10(iRes118, iRes119, m[27], m[28], m[29]);
        carrySaveAdder csa11(iRes120, iRes121, m[30], m[31], m[32]);
        carrySaveAdder csa12(iRes122, iRes123, m[33], m[34], m[35]);
        carrySaveAdder csa13(iRes124, iRes125, m[36], m[37], m[38]);
        carrySaveAdder csa14(iRes126, iRes127, m[39], m[40], m[41]);
        carrySaveAdder csa15(iRes128, iRes129, m[42], m[43], m[44]);
        carrySaveAdder csa16(iRes130, iRes131, m[45], m[46], m[47]);
        carrySaveAdder csa17(iRes132, iRes133, m[48], m[49], m[50]);
        carrySaveAdder csa18(iRes134, iRes135, m[51], m[52], m[53]);
        carrySaveAdder csa19(iRes136, iRes137, m[54], m[55], m[56]);
        carrySaveAdder csa20(iRes138, iRes139, m[57], m[58], m[59]);
        carrySaveAdder csa21(iRes140, iRes141, m[60], m[61], m[62]);

//*********************************************************************************************
        //for intermiediate values----level2
//*********************************************************************************************

        carrySaveAdder csa22(iRes20,  iRes21,  iRes10,  iRes11,  iRes12);
        carrySaveAdder csa23(iRes22,  iRes23,  iRes13,  iRes14,  iRes15);
        carrySaveAdder csa24(iRes24,  iRes25,  iRes16,  iRes17,  iRes18);
        carrySaveAdder csa25(iRes26,  iRes27,  iRes19,  iRes110, iRes111);
        carrySaveAdder csa26(iRes28,  iRes29,  iRes112, iRes113, iRes114);
        carrySaveAdder csa27(iRes210, iRes211, iRes115, iRes116, iRes117);
        carrySaveAdder csa28(iRes212, iRes213, iRes118, iRes119, iRes120);
        carrySaveAdder csa29(iRes214, iRes215, iRes121, iRes122, iRes123);
        carrySaveAdder csa30(iRes216, iRes217, iRes124, iRes125, iRes126);
        carrySaveAdder csa31(iRes218, iRes219, iRes127, iRes128, iRes129);
        carrySaveAdder csa32(iRes220, iRes221, iRes130, iRes131, iRes132);
        carrySaveAdder csa33(iRes222, iRes223, iRes133, iRes134, iRes135);
        carrySaveAdder csa34(iRes224, iRes225, iRes136, iRes137, iRes138);
        carrySaveAdder csa35(iRes226, iRes227, iRes139, iRes140, iRes141);



//*********************************************************************************************
        //for intermiediate values-----level3
//*********************************************************************************************

        carrySaveAdder csa36(iRes30, iRes31, iRes20,  iRes21,  iRes22);
        carrySaveAdder csa37(iRes32, iRes33, iRes23,  iRes24,  iRes25);
        carrySaveAdder csa38(iRes34, iRes35, iRes26,  iRes27,  iRes28);
        carrySaveAdder csa39(iRes36, iRes37, iRes29,  iRes210, iRes211);
        carrySaveAdder csa40(iRes38, iRes39, iRes212, iRes213, iRes214);
        carrySaveAdder csa41(iRes310, iRes311, iRes215, iRes216, iRes217);
        carrySaveAdder csa42(iRes312, iRes313, iRes218, iRes219, iRes220);
        carrySaveAdder csa43(iRes314, iRes315, iRes221, iRes222, iRes223);
        carrySaveAdder csa44(iRes316, iRes317, iRes224, iRes225, iRes226);

//*********************************************************************************************
        //for intermiediate values-----level4
//*********************************************************************************************

        carrySaveAdder csa45(iRes40, iRes41, iRes30, iRes31, iRes32);
        carrySaveAdder csa46(iRes42, iRes43, iRes33, iRes34, iRes35);
        carrySaveAdder csa47(iRes44, iRes45, iRes36, iRes37, iRes38);
        carrySaveAdder csa48(iRes46, iRes47, iRes39, iRes310, iRes311);
        carrySaveAdder csa49(iRes48, iRes49, iRes312, iRes313, iRes314);
        carrySaveAdder csa50(iRes410, iRes411, iRes315, iRes316, iRes317);

//*********************************************************************************************
        //for intermiediate values----level5
//*********************************************************************************************

        carrySaveAdder csa51(iRes50, iRes51, iRes40, iRes41, iRes42);
        carrySaveAdder csa52(iRes52, iRes53, iRes43, iRes44, iRes45);
        carrySaveAdder csa53(iRes54, iRes55, iRes46, iRes47, iRes48);
        carrySaveAdder csa54(iRes56, iRes57, iRes49, iRes410, iRes411);

//*********************************************************************************************
        //for intermiediate values-----level6
//*********************************************************************************************

        carrySaveAdder csa55(iRes60, iRes61, iRes50, iRes51, iRes52);
        carrySaveAdder csa56(iRes62, iRes63, iRes53, iRes54, iRes55);
        carrySaveAdder csa57(iRes64, iRes65, iRes56, iRes57, iRes227);

//*********************************************************************************************
        //for intermiediate values-----level7
//*********************************************************************************************

        carrySaveAdder csa58(iRes70, iRes71, iRes60, iRes61, iRes62);
        carrySaveAdder csa59(iRes72, iRes73, iRes63, iRes64, iRes65);

//*********************************************************************************************
        //for intermiediate values-----level8
//*********************************************************************************************

        carrySaveAdder csa60(iRes80, iRes81, iRes70, iRes71, iRes72);


        carrySaveAdder csa61(iRes90, iRes91, iRes80, iRes81, iRes73);

        carrySaveAdder csa62(output1, output2, iRes90, iRes91, m[63]);
//*********************************************************************************************
// Invoking carryLookAhead adder module
//*********************************************************************************************

        cla64Bit cla1( result1,carriesout[64:1],output2[`SIZE32:0], output1[`SIZE32:0],  1'b0);
        cla64Bit cla2(  result2,carriesout[128:65],output2[`SIZE64:64], output1[`SIZE64:64], carriesout[64]);

        always @(operand1 or operand2)
        begin

                for(count = 0; count <= `SIZE32; count = count + 1)
                begin
                        if(operand2[count] == 1'b1)
                                m[count] = operand1<<count;//shifiting the intermiediate reslts by one each time
                        else
                            m[count] = 0;
                end


        end
        always @ (result1 or result2)
        begin

                product = {result2,result1};
        end

endmodule