基于Radix-4的Booth乘法器


先说明为何需要基于Radix-4的Booth乘法器,这是因为这种方法的加法可以使级数降低一半。

一、基于Radix-4的Booth乘法器原理

1.基本原理

对于有符号数的二进制数,将其转化为十进制数的公式如下:

B = − B n − 1 2 n − 1 + ( ∑ i = 0 n − 2 B i ∗ 2 i ) B=-B_{n-1} 2^{n-1}+\left(\sum_{i=0}^{\mathrm{n}-2} B_{i} * 2^{i}\right) B=Bn12n1+(i=0n2Bi2i)

Radix-4的基系数为:

C o e f i = ( − 2 B i + 1 + B i + B i − 1 ) Coef_i =(-2B_{i+1}+B_i+B_{i-1}) Coefi=(2Bi+1+Bi+Bi1)

对B展开:

B = − B n − 1 2 n − 1 + ( ∑ i = 0 n − 2 B i ∗ 2 i )      = − B n − 1 2 n − 1 + B n − 2 2 n − 2 + B n − 3 2 n − 3 + B n − 4 2 n − 4 + … … +            B 3 2 3 + B 2 2 2 + B 1 2 1 + B 0 2 0 + B − 1      = ( − 2 B n − 1 + B n − 2 + B n − 3 ) 2 n − 2 + ( − 2 B n − 3 + B n − 4 + B n − 5 ) 2 n − 4 + … … +          ( − 2 B 5 + B 4 + B 3 ) 2 4 + ( − 2 B 3 + B 2 + B 1 ) 2 2 + ( − 2 B 1 + B 0 + B − 1 ) 2 0 \begin{array}{l}B=-B_{n-1} 2^{n-1}+\left(\sum_{i=0}^{\mathrm{n}-2} B_{i} * 2^{i}\right) \\ \\ \space \space\space\space=-B_{\mathrm{n}-1} 2^{\mathrm{n}-1}+B_{\mathrm{n}-2} 2^{\mathrm{n}-2}+B_{\mathrm{n}-3} 2^{\mathrm{n}-3}+B_{\mathrm{n}-4} 2^{\mathrm{n}-4}+\ldots \ldots+ \\ \\ \space\space\space\space\space\space\space\space\space\ B_{3} 2^{3}+B_{2} 2^{2}+B_{1} 2^{1}+B_{0} 2^{0}+B_{-1} \\ \\ \space\space\space\space=\left(-2 B_{\mathrm{n}-1}+B_{\mathrm{n}-2}+B_{\mathrm{n}-3}\right) 2^{\mathrm{n}-2}+\left(-2 B_{\mathrm{n}-3}+B_{\mathrm{n}-4}+B_{\mathrm{n}-5}\right) 2^{\mathrm{n}-4}+\ldots \ldots+ \\ \\ \space\space\space\space\space\space\space\space\left(-2 B_{5}+B_{4}+B_{3}\right) 2^{4}+\left(-2 B_{3}+B_{2}+B_{1}\right) 2^{2}+\left(-2 B_{1}+B_{0}+B_{-1}\right) 2^{0}\end{array} B=Bn12n1+(i=0n2Bi2i)    =Bn12n1+Bn22n2+Bn32n3+Bn42n4+……+          B323+B222+B121+B020+B1    =(2Bn1+Bn2+Bn3)2n2+(2Bn3+Bn4+Bn5)2n4+……+        (2B5+B4+B3)24+(2B3+B2+B1)22+(2B1+B0+B1)20

上述公式中B_-1为0,是为了方便对公式进行整理添加的。

则A*B可以写成如下形式:

A ∗ B = A ∗ ( − 2 B n − 1 + B n − 2 + B n − 3 ) 2 n − 2 + A ∗ ( − 2 B n − 3 + B n − 4 + B n − 5 ) 2 n − 4 + … …              + A ∗ ( − 2 B 5 + B 4 + B 3 ) 2 4 + A ∗ ( − 2 B 3 + B 2 + B 1 ) 2 2 + A ∗ ( − 2 B 1 + B 0 + B − 1 ) 2 0 \begin{array}{l} A*B=A*(-2 B_{\mathrm{n}-1}+B_{\mathrm{n}-2}+B_{\mathrm{n}-3}) 2^{\mathrm{n}-2}+A*(-2 B_{\mathrm{n}-3}+B_{\mathrm{n}-4}+B_{\mathrm{n}-5}) 2^{\mathrm{n}-4}+\ldots \ldots\\\\\space\space\space\space \space\space\space\space\space\space\space\space+A*(-2 B_{5}+B_{4}+B_{3}) 2^{4}+A*(-2 B_{3}+B_{2}+B_{1}) 2^{2}+A*(-2 B_{1}+B_{0}+B_{-1}) 2^{0}\end{array} AB=A(2Bn1+Bn2+Bn3)2n2+A(2Bn3+Bn4+Bn5)2n4+……            +A(2B5+B4+B3)24+A(2B3+B2+B1)22+A(2B1+B0+B1)20

按照上述操作,我们可以发现加法的级数降低了一半

下面给出基4 Booth编码表:

Bi+1BiBi-1Cofe部分积
00000
001+1A
010+1A
011+22A
100-2-2A
101-1-A
110-1-A
11100

因此每次计算时,只需要从最低位置开始,按照基系数Coef计算出相邻三个bit的和,然后根据和为-2、-1、0、1、2来得到乘法结果并移位,之后将所有得到的乘法结果相加即可。

2.无符号数的Booth乘法器

需要注意的是,上述方法针对的是有符号数的乘法运算,对于无符号数,除了在低位要补0外,还需要高位扩展两位的符号位(两个0)。

为什么是扩展两个0 ?举个例子,如果对十进制数11进行分解,其二进制位1011,低位扩展0后变为10110,这样得到的Cofe如下:

在这里插入图片描述

无符号数的最高位1被当作符号位进行运算了,这与Booth乘法器的原理不符合,接下来最高位的1将作为Bi-1参与Cofe的计算,那么就需要额外的两bit数,因此在高位需要扩展两个0,这是需要的最多的额外bit的情况。如果乘数是7,那么扩展低位后变为1110,这时候变为如下的情况,只需要1bit即可,但是扩展两位并不影响运算。

在这里插入图片描述

二、Verilog及综合电路

Verilog代码如下:

module multiplication(
    input [3:0] a,
    input [3:0] b,
    input data_valid,
    output [7:0] sum
    );
    
reg add=0;
reg [7:0]adder=0;
reg [6:0]b_reg=0;
reg [3:0]a_reg=0;
reg [4:0]a_reg2=0;
reg [7:0] sum=0;
integer i=0;

always@(*)
begin
if(data_valid)
begin
    b_reg={2'b00,b,1'b0};
    a_reg=a;
    a_reg2=a<<1;
         
    for(i=0;i<=4;i=i+2)
    begin
        case(b_reg[2:0])
                    3'b000:begin
                            adder=0;
                            add=0;
                           end
                    3'b001:begin
                            adder=a_reg;
                            add=0;
                           end
                    3'b010:begin
                            adder=a_reg;
                            add=0;
                           end
                    3'b011:begin
                            adder=a_reg2;
                            add=0;
                           end
                    3'b100:begin
                            adder=a_reg2;
                            add=1;
                           end
                    3'b101:begin
                            adder=a_reg;
                            add=1;
                           end
                    3'b110:begin
                            adder=a_reg;
                            add=1;
                           end
                    3'b111:begin
                            adder=0;
                            add=0;
                           end
            endcase
            sum=add?(sum-(adder<<(i-4))):(sum+(adder<<(i-4)));
            b_reg=b_reg>>2;

    end
end
else
begin
    sum=0;
    i=0;
end
end
endmodule

上述代码中,adder代表本次要加减的数据大小,add表示加还是减,当为1时表示减操作,否则为加操作。

综合结果如下所示:

在这里插入图片描述

图中的多个MUX以及移位寄存器是因为采用了for循环的原因,因为一共有三次部分积操作,因此一共有三组。

testbench代码如下:

module tb_top();
reg [3:0]a;
reg [3:0]b;
wire [7:0]sum;
reg data_valid;
initial begin
    a=0;b=0;
    data_valid=0;
    #100
    a=4'b0011;
    b=4'b1010;
    data_valid=1;
    #100
    a=0;b=0;
    data_valid=0;
    #100
    a=4'b1111;
    b=4'b1111;
    data_valid=1;
    #100
    a=0;b=0;
    data_valid=0;
    #100
    a=4'b1100;
    b=4'b1100;
    data_valid=1;
    #100
    a=0;b=0;
    data_valid=0;
end

    multiplication inst_multiplication (.a(a), .b(b), .data_valid(data_valid),.sum(sum));
endmodule

仿真结果如图:

在这里插入图片描述

三、基4 Booth乘法器实例

我们以上述仿真中的第一个测试例说明,即:

a = 3 , b = 10 a=3,b=10 a=3,b=10

我们对b=4’b1010进行基系数计算:

首先对其低位和符号位进行扩展得到:4’b0010100

基系数为

在这里插入图片描述

a ∗ b = − 2 a + − a ∗ 2 2 + a ∗ 2 4 = 30 a*b=-2a+-a*2^2+a*2^4=30 ab=2a+a22+a24=30

对应下表:

Booth(从低位开始)部分积数值
-2-2a1111 1010
-1-a,左移两位1111 0100
1a,左移四位0011 0000
0001 1110
  • 11
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值