-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScoreboard.bsv
More file actions
executable file
·303 lines (268 loc) · 10.9 KB
/
Copy pathScoreboard.bsv
File metadata and controls
executable file
·303 lines (268 loc) · 10.9 KB
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// Copyright (c) 2016-2018 Massachusetts Institute of Technology
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import Vector::*;
interface Scoreboard#(numeric type size);
method Action insert(Maybe#(Bit#(5)) dst);
method Action remove;
method Bool search1(Maybe#(Bit#(5)) src1);
method Bool search2(Maybe#(Bit#(5)) src2);
endinterface
// search < insert
// search < remove
// insert CF remove
module mkScoreboard(Scoreboard#(size));
function Bool isFound(Maybe#(Bit#(5)) x, Maybe#(Bit#(5)) y);
return isValid(x) && isValid(y) && x == y && fromMaybe(0, x)!=0;
endfunction
SearchFIFO#(size, Maybe#(Bit#(5)), Maybe#(Bit#(5))) f <- mkSearchFIFO(isFound);
method insert = f.enq;
method remove = f.deq;
method search1 = f.search;
method search2 = f.search;
endmodule
// scoreboard for bypassing
// search < insert
// search > remove
// insert CF remove
module mkBypassingScoreboard(Scoreboard#(size));
function Bool isFound(Maybe#(Bit#(5)) x, Maybe#(Bit#(5)) y);
return isValid(x) && isValid(y) && x == y && fromMaybe(0, x)!=0;
endfunction
SearchFIFO#(size, Maybe#(Bit#(5)), Maybe#(Bit#(5))) f <- mkPipelineSearchFIFO(isFound);
method insert = f.enq;
method remove = f.deq;
method search1 = f.search;
method search2 = f.search;
endmodule
// SearchFIFO used by Scoreboard
interface SearchFIFO#(numeric type size, type dataType, type searchType);
method Action enq(dataType x);
method Action deq;
method dataType first;
method Action clear;
method Bool notEmpty;
method Bool notFull;
method Bool search(searchType x);
endinterface
// {search, notEmpty, notFull} < {enq, deq} < clear
// first < deq
module mkSearchFIFO#(function Bool isMatch(searchType s, dataType d))(SearchFIFO#(size, dataType, searchType)) provisos (Bits#(dataType, dataSize));
// use valid bits to make search logic smaller
Vector#(size, Reg#(Maybe#(dataType))) data <- replicateM(mkReg(tagged Invalid));
Reg#(Bit#(TLog#(size))) enqP <- mkReg(0);
Reg#(Bit#(TLog#(size))) deqP <- mkReg(0);
Reg#(Bool) full <- mkReg(False);
Reg#(Bool) empty <- mkReg(True);
// EHRs to avoid conflicts between enq and deq
Array#(Reg#(Bool)) deqReq <- mkCReg(3, False);
Array#(Reg#(Maybe#(dataType))) enqReq <- mkCReg(3, tagged Invalid);
// Canonicalize rule to handle enq and deq.
// These attributes are statically checked by the compiler.
(* no_implicit_conditions *) // CAN_FIRE == guard (True)
rule canonicalize;
Bool enqueued = False;
let nextEnqP = enqP;
Bool dequeued = False;
let nextDeqP = deqP;
// enqueue logic
if (enqReq[2] matches tagged Valid .enqVal) begin
enqueued = True;
nextEnqP = (enqP == fromInteger(valueOf(size) - 1)) ? 0 : enqP + 1;
end
// dequeue logic
if (deqReq[2] == True) begin
dequeued = True;
nextDeqP = (deqP == fromInteger(valueOf(size) - 1)) ? 0 : deqP + 1;
end
// update data
for (Integer i = 0 ; i < valueOf(size) ; i = i+1) begin
Bool update = False;
Maybe#(dataType) newValue = tagged Invalid;
if (fromInteger(i) == enqP && isValid(enqReq[2])) begin
update = True;
newValue = enqReq[2];
end else if (fromInteger(i) == deqP && deqReq[2]) begin
update = True;
newValue = tagged Invalid;
end
// should perform at most two writes, but avoids false conflicts
if (update) begin
data[i] <= newValue;
end
end
// update empty and full if an element was enqueued or dequeued
if (enqueued || dequeued) begin
full <= (nextEnqP == nextDeqP) ? enqueued : False;
empty <= (nextEnqP == nextDeqP) ? dequeued : False;
enqP <= nextEnqP;
deqP <= nextDeqP;
end
// clear request EHRs
enqReq[2] <= tagged Invalid;
deqReq[2] <= False;
endrule
method Action enq(dataType x) if (!full && !isValid(enqReq[0]));
enqReq[0] <= tagged Valid x;
endmethod
method Action deq if (!empty && !deqReq[0]);
deqReq[0] <= True;
endmethod
method dataType first if (!empty && !deqReq[0]);
return fromMaybe(?, data[deqP]);
endmethod
method Action clear;
writeVReg(data, replicate(tagged Invalid));
enqP <= 0;
deqP <= 0;
full <= False;
empty <= True;
// clear any pending enq or deq
enqReq[1] <= tagged Invalid;
deqReq[1] <= False;
endmethod
method Bool notEmpty if (!isValid(enqReq[0]) && !deqReq[0]);
return !empty;
endmethod
method Bool notFull if (!isValid(enqReq[0]) && !deqReq[0]);
return !full;
endmethod
// different search implementations
// search < {enq, deq}
method Bool search(searchType x) if (!isValid(enqReq[0]) && !deqReq[0]);
// helper function for isMatch when dataType has valid bits
function Bool maybeIsMatch(searchType s, Maybe#(dataType) md);
return md matches tagged Valid. d ? isMatch(s, d) : False;
endfunction
return any(id, map(compose(maybeIsMatch(x), readReg), data));
endmethod
endmodule
// {notEmpty, notFull} < deq < search < enq < clear
// first < deq
module mkPipelineSearchFIFO#(function Bool isMatch(searchType s, dataType d))(SearchFIFO#(size, dataType, searchType)) provisos (Bits#(dataType, dataSize));
// use valid bits to make search logic smaller
Vector#(size, Reg#(Maybe#(dataType))) data <- replicateM(mkReg(tagged Invalid));
Reg#(Bit#(TLog#(size))) enqP <- mkReg(0);
Reg#(Bit#(TLog#(size))) deqP <- mkReg(0);
Reg#(Bool) full <- mkReg(False);
Reg#(Bool) empty <- mkReg(True);
// EHRs to avoid conflicts between enq and deq
Array#(Reg#(Bool)) deqReq <- mkCReg(3, False);
Array#(Reg#(Maybe#(dataType))) enqReq <- mkCReg(3, tagged Invalid);
// Canonicalize rule to handle enq and deq.
// These attributes are statically checked by the compiler.
// (* fire_when_enabled *) // WILL_FIRE == CAN_FIRE // XXX: Not used due to clear conflict
(* no_implicit_conditions *) // CAN_FIRE == guard (True)
rule canonicalize;
Bool enqueued = False;
let nextEnqP = enqP;
Bool dequeued = False;
let nextDeqP = deqP;
// enqueue logic
if (enqReq[2] matches tagged Valid .enqVal) begin
enqueued = True;
nextEnqP = (enqP == fromInteger(valueOf(size) - 1)) ? 0 : enqP + 1;
// perform state updates
// data[enqP] <= tagged Valid enqVal;
// enqP <= nextEnqP;
end
// dequeue logic
if (deqReq[2] == True) begin
dequeued = True;
nextDeqP = (deqP == fromInteger(valueOf(size) - 1)) ? 0 : deqP + 1;
// perform state updates
// data[deqP] <= tagged Invalid;
// deqP <= nextDeqP;
end
// update data
// this is done in this way to avoid a false conflict detected by the
// compiler (enqReq[2] is valid, deqReq[2] is true, and enqP == deqP)
for (Integer i = 0 ; i < valueOf(size) ; i = i+1) begin
Bool update = False;
Maybe#(dataType) newValue = tagged Invalid;
if (fromInteger(i) == enqP && isValid(enqReq[2])) begin
update = True;
newValue = enqReq[2];
end else if (fromInteger(i) == deqP && deqReq[2]) begin
update = True;
newValue = tagged Invalid;
end
// should perform at most two writes, but avoids false conflicts
if (update) begin
data[i] <= newValue;
end
end
// update empty and full if an element was enqueued or dequeued
if (enqueued || dequeued) begin
full <= (nextEnqP == nextDeqP) ? enqueued : False;
empty <= (nextEnqP == nextDeqP) ? dequeued : False;
enqP <= nextEnqP;
deqP <= nextDeqP;
end
// clear request EHRs
enqReq[2] <= tagged Invalid;
deqReq[2] <= False;
endrule
method Action enq(dataType x) if (!full && !isValid(enqReq[0]));
enqReq[0] <= tagged Valid x;
endmethod
method Action deq if (!empty && !deqReq[0]);
deqReq[0] <= True;
endmethod
method dataType first if (!empty && !deqReq[0]);
return fromMaybe(?, data[deqP]);
endmethod
method Action clear;
writeVReg(data, replicate(tagged Invalid));
enqP <= 0;
deqP <= 0;
full <= False;
empty <= True;
// clear any pending enq or deq
enqReq[1] <= tagged Invalid;
deqReq[1] <= False;
endmethod
method Bool notEmpty if (!isValid(enqReq[0]));
// old implementation:
// return !empty;
// TODO: make this more efficient
// compute dataPostDeq by considering deqReq[1]
Vector#(size, Maybe#(dataType)) dataPostDeq = readVReg(data);
if (deqReq[1]) begin
dataPostDeq[deqP] = tagged Invalid;
end
return any(isValid, dataPostDeq);
endmethod
method Bool notFull if (!isValid(enqReq[0]) && !deqReq[0]);
return !full;
endmethod
// Alternate search implementation with the scheulde:
// deq < search < enq
method Bool search(searchType x) if (!isValid(enqReq[0]));
// compute dataPostDeq by considering deqReq[1]
Vector#(size, Maybe#(dataType)) dataPostDeq = readVReg(data);
if (deqReq[1]) begin
dataPostDeq[deqP] = tagged Invalid;
end
// helper function for isMatch when dataType has valid bits
function Bool maybeIsMatch(searchType s, Maybe#(dataType) md);
return md matches tagged Valid. d ? isMatch(s, d) : False;
endfunction
return any(id, map(maybeIsMatch(x), dataPostDeq));
endmethod
endmodule