Multipliers - 4 Wallace tree multiplier based implementation

    Bloggers recent study adder multiplication where knowledge when learning multiplier booth encoding plus Wallace tree compression, compression found when the partial product uses carry-save adder (Carry the Save Adder) , the addition of such bloggers is not very understanding, but dragged on for a long time, I always thought carry-save adder is a general serial adder, finally some understanding here today to share with you.

  First, we give an example, for four unsigned multiplication 1110 and 1011, we get the following equation:

          1  0  1  1
              x   1  1  1  0
        ------------------------------
                  0  0  0  0             PP1
               1  0  1  1                PP2
            1  0  1  1                   PP3
         1  0  1  1                      PP4
        ------------------------------   
  乘积项中间结果有4个:PP1、PP2、PP3、PP4。由于进位保存加法器只能进行三个数的相加,因而可采用两个进位保存加法器实现。第一个进位保存加法器实现PP1、PP2、PP3的加法,第二个进位保存加法器将PP3和上一级的S和C相加。最终通过一个并行加法器输出积。计算过程如下:
第一个进位保存加法器
PP1:                    0  0  0  0
PP2:                 1  0  1  1  0
PP3:              1  0  1  1  0  0
---------------------------------------
sum1              1  1  1  0  1  0
c1                0  0  0  1  0  0   
第二个进位保存加法器 
carry_in:         1  0  1  1  0  0  0
sum1              0  1  1  1  0  1  0                   
c1                0  0  0  1  0  0  0
---------------------------------------
sum2:             1  1  0  1  0  1  0
c2:              0  0  1  1  0  0  0
并行加法器:
sum2:             1  1  0  1  0  1  0
c2:              0  1  1  0  0  0  0
---------------------------------------
result            1  0  0  1  1  0  1  0  

  我们注意到,在参与下一级运算的过程中,由于进位要用于高位的求和,故c1,c2均应左移一位求。算出来的结果为:10011010(154)。
所谓“进位保留”,便是进位不进上去,只在本位之间计算。
基于Wallace树的4位乘法器实现Verilog代码如下所示:

module wallace_multiplier(
input [3:0] a,
input [3:0] b,
output [7:0] result
);

 

wire [7:0] pp1;
wire [7:0] pp2;
wire [7:0] pp3;
wire [7:0] pp4;

 

wire [7:0] sum1;
wire [7:0] carry1;
wire [7:0] sum2;
wire [7:0] carry2;

 

assign pp1 = b[0] ? a : 'd0;
assign pp2 = b[1] ? a : 'd0;
assign pp3 = b[2] ? a : 'd0;
assign pp4 = b[3] ? a : 'd0;

 

assign result = sum2 + (carry2 << 1);

 

carry_save_adder u1_carry_save_adder(
pp1 ,
pp2 << 1'b1,
pp3 << 2'd2,
sum1 ,
carry1
);

 

carry_save_adder u2_carry_save_adder(
pp4 << 2'd3 ,
sum1 ,
carry1 << 1'b1,
sum2 ,
carry2
);
endmodule

 

module carry_save_adder
#(
parameter DATA_WIDTH = 7
)
(
input [DATA_WIDTH:0] a,
input [DATA_WIDTH:0] b,
input [DATA_WIDTH:0] cin,
output [DATA_WIDTH:0] sum,
output [DATA_WIDTH:0] cout
);

 

assign sum = a ^ b ^ cin;
assign cout = a & b | (a | b) & cin;

 

endmodule

 

testbench:

`timescale 1ns / 1ns

module wallace_multiplier_tb();

reg [3:0] a;
reg [3:0] b;
wire[7:0] result;

wallace_multiplier u_wallace_multiplier(
.a (a ),
.b (b ),
.result (result )
);

initial begin
a = 4'b0010;
b = 4'b0110;
#10;
a = 4'b0001;
b = 4'b1000;
#10;
a = 4'b1010;
b = 4'b0111;
#10;
a = 4'b1110;
b = 4'b0010;
#10;
a = 4'b1111;
b = 4'b1111;
#10;
a = 4'b0110;
b = 4'b1001;
end

endmodule

  仿真结果如下图:

  以上就是Wallace树型4位乘法器的实现了,我认为关键在于进位保留加法器(Carry Save Adder)的理解,希望能给大家带来帮助。  

 

 

 

 


 

Guess you like

Origin www.cnblogs.com/wangkai2019/p/11228411.html