?? multiplier_unit.v
字號:
// --------------------------------------------
// module multiplier_unit_4 multiplier_unit_5 multiplier_quick_add_4 multiplier_quick_add_5
// file name: multiplier_unit.v
// purpose: full addr
// author Hejun
// simulate Modelsim
//------------------------------------------
// Revision List
// version 1.0
`timescale 1ns/1ns
module multiplier_unit_4(
y,
x,
shiftin,
shiftout,
cin,
cout,
pp
);
input [3:0] y;
input [3:0] x;
//input shiftin1;
input [1:0] shiftin;
output [3:0] shiftout;
input cin;
output [3:0] pp;
output cout;
//output cout2;
//output c;
wire [3:0] shiftout;
wire [3:0] pp;
wire k;
wire w;
wire p1;
wire p2;
wire [3:0] t1;
wire [3:0] t2;
wire [3:0] t3;
wire [3:0] t4;
wire c;
wire cout;
//wire cout2;
assign k = y[3] & y[2] & y[1] & y[0] | ~y[3] & ~y[2] & ~y[1] & ~y[0];
assign w = y[0] ? ~y[1] : y[1];
assign p1 = y[3] ? ~y[2] : y[2];
assign p2 = y[2] ? ~y[1] : y[1];
assign shiftout[3:0] = ~(x[3:0]^{y[3],y[3],y[3],y[3]});
assign t1[3:0] = w ? shiftout[3:0] : {shiftout[2:0],shiftin[1]};
assign t2[3:0] = w ? {shiftout[2:0],shiftin[1]} : {shiftout[1:0],shiftin[1:0]};
assign t3[3:0] = (w & ~p1) ? t1[3:0] : 4'bz; //x
//assign t3 = (w & p1) ? ((~(~t2 ^ ~shiftout)) & ~y[3]) | ((t2 ^ shiftout) & y[3]):'bz;
assign t3 = (~w & p2) ? t1 : 4'bz; //2x
assign t3 = (~w & ~p2) ? t2 : 4'bz; //4x
assign t3 = (w & p1) ? (~t4[3:0] & {~y[3],~y[3],~y[3],~y[3]}) | (t4[3:0] & {y[3],y[3],y[3],y[3]}): 4'bz; //3x
multiplier_quick_add_4 multiplier_quick_add_4_1(
.a ((shiftout & {y[3],y[3],y[3],y[3]})|(~shiftout & {~y[3],~y[3],~y[3],~y[3]})),
.b (({shiftout[2:0],shiftin[1]} & {y[3],y[3],y[3],y[3]})|({~shiftout[2:0],~shiftin[1]} & {~y[3],~y[3],~y[3],~y[3]})),
.cin (cin),
.s (t4),
.cout (c)
);
assign pp[3:0] = k? 4'b0 : ~t3[3:0];
assign cout =(w & p1) ? c : 1'b0;
//assign sumout = ((sumin & ^ cin1 ^ pp) & ~y[3]) | ((~(sumin ^ cin1 ^ ~pp)) & y[3]);
endmodule
module multiplier_full_add(
a,
b,
cin,
s,
cout
);
input a;
input b;
input cin;
output s;
output cout;
wire s;
wire cout;
assign s = a ^ b ^ cin;
assign cout = ((a ^ b) & cin) | (~(a ^ b) & a);
endmodule
module multiplier_quick_add_4(
a,
b,
cin,
s,
cout
);
input [4:1] a;
input [4:1] b;
input cin;
output [4:1] s;
output cout;
wire [4:1] s;
wire cout;
wire [4:1] p;
wire [4:1] g;
wire [4:0] c;
assign g[4:1] = a[4:1] & b[4:1];
assign p[4:1] = a[4:1] | b[4:1];
assign c[0] = cin;
assign c[1] = g[1] | p[1] & cin;
assign c[2] = g[2] | p[2] & g[1] | p[2] & p[1] & cin;
assign c[3] = g[3] | p[3] & g[2] | p[3] & p[2] & g[1] | p[3] & p[2] & p[1] & cin ;
assign c[4] = g[4] | p[4] & g[3] | p[4] & p[3] & g[2] | p[4] & p[3] & p[2] & g[1] | p[4] & p[3] & p[2] & p[1] & cin;
assign s[4:1] = a[4:1] ^ b[4:1] ^ c[3:0];
assign cout = c[4];
endmodule
module multiplier_quick_add_5(
a,
b,
cin,
s,
cout
);
input [5:1] a;
input [5:1] b;
input cin;
output [5:1] s;
output cout;
wire [5:1] s;
wire cout;
wire [5:1] p;
wire [5:1] g;
wire [5:0] c;
assign g[5:1] = a[5:1] & b[5:1];
assign p[5:1] = a[5:1] | b[5:1];
assign c[0] = cin;
assign c[1] = g[1] | p[1] & cin;
assign c[2] = g[2] | p[2] & g[1] | p[2] & p[1] & cin;
assign c[3] = g[3] | p[3] & g[2] | p[3] & p[2] & g[1] | p[3] & p[2] & p[1] & cin ;
assign c[4] = g[4] | p[4] & g[3] | p[4] & p[3] & g[2] | p[4] & p[3] & p[2] & g[1] | p[4] & p[3] & p[2] & p[1] & cin;
assign c[5] = g[5] | p[5] & g[4] | p[5] & p[4] & g[3] | p[5] & p[4] & p[3] & g[2] | p[5] & p[4] & p[3] & p[2] & g[1] | p[5] & p[4] & p[3] & p[2] & p[1] & cin;
assign s[5:1] = a[5:1] ^ b[5:1] ^ c[4:0];
assign cout = c[5];
endmodule
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -