-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfw_control.v
271 lines (232 loc) · 5.27 KB
/
fw_control.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
*
* $Id: fw_control.v,v 1.22 2005/10/24 06:39:05 osc0414 Exp $
*
* Creates control instructions for the array of PEs
*
* check pe_instr_decoder.v for instruction format
*
* Copyright (C) 2005 Uday Bondhugula
* Copyright (C) 2005 Ananth Devulapalli
*
* Please see the LICENSE file for details.
*
*/
`include "params.v"
`define READ_PHASE 1'b0
`define SEND_PHASE 1'b1
`define PROCESS_PHASE `SEND_PHASE
module fw_control(
in_valid,
inD,
reset,
clk,
instr_out,
dOut
);
input reset, in_valid, clk;
input [`L*`WIDTH-1: 0] inD;
/* the type of block we are processing */
output [`INSTR_WIDTH-1: 0] instr_out;
output [`L*`WIDTH-1: 0] dOut;
reg [`INSTR_WIDTH-1: 0] instr_out = {`logB'b0, `IDLE};
reg [`L*`WIDTH-1: 0] dOut;
reg [1:0] phase;
/* FSM for instruction encoding */
// there are basically two kinds of instructions
reg state = `READ_PHASE;
reg [`OP_WIDTH-1: 0] op = `READ_ROW;
reg [`logB-1: 0] id = `logB'b0;
/* We need a mod(2B^2/L) and a mod(B^2/L) counter */
reg [(1+2*`logB-`logL-1): 0] counter1 = 0;
reg [(2*`logB-`logL-1): 0] counter2 = 0;
reg fwd = 1'b1;
reg fwd1 = 1'b0;
always @(posedge clk, posedge reset)
begin
if (reset)
begin
instr_out <= {`logB'b0, `IDLE};
op <= `READ_ROW;
id <= 0;
state <= `READ_PHASE;
counter1 <= 0;
counter2 <= 0;
dOut <= {`L*`WIDTH{1'b1}};
fwd <= 1'b1;
fwd1 <= 1'b0;
end
else
begin
/* The READ_PHASE is 2*B*B/L clock cycles and the SEND_PHASE is
* B*B/L clock cycles with stalls inserted whenever we don't have
* valid data (even for SEND_CASE in order to maintain the same
* latency for all kinds of tiles.
*/
if (in_valid)
begin
case (phase)
`SELF_DEP:
begin
case (state)
`READ_PHASE:
begin
counter1 <= counter1 + 1'b1;
if (counter1%(`B/`L) == {`logB-`logL{1'b1}})
begin
// flip the last bit to make read_row read_col
// and vice versa
op <= op^1'b1;
end
if (counter1%(2*`B/`L) == {1+`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
if (counter1 == 2*`B*`B/`L-1'b1)
begin
state <= `SEND_PHASE;
op <= `SEND_ROW;
end
instr_out <= {1'b0, id, op};
end
`SEND_PHASE:
begin
counter2 <= counter2 + 1'b1;
op <= `SEND_ROW;
if (counter2%(`B/`L) == {`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
if (counter2 == `B*`B/`L-1'b1)
begin
state <= `READ_PHASE;
op <= `READ_ROW;
end
instr_out <= {1'b0, id, op};
end
endcase
end
`DOUBLY_DEP:
begin
case (state)
`READ_PHASE:
begin
counter1 <= counter1 + 1'b1;
if (counter1%(`B/`L) == {`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
if (counter1 == `B*`B/`L-1'b1)
begin
op <= `READ_COL;
end
if (counter1 == 2*`B*`B/`L-1'b1)
begin
op <= `PROCESS_ROW;
state <= `PROCESS_PHASE;
end
instr_out <= {1'b1, id, op};
end
`PROCESS_PHASE:
begin
counter2 <= counter2 + 1'b1;
if (counter2 == `B*`B/`L-1'b1)
begin
state <= `READ_PHASE;
op <= `READ_ROW;
end
if (counter2%(`B/`L) == {`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
instr_out <= {1'b0, id, op};
end
endcase // DOUBLY_DEP
end
`ROW_DEP:
begin
case (state)
`READ_PHASE:
begin
counter1 <= counter1 + 1'b1;
if (counter1%(`B/`L) == {`logB-`logL{1'b1}})
begin
op <= op^1'b1;
fwd <= fwd^1'b1;
end
if (counter1%(2*`B/`L) == {1+`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
if (counter1 == 2*`B*`B/`L-1'b1)
begin
op <= `SEND_COL;
state <= `PROCESS_PHASE;
end
instr_out <= {fwd, id, op};
end
`PROCESS_PHASE:
begin
counter2 <= counter2 + 1'b1;
if (counter2%(`B/`L) == {`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
if (counter2 == `B*`B/`L-1'b1)
begin
op <= `READ_ROW;
state <= `READ_PHASE;
end
// everyone does process row
instr_out <= {1'b0, id, op};
end
endcase
end
`COL_DEP:
begin
case (state)
`READ_PHASE:
begin
counter1 <= counter1 + 1'b1;
if (counter1%(`B/`L) == {`logB-`logL{1'b1}})
begin
op <= op^1'b1;
fwd1 <= fwd1^1'b1;
end
if (counter1%(2*`B/`L) == {1+`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
if (counter1 == 2*`B*`B/`L-1'b1)
begin
op <= `SEND_ROW;
state <= `PROCESS_PHASE;
end
instr_out <= {fwd1, id, op};
end
`PROCESS_PHASE:
begin
counter2 <= counter2 + 1'b1;
if (counter2%(`B/`L) == {`logB-`logL{1'b1}})
begin
id <= id + 1'b1;
end
if (counter2 == `B*`B/`L-1'b1)
begin
state <= `READ_PHASE;
op <= `READ_ROW;
end
instr_out <= {1'b0, id, op};
end
endcase // for COL_DEP
end
endcase // for phase
end // for in_valid
else
begin
instr_out <= {1'b0, `logB'b0, `IDLE};
end
dOut <= inD;
end // for reset
end // always block
endmodule