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