forked from aolofsson/oh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
oh_csa42.v
60 lines (50 loc) · 1.75 KB
/
oh_csa42.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//#############################################################################
//# Function: Carry Save Adder (4:2) #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
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
);
localparam ASIC = `CFG_ASIC; // use asic library
generate
if(ASIC)
begin
asic_csa42 i_csa42[DW-1:0] (.s(s[DW-1:0]),
.cout(cout[DW-1:0]),
.c(c[DW-1:0]),
.cin(cin[DW-1:0]),
.in3(in3[DW-1:0]),
.in2(in2[DW-1:0]),
.in1(in1[DW-1:0]),
.in0(in0[DW-1:0]));
end
else
begin
wire [DW-1:0] s_int;
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];
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 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]);
end // else: !if(ASIC)
endgenerate
endmodule // oh_csa42