-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path11_adder8_4pipeline.v
184 lines (153 loc) · 2.55 KB
/
11_adder8_4pipeline.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// 8 bits adder based on 4 stages pipeline
//author:WangFW
//date:2020-5-14
module adder8_4pipeline(clk,rst_n,ain,bin,cin,sum,cout);
input clk;
input rst_n;
input cin;
input [7:0] ain;
input [7:0] bin;
output reg cout;
output reg [7:0] sum;
//The registers needed by pipeline
reg [1:0] sum1;
reg [3:0] sum2;
reg [5:0] sum3;
reg cout1;
reg cout2;
reg cout3;
reg [1:0] ain1;
reg [1:0] bin1;
reg [1:0] ain2;
reg [1:0] bin2;
reg [1:0] ain2_2;
reg [1:0] bin2_2;
reg [1:0] ain3;
reg [1:0] bin3;
reg [1:0] ain3_2;
reg [1:0] bin3_2;
reg [1:0] ain3_3;
reg [1:0] bin3_3;
//The 1 statge pipeline
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
cout1<=1'b0;
sum1<=2'd0;
end
else
{cout1,sum1}<={1'b0,ain[1:0]}+{1'b0,bin[1:0]}+cin;
end
//The 2 statge pipeline
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
ain1<=2'd0;
bin1<=2'd0;
end
else
begin
ain1<=ain[3:2];
bin1<=bin[3:2];
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
cout2<=1'b0;
sum2<=4'd0;
end
else
{cout2,sum2}<={{1'b0,ain1}+{1'b0,bin1}+cout1,sum1};
end
//The 3 statge pipeline
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
ain2<=2'd0;
bin2<=2'd0;
end
else
begin
ain2<=ain[5:4];
bin2<=bin[5:4];
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
ain2_2<=2'd0;
bin2_2<=2'd0;
end
else
begin
ain2_2<=ain2;
bin2_2<=bin2;
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
cout3<=1'b0;
sum3<=6'd0;
end
else
{cout3,sum3}<={{1'b0,ain2_2}+{1'b0,bin2_2}+cout2,sum2};
end
//The 4 statge pipeline
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
ain3<=2'd0;
bin3<=2'd0;
end
else
begin
ain3<=ain[7:6];
bin3<=bin[7:6];
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
ain3_2<=2'd0;
bin3_2<=2'd0;
end
else
begin
ain3_2<=ain3;
bin3_2<=bin3;
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
ain3_3<=2'd0;
bin3_3<=2'd0;
end
else
begin
ain3_3<=ain3_2;
bin3_3<=bin3_2;
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
cout<=1'b0;
sum<=8'd0;
end
else
{cout,sum}<={{1'b0,ain3_3}+{1'b0,bin3_3}+cout3,sum3};
end
endmodule