understanding a binary multiplier using gate-level diagram












0















I am having problem understanding the following code (bimpy.v) that does unsigned 2-bit multiply operation.



Edit: Added comment from one of my friend: the following modification does the same thing with fewer logic !!



o_r <= (i_a[0] ? i_b : 0) + (i_a[1] ? i_b:0)<<1;


What are the purposes of the two signals (w_r and c) in bimpy.v ?



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}});


The code does not match the 2-bit by 2-bit binary multiplier gate-level diagram , please correct me if wrong



2-bit by 2-bit binary multiplier



I am also attaching a working waveform from bimpy.v for a simple 2x2 unsigned multiplier.



bimpy.v waveform



I have also generated a gate-level representation diagram for bimpy.v



gate-level representation of 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









share|improve this question

























  • This might be more suitable for electronics.stackexchange.com?

    – Andreas
    6 hours ago











  • @Andreas Is there any way to cross-post to electronics.stackexchange.com without re-creating the post content ?

    – kevin998x
    6 hours ago











  • No idea about that, but I know that the post can be migrated to there

    – Andreas
    5 hours ago











  • "The code does not match" .. I did not check but it may well produce the same result. To check if they are the same you could throw them at a formal verification tool or run a side-by-side simulation with all 16 possible inputs.

    – Oldfart
    2 hours ago
















0















I am having problem understanding the following code (bimpy.v) that does unsigned 2-bit multiply operation.



Edit: Added comment from one of my friend: the following modification does the same thing with fewer logic !!



o_r <= (i_a[0] ? i_b : 0) + (i_a[1] ? i_b:0)<<1;


What are the purposes of the two signals (w_r and c) in bimpy.v ?



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}});


The code does not match the 2-bit by 2-bit binary multiplier gate-level diagram , please correct me if wrong



2-bit by 2-bit binary multiplier



I am also attaching a working waveform from bimpy.v for a simple 2x2 unsigned multiplier.



bimpy.v waveform



I have also generated a gate-level representation diagram for bimpy.v



gate-level representation of 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









share|improve this question

























  • This might be more suitable for electronics.stackexchange.com?

    – Andreas
    6 hours ago











  • @Andreas Is there any way to cross-post to electronics.stackexchange.com without re-creating the post content ?

    – kevin998x
    6 hours ago











  • No idea about that, but I know that the post can be migrated to there

    – Andreas
    5 hours ago











  • "The code does not match" .. I did not check but it may well produce the same result. To check if they are the same you could throw them at a formal verification tool or run a side-by-side simulation with all 16 possible inputs.

    – Oldfart
    2 hours ago














0












0








0








I am having problem understanding the following code (bimpy.v) that does unsigned 2-bit multiply operation.



Edit: Added comment from one of my friend: the following modification does the same thing with fewer logic !!



o_r <= (i_a[0] ? i_b : 0) + (i_a[1] ? i_b:0)<<1;


What are the purposes of the two signals (w_r and c) in bimpy.v ?



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}});


The code does not match the 2-bit by 2-bit binary multiplier gate-level diagram , please correct me if wrong



2-bit by 2-bit binary multiplier



I am also attaching a working waveform from bimpy.v for a simple 2x2 unsigned multiplier.



bimpy.v waveform



I have also generated a gate-level representation diagram for bimpy.v



gate-level representation of 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









share|improve this question
















I am having problem understanding the following code (bimpy.v) that does unsigned 2-bit multiply operation.



Edit: Added comment from one of my friend: the following modification does the same thing with fewer logic !!



o_r <= (i_a[0] ? i_b : 0) + (i_a[1] ? i_b:0)<<1;


What are the purposes of the two signals (w_r and c) in bimpy.v ?



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}});


The code does not match the 2-bit by 2-bit binary multiplier gate-level diagram , please correct me if wrong



2-bit by 2-bit binary multiplier



I am also attaching a working waveform from bimpy.v for a simple 2x2 unsigned multiplier.



bimpy.v waveform



I have also generated a gate-level representation diagram for bimpy.v



gate-level representation of 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






binary verilog fpga multiplication synthesis






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago







kevin998x

















asked 6 hours ago









kevin998xkevin998x

213




213













  • This might be more suitable for electronics.stackexchange.com?

    – Andreas
    6 hours ago











  • @Andreas Is there any way to cross-post to electronics.stackexchange.com without re-creating the post content ?

    – kevin998x
    6 hours ago











  • No idea about that, but I know that the post can be migrated to there

    – Andreas
    5 hours ago











  • "The code does not match" .. I did not check but it may well produce the same result. To check if they are the same you could throw them at a formal verification tool or run a side-by-side simulation with all 16 possible inputs.

    – Oldfart
    2 hours ago



















  • This might be more suitable for electronics.stackexchange.com?

    – Andreas
    6 hours ago











  • @Andreas Is there any way to cross-post to electronics.stackexchange.com without re-creating the post content ?

    – kevin998x
    6 hours ago











  • No idea about that, but I know that the post can be migrated to there

    – Andreas
    5 hours ago











  • "The code does not match" .. I did not check but it may well produce the same result. To check if they are the same you could throw them at a formal verification tool or run a side-by-side simulation with all 16 possible inputs.

    – Oldfart
    2 hours ago

















This might be more suitable for electronics.stackexchange.com?

– Andreas
6 hours ago





This might be more suitable for electronics.stackexchange.com?

– Andreas
6 hours ago













@Andreas Is there any way to cross-post to electronics.stackexchange.com without re-creating the post content ?

– kevin998x
6 hours ago





@Andreas Is there any way to cross-post to electronics.stackexchange.com without re-creating the post content ?

– kevin998x
6 hours ago













No idea about that, but I know that the post can be migrated to there

– Andreas
5 hours ago





No idea about that, but I know that the post can be migrated to there

– Andreas
5 hours ago













"The code does not match" .. I did not check but it may well produce the same result. To check if they are the same you could throw them at a formal verification tool or run a side-by-side simulation with all 16 possible inputs.

– Oldfart
2 hours ago





"The code does not match" .. I did not check but it may well produce the same result. To check if they are the same you could throw them at a formal verification tool or run a side-by-side simulation with all 16 possible inputs.

– Oldfart
2 hours ago












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54247731%2funderstanding-a-binary-multiplier-using-gate-level-diagram%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54247731%2funderstanding-a-binary-multiplier-using-gate-level-diagram%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage