8×8 bitwallace tree multiplier:
add submodules with same module name adder_full and adder_half in same folder.
module multiplier_wallace(
output reg [15:0] product,
input [7:0] multiplicand, multiplier,
input clock, clear);
integer i, j ;
wire [63:0] s ,c ;
reg p [7:0][7:0];
always@(multiplier, multiplicand)
begin
for (i = 0; i <= 7; i = i + 1)
for (j = 0; j <= 7; j = j + 1)
p[j] <= multiplicand[j] & multiplier;
end
adder_half ha_11 ( .sum(s[0]), .carry(c[0]), .a(p[1][0]), .b( p[0][1]) );
adder_full fa_11 ( .sum(s[1]), .carry(c[1]), .a(p[2][0]), .b( p[1][1]), .cin( p[0][2]) );
adder_full fa_12 ( .sum(s[2]), .carry(c[2]), .a(p[3][0]), .b( p[2][1]), .cin( p[1][2]) );
adder_full fa_13 ( .sum(s[3]), .carry(c[3]), .a(p[4][0]), .b( p[3][1]), .cin( p[2][2]) );
adder_full fa_14 ( .sum(s[4]), .carry(c[4]), .a(p[5][0]), .b( p[4][1]), .cin( p[3][2]) );
adder_full fa_15 ( .sum(s[5]), .carry(c[5]), .a(p[6][0]), .b( p[5][1]), .cin( p[4][2]) );
adder_full fa_16 ( .sum(s[6]), .carry(c[6]), .a(p[7][0]), .b( p[6][1]), .cin( p[5][2]) );
adder_half ha_12 ( .sum(s[7]), .carry(c[7]), .a( p[7][1]), .b ( p[6][2]) );
adder_half ha_21 ( .sum( s[8] ), .carry( c[8 ]), .a( p[1][3]), .b( p[0][4]) );
adder_full fa_21 ( .sum( s[9] ), .carry( c[9 ]), .a( p[2][3]), .b( p[1][4]), .cin( p[0][5]) );
adder_full fa_22 ( .sum( s[10]), .carry( c[10]), .a( p[3][3]), .b( p[2][4]), .cin( p[1][5]) );
adder_full fa_23 ( .sum( s[11]), .carry( c[11]), .a( p[4][3]), .b( p[3][4]), .cin( p[2][5]) );
adder_full fa_24 ( .sum( s[12]), .carry( c[12]), .a( p[5][3]), .b( p[4][4]), .cin( p[3][5]) );
adder_full fa_25 ( .sum( s[13]), .carry( c[13]), .a( p[6][3]), .b( p[5][4]), .cin( p[4][5]) );
adder_full fa_26 ( .sum( s[14]), .carry( c[14]), .a( p[7][3]), .b( p[6][4]), .cin( p[5][5]) );
adder_half ha_22 ( .sum( s[15]), .carry( c[15]), .a( p[7][4]), .b ( p[6][5]) );
adder_half ha_31 ( .sum( s[16]), .carry( c[16]), .a( c[0]) , .b ( s[1]) );
adder_full fa_31 ( .sum( s[17]), .carry( c[17]), .a( c[1]) , .b ( s[2]) , .cin ( p[0][3]) );
adder_full fa_32 ( .sum( s[18]), .carry( c[18]), .a( c[2]) , .b ( s[3]) , .cin ( s[8] ) );
adder_full fa_33 ( .sum( s[19]), .carry( c[19]), .a( c[3]) , .b ( s[4]) , .cin ( s[9] ) );
adder_full fa_34 ( .sum( s[20]), .carry( c[20]), .a( c[4]) , .b ( s[5]) , .cin ( s[10]) );
adder_full fa_35 ( .sum( s[21]), .carry( c[21]), .a( c[5]) , .b ( s[6]) , .cin ( s[11]) );
adder_full fa_36 ( .sum( s[22]), .carry( c[22]), .a( c[6]) , .b ( s[7]) , .cin ( s[12]) );
adder_full fa_37 ( .sum( s[23]), .carry( c[23]), .a( c[7]) , .b ( p[7][2]), .cin ( s[13]) );
adder_half ha_41 ( .sum( s[24]), .carry( c[24]), .a( c[9] ) , .b( p[0][6]) );
adder_full fa_41 ( .sum( s[25]), .carry( c[25]), .a( c[10]) , .b( p[1][6]), .cin( p[0][7]) );
adder_full fa_42 ( .sum( s[26]), .carry( c[26]), .a( c[11]) , .b( p[2][6]), .cin( p[1][7]) );
adder_full fa_43 ( .sum( s[27]), .carry( c[27]), .a( c[12]) , .b( p[3][6]), .cin( p[2][7]) );
adder_full fa_44 ( .sum( s[28]), .carry( c[28]), .a( c[13]) , .b( p[4][6]), .cin( p[3][7]) );
adder_full fa_45 ( .sum( s[29]), .carry( c[29]), .a( c[14]) , .b( p[5][6]), .cin( p[4][7]) );
adder_full fa_46 ( .sum( s[30]), .carry( c[30]), .a( c[15]) , .b( p[6][6]), .cin( p[5][7]) );
adder_half fa_47 ( .sum( s[31]), .carry( c[31]), .a( p[7][6]), .b ( p[6][7]) );
adder_half ha_51 ( .sum( s[32]), .carry( c[32]), .a( s[17]) , .b( c[16]) );
adder_half fa_51 ( .sum( s[33]), .carry( c[33]), .a( s[18]) , .b( c[17]) );
adder_full fa_52 ( .sum( s[34]), .carry( c[34]), .a( s[19]) , .b( c[18]), .cin( c[8] ) );
adder_full fa_53 ( .sum( s[35]), .carry( c[35]), .a( s[20]) , .b( c[19]), .cin( s[24]) );
adder_full fa_54 ( .sum( s[36]), .carry( c[36]), .a( s[21]) , .b( c[20]), .cin( s[25]) );
adder_full fa_55 ( .sum( s[37]), .carry( c[37]), .a( s[22]) , .b( c[21]), .cin( s[26]) );
adder_full fa_56 ( .sum( s[38]), .carry( c[38]), .a( s[23]) , .b( c[22]), .cin( s[27]) );
adder_full fa_57 ( .sum( s[39]), .carry( c[39]), .a( s[14]) , .b( c[23]), .cin( s[28]) );
adder_half ha_52 ( .sum( s[40]), .carry( c[40]), .a( s[15]) , .b ( s[29]) );
adder_half ha_53 ( .sum( s[41]), .carry( c[41]), .a( p[7][5]), .b ( s[30]) );
adder_half ha_61 ( .sum( s[42]), .carry( c[42]), .a( s[33]) , .b( c[32]) );
adder_half ha_62 ( .sum( s[43]), .carry( c[43]), .a( s[34]) , .b( c[33]) );
adder_half ha_63 ( .sum( s[44]), .carry( c[44]), .a( s[35]) , .b( c[34]) );
adder_full fa_61 ( .sum( s[45]), .carry( c[45]), .a( s[36]) , .b( c[35]), .cin( c[24]) );
adder_full fa_62 ( .sum( s[46]), .carry( c[46]), .a( s[37]) , .b( c[36]), .cin( c[25]) );
adder_full fa_63 ( .sum( s[47]), .carry( c[47]), .a( s[38]) , .b( c[37]), .cin( c[26]) );
adder_full fa_64 ( .sum( s[48]), .carry( c[48]), .a( s[39]) , .b( c[38]), .cin( c[27]) );
adder_full fa_65 ( .sum( s[49]), .carry( c[49]), .a( s[40]) , .b( c[39]), .cin( c[28]) );
adder_full fa_66 ( .sum( s[50]), .carry( c[50]), .a( s[41]) , .b( c[40]), .cin( c[29]) );
adder_full fa_67 ( .sum( s[51]), .carry( c[51]), .a( s[31]) , .b( c[41]), .cin( c[30]) );
adder_half ha_64 ( .sum( s[52]), .carry( c[52]), .a( p[7][7]), .b ( c[31]) );
adder_half ha_71 ( .sum( s[53]), .carry( c[53]), .a( s[43]) , .b( c[42]) );
adder_full fa_71 ( .sum( s[54]), .carry( c[54]), .a( s[44]) , .b( c[43]), .cin ( c[53]) );
adder_full fa_72 ( .sum( s[55]), .carry( c[55]), .a( s[45]) , .b( c[44]), .cin ( c[54]) );
adder_full fa_73 ( .sum( s[56]), .carry( c[56]), .a( s[46]) , .b( c[45]), .cin ( c[55]) );
adder_full fa_74 ( .sum( s[57]), .carry( c[57]), .a( s[47]) , .b( c[46]), .cin ( c[56]) );
adder_full fa_75 ( .sum( s[58]), .carry( c[58]), .a( s[48]) , .b( c[47]), .cin ( c[57]) );
adder_full fa_76 ( .sum( s[59]), .carry( c[59]), .a( s[49]) , .b( c[48]), .cin ( c[58]) );
adder_full fa_77 ( .sum( s[60]), .carry( c[60]), .a( s[50]) , .b( c[49]), .cin ( c[59]) );
adder_full fa_78 ( .sum( s[61]), .carry( c[61]), .a( s[51]) , .b( c[50]), .cin ( c[60]) );
adder_full fa_79 ( .sum( s[62]), .carry( c[62]), .a( s[52]) , .b( c[51]), .cin ( c[61]) );
adder_half ha_72 ( .sum( s[63]), .carry( c[63]), .a( c[52]), .b ( c[62]) );
always@(posedge clock, negedge clear)
if(!clear) product <= 16'b0;
else product <= {s[63 : 53],s[42],s[32],s[16],s[0],p[0][0]};
endmodule