1 |
92 |
jamey.hick |
// The MIT License
|
2 |
|
|
|
3 |
|
|
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
|
4 |
|
|
|
5 |
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
|
|
// of this software and associated documentation files (the "Software"), to deal
|
7 |
|
|
// in the Software without restriction, including without limitation the rights
|
8 |
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
|
|
// copies of the Software, and to permit persons to whom the Software is
|
10 |
|
|
// furnished to do so, subject to the following conditions:
|
11 |
|
|
|
12 |
|
|
// The above copyright notice and this permission notice shall be included in
|
13 |
|
|
// all copies or substantial portions of the Software.
|
14 |
|
|
|
15 |
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21 |
|
|
// THE SOFTWARE.
|
22 |
|
|
//**********************************************************************
|
23 |
|
|
// Buffer Controller
|
24 |
|
|
//----------------------------------------------------------------------
|
25 |
|
|
//
|
26 |
|
|
//
|
27 |
|
|
|
28 |
|
|
package mkBufferControl;
|
29 |
|
|
|
30 |
|
|
import H264Types::*;
|
31 |
|
|
|
32 |
|
|
import IBufferControl::*;
|
33 |
|
|
import FIFO::*;
|
34 |
|
|
import Vector::*;
|
35 |
|
|
|
36 |
|
|
import Connectable::*;
|
37 |
|
|
import GetPut::*;
|
38 |
|
|
import ClientServer::*;
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
//-----------------------------------------------------------
|
43 |
|
|
// Local Datatypes
|
44 |
|
|
//-----------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
typedef union tagged
|
47 |
|
|
{
|
48 |
|
|
void Idle; //not working on anything in particular
|
49 |
|
|
void Y;
|
50 |
|
|
void U;
|
51 |
|
|
void V;
|
52 |
|
|
}
|
53 |
|
|
Outprocess deriving(Eq,Bits);
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
//-----------------------------------------------------------
|
57 |
|
|
// Short term pic list submodule
|
58 |
|
|
//-----------------------------------------------------------
|
59 |
|
|
|
60 |
|
|
typedef union tagged
|
61 |
|
|
{
|
62 |
|
|
void Idle; //not working on anything in particular
|
63 |
|
|
void Remove;
|
64 |
|
|
void RemoveOutput;
|
65 |
|
|
void RemoveFound;
|
66 |
|
|
void InsertGap;
|
67 |
|
|
void Search;
|
68 |
|
|
void ListAll;
|
69 |
|
|
}
|
70 |
|
|
ShortTermPicListState deriving(Eq,Bits);
|
71 |
|
|
|
72 |
|
|
interface ShortTermPicList;
|
73 |
|
|
method Action clear();
|
74 |
|
|
method Action insert( Bit#(16) frameNum, Bit#(5) slot, Bit#(5) maxAllowed );
|
75 |
|
|
method Action insert_gap( Bit#(16) frameNum, Bit#(5) slot, Bit#(5) maxAllowed, Bit#(16) gap, Bit#(5) log2_max_frame_num );
|
76 |
|
|
method Action remove( Bit#(16) frameNum, Bool removeOutputFlag );
|
77 |
|
|
method Action search( Bit#(16) frameNum );
|
78 |
|
|
method Action listAll();
|
79 |
|
|
method Action deq();
|
80 |
|
|
method Maybe#(Bit#(5)) resultSlot();
|
81 |
|
|
method Bit#(5) numPics();
|
82 |
|
|
endinterface
|
83 |
|
|
|
84 |
|
|
module mkShortTermPicList( ShortTermPicList );
|
85 |
|
|
function Bit#(5) shortTermPicListNext( Bit#(5) addrFunc );
|
86 |
|
|
if(addrFunc
|
87 |
|
|
return addrFunc+1;
|
88 |
|
|
else
|
89 |
|
|
return 0;
|
90 |
|
|
endfunction
|
91 |
|
|
function Bit#(5) shortTermPicListPrev( Bit#(5) addrFunc );
|
92 |
|
|
if(addrFunc==0)
|
93 |
|
|
return maxRefFrames-1;
|
94 |
|
|
else
|
95 |
|
|
return addrFunc-1;
|
96 |
|
|
endfunction
|
97 |
|
|
|
98 |
|
|
RFile1#(Bit#(5),Tuple2#(Bit#(16),Bit#(5))) rfile <- mkRFile1(0,maxRefFrames-1);
|
99 |
|
|
Reg#(ShortTermPicListState) state <- mkReg(Idle);
|
100 |
|
|
Reg#(Bit#(5)) log2_mfn <- mkReg(0);
|
101 |
|
|
Reg#(Bit#(5)) nextPic <- mkReg(0);
|
102 |
|
|
Reg#(Bit#(5)) picCount <- mkReg(0);
|
103 |
|
|
Reg#(Bit#(5)) tempPic <- mkReg(0);
|
104 |
|
|
Reg#(Bit#(5)) tempCount <- mkReg(0);
|
105 |
|
|
Reg#(Bit#(16)) tempNum <- mkReg(0);
|
106 |
|
|
FIFO#(Maybe#(Bit#(5))) returnList <- mkFIFO();
|
107 |
|
|
|
108 |
|
|
rule removing ( state==Remove || state==RemoveOutput || state==RemoveFound );
|
109 |
|
|
if(state!=RemoveFound)
|
110 |
|
|
begin
|
111 |
|
|
Tuple2#(Bit#(16),Bit#(5)) temp = rfile.sub(tempPic);
|
112 |
|
|
if(tpl_1(temp)==tempNum)
|
113 |
|
|
begin
|
114 |
|
|
state <= RemoveFound;
|
115 |
|
|
if(state==RemoveOutput)
|
116 |
|
|
returnList.enq(tagged Valid tpl_2(temp));
|
117 |
|
|
end
|
118 |
|
|
if(tempCount>=picCount)
|
119 |
|
|
$display( "ERROR BufferControl: ShortTermPicList removing not found");
|
120 |
|
|
end
|
121 |
|
|
else
|
122 |
|
|
begin
|
123 |
|
|
Bit#(5) tempPrev = shortTermPicListPrev(tempPic);
|
124 |
|
|
rfile.upd(tempPrev,rfile.sub(tempPic));
|
125 |
|
|
if(tempCount==picCount)
|
126 |
|
|
begin
|
127 |
|
|
picCount <= picCount-1;
|
128 |
|
|
nextPic <= tempPrev;
|
129 |
|
|
state <= Idle;
|
130 |
|
|
end
|
131 |
|
|
end
|
132 |
|
|
tempCount <= tempCount+1;
|
133 |
|
|
tempPic <= shortTermPicListNext(tempPic);
|
134 |
|
|
endrule
|
135 |
|
|
|
136 |
|
|
rule insertingGap ( state matches tagged InsertGap );
|
137 |
|
|
if(tempCount>0)
|
138 |
|
|
begin
|
139 |
|
|
if(tempCount>1)
|
140 |
|
|
rfile.upd(nextPic,tuple2(tempNum,31));
|
141 |
|
|
else
|
142 |
|
|
rfile.upd(nextPic,tuple2(tempNum,tempPic));
|
143 |
|
|
nextPic <= shortTermPicListNext(nextPic);
|
144 |
|
|
end
|
145 |
|
|
else
|
146 |
|
|
state <= Idle;
|
147 |
|
|
Bit#(17) tempOne = 1;
|
148 |
|
|
Bit#(17) maxPicNum = tempOne << log2_mfn;
|
149 |
|
|
if(zeroExtend(tempNum) == maxPicNum-1)
|
150 |
|
|
tempNum <= 0;
|
151 |
|
|
else
|
152 |
|
|
tempNum <= tempNum+1;
|
153 |
|
|
tempCount <= tempCount-1;
|
154 |
|
|
endrule
|
155 |
|
|
|
156 |
|
|
rule searching ( state matches tagged Search );
|
157 |
|
|
if(tempCount
|
158 |
|
|
begin
|
159 |
|
|
Tuple2#(Bit#(16),Bit#(5)) temp = rfile.sub(tempPic);
|
160 |
|
|
if(tpl_1(temp)==tempNum)
|
161 |
|
|
begin
|
162 |
|
|
returnList.enq(tagged Valid tpl_2(temp));
|
163 |
|
|
state <= Idle;
|
164 |
|
|
end
|
165 |
|
|
tempPic <= shortTermPicListPrev(tempPic);
|
166 |
|
|
tempCount <= tempCount+1;
|
167 |
|
|
end
|
168 |
|
|
else
|
169 |
|
|
$display( "ERROR BufferControl: ShortTermPicList searching not found");
|
170 |
|
|
endrule
|
171 |
|
|
|
172 |
|
|
rule listingAll ( state matches tagged ListAll );
|
173 |
|
|
if(tempCount
|
174 |
|
|
begin
|
175 |
|
|
Tuple2#(Bit#(16),Bit#(5)) temp = rfile.sub(tempPic);
|
176 |
|
|
returnList.enq(tagged Valid tpl_2(temp));
|
177 |
|
|
tempPic <= shortTermPicListPrev(tempPic);
|
178 |
|
|
tempCount <= tempCount+1;
|
179 |
|
|
end
|
180 |
|
|
else
|
181 |
|
|
begin
|
182 |
|
|
returnList.enq(tagged Invalid);
|
183 |
|
|
state <= Idle;
|
184 |
|
|
end
|
185 |
|
|
endrule
|
186 |
|
|
|
187 |
|
|
method Action clear() if(state matches tagged Idle);
|
188 |
|
|
picCount <= 0;
|
189 |
|
|
nextPic <= 0;
|
190 |
|
|
endmethod
|
191 |
|
|
|
192 |
|
|
method Action insert( Bit#(16) frameNum, Bit#(5) slot, Bit#(5) maxAllowed ) if(state matches tagged Idle);
|
193 |
|
|
rfile.upd(nextPic,tuple2(frameNum,slot));
|
194 |
|
|
nextPic <= shortTermPicListNext(nextPic);
|
195 |
|
|
if(maxAllowed>picCount)
|
196 |
|
|
picCount <= picCount+1;
|
197 |
|
|
endmethod
|
198 |
|
|
|
199 |
|
|
method Action insert_gap( Bit#(16) frameNum, Bit#(5) slot, Bit#(5) maxAllowed, Bit#(16) gap, Bit#(5) log2_max_frame_num ) if(state matches tagged Idle);
|
200 |
|
|
state <= InsertGap;
|
201 |
|
|
log2_mfn <= log2_max_frame_num;
|
202 |
|
|
if(zeroExtend(picCount)+gap+1 >= zeroExtend(maxAllowed))
|
203 |
|
|
picCount <= maxAllowed;
|
204 |
|
|
else
|
205 |
|
|
picCount <= truncate(zeroExtend(picCount)+gap+1);
|
206 |
|
|
Bit#(5) temp;
|
207 |
|
|
if(gap+1 >= zeroExtend(maxAllowed))
|
208 |
|
|
temp = maxAllowed;
|
209 |
|
|
else
|
210 |
|
|
temp = truncate(gap+1);
|
211 |
|
|
tempCount <= temp;
|
212 |
|
|
Bit#(17) tempOne = 1;
|
213 |
|
|
Bit#(17) maxPicNum = tempOne << log2_max_frame_num;
|
214 |
|
|
Bit#(17) tempFrameNum = zeroExtend(frameNum);
|
215 |
|
|
if(tempFrameNum+1 > zeroExtend(temp))
|
216 |
|
|
tempNum <= truncate(tempFrameNum+1-zeroExtend(temp));
|
217 |
|
|
else
|
218 |
|
|
tempNum <= truncate(maxPicNum+tempFrameNum+1-zeroExtend(temp));
|
219 |
|
|
tempPic <= slot;
|
220 |
|
|
endmethod
|
221 |
|
|
|
222 |
|
|
method Action remove( Bit#(16) frameNum, Bool removeOutputFlag ) if(state matches tagged Idle);
|
223 |
|
|
if(removeOutputFlag)
|
224 |
|
|
state <= RemoveOutput;
|
225 |
|
|
else
|
226 |
|
|
state <= Remove;
|
227 |
|
|
tempCount <= 0;
|
228 |
|
|
Bit#(5) temp = (maxRefFrames-picCount)+nextPic;
|
229 |
|
|
if(temp>maxRefFrames-1)
|
230 |
|
|
tempPic <= temp-maxRefFrames;
|
231 |
|
|
else
|
232 |
|
|
tempPic <= temp;
|
233 |
|
|
tempNum <= frameNum;
|
234 |
|
|
endmethod
|
235 |
|
|
|
236 |
|
|
method Action search( Bit#(16) frameNum ) if(state matches tagged Idle);
|
237 |
|
|
state <= Search;
|
238 |
|
|
tempCount <= 0;
|
239 |
|
|
tempPic <= shortTermPicListPrev(nextPic);
|
240 |
|
|
tempNum <= frameNum;
|
241 |
|
|
endmethod
|
242 |
|
|
|
243 |
|
|
method Action listAll() if(state matches tagged Idle);
|
244 |
|
|
state <= ListAll;
|
245 |
|
|
tempCount <= 0;
|
246 |
|
|
tempPic <= shortTermPicListPrev(nextPic);
|
247 |
|
|
endmethod
|
248 |
|
|
|
249 |
|
|
method Action deq();
|
250 |
|
|
returnList.deq();
|
251 |
|
|
endmethod
|
252 |
|
|
|
253 |
|
|
method Maybe#(Bit#(5)) resultSlot();
|
254 |
|
|
return returnList.first();
|
255 |
|
|
endmethod
|
256 |
|
|
|
257 |
|
|
method Bit#(5) numPics() if(state matches tagged Idle);
|
258 |
|
|
return picCount;
|
259 |
|
|
endmethod
|
260 |
|
|
endmodule
|
261 |
|
|
|
262 |
|
|
//-----------------------------------------------------------
|
263 |
|
|
// Long term pic list submodule
|
264 |
|
|
//-----------------------------------------------------------
|
265 |
|
|
|
266 |
|
|
typedef union tagged
|
267 |
|
|
{
|
268 |
|
|
void Idle; //not working on anything in particular
|
269 |
|
|
void Clear;
|
270 |
|
|
void ListAll;
|
271 |
|
|
}
|
272 |
|
|
LongTermPicListState deriving(Eq,Bits);
|
273 |
|
|
|
274 |
|
|
interface LongTermPicList;
|
275 |
|
|
method Action clear();
|
276 |
|
|
method Action insert( Bit#(5) frameNum, Bit#(5) slot );
|
277 |
|
|
method Action remove( Bit#(5) frameNum );
|
278 |
|
|
method Action maxIndexPlus1( Bit#(5) maxAllowed );
|
279 |
|
|
method Action search( Bit#(5) frameNum );
|
280 |
|
|
method Action listAll();
|
281 |
|
|
method Action deq();
|
282 |
|
|
method Maybe#(Bit#(5)) resultSlot();
|
283 |
|
|
method Bit#(5) numPics();
|
284 |
|
|
endinterface
|
285 |
|
|
|
286 |
|
|
module mkLongTermPicList( LongTermPicList );
|
287 |
|
|
// RegFile#(Bit#(5),Maybe#(Bit#(5))) rfile <- mkRegFile(0,maxRefFrames-1);
|
288 |
|
|
RFile1#(Bit#(5),Maybe#(Bit#(5))) rfile <- mkRFile1Full();
|
289 |
|
|
Reg#(LongTermPicListState) state <- mkReg(Idle);
|
290 |
|
|
Reg#(Bit#(5)) picCount <- mkReg(0);
|
291 |
|
|
Reg#(Bit#(5)) tempPic <- mkReg(0);
|
292 |
|
|
FIFO#(Maybe#(Bit#(5))) returnList <- mkFIFO();
|
293 |
|
|
|
294 |
|
|
rule clearing ( state matches tagged Clear );
|
295 |
|
|
if(tempPic
|
296 |
|
|
begin
|
297 |
|
|
if(rfile.sub(tempPic) matches tagged Valid .data &&& picCount!=0)
|
298 |
|
|
picCount <= picCount-1;
|
299 |
|
|
rfile.upd(tempPic,Invalid);
|
300 |
|
|
tempPic <= tempPic+1;
|
301 |
|
|
end
|
302 |
|
|
else
|
303 |
|
|
state <= Idle;
|
304 |
|
|
//$display( "TRACE BufferControl: LongTermPicList clearing %h %h", picCount, tempPic);
|
305 |
|
|
endrule
|
306 |
|
|
|
307 |
|
|
rule listingAll ( state matches tagged ListAll );
|
308 |
|
|
if(tempPic
|
309 |
|
|
begin
|
310 |
|
|
Maybe#(Bit#(5)) temp = rfile.sub(tempPic);
|
311 |
|
|
if(temp matches tagged Valid .data)
|
312 |
|
|
returnList.enq(tagged Valid data);
|
313 |
|
|
tempPic <= tempPic+1;
|
314 |
|
|
end
|
315 |
|
|
else
|
316 |
|
|
begin
|
317 |
|
|
returnList.enq(Invalid);
|
318 |
|
|
state <= Idle;
|
319 |
|
|
end
|
320 |
|
|
//$display( "TRACE BufferControl: LongTermPicList listingAll %h %h", picCount, tempPic);
|
321 |
|
|
endrule
|
322 |
|
|
|
323 |
|
|
method Action clear() if(state matches tagged Idle);
|
324 |
|
|
state <= Clear;
|
325 |
|
|
tempPic <= 0;
|
326 |
|
|
//$display( "TRACE BufferControl: LongTermPicList clear %h", picCount);
|
327 |
|
|
endmethod
|
328 |
|
|
|
329 |
|
|
method Action insert( Bit#(5) frameNum, Bit#(5) slot ) if(state matches tagged Idle);
|
330 |
|
|
if(rfile.sub(frameNum) matches tagged Invalid)
|
331 |
|
|
picCount <= picCount+1;
|
332 |
|
|
rfile.upd(frameNum,tagged Valid slot);
|
333 |
|
|
//$display( "TRACE BufferControl: LongTermPicList insert %h %h %h", picCount, frameNum, slot);
|
334 |
|
|
endmethod
|
335 |
|
|
|
336 |
|
|
method Action remove( Bit#(5) frameNum ) if(state matches tagged Idle);
|
337 |
|
|
if(rfile.sub(frameNum) matches tagged Invalid)
|
338 |
|
|
$display( "ERROR BufferControl: LongTermPicList removing not found");
|
339 |
|
|
else
|
340 |
|
|
picCount <= picCount-1;
|
341 |
|
|
rfile.upd(frameNum,Invalid);
|
342 |
|
|
//$display( "TRACE BufferControl: LongTermPicList remove %h %h", picCount, frameNum);
|
343 |
|
|
endmethod
|
344 |
|
|
|
345 |
|
|
method Action maxIndexPlus1( Bit#(5) index ) if(state matches tagged Idle);
|
346 |
|
|
state <= Clear;
|
347 |
|
|
tempPic <= index;
|
348 |
|
|
//$display( "TRACE BufferControl: LongTermPicList maxIndexPlus1 %h %h", picCount, index);
|
349 |
|
|
endmethod
|
350 |
|
|
|
351 |
|
|
method Action search( Bit#(5) frameNum ) if(state matches tagged Idle);
|
352 |
|
|
returnList.enq(rfile.sub(frameNum));
|
353 |
|
|
//$display( "TRACE BufferControl: LongTermPicList search %h %h", picCount, frameNum);
|
354 |
|
|
endmethod
|
355 |
|
|
|
356 |
|
|
method Action listAll() if(state matches tagged Idle);
|
357 |
|
|
state <= ListAll;
|
358 |
|
|
tempPic <= 0;
|
359 |
|
|
//$display( "TRACE BufferControl: LongTermPicList listAll %h", picCount);
|
360 |
|
|
endmethod
|
361 |
|
|
|
362 |
|
|
method Action deq();
|
363 |
|
|
returnList.deq();
|
364 |
|
|
//$display( "TRACE BufferControl: LongTermPicList deq %h", picCount);
|
365 |
|
|
endmethod
|
366 |
|
|
|
367 |
|
|
method Maybe#(Bit#(5)) resultSlot();
|
368 |
|
|
return returnList.first();
|
369 |
|
|
endmethod
|
370 |
|
|
|
371 |
|
|
method Bit#(5) numPics() if(state matches tagged Idle);
|
372 |
|
|
return picCount;
|
373 |
|
|
endmethod
|
374 |
|
|
endmodule
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
//-----------------------------------------------------------
|
378 |
|
|
// Free slot module
|
379 |
|
|
//-----------------------------------------------------------
|
380 |
|
|
|
381 |
|
|
interface FreeSlots;
|
382 |
|
|
method Action init();
|
383 |
|
|
method Action add( Bit#(5) slot );
|
384 |
|
|
method Action remove( Bit#(5) slot );
|
385 |
|
|
method Bit#(5) first( Bit#(5) exception );
|
386 |
|
|
endinterface
|
387 |
|
|
|
388 |
|
|
module mkFreeSlots( FreeSlots );
|
389 |
|
|
Reg#(Vector#(18,Bit#(1))) slots <- mkRegU();
|
390 |
|
|
|
391 |
|
|
method Action init();
|
392 |
|
|
Vector#(18,Bit#(1)) tempSlots = replicate(0);
|
393 |
|
|
slots <= tempSlots;
|
394 |
|
|
endmethod
|
395 |
|
|
|
396 |
|
|
method Action add( Bit#(5) slot );
|
397 |
|
|
Vector#(18,Bit#(1)) tempSlots = slots;
|
398 |
|
|
tempSlots[slot] = 0;
|
399 |
|
|
slots <= tempSlots;
|
400 |
|
|
if(slot >= maxRefFrames+2)
|
401 |
|
|
$display( "ERROR BufferControl: FreeSlots add out of bounds");
|
402 |
|
|
endmethod
|
403 |
|
|
|
404 |
|
|
method Action remove( Bit#(5) slot );
|
405 |
|
|
Vector#(18,Bit#(1)) tempSlots = slots;
|
406 |
|
|
if(slot != 31)
|
407 |
|
|
begin
|
408 |
|
|
tempSlots[slot] = 1;
|
409 |
|
|
slots <= tempSlots;
|
410 |
|
|
if(slot >= maxRefFrames+2)
|
411 |
|
|
$display( "ERROR BufferControl: FreeSlots remove out of bounds");
|
412 |
|
|
end
|
413 |
|
|
endmethod
|
414 |
|
|
|
415 |
|
|
method Bit#(5) first( Bit#(5) exception );
|
416 |
|
|
Bit#(5) tempout = 31;
|
417 |
|
|
for(Integer ii=17; ii>=0; ii=ii-1)
|
418 |
|
|
begin
|
419 |
|
|
if(slots[fromInteger(ii)]==1'b0 && fromInteger(ii)!=exception)
|
420 |
|
|
tempout = fromInteger(ii);
|
421 |
|
|
end
|
422 |
|
|
return tempout;
|
423 |
|
|
endmethod
|
424 |
|
|
|
425 |
|
|
endmodule
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
//-----------------------------------------------------------
|
429 |
|
|
// Helper functions
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
//-----------------------------------------------------------
|
434 |
|
|
// Buffer Controller Module
|
435 |
|
|
//-----------------------------------------------------------
|
436 |
|
|
|
437 |
|
|
|
438 |
|
|
(* synthesize *)
|
439 |
|
|
module mkBufferControl( IBufferControl );
|
440 |
|
|
|
441 |
|
|
FIFO#(DeblockFilterOT) infifo <- mkSizedFIFO(bufferControl_infifo_size);
|
442 |
|
|
FIFO#(BufferControlOT) outfifo <- mkFIFO();
|
443 |
|
|
|
444 |
|
|
FIFO#(FrameBufferLoadReq) loadReqQ1 <- mkFIFO();
|
445 |
|
|
FIFO#(FrameBufferLoadResp) loadRespQ1 <- mkFIFO();
|
446 |
|
|
FIFO#(FrameBufferLoadReq) loadReqQInLuma <- mkFIFO();
|
447 |
|
|
FIFO#(FrameBufferLoadResp) loadRespQInLuma <- mkFIFO();
|
448 |
|
|
FIFO#(FrameBufferLoadReq) loadReqQInChroma <- mkFIFO();
|
449 |
|
|
FIFO#(FrameBufferLoadResp) loadRespQInChroma <- mkFIFO();
|
450 |
|
|
FIFO#(FrameBufferStoreReq) storeReqQ <- mkFIFO();
|
451 |
|
|
|
452 |
|
|
FIFO#(InterpolatorLoadReq) inLoadReqQLuma <- mkFIFO();
|
453 |
|
|
FIFO#(InterpolatorLoadResp) inLoadRespQLuma <- mkFIFO();
|
454 |
|
|
FIFO#(Bit#(2)) inLoadOutOfBoundsLuma <- mkSizedFIFO(64); // What is this doing?
|
455 |
|
|
|
456 |
|
|
FIFO#(InterpolatorLoadReq) inLoadReqQChroma <- mkFIFO();
|
457 |
|
|
FIFO#(InterpolatorLoadResp) inLoadRespQChroma <- mkFIFO();
|
458 |
|
|
FIFO#(Bit#(2)) inLoadOutOfBoundsChroma <- mkSizedFIFO(64);
|
459 |
|
|
|
460 |
|
|
|
461 |
|
|
Reg#(Bit#(5)) log2_max_frame_num <- mkReg(0);
|
462 |
|
|
Reg#(Bit#(5)) num_ref_frames <- mkReg(0);
|
463 |
|
|
Reg#(Bit#(1)) gaps_in_frame_num_allowed_flag <- mkReg(0);
|
464 |
|
|
Reg#(Bit#(PicWidthSz)) picWidth <- mkReg(maxPicWidthInMB);
|
465 |
|
|
Reg#(Bit#(PicHeightSz)) picHeight <- mkReg(0);
|
466 |
|
|
Reg#(Bit#(PicAreaSz)) frameinmb <- mkReg(0);
|
467 |
|
|
|
468 |
|
|
Reg#(Bit#(5)) ppsnum_ref_idx_l0_active <- mkReg(0);
|
469 |
|
|
Reg#(Bit#(16)) frame_num <- mkReg(0);
|
470 |
|
|
Reg#(Bit#(16)) prevRefFrameNum <- mkReg(0);
|
471 |
|
|
Reg#(Bit#(5)) num_ref_idx_l0_active <- mkReg(0);
|
472 |
|
|
Reg#(Bit#(2)) reordering_of_pic_nums_idc <- mkReg(0);
|
473 |
|
|
Reg#(Bit#(16)) picNumLXPred <- mkReg(0);
|
474 |
|
|
Reg#(Bit#(3)) memory_management_control_operation <- mkReg(0);
|
475 |
|
|
|
476 |
|
|
Reg#(Bool) newInputFrame <- mkReg(True);
|
477 |
|
|
Reg#(Bool) noMoreInput <- mkReg(False);
|
478 |
|
|
Reg#(Bool) inputframedone <- mkReg(False);
|
479 |
|
|
Reg#(Outprocess) outprocess <- mkReg(Idle);
|
480 |
|
|
Reg#(Bool) outputframedone <- mkReg(True);
|
481 |
|
|
|
482 |
|
|
Reg#(Bit#(5)) inSlot <- mkReg(0);
|
483 |
|
|
Reg#(Bit#(FrameBufferSz)) inAddrBase <- mkReg(0);
|
484 |
|
|
Reg#(Bit#(5)) outSlot <- mkReg(31);
|
485 |
|
|
Reg#(Bit#(FrameBufferSz)) outAddrBase <- mkReg(0);
|
486 |
|
|
Reg#(Bit#(TAdd#(PicAreaSz,7))) outReqCount <- mkReg(0);
|
487 |
|
|
Reg#(Bit#(TAdd#(PicAreaSz,7))) outRespCount <- mkReg(0);
|
488 |
|
|
|
489 |
|
|
FreeSlots freeSlots <- mkFreeSlots();//may include outSlot (have to make sure it's not used)
|
490 |
|
|
ShortTermPicList shortTermPicList <- mkShortTermPicList();
|
491 |
|
|
LongTermPicList longTermPicList <- mkLongTermPicList();
|
492 |
|
|
RFile1#(Bit#(5),Bit#(5)) refPicList <- mkRFile1(0,maxRefFrames-1);
|
493 |
|
|
Reg#(Bit#(5)) refPicListCount <- mkReg(0);
|
494 |
|
|
Reg#(Bool) initRefPicList <- mkReg(False);
|
495 |
|
|
Reg#(Bool) reorderRefPicList <- mkReg(False);
|
496 |
|
|
Reg#(Bit#(5)) refIdx <- mkReg(0);
|
497 |
|
|
Reg#(Bit#(5)) tempSlot <- mkReg(0);
|
498 |
|
|
Reg#(Bit#(5)) tempSlot2 <- mkReg(0);
|
499 |
|
|
Reg#(Bit#(2)) adjustFreeSlots <- mkReg(0);
|
500 |
|
|
|
501 |
|
|
Reg#(Bool) refPicListDone <- mkReg(False);
|
502 |
|
|
Reg#(Bool) lockInterLoads <- mkReg(True);
|
503 |
|
|
DoNotFire donotfire <- mkDoNotFire();
|
504 |
|
|
|
505 |
|
|
|
506 |
|
|
//-----------------------------------------------------------
|
507 |
|
|
// Rules
|
508 |
|
|
|
509 |
|
|
rule inputing ( !noMoreInput && !inputframedone );
|
510 |
|
|
//$display( "Trace Buffer Control: passing infifo packed %h", pack(infifo.first()));
|
511 |
|
|
case (infifo.first()) matches
|
512 |
|
|
tagged EDOT .indata :
|
513 |
|
|
begin
|
514 |
|
|
case (indata) matches
|
515 |
|
|
tagged SPSlog2_max_frame_num .xdata :
|
516 |
|
|
begin
|
517 |
|
|
if(adjustFreeSlots == 0)
|
518 |
|
|
begin
|
519 |
|
|
infifo.deq();
|
520 |
|
|
log2_max_frame_num <= xdata;
|
521 |
|
|
freeSlots.init();
|
522 |
|
|
shortTermPicList.clear();
|
523 |
|
|
longTermPicList.clear();
|
524 |
|
|
end
|
525 |
|
|
else
|
526 |
|
|
donotfire.doNotFire();
|
527 |
|
|
end
|
528 |
|
|
tagged SPSnum_ref_frames .xdata :
|
529 |
|
|
begin
|
530 |
|
|
infifo.deq();
|
531 |
|
|
num_ref_frames <= xdata;
|
532 |
|
|
end
|
533 |
|
|
tagged SPSgaps_in_frame_num_allowed_flag .xdata :
|
534 |
|
|
begin
|
535 |
|
|
infifo.deq();
|
536 |
|
|
gaps_in_frame_num_allowed_flag <= xdata;
|
537 |
|
|
end
|
538 |
|
|
tagged SPSpic_width_in_mbs .xdata :
|
539 |
|
|
begin
|
540 |
|
|
infifo.deq();
|
541 |
|
|
picWidth <= xdata;
|
542 |
|
|
end
|
543 |
|
|
tagged SPSpic_height_in_map_units .xdata :
|
544 |
|
|
begin
|
545 |
|
|
infifo.deq();
|
546 |
|
|
picHeight <= xdata;
|
547 |
|
|
frameinmb <= zeroExtend(picWidth)*zeroExtend(xdata);
|
548 |
|
|
end
|
549 |
|
|
tagged PPSnum_ref_idx_l0_active .xdata :
|
550 |
|
|
begin
|
551 |
|
|
infifo.deq();
|
552 |
|
|
ppsnum_ref_idx_l0_active <= xdata;
|
553 |
|
|
end
|
554 |
|
|
tagged SHfirst_mb_in_slice .xdata :
|
555 |
|
|
begin
|
556 |
|
|
if(adjustFreeSlots == 0)
|
557 |
|
|
begin
|
558 |
|
|
infifo.deq();
|
559 |
|
|
newInputFrame <= False;
|
560 |
|
|
shortTermPicList.listAll();
|
561 |
|
|
longTermPicList.listAll();
|
562 |
|
|
initRefPicList <= True;
|
563 |
|
|
refPicListCount <= 0;
|
564 |
|
|
if(newInputFrame)
|
565 |
|
|
begin
|
566 |
|
|
inSlot <= freeSlots.first(outSlot);
|
567 |
|
|
inAddrBase <= (zeroExtend(freeSlots.first(outSlot))*zeroExtend(frameinmb)*3)<<5;
|
568 |
|
|
end
|
569 |
|
|
$display( "Trace BufferControl: passing SHfirst_mb_in_slice %h %h %0d", freeSlots.first(outSlot), outSlot, (newInputFrame ? 1 : 0));
|
570 |
|
|
end
|
571 |
|
|
else
|
572 |
|
|
donotfire.doNotFire();
|
573 |
|
|
end
|
574 |
|
|
tagged SHframe_num .xdata :
|
575 |
|
|
begin
|
576 |
|
|
infifo.deq();
|
577 |
|
|
frame_num <= xdata;
|
578 |
|
|
picNumLXPred <= frame_num;
|
579 |
|
|
end
|
580 |
|
|
tagged SHnum_ref_idx_active_override_flag .xdata :
|
581 |
|
|
begin
|
582 |
|
|
infifo.deq();
|
583 |
|
|
num_ref_idx_l0_active <= ppsnum_ref_idx_l0_active;
|
584 |
|
|
end
|
585 |
|
|
tagged SHnum_ref_idx_l0_active .xdata :
|
586 |
|
|
begin
|
587 |
|
|
infifo.deq();
|
588 |
|
|
num_ref_idx_l0_active <= xdata;
|
589 |
|
|
end
|
590 |
|
|
tagged SHRref_pic_list_reordering_flag_l0 .xdata :
|
591 |
|
|
begin
|
592 |
|
|
if(!initRefPicList)
|
593 |
|
|
begin
|
594 |
|
|
infifo.deq();
|
595 |
|
|
if(xdata==0)
|
596 |
|
|
refPicListDone <= True;
|
597 |
|
|
end
|
598 |
|
|
else
|
599 |
|
|
donotfire.doNotFire();
|
600 |
|
|
refIdx <= 0;
|
601 |
|
|
end
|
602 |
|
|
tagged SHRreordering_of_pic_nums_idc .xdata :
|
603 |
|
|
begin
|
604 |
|
|
if(!reorderRefPicList)
|
605 |
|
|
begin
|
606 |
|
|
infifo.deq();
|
607 |
|
|
reordering_of_pic_nums_idc <= xdata;
|
608 |
|
|
if(xdata==3)
|
609 |
|
|
refPicListDone <= True;
|
610 |
|
|
end
|
611 |
|
|
else
|
612 |
|
|
donotfire.doNotFire();
|
613 |
|
|
end
|
614 |
|
|
tagged SHRabs_diff_pic_num .xdata :
|
615 |
|
|
begin
|
616 |
|
|
if(!reorderRefPicList)
|
617 |
|
|
begin
|
618 |
|
|
infifo.deq();
|
619 |
|
|
Bit#(16) picNumLXNoWrap;
|
620 |
|
|
Bit#(17) tempOne = 1;
|
621 |
|
|
Bit#(17) maxPicNum = tempOne << log2_max_frame_num;
|
622 |
|
|
if(reordering_of_pic_nums_idc==0)
|
623 |
|
|
begin
|
624 |
|
|
if(picNumLXPred < truncate(xdata))
|
625 |
|
|
picNumLXNoWrap = truncate(zeroExtend(picNumLXPred)-xdata+maxPicNum);
|
626 |
|
|
else
|
627 |
|
|
picNumLXNoWrap = truncate(zeroExtend(picNumLXPred)-xdata);
|
628 |
|
|
end
|
629 |
|
|
else
|
630 |
|
|
begin
|
631 |
|
|
if(zeroExtend(picNumLXPred)+xdata >= maxPicNum)
|
632 |
|
|
picNumLXNoWrap = truncate(zeroExtend(picNumLXPred)+xdata-maxPicNum);
|
633 |
|
|
else
|
634 |
|
|
picNumLXNoWrap = truncate(zeroExtend(picNumLXPred)+xdata);
|
635 |
|
|
end
|
636 |
|
|
picNumLXPred <= picNumLXNoWrap;
|
637 |
|
|
shortTermPicList.search(picNumLXNoWrap);
|
638 |
|
|
reorderRefPicList <= True;
|
639 |
|
|
refPicListCount <= 0;
|
640 |
|
|
end
|
641 |
|
|
else
|
642 |
|
|
donotfire.doNotFire();
|
643 |
|
|
end
|
644 |
|
|
tagged SHRlong_term_pic_num .xdata :
|
645 |
|
|
begin
|
646 |
|
|
if(!reorderRefPicList)
|
647 |
|
|
begin
|
648 |
|
|
infifo.deq();
|
649 |
|
|
longTermPicList.search(xdata);
|
650 |
|
|
reorderRefPicList <= True;
|
651 |
|
|
refPicListCount <= 0;
|
652 |
|
|
end
|
653 |
|
|
else
|
654 |
|
|
donotfire.doNotFire();
|
655 |
|
|
end
|
656 |
|
|
tagged SHDlong_term_reference_flag .xdata :
|
657 |
|
|
begin
|
658 |
|
|
infifo.deq();
|
659 |
|
|
if(xdata==0)
|
660 |
|
|
shortTermPicList.insert(frame_num,inSlot,num_ref_frames);
|
661 |
|
|
else
|
662 |
|
|
longTermPicList.insert(0,inSlot);
|
663 |
|
|
adjustFreeSlots <= 1;
|
664 |
|
|
end
|
665 |
|
|
tagged SHDadaptive_ref_pic_marking_mode_flag .xdata :
|
666 |
|
|
begin
|
667 |
|
|
infifo.deq();
|
668 |
|
|
Bit#(17) tempFrameNum = zeroExtend(frame_num);
|
669 |
|
|
Bit#(17) tempOne = 1;
|
670 |
|
|
Bit#(17) maxPicNum = tempOne << log2_max_frame_num;
|
671 |
|
|
Bit#(16) tempGap = 0;
|
672 |
|
|
if(frame_num < prevRefFrameNum)
|
673 |
|
|
tempFrameNum = tempFrameNum + maxPicNum;
|
674 |
|
|
if(tempFrameNum-zeroExtend(prevRefFrameNum) > 1)
|
675 |
|
|
tempGap = truncate(tempFrameNum-zeroExtend(prevRefFrameNum)-1);
|
676 |
|
|
if(xdata==0)
|
677 |
|
|
begin
|
678 |
|
|
if(tempGap==0)
|
679 |
|
|
shortTermPicList.insert(frame_num,inSlot,(num_ref_frames-longTermPicList.numPics()));
|
680 |
|
|
else
|
681 |
|
|
shortTermPicList.insert_gap(frame_num,inSlot,(num_ref_frames-longTermPicList.numPics()),tempGap,log2_max_frame_num);
|
682 |
|
|
adjustFreeSlots <= 1;
|
683 |
|
|
end
|
684 |
|
|
prevRefFrameNum <= frame_num;
|
685 |
|
|
end
|
686 |
|
|
tagged SHDmemory_management_control_operation .xdata :
|
687 |
|
|
begin
|
688 |
|
|
infifo.deq();
|
689 |
|
|
memory_management_control_operation <= xdata;
|
690 |
|
|
if(xdata==0)
|
691 |
|
|
adjustFreeSlots <= 1;
|
692 |
|
|
else if(xdata==5)
|
693 |
|
|
begin
|
694 |
|
|
shortTermPicList.clear();
|
695 |
|
|
longTermPicList.clear();
|
696 |
|
|
end
|
697 |
|
|
end
|
698 |
|
|
tagged SHDdifference_of_pic_nums .xdata :
|
699 |
|
|
begin
|
700 |
|
|
infifo.deq();
|
701 |
|
|
Bit#(16) picNumXNoWrap;
|
702 |
|
|
Bit#(17) tempOne = 1;
|
703 |
|
|
Bit#(17) maxPicNum = tempOne << log2_max_frame_num;
|
704 |
|
|
if(frame_num < truncate(xdata))
|
705 |
|
|
picNumXNoWrap = truncate(zeroExtend(frame_num)-xdata+maxPicNum);
|
706 |
|
|
else
|
707 |
|
|
picNumXNoWrap = truncate(zeroExtend(frame_num)-xdata);
|
708 |
|
|
if(memory_management_control_operation == 1)
|
709 |
|
|
shortTermPicList.remove(picNumXNoWrap,False);
|
710 |
|
|
else
|
711 |
|
|
shortTermPicList.remove(picNumXNoWrap,True);
|
712 |
|
|
end
|
713 |
|
|
tagged SHDlong_term_pic_num .xdata :
|
714 |
|
|
begin
|
715 |
|
|
infifo.deq();
|
716 |
|
|
longTermPicList.remove(xdata);
|
717 |
|
|
end
|
718 |
|
|
tagged SHDlong_term_frame_idx .xdata :
|
719 |
|
|
begin
|
720 |
|
|
infifo.deq();
|
721 |
|
|
if(memory_management_control_operation == 3)
|
722 |
|
|
begin
|
723 |
|
|
if(shortTermPicList.resultSlot() matches tagged Valid .validdata)
|
724 |
|
|
longTermPicList.insert(xdata,validdata);
|
725 |
|
|
else
|
726 |
|
|
$display( "ERROR BufferControl: SHDlong_term_frame_idx Invalid output from shortTermPicList");
|
727 |
|
|
shortTermPicList.deq();
|
728 |
|
|
end
|
729 |
|
|
else
|
730 |
|
|
longTermPicList.insert(xdata,inSlot);
|
731 |
|
|
end
|
732 |
|
|
tagged SHDmax_long_term_frame_idx_plus1 .xdata :
|
733 |
|
|
begin
|
734 |
|
|
infifo.deq();
|
735 |
|
|
longTermPicList.maxIndexPlus1(xdata);
|
736 |
|
|
end
|
737 |
|
|
tagged EndOfFile :
|
738 |
|
|
begin
|
739 |
|
|
infifo.deq();
|
740 |
|
|
$display( "INFO Buffer Control: EndOfFile reached");
|
741 |
|
|
noMoreInput <= True;
|
742 |
|
|
//$finish(0);
|
743 |
|
|
//outfifo.enq(EndOfFile);
|
744 |
|
|
end
|
745 |
|
|
default:
|
746 |
|
|
begin
|
747 |
|
|
$display("WARNING: Why are we in this clause");
|
748 |
|
|
infifo.deq();
|
749 |
|
|
end
|
750 |
|
|
endcase
|
751 |
|
|
end
|
752 |
|
|
tagged DFBLuma .indata :
|
753 |
|
|
begin
|
754 |
|
|
infifo.deq();
|
755 |
|
|
//$display( "TRACE Buffer Control: input Luma %0d %h %h", indata.mb, indata.pixel, indata.data);
|
756 |
|
|
Bit#(TAdd#(PicAreaSz,6)) addr = {(zeroExtend(indata.ver)*zeroExtend(picWidth)),2'b00}+zeroExtend(indata.hor);
|
757 |
|
|
storeReqQ.enq(FBStoreReq {addr:inAddrBase+zeroExtend(addr),data:indata.data});
|
758 |
|
|
end
|
759 |
|
|
tagged DFBChroma .indata :
|
760 |
|
|
begin
|
761 |
|
|
infifo.deq();
|
762 |
|
|
Bit#(TAdd#(PicAreaSz,4)) addr = {(zeroExtend(indata.ver)*zeroExtend(picWidth)),1'b0}+zeroExtend(indata.hor);
|
763 |
|
|
Bit#(TAdd#(PicAreaSz,6)) chromaOffset = {frameinmb,6'b000000};
|
764 |
|
|
Bit#(TAdd#(PicAreaSz,4)) vOffset = 0;
|
765 |
|
|
if(indata.uv == 1)
|
766 |
|
|
vOffset = {frameinmb,4'b0000};
|
767 |
|
|
storeReqQ.enq(FBStoreReq {addr:(inAddrBase+zeroExtend(chromaOffset)+zeroExtend(vOffset)+zeroExtend(addr)),data:indata.data});
|
768 |
|
|
//$display( "TRACE Buffer Control: input Chroma %0d %0h %h %h %h %h", indata.uv, indata.ver, indata.hor, indata.data, addr, (inAddrBase+zeroExtend(chromaOffset)+zeroExtend(vOffset)+zeroExtend(addr)));
|
769 |
|
|
end
|
770 |
|
|
tagged EndOfFrame :
|
771 |
|
|
begin
|
772 |
|
|
infifo.deq();
|
773 |
|
|
$display( "INFO Buffer Control: EndOfFrame reached");
|
774 |
|
|
inputframedone <= True;
|
775 |
|
|
newInputFrame <= True;
|
776 |
|
|
refPicListDone <= False;
|
777 |
|
|
end
|
778 |
|
|
default: infifo.deq();
|
779 |
|
|
endcase
|
780 |
|
|
endrule
|
781 |
|
|
|
782 |
|
|
|
783 |
|
|
rule initingRefPicList ( initRefPicList );
|
784 |
|
|
if(shortTermPicList.resultSlot() matches tagged Valid .xdata)
|
785 |
|
|
begin
|
786 |
|
|
shortTermPicList.deq();
|
787 |
|
|
refPicList.upd(refPicListCount,xdata);
|
788 |
|
|
refPicListCount <= refPicListCount+1;
|
789 |
|
|
$display( "Trace BufferControl: initingRefPicList shortTermPicList %h", xdata);
|
790 |
|
|
end
|
791 |
|
|
else if(longTermPicList.resultSlot() matches tagged Valid .xdata)
|
792 |
|
|
begin
|
793 |
|
|
longTermPicList.deq();
|
794 |
|
|
refPicList.upd(refPicListCount,xdata);
|
795 |
|
|
refPicListCount <= refPicListCount+1;
|
796 |
|
|
$display( "Trace BufferControl: initingRefPicList longTermPicList %h", xdata);
|
797 |
|
|
end
|
798 |
|
|
else
|
799 |
|
|
begin
|
800 |
|
|
shortTermPicList.deq();
|
801 |
|
|
longTermPicList.deq();
|
802 |
|
|
initRefPicList <= False;
|
803 |
|
|
refPicListCount <= 0;
|
804 |
|
|
$display( "Trace BufferControl: initingRefPicList end");
|
805 |
|
|
end
|
806 |
|
|
endrule
|
807 |
|
|
|
808 |
|
|
|
809 |
|
|
rule reorderingRefPicList ( reorderRefPicList );
|
810 |
|
|
$display( "Trace BufferControl: reorderingRefPicList");
|
811 |
|
|
if(shortTermPicList.resultSlot() matches tagged Valid .xdata)//////////////////////////////////////////////////////////////////////////////////////////
|
812 |
|
|
begin
|
813 |
|
|
shortTermPicList.deq();
|
814 |
|
|
tempSlot <= refPicList.sub(refIdx);
|
815 |
|
|
refPicList.upd(refIdx,xdata);
|
816 |
|
|
refPicListCount <= refIdx+1;
|
817 |
|
|
tempSlot2 <= xdata;
|
818 |
|
|
end
|
819 |
|
|
else if(longTermPicList.resultSlot() matches tagged Valid .xdata)/////////////////////////////////////////////////////////////////////////////////////may get stuck?
|
820 |
|
|
begin
|
821 |
|
|
longTermPicList.deq();
|
822 |
|
|
tempSlot <= refPicList.sub(refIdx);
|
823 |
|
|
refPicList.upd(refIdx,xdata);
|
824 |
|
|
refPicListCount <= refIdx+1;
|
825 |
|
|
tempSlot2 <= xdata;
|
826 |
|
|
end
|
827 |
|
|
else
|
828 |
|
|
begin
|
829 |
|
|
if(refPicListCount
|
830 |
|
|
begin
|
831 |
|
|
tempSlot <= refPicList.sub(refPicListCount);
|
832 |
|
|
refPicList.upd(refPicListCount,tempSlot);
|
833 |
|
|
refPicListCount <= refPicListCount+1;
|
834 |
|
|
end
|
835 |
|
|
else
|
836 |
|
|
begin
|
837 |
|
|
reorderRefPicList <= False;
|
838 |
|
|
refPicListCount <= 0;
|
839 |
|
|
refIdx <= refIdx+1;
|
840 |
|
|
end
|
841 |
|
|
end
|
842 |
|
|
endrule
|
843 |
|
|
|
844 |
|
|
|
845 |
|
|
rule adjustingFreeSlots ( adjustFreeSlots != 0 );
|
846 |
|
|
if(adjustFreeSlots == 1)
|
847 |
|
|
begin
|
848 |
|
|
shortTermPicList.listAll();
|
849 |
|
|
longTermPicList.listAll();
|
850 |
|
|
freeSlots.init();
|
851 |
|
|
adjustFreeSlots <= 2;
|
852 |
|
|
$display( "Trace BufferControl: adjustingFreeSlots begin");
|
853 |
|
|
end
|
854 |
|
|
else
|
855 |
|
|
begin
|
856 |
|
|
if(shortTermPicList.resultSlot() matches tagged Valid .xdata)
|
857 |
|
|
begin
|
858 |
|
|
shortTermPicList.deq();
|
859 |
|
|
freeSlots.remove(xdata);
|
860 |
|
|
$display( "Trace BufferControl: adjustingFreeSlots shortTermPicList %h", xdata);
|
861 |
|
|
end
|
862 |
|
|
else if(longTermPicList.resultSlot() matches tagged Valid .xdata)
|
863 |
|
|
begin
|
864 |
|
|
longTermPicList.deq();
|
865 |
|
|
freeSlots.remove(xdata);
|
866 |
|
|
$display( "Trace BufferControl: adjustingFreeSlots longTermPicList %h", xdata);
|
867 |
|
|
end
|
868 |
|
|
else
|
869 |
|
|
begin
|
870 |
|
|
shortTermPicList.deq();
|
871 |
|
|
longTermPicList.deq();
|
872 |
|
|
adjustFreeSlots <= 0;
|
873 |
|
|
$display( "Trace BufferControl: adjustingFreeSlots end");
|
874 |
|
|
end
|
875 |
|
|
end
|
876 |
|
|
endrule
|
877 |
|
|
|
878 |
|
|
|
879 |
|
|
rule outputingReq ( outprocess != Idle );
|
880 |
|
|
if(outprocess==Y)
|
881 |
|
|
begin
|
882 |
|
|
loadReqQ1.enq(FBLoadReq (outAddrBase+zeroExtend(outReqCount)));
|
883 |
|
|
if(outReqCount == {1'b0,frameinmb,6'b000000}-1)
|
884 |
|
|
outprocess <= U;
|
885 |
|
|
outReqCount <= outReqCount+1;
|
886 |
|
|
end
|
887 |
|
|
else if(outprocess==U)
|
888 |
|
|
begin
|
889 |
|
|
loadReqQ1.enq(FBLoadReq (outAddrBase+zeroExtend(outReqCount)));
|
890 |
|
|
if(outReqCount == {1'b0,frameinmb,6'b000000}+{3'b000,frameinmb,4'b0000}-1)
|
891 |
|
|
outprocess <= V;
|
892 |
|
|
outReqCount <= outReqCount+1;
|
893 |
|
|
end
|
894 |
|
|
else
|
895 |
|
|
begin
|
896 |
|
|
//$display( "TRACE BufferControl: outputingReq V %h %h %h", outAddrBase, outReqCount, (outAddrBase+zeroExtend(outReqCount)));
|
897 |
|
|
loadReqQ1.enq(FBLoadReq (outAddrBase+zeroExtend(outReqCount)));
|
898 |
|
|
if(outReqCount == {1'b0,frameinmb,6'b000000}+{2'b00,frameinmb,5'b00000}-1)
|
899 |
|
|
outprocess <= Idle;
|
900 |
|
|
outReqCount <= outReqCount+1;
|
901 |
|
|
end
|
902 |
|
|
endrule
|
903 |
|
|
|
904 |
|
|
|
905 |
|
|
rule outputingResp ( !outputframedone );
|
906 |
|
|
if(loadRespQ1.first() matches tagged FBLoadResp .xdata)
|
907 |
|
|
begin
|
908 |
|
|
loadRespQ1.deq();
|
909 |
|
|
outfifo.enq(tagged YUV xdata);
|
910 |
|
|
if(outRespCount == {1'b0,frameinmb,6'b000000}+{2'b00,frameinmb,5'b00000}-1)
|
911 |
|
|
outputframedone <= True;
|
912 |
|
|
outRespCount <= outRespCount+1;
|
913 |
|
|
end
|
914 |
|
|
endrule
|
915 |
|
|
|
916 |
|
|
|
917 |
|
|
// XXX need to handle the double EOF deq here XXX
|
918 |
|
|
rule goToNextFrame ( outputframedone && inputframedone &&
|
919 |
|
|
(inLoadReqQLuma.first()==IPLoadEndFrame) &&
|
920 |
|
|
(inLoadReqQChroma.first()==IPLoadEndFrame));
|
921 |
|
|
inputframedone <= False;
|
922 |
|
|
outprocess <= Y;
|
923 |
|
|
outputframedone <= False;
|
924 |
|
|
outSlot <= inSlot;
|
925 |
|
|
outAddrBase <= inAddrBase;
|
926 |
|
|
outReqCount <= 0;
|
927 |
|
|
outRespCount <= 0;
|
928 |
|
|
loadReqQ1.enq(FBEndFrameSync);
|
929 |
|
|
loadReqQInLuma.enq(FBEndFrameSync);
|
930 |
|
|
loadReqQInChroma.enq(FBEndFrameSync);
|
931 |
|
|
storeReqQ.enq(FBEndFrameSync);
|
932 |
|
|
inLoadReqQLuma.deq();
|
933 |
|
|
inLoadReqQChroma.deq();
|
934 |
|
|
lockInterLoads <= True;
|
935 |
|
|
$display(" Buffer Control: going to next frame ");
|
936 |
|
|
endrule
|
937 |
|
|
|
938 |
|
|
|
939 |
|
|
rule unlockInterLoads ( lockInterLoads && refPicListDone );
|
940 |
|
|
lockInterLoads <= False;
|
941 |
|
|
endrule
|
942 |
|
|
|
943 |
|
|
|
944 |
|
|
rule theEndOfFile ( outputframedone && noMoreInput );
|
945 |
|
|
outfifo.enq(tagged EndOfFile);
|
946 |
|
|
endrule
|
947 |
|
|
|
948 |
|
|
|
949 |
|
|
rule interLumaReq ( inLoadReqQLuma.first() matches tagged IPLoadLuma .reqdata &&& !lockInterLoads );
|
950 |
|
|
inLoadReqQLuma.deq();
|
951 |
|
|
Bit#(5) slot = refPicList.sub(zeroExtend(reqdata.refIdx));
|
952 |
|
|
Bit#(FrameBufferSz) addrBase = (zeroExtend(slot)*zeroExtend(frameinmb)*3)<<5;
|
953 |
|
|
Bit#(TAdd#(PicAreaSz,6)) addr = {(zeroExtend(reqdata.ver)*zeroExtend(picWidth)),2'b00}+zeroExtend(reqdata.hor);
|
954 |
|
|
inLoadOutOfBoundsLuma.enq({reqdata.horOutOfBounds,(reqdata.hor==0 ? 0 : 1)});
|
955 |
|
|
loadReqQInLuma.enq(FBLoadReq (addrBase+zeroExtend(addr)));
|
956 |
|
|
$display( "PARDEBLOCK Trace BufferControl: interLumaReq %h %h %h %h %h", reqdata.refIdx, slot, addrBase, addr, addrBase+zeroExtend(addr));
|
957 |
|
|
endrule
|
958 |
|
|
|
959 |
|
|
|
960 |
|
|
rule interChromaReq ( inLoadReqQChroma.first() matches tagged IPLoadChroma .reqdata &&& !lockInterLoads );
|
961 |
|
|
inLoadReqQChroma.deq();
|
962 |
|
|
Bit#(5) slot = refPicList.sub(zeroExtend(reqdata.refIdx));
|
963 |
|
|
Bit#(FrameBufferSz) addrBase = (zeroExtend(slot)*zeroExtend(frameinmb)*3)<<5;
|
964 |
|
|
Bit#(TAdd#(PicAreaSz,6)) chromaOffset = {frameinmb,6'b000000};
|
965 |
|
|
Bit#(TAdd#(PicAreaSz,4)) vOffset = 0;
|
966 |
|
|
if(reqdata.uv == 1)
|
967 |
|
|
vOffset = {frameinmb,4'b0000};
|
968 |
|
|
Bit#(TAdd#(PicAreaSz,6)) addr = {(zeroExtend(reqdata.ver)*zeroExtend(picWidth)),1'b0}+zeroExtend(reqdata.hor);
|
969 |
|
|
inLoadOutOfBoundsChroma.enq({reqdata.horOutOfBounds,(reqdata.hor==0 ? 0 : 1)});
|
970 |
|
|
loadReqQInChroma.enq(FBLoadReq (addrBase+zeroExtend(chromaOffset)+zeroExtend(vOffset)+zeroExtend(addr)));
|
971 |
|
|
$display( "PARDEBLOCK Trace BufferControl: interChromaReq %h %h %h %h %h", reqdata.refIdx, slot, addrBase, addr, addrBase+zeroExtend(chromaOffset)+zeroExtend(vOffset)+zeroExtend(addr));
|
972 |
|
|
endrule
|
973 |
|
|
|
974 |
|
|
rule monitorRespLuma;
|
975 |
|
|
$display("Trace BufferControl check loadRespQInLuma %h", loadRespQInLuma.first());
|
976 |
|
|
endrule
|
977 |
|
|
|
978 |
|
|
rule monitorRespChroma;
|
979 |
|
|
$display("Trace BufferControl check loadRespQInChroma", loadRespQInChroma.first());
|
980 |
|
|
endrule
|
981 |
|
|
|
982 |
|
|
rule interRespLuma ( loadRespQInLuma.first() matches tagged FBLoadResp .data );
|
983 |
|
|
loadRespQInLuma.deq();
|
984 |
|
|
if(inLoadOutOfBoundsLuma.first() == 2'b10)
|
985 |
|
|
inLoadRespQLuma.enq(IPLoadResp ({data[7:0],data[7:0],data[7:0],data[7:0]}));
|
986 |
|
|
else if(inLoadOutOfBoundsLuma.first() == 2'b11)
|
987 |
|
|
inLoadRespQLuma.enq(IPLoadResp ({data[31:24],data[31:24],data[31:24],data[31:24]}));
|
988 |
|
|
else
|
989 |
|
|
inLoadRespQLuma.enq(tagged IPLoadResp data);
|
990 |
|
|
inLoadOutOfBoundsLuma.deq();
|
991 |
|
|
$display( " PARDEBLOCK Trace BufferControl: interRespLuma %h %h", inLoadOutOfBoundsLuma.first(), data);
|
992 |
|
|
endrule
|
993 |
|
|
|
994 |
|
|
rule interRespChroma ( loadRespQInChroma.first() matches tagged FBLoadResp .data );
|
995 |
|
|
loadRespQInChroma.deq();
|
996 |
|
|
if(inLoadOutOfBoundsChroma.first() == 2'b10)
|
997 |
|
|
inLoadRespQChroma.enq(IPLoadResp ({data[7:0],data[7:0],data[7:0],data[7:0]}));
|
998 |
|
|
else if(inLoadOutOfBoundsChroma.first() == 2'b11)
|
999 |
|
|
inLoadRespQChroma.enq(IPLoadResp ({data[31:24],data[31:24],data[31:24],data[31:24]}));
|
1000 |
|
|
else
|
1001 |
|
|
inLoadRespQChroma.enq(tagged IPLoadResp data);
|
1002 |
|
|
inLoadOutOfBoundsChroma.deq();
|
1003 |
|
|
$display(" PARDEBLOCK Trace BufferControl: interRespChroma %h %h", inLoadOutOfBoundsChroma.first(), data);
|
1004 |
|
|
endrule
|
1005 |
|
|
|
1006 |
|
|
interface Put ioin = fifoToPut(infifo);
|
1007 |
|
|
interface Get ioout = fifoToGet(outfifo);
|
1008 |
|
|
interface Client buffer_client_load1;
|
1009 |
|
|
interface Get request = fifoToGet(loadReqQ1);
|
1010 |
|
|
interface Put response = fifoToPut(loadRespQ1);
|
1011 |
|
|
endinterface
|
1012 |
|
|
interface Client buffer_client_load2;
|
1013 |
|
|
interface Get request = fifoToGet(loadReqQInLuma);
|
1014 |
|
|
interface Put response = fifoToPut(loadRespQInLuma);
|
1015 |
|
|
endinterface
|
1016 |
|
|
interface Client buffer_client_load3;
|
1017 |
|
|
interface Get request = fifoToGet(loadReqQInChroma);
|
1018 |
|
|
interface Put response = fifoToPut(loadRespQInChroma);
|
1019 |
|
|
endinterface
|
1020 |
|
|
|
1021 |
|
|
interface Get buffer_client_store = fifoToGet(storeReqQ);
|
1022 |
|
|
|
1023 |
|
|
interface Server inter_server_luma;
|
1024 |
|
|
interface Put request = fifoToPut(inLoadReqQLuma);
|
1025 |
|
|
interface Get response = fifoToGet(inLoadRespQLuma);
|
1026 |
|
|
endinterface
|
1027 |
|
|
|
1028 |
|
|
interface Server inter_server_chroma;
|
1029 |
|
|
interface Put request = fifoToPut(inLoadReqQChroma);
|
1030 |
|
|
interface Get response = fifoToGet(inLoadRespQChroma);
|
1031 |
|
|
endinterface
|
1032 |
|
|
|
1033 |
|
|
|
1034 |
|
|
endmodule
|
1035 |
|
|
|
1036 |
|
|
endpackage
|