mirror of
https://github.com/aolofsson/oh.git
synced 2025-01-17 20:02:53 +08:00
Vectorizing csa modules
This commit is contained in:
parent
d2fbbcf341
commit
f62d7c0975
@ -1,19 +1,23 @@
|
||||
module oh_csa32 (/*AUTOARG*/
|
||||
// Outputs
|
||||
c, s,
|
||||
// Inputs
|
||||
in0, in1, in2
|
||||
);
|
||||
//#############################################################################
|
||||
//# Function: Carry Save Adder (3:2) #
|
||||
//#############################################################################
|
||||
//# Author: Andreas Olofsson #
|
||||
//# License: MIT (see LICENSE file in this repository) #
|
||||
//#############################################################################
|
||||
|
||||
input in0;
|
||||
input in1;
|
||||
input in2;
|
||||
|
||||
output c;
|
||||
output s;
|
||||
|
||||
assign s = in0 ^ in1 ^ in2;
|
||||
assign c = (in0 & in1) | ( in1 & in2) | ( in2 & in0 );
|
||||
module oh_csa32 #( parameter DW = 1 // data width
|
||||
)
|
||||
( input [DW-1:0] in0, //input
|
||||
input [DW-1:0] in1,//input
|
||||
input [DW-1:0] in2,//input
|
||||
output [DW-1:0] s, //sum
|
||||
output [DW-1:0] c //carry
|
||||
);
|
||||
|
||||
assign s[DW-1:0] = in0[DW-1:0] ^ in1[DW-1:0] ^ in2[DW-1:0];
|
||||
assign c[DW-1:0] = (in0[DW-1:0] & in1[DW-1:0]) |
|
||||
(in1[DW-1:0] & in2[DW-1:0]) |
|
||||
(in2[DW-1:0] & in0[DW-1:0] );
|
||||
|
||||
endmodule // oh_csa32
|
||||
|
||||
|
@ -1,27 +1,41 @@
|
||||
//CSA4:2 Compressor
|
||||
module oh_csa42 (/*AUTOARG*/
|
||||
// Outputs
|
||||
s, c, cout,
|
||||
// Inputs
|
||||
in0, in1, in2, in3, cin
|
||||
);
|
||||
//#############################################################################
|
||||
//# Function: Carry Save Adder (4:2) #
|
||||
//#############################################################################
|
||||
//# Author: Andreas Olofsson #
|
||||
//# License: MIT (see LICENSE file in this repository) #
|
||||
//#############################################################################
|
||||
|
||||
input in0;
|
||||
input in1;
|
||||
input in2;
|
||||
input in3;
|
||||
input cin;
|
||||
module oh_csa42 #( parameter DW = 1 // data width
|
||||
)
|
||||
( input [DW-1:0] in0, //input
|
||||
input [DW-1:0] in1,//input
|
||||
input [DW-1:0] in2,//input
|
||||
input [DW-1:0] in3,//input
|
||||
input [DW-1:0] cin,//carry in
|
||||
output [DW-1:0] s, //sum
|
||||
output [DW-1:0] c, //carry
|
||||
output [DW-1:0] cout //carry out
|
||||
);
|
||||
|
||||
wire [DW-1:0] s_int;
|
||||
|
||||
output s;
|
||||
output c;
|
||||
output cout;
|
||||
assign s[DW-1:0] = in0[DW-1:0] ^
|
||||
in1[DW-1:0] ^
|
||||
in2[DW-1:0] ^
|
||||
in3[DW-1:0] ^
|
||||
cin[DW-1:0];
|
||||
|
||||
assign s_int[DW-1:0] = in1[DW-1:0] ^
|
||||
in2[DW-1:0] ^
|
||||
in3[DW-1:0];
|
||||
|
||||
wire s_int;
|
||||
assign c[DW-1:0] = (in0[DW-1:0] & s_int[DW-1:0]) |
|
||||
(in0[DW-1:0] & cin[DW-1:0]) |
|
||||
(s_int[DW-1:0] & cin[DW-1:0]);
|
||||
|
||||
assign s = in0 ^ in1 ^in2 ^in3 ^ cin;
|
||||
assign s_int = in1 ^ in2 ^ in3;
|
||||
assign c = (in0 & s_int) | (in0 & cin) | (s_int & cin);
|
||||
assign cout = (in1 & in2) | (in1 & in3) | (in2 & in3);
|
||||
assign cout[DW-1:0] = (in1[DW-1:0] & in2[DW-1:0]) |
|
||||
(in1[DW-1:0] & in3[DW-1:0]) |
|
||||
(in2[DW-1:0] & in3[DW-1:0]);
|
||||
|
||||
endmodule // oh_csa42
|
||||
|
||||
|
@ -1,35 +1,52 @@
|
||||
//CSA6:2 Compressor
|
||||
module oh_csa62 (/*AUTOARG*/
|
||||
// Outputs
|
||||
s, c, cout0, cout1, cout2,
|
||||
// Inputs
|
||||
in0, in1, in2, in3, in4, in5, cin0, cin1, cin2
|
||||
);
|
||||
//#############################################################################
|
||||
//# Function: Carry Save Adder (6:2) #
|
||||
//#############################################################################
|
||||
//# Author: Andreas Olofsson #
|
||||
//# License: MIT (see LICENSE file in this repository) #
|
||||
//#############################################################################
|
||||
|
||||
input in0;
|
||||
input in1;
|
||||
input in2;
|
||||
input in3;
|
||||
input in4;
|
||||
input in5;
|
||||
input cin0;
|
||||
input cin1;
|
||||
input cin2;
|
||||
module oh_csa62 #( parameter DW = 1 // data width
|
||||
)
|
||||
( input [DW-1:0] in0, //input
|
||||
input [DW-1:0] in1,//input
|
||||
input [DW-1:0] in2,//input
|
||||
input [DW-1:0] in3,//input
|
||||
input [DW-1:0] in4,//input
|
||||
input [DW-1:0] in5,//input
|
||||
input [DW-1:0] cin0,//carry in
|
||||
input [DW-1:0] cin1,//carry in
|
||||
input [DW-1:0] cin2,//carry in
|
||||
output [DW-1:0] s, //sum
|
||||
output [DW-1:0] c, //carry
|
||||
output [DW-1:0] cout0, //carry out
|
||||
output [DW-1:0] cout1, //carry out
|
||||
output [DW-1:0] cout2 //carry out
|
||||
);
|
||||
|
||||
wire [DW-1:0] s_int0;
|
||||
wire [DW-1:0] s_int1;
|
||||
|
||||
output s;
|
||||
output c;
|
||||
output cout0;
|
||||
output cout1;
|
||||
output cout2;
|
||||
oh_csa32 #(.DW(DW)) csa32_0 (.in0(in0[DW-1:0]),
|
||||
.in1(in1[DW-1:0]),
|
||||
.in2(in2[DW-1:0]),
|
||||
.c(cout0[DW-1:0]),
|
||||
.s(s_int0[DW-1:0]));
|
||||
|
||||
wire s_int0;
|
||||
wire s_int1;
|
||||
oh_csa32 #(.DW(DW)) csa32_1 (.in0(in3[DW-1:0]),
|
||||
.in1(in4[DW-1:0]),
|
||||
.in2(in5[DW-1:0]),
|
||||
.c(cout1[DW-1:0]),
|
||||
.s(s_int1[DW-1:0]));
|
||||
|
||||
oh_csa32 csa32_0 (.in0(in0),.in1(in1),.in2(in2),.c(cout0),.s(s_int0));
|
||||
oh_csa32 csa32_1 (.in0(in3),.in1(in4),.in2(in5),.c(cout1),.s(s_int1));
|
||||
|
||||
oh_csa42 csa42 (.in0(s_int0),.in1(s_int1),.in2(cin0),.in3(cin1),.cin(cin2),
|
||||
.cout(cout2),.c(c),.s(s));
|
||||
oh_csa42 #(.DW(DW)) csa42 (.in0(s_int0[DW-1:0]),
|
||||
.in1(s_int1[DW-1:0]),
|
||||
.in2(cin0[DW-1:0]),
|
||||
.in3(cin1[DW-1:0]),
|
||||
.cin(cin2[DW-1:0]),
|
||||
.cout(cout2[DW-1:0]),
|
||||
.c(c[DW-1:0]),
|
||||
.s(s[DW-1:0]));
|
||||
|
||||
endmodule // oh_csa62
|
||||
|
||||
|
@ -1,51 +1,75 @@
|
||||
//CSA9:2 Compressor
|
||||
module oh_csa92 (/*AUTOARG*/
|
||||
// Outputs
|
||||
s, c, cout0, cout1, cout2, cout3, cout4, cout5,
|
||||
// Inputs
|
||||
in0, in1, in2, in3, in4, in5, in6, in7, in8, cin0, cin1, cin2,
|
||||
cin3, cin4, cin5
|
||||
);
|
||||
//#############################################################################
|
||||
//# Function: Carry Save Adder (9:2) #
|
||||
//#############################################################################
|
||||
//# Author: Andreas Olofsson #
|
||||
//# License: MIT (see LICENSE file in this repository) #
|
||||
//#############################################################################
|
||||
|
||||
input in0;
|
||||
input in1;
|
||||
input in2;
|
||||
input in3;
|
||||
input in4;
|
||||
input in5;
|
||||
input in6;
|
||||
input in7;
|
||||
input in8;
|
||||
module oh_csa92 #( parameter DW = 1 // data width
|
||||
)
|
||||
|
||||
input cin0;
|
||||
input cin1;
|
||||
input cin2;
|
||||
input cin3;
|
||||
input cin4;
|
||||
input cin5;
|
||||
( input [DW-1:0] in0, //input
|
||||
input [DW-1:0] in1,//input
|
||||
input [DW-1:0] in2,//input
|
||||
input [DW-1:0] in3,//input
|
||||
input [DW-1:0] in4,//input
|
||||
input [DW-1:0] in5,//input
|
||||
input [DW-1:0] in6,//input
|
||||
input [DW-1:0] in7,//input
|
||||
input [DW-1:0] in8,//input
|
||||
input [DW-1:0] cin0,//carry in
|
||||
input [DW-1:0] cin1,//carry in
|
||||
input [DW-1:0] cin2,//carry in
|
||||
input [DW-1:0] cin3,//carry in
|
||||
input [DW-1:0] cin4,//carry in
|
||||
input [DW-1:0] cin5,//carry in
|
||||
output [DW-1:0] s, //sum
|
||||
output [DW-1:0] c, //carry
|
||||
output [DW-1:0] cout0, //carry out
|
||||
output [DW-1:0] cout1, //carry out
|
||||
output [DW-1:0] cout2, //carry out
|
||||
output [DW-1:0] cout3, //carry out
|
||||
output [DW-1:0] cout4, //carry out
|
||||
output [DW-1:0] cout5 //carry out
|
||||
);
|
||||
|
||||
output s;
|
||||
output c;
|
||||
output cout0;
|
||||
output cout1;
|
||||
output cout2;
|
||||
output cout3;
|
||||
output cout4;
|
||||
output cout5;
|
||||
|
||||
wire s_int0;
|
||||
wire s_int1;
|
||||
wire s_int2;
|
||||
wire [DW-1:0] s_int0;
|
||||
wire [DW-1:0] s_int1;
|
||||
wire [DW-1:0] s_int2;
|
||||
|
||||
oh_csa32 csa32_0 (.in0(in0),.in1(in1),.in2(in2),.c(cout0),.s(s_int0));
|
||||
oh_csa32 csa32_1 (.in0(in3),.in1(in4),.in2(in5),.c(cout1),.s(s_int1));
|
||||
oh_csa32 csa32_2 (.in0(in6),.in1(in7),.in2(in8),.c(cout2),.s(s_int2));
|
||||
oh_csa32 #(.DW(DW)) csa32_0 (.in0(in0[DW-1:0]),
|
||||
.in1(in1[DW-1:0]),
|
||||
.in2(in2[DW-1:0]),
|
||||
.c(cout0[DW-1:0]),
|
||||
.s(s_int0[DW-1:0]));
|
||||
|
||||
oh_csa62 csa62 (.in0(s_int0), .in1(s_int1), .in2(s_int2),
|
||||
.in3(cin0), .in4(cin1), .in5(cin2),
|
||||
.cin0(cin3), .cin1(cin4), .cin2(cin5),
|
||||
.cout0(cout3),.cout1(cout4),.cout2(cout5),
|
||||
.c(c),.s(s));
|
||||
oh_csa32 #(.DW(DW)) csa32_1 (.in0(in3[DW-1:0]),
|
||||
.in1(in4[DW-1:0]),
|
||||
.in2(in5[DW-1:0]),
|
||||
.c(cout1[DW-1:0]),
|
||||
.s(s_int1[DW-1:0]));
|
||||
|
||||
oh_csa32 #(.DW(DW)) csa32_2 (.in0(in6[DW-1:0]),
|
||||
.in1(in7[DW-1:0]),
|
||||
.in2(in8[DW-1:0]),
|
||||
.c(cout2[DW-1:0]),
|
||||
.s(s_int2[DW-1:0]));
|
||||
|
||||
oh_csa62 #(.DW(DW)) csa62 (.in0(s_int0[DW-1:0]),
|
||||
.in1(s_int1[DW-1:0]),
|
||||
.in2(s_int2[DW-1:0]),
|
||||
.in3(cin0[DW-1:0]),
|
||||
.in4(cin1[DW-1:0]),
|
||||
.in5(cin2[DW-1:0]),
|
||||
.cin0(cin3[DW-1:0]),
|
||||
.cin1(cin4[DW-1:0]),
|
||||
.cin2(cin5[DW-1:0]),
|
||||
.cout0(cout3[DW-1:0]),
|
||||
.cout1(cout4[DW-1:0]),
|
||||
.cout2(cout5[DW-1:0]),
|
||||
.c(c[DW-1:0]),
|
||||
.s(s[DW-1:0]));
|
||||
|
||||
endmodule // oh_csa92
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user