Binary 用门级图理解二进制乘法器

Binary 用门级图理解二进制乘法器,binary,verilog,fpga,multiplication,synthesis,Binary,Verilog,Fpga,Multiplication,Synthesis,我在理解以下执行无符号2位乘法运算的(bimpy.v)时遇到问题 编辑:添加了我的一位朋友的评论:以下修改对更少的逻辑做了同样的事情 o_r <= (i_a[0] ? i_b : 2'b0) + ((i_a[1] ? i_b : 2'b0) << 1); 代码与2位乘2位二进制乘法器不匹配,如果错误,请更正 我还附加了一个来自bimpy.v的工作波形,用于一个简单的2x2无符号乘法器 我还为bimpy.v生成了门级表示图 ////////////////////////

我在理解以下执行无符号2位乘法运算的(bimpy.v)时遇到问题

编辑:添加了我的一位朋友的评论:以下修改对更少的逻辑做了同样的事情

o_r <= (i_a[0] ? i_b : 2'b0) + ((i_a[1] ? i_b : 2'b0) << 1);
代码与2位乘2位二进制乘法器不匹配,如果错误,请更正

我还附加了一个来自bimpy.v的工作波形,用于一个简单的2x2无符号乘法器

我还为bimpy.v生成了门级表示图

 ////////////////////////////////////////////////////////////////////////////////
//
// Filename:    bimpy
//
// Project: A multiply core generator
//
// Purpose: An unsigned 2-bit multiply based upon the fact that LUT's allow
//      6-bits of input, but a 2x2 bit multiply will never carry more
//  than one bit.  While this multiply is hardware independent, it is
//  really motivated by trying to optimize for a specific piece of
//  hardware (Xilinx-7 series ...) that has 4-input LUT's with carry
//  chains.
//
// Creator: Dan Gisselquist, Ph.D.
//      Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015,2017-2019, Gisselquist Technology, LLC
//
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program.  If not, see <http://www.gnu.org/licenses/> for a
// copy.
//
// License: GPL, v3, as defined and found on www.gnu.org,
//      http://www.gnu.org/licenses/gpl.html
//
//
////////////////////////////////////////////////////////////////////////////////
module  bimpy(i_clk, i_reset, i_ce, i_a, i_b, o_r);
    parameter   BW=2, LUTB=2;
    input               i_clk, i_reset, i_ce;
    input       [(LUTB-1):0]    i_a;
    input       [(BW-1):0]  i_b;
    output  reg [(BW+LUTB-1):0] o_r;

    wire    [(BW+LUTB-2):0] w_r;
    wire    [(BW+LUTB-3):1] c;

    assign  w_r =  { ((i_a[1])?i_b:{(BW){1'b0}}), 1'b0 }
                ^ { 1'b0, ((i_a[0])?i_b:{(BW){1'b0}}) };
    assign  c = { ((i_a[1])?i_b[(BW-2):0]:{(BW-1){1'b0}}) }
            & ((i_a[0])?i_b[(BW-1):1]:{(BW-1){1'b0}});

    initial o_r = 0;
    always @(posedge i_clk)
        if (i_reset)
            o_r <= 0;
        else if (i_ce)
            o_r <= w_r + { c, 2'b0 };

endmodule

////////////////////////////////////////////////////////////////////////////////
//
//文件名:bimpy
//
//项目:多芯发电机
//
//用途:基于LUT允许的事实的无符号2位乘法
//6位输入,但2x2位乘法永远不会携带更多
//不止一点。虽然此乘法与硬件无关,但它是
//真正的动机是尝试优化特定的
//具有带进位的4输入LUT的硬件(Xilinx-7系列…)
//锁链。
//
//创作者:丹·吉斯尔奎斯特博士。
//吉赛尔奎斯特技术有限责任公司
//
////////////////////////////////////////////////////////////////////////////////
//
//版权所有(C)20152017-2019,Gisselquist Technology,LLC
//
//此程序是免费软件(固件):您可以重新分发和/或
//根据发布的GNU通用公共许可证的条款对其进行修改
//通过自由软件基金会,许可证的版本3,或(AT)
//您的选择)任何更高版本。
//
//这个程序的发布是希望它会有用,但是没有
//任何保证;甚至没有暗示的适销性保证或
//适合某一特定目的。请参阅GNU通用公共许可证
//更多细节。
//
//您应该已经收到了GNU通用公共许可证的副本
//用这个程序。如果没有,请参阅以获取详细信息
//抄袭。
//
//许可证:GPL,v3,定义见www.gnu.org,
//      http://www.gnu.org/licenses/gpl.html
//
//
////////////////////////////////////////////////////////////////////////////////
模块bimpy(i_clk、i_reset、i_ce、i_a、i_b、o_r);
参数BW=2,LUTB=2;
输入i_clk、i_reset、i_ce;
输入[(LUTB-1):0]i_a;
输入[(BW-1):0]i_b;
输出寄存器[(BW+LUTB-1):0]o\u r;
导线[(BW+LUTB-2):0]w\U r;
导线[(BW+LUTB-3):1]c;
赋值w_r={((i_a[1])?i_b:{(BW){1'b0}}),1'b0}
^{1'b0,((i_a[0])?i_b:{(BW){1'b0}}});
赋值c={((i_a[1])?i_b[(BW-2):0]:{(BW-1){1'b0}}}
&((i_a[0])?i_b[(BW-1):1]:{(BW-1){1'b0}});
初始o_r=0;
始终@(posedge i_clk)
如果(i_重置)

o_r关于MUX的注意事项

回想一下,
描述了多路复用器(MUX),因此该语句:

out=sel?x:y

在门级实现中等同于:

out=(sel&x)|(~sel&y)


(当
sel=1
out这可能更适合?@Andreas有没有办法在不重新创建帖子内容的情况下将帖子迁移到那里?不知道,但我知道帖子可以迁移到那里“代码不匹配”…我没有检查,但它很可能会产生相同的结果。要检查它们是否相同,你可以将它们扔向正式的验证工具,或者使用所有16种可能的输入运行并行模拟。为什么“w_r[0]=0^(A0&B0)=0&B0”?为什么“o_r[0]=0+w_r[0]=A0&B0”?你是对的,这是一个输入错误;用正确的
w_r修正了它[0]=0^(A0&B0)=A0&B0
,所以你得到了
o_r[0]=0+w_r[0]=A0&B0
“o_r[2]=c+w_r[2]=c+w_r[2]=(A1&B0&A0&B1)+(A1&B1)——如果我们加上它们,那么总和就是它们的异或,进位就是它们的和,即:o_r[2]=(A1&B0&A0&B1)^(A1&B1)=(A1&A1)中还有一个输入错误手动优化如何帮助使用进位链安装Xilinx 4-input-LUT?请记住,有两个XOR门
 ////////////////////////////////////////////////////////////////////////////////
//
// Filename:    bimpy
//
// Project: A multiply core generator
//
// Purpose: An unsigned 2-bit multiply based upon the fact that LUT's allow
//      6-bits of input, but a 2x2 bit multiply will never carry more
//  than one bit.  While this multiply is hardware independent, it is
//  really motivated by trying to optimize for a specific piece of
//  hardware (Xilinx-7 series ...) that has 4-input LUT's with carry
//  chains.
//
// Creator: Dan Gisselquist, Ph.D.
//      Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015,2017-2019, Gisselquist Technology, LLC
//
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program.  If not, see <http://www.gnu.org/licenses/> for a
// copy.
//
// License: GPL, v3, as defined and found on www.gnu.org,
//      http://www.gnu.org/licenses/gpl.html
//
//
////////////////////////////////////////////////////////////////////////////////
module  bimpy(i_clk, i_reset, i_ce, i_a, i_b, o_r);
    parameter   BW=2, LUTB=2;
    input               i_clk, i_reset, i_ce;
    input       [(LUTB-1):0]    i_a;
    input       [(BW-1):0]  i_b;
    output  reg [(BW+LUTB-1):0] o_r;

    wire    [(BW+LUTB-2):0] w_r;
    wire    [(BW+LUTB-3):1] c;

    assign  w_r =  { ((i_a[1])?i_b:{(BW){1'b0}}), 1'b0 }
                ^ { 1'b0, ((i_a[0])?i_b:{(BW){1'b0}}) };
    assign  c = { ((i_a[1])?i_b[(BW-2):0]:{(BW-1){1'b0}}) }
            & ((i_a[0])?i_b[(BW-1):1]:{(BW-1){1'b0}});

    initial o_r = 0;
    always @(posedge i_clk)
        if (i_reset)
            o_r <= 0;
        else if (i_ce)
            o_r <= w_r + { c, 2'b0 };

endmodule