data/full_repos/permissive/433624543/generic_n_x_n_mult.v
data/verilator_xmls/77bc6db2-608d-4a2f-a0fe-edfaf76a4baf.xml
module ArrayMultiplier_generic
#(parameter m = 64, n = 64)
(product, a, b);


    output wire [m+n-1:0] product;
    input[m-1:0] a;
    input[n-1:0] b;

    wire c_partial[(m-1)*(n):0];
    wire s_partial[(m-1)*(n):0];


    two_in_and_gate two_and(.a(a[0]), .b(b[0]), .z(product[0]));


    genvar i;
    generate
        for(i=0; i<m-1; i=i+1)
        begin
                Full_Adder_four_in FA_first(.a_old(a[i]), .a_new(a[i+1]), .b_old(b[0]), .b_new(b[1]), .carry_in(1'b0), .sum(s_partial[i]), .carry_out(c_partial[i]));
        end
    endgenerate


    genvar j, k;
    generate
        for(k=0; k<n-2; k=k+1)
        begin
            for(j=0; j<m-2; j=j+1)
            begin
                Full_Adder_three_in FA_middle(.a_this(a[j]), .b_row(b[k+2]), .last_sum(s_partial[((m-1)*k)+(j+1)]), .carry_in(c_partial[((m-1)*k)+j]),
                 .sum(s_partial[((m-1)*(k+1))+j]), .carry_out(c_partial[((m-1)*(k+1))+j]));
            end
        end
    endgenerate


    genvar z;
    generate
        for(z=0; z<n-2; z=z+1)
        begin
            Full_Adder_four_in FA_middle_last_column(.a_old(a[m-2]), .a_new(a[m-1]), .b_old(b[z+1]), .b_new(b[z+2]), .carry_in(c_partial[(m-1)*(z)+(m-2)]),
             .sum(s_partial[((m-1)*(z+1))+(m-2)]), .carry_out(c_partial[((m-1)*(z+1))+(m-2)]));
        end
    endgenerate


    genvar l;
    generate
        for(l=0; l<n-1; l=l+1)
        begin
            if(l==0)
            begin
                Full_Adder_two_in Last_row_first_column(.a(s_partial[((m-1)*(n-2))+1]), .b(c_partial[((m-1)*(n-2))+l]), .carry_in(1'b0),
                 .sum(s_partial[((m-1)*(n-1))+l]), .carry_out(c_partial[((m-1)*(n-1))+l]));
            end else if (l < m-2)
            begin
                Full_Adder_two_in Last_row_middle_columns(.a(s_partial[((m-1)*(n-2))+l+1]), .b(c_partial[((m-1)*(n-2))+l]), .carry_in(c_partial[((m-1)*(n-1))+l-1]),
                 .sum(s_partial[((m-1)*(n-1))+l]), .carry_out(c_partial[((m-1)*(n-1))+l]));
            end else begin
                Full_Adder_three_in Last_row_last_column(.a_this(a[m-1]), .b_row(b[n-1]), .last_sum(c_partial[((m-1)*(n-2))+l]), .carry_in(c_partial[((m-1)*(n-1))+l-1]),
                 .sum(s_partial[((m-1)*(n-1))+l]), .carry_out(c_partial[((m-1)*(n-1))+l]));
            end
        end
    endgenerate


    generate
        for(i=0; i<n-1; i=i+1)
        begin
            buf (product[i+1], s_partial[(m-1)*i]);
        end
    endgenerate


    generate
        for(i=0; i<n-1; i=i+1)
        begin
            buf (product[i+n], s_partial[((m-1)*(n-1))+i]);
        end
    endgenerate


    buf (product[m+n-1], c_partial[((m-1)*(n))-1]);
endmodule
module ArrayMultiplier_generic
#(parameter m = 64, n = 64)
(product, a, b);



    output wire [m+n-1:0] product;
    input[m-1:0] a;
    input[n-1:0] b;

    wire c_partial[(m-1)*(n):0];
    wire s_partial[(m-1)*(n):0];


    two_in_and_gate two_and(.a(a[0]), .b(b[0]), .z(product[0]));


    genvar i;
    generate
        for(i=0; i<m-1; i=i+1)
        begin
                Full_Adder_four_in FA_first(.a_old(a[i]), .a_new(a[i+1]), .b_old(b[0]), .b_new(b[1]), .carry_in(1'b0), .sum(s_partial[i]), .carry_out(c_partial[i]));
        end
    endgenerate


    genvar j, k;
    generate
        for(k=0; k<n-2; k=k+1)
        begin
            for(j=0; j<m-2; j=j+1)
            begin
                Full_Adder_three_in FA_middle(.a_this(a[j]), .b_row(b[k+2]), .last_sum(s_partial[((m-1)*k)+(j+1)]), .carry_in(c_partial[((m-1)*k)+j]),
                 .sum(s_partial[((m-1)*(k+1))+j]), .carry_out(c_partial[((m-1)*(k+1))+j]));
            end
        end
    endgenerate


    genvar z;
    generate
        for(z=0; z<n-2; z=z+1)
        begin
            Full_Adder_four_in FA_middle_last_column(.a_old(a[m-2]), .a_new(a[m-1]), .b_old(b[z+1]), .b_new(b[z+2]), .carry_in(c_partial[(m-1)*(z)+(m-2)]),
             .sum(s_partial[((m-1)*(z+1))+(m-2)]), .carry_out(c_partial[((m-1)*(z+1))+(m-2)]));
        end
    endgenerate


    genvar l;
    generate
        for(l=0; l<n-1; l=l+1)
        begin
            if(l==0)
            begin
                Full_Adder_two_in Last_row_first_column(.a(s_partial[((m-1)*(n-2))+1]), .b(c_partial[((m-1)*(n-2))+l]), .carry_in(1'b0),
                 .sum(s_partial[((m-1)*(n-1))+l]), .carry_out(c_partial[((m-1)*(n-1))+l]));
            end else if (l < m-2)
            begin
                Full_Adder_two_in Last_row_middle_columns(.a(s_partial[((m-1)*(n-2))+l+1]), .b(c_partial[((m-1)*(n-2))+l]), .carry_in(c_partial[((m-1)*(n-1))+l-1]),
                 .sum(s_partial[((m-1)*(n-1))+l]), .carry_out(c_partial[((m-1)*(n-1))+l]));
            end else begin
                Full_Adder_three_in Last_row_last_column(.a_this(a[m-1]), .b_row(b[n-1]), .last_sum(c_partial[((m-1)*(n-2))+l]), .carry_in(c_partial[((m-1)*(n-1))+l-1]),
                 .sum(s_partial[((m-1)*(n-1))+l]), .carry_out(c_partial[((m-1)*(n-1))+l]));
            end
        end
    endgenerate


    generate
        for(i=0; i<n-1; i=i+1)
        begin
            buf (product[i+1], s_partial[(m-1)*i]);
        end
    endgenerate


    generate
        for(i=0; i<n-1; i=i+1)
        begin
            buf (product[i+n], s_partial[((m-1)*(n-1))+i]);
        end
    endgenerate


    buf (product[m+n-1], c_partial[((m-1)*(n))-1]);
endmodule