1 |
2 |
jamey.hick |
//**********************************************************************
|
2 |
|
|
// Prediction
|
3 |
|
|
//----------------------------------------------------------------------
|
4 |
|
|
//
|
5 |
|
|
//
|
6 |
|
|
|
7 |
|
|
package mkPrediction;
|
8 |
|
|
|
9 |
|
|
import H264Types::*;
|
10 |
|
|
|
11 |
|
|
import IPrediction::*;
|
12 |
|
|
import IInterpolator::*;
|
13 |
|
|
import mkInterpolator::*;
|
14 |
|
|
import FIFO::*;
|
15 |
|
|
import FIFOF::*;
|
16 |
|
|
import Vector::*;
|
17 |
|
|
|
18 |
|
|
import Connectable::*;
|
19 |
|
|
import GetPut::*;
|
20 |
|
|
import ClientServer::*;
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
//-----------------------------------------------------------
|
24 |
|
|
// Local Datatypes
|
25 |
|
|
//-----------------------------------------------------------
|
26 |
|
|
|
27 |
|
|
typedef union tagged
|
28 |
|
|
{
|
29 |
|
|
void Intra; //Intra non-4x4
|
30 |
|
|
void Intra4x4;
|
31 |
|
|
void Inter;
|
32 |
|
|
}
|
33 |
|
|
OutState deriving(Eq,Bits);
|
34 |
|
|
|
35 |
|
|
typedef union tagged
|
36 |
|
|
{
|
37 |
|
|
void Start; //not working on anything in particular
|
38 |
|
|
void Intra16x16;
|
39 |
|
|
void Intra4x4;
|
40 |
|
|
void IntraPCM;
|
41 |
|
|
}
|
42 |
|
|
IntraState deriving(Eq,Bits);
|
43 |
|
|
|
44 |
|
|
typedef union tagged
|
45 |
|
|
{
|
46 |
|
|
void Start; //not working on anything in particular
|
47 |
|
|
void InterP16x16;
|
48 |
|
|
void InterP16x8;
|
49 |
|
|
void InterP8x16;
|
50 |
|
|
void InterP8x8;
|
51 |
|
|
void InterP8x8ref0;
|
52 |
|
|
void InterPskip;
|
53 |
|
|
}
|
54 |
|
|
InterState deriving(Eq,Bits);
|
55 |
|
|
|
56 |
|
|
typedef union tagged
|
57 |
|
|
{
|
58 |
|
|
Bit#(1) NotInter;//0 for not available, 1 for intra-coded
|
59 |
|
|
struct {Bit#(4) refIdx; Bit#(14) mvhor; Bit#(12) mvver; Bit#(1) nonZeroTransCoeff;} BlockMv;
|
60 |
|
|
}
|
61 |
|
|
InterBlockMv deriving(Eq,Bits);
|
62 |
|
|
|
63 |
|
|
typedef union tagged
|
64 |
|
|
{
|
65 |
|
|
void SkipMB;
|
66 |
|
|
void NonSkipMB;
|
67 |
|
|
void Intra4x4;
|
68 |
|
|
void Intra4x4PlusChroma;
|
69 |
|
|
}
|
70 |
|
|
NextOutput deriving(Eq,Bits);
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
//-----------------------------------------------------------
|
75 |
|
|
// Helper functions
|
76 |
|
|
|
77 |
|
|
function Bit#(8) intra4x4SelectTop( Bit#(72) valVector, Bit#(4) idx );
|
78 |
|
|
case(idx)
|
79 |
|
|
0: return valVector[15:8];
|
80 |
|
|
1: return valVector[23:16];
|
81 |
|
|
2: return valVector[31:24];
|
82 |
|
|
3: return valVector[39:32];
|
83 |
|
|
4: return valVector[47:40];
|
84 |
|
|
5: return valVector[55:48];
|
85 |
|
|
6: return valVector[63:56];
|
86 |
|
|
7: return valVector[71:64];
|
87 |
|
|
default: return valVector[7:0];
|
88 |
|
|
endcase
|
89 |
|
|
endfunction
|
90 |
|
|
|
91 |
|
|
function Bit#(8) intra4x4SelectLeft( Bit#(40) valVector, Bit#(3) idx );
|
92 |
|
|
case(idx)
|
93 |
|
|
0: return valVector[15:8];
|
94 |
|
|
1: return valVector[23:16];
|
95 |
|
|
2: return valVector[31:24];
|
96 |
|
|
3: return valVector[39:32];
|
97 |
|
|
default: return valVector[7:0];
|
98 |
|
|
endcase
|
99 |
|
|
endfunction
|
100 |
|
|
|
101 |
|
|
function Bit#(8) select32to8( Bit#(32) valVector, Bit#(2) idx );
|
102 |
|
|
case(idx)
|
103 |
|
|
0: return valVector[7:0];
|
104 |
|
|
1: return valVector[15:8];
|
105 |
|
|
2: return valVector[23:16];
|
106 |
|
|
3: return valVector[31:24];
|
107 |
|
|
endcase
|
108 |
|
|
endfunction
|
109 |
|
|
|
110 |
|
|
function Bit#(8) select16to8( Bit#(16) valVector, Bit#(1) idx );
|
111 |
|
|
case(idx)
|
112 |
|
|
0: return valVector[7:0];
|
113 |
|
|
1: return valVector[15:8];
|
114 |
|
|
endcase
|
115 |
|
|
endfunction
|
116 |
|
|
|
117 |
|
|
function Bool absDiffGEFour14( Bit#(14) val1, Bit#(14) val2 );
|
118 |
|
|
Int#(15) int1 = unpack(signExtend(val1));
|
119 |
|
|
Int#(15) int2 = unpack(signExtend(val2));
|
120 |
|
|
if(int1>=int2)
|
121 |
|
|
return (int1 >= (int2+4));
|
122 |
|
|
else
|
123 |
|
|
return (int2 >= (int1+4));
|
124 |
|
|
endfunction
|
125 |
|
|
|
126 |
|
|
function Bool absDiffGEFour12( Bit#(12) val1, Bit#(12) val2 );
|
127 |
|
|
Int#(13) int1 = unpack(signExtend(val1));
|
128 |
|
|
Int#(13) int2 = unpack(signExtend(val2));
|
129 |
|
|
if(int1>=int2)
|
130 |
|
|
return (int1 >= (int2+4));
|
131 |
|
|
else
|
132 |
|
|
return (int2 >= (int1+4));
|
133 |
|
|
endfunction
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
//-----------------------------------------------------------
|
137 |
|
|
// Prediction Module
|
138 |
|
|
//-----------------------------------------------------------
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
(* synthesize *)
|
142 |
|
|
module mkPrediction( IPrediction );
|
143 |
|
|
|
144 |
|
|
//Common state
|
145 |
|
|
FIFO#(EntropyDecOT) infifo <- mkSizedFIFO(prediction_infifo_size);
|
146 |
|
|
FIFO#(InverseTransOT) infifo_ITB <- mkSizedFIFO(prediction_infifo_ITB_size);
|
147 |
|
|
FIFO#(EntropyDecOT) outfifo <- mkFIFO;
|
148 |
|
|
Reg#(Bool) passFlag <- mkReg(True);
|
149 |
|
|
Reg#(Bit#(4)) blockNum <- mkReg(0);
|
150 |
|
|
Reg#(Bit#(4)) pixelNum <- mkReg(0);
|
151 |
|
|
|
152 |
|
|
Reg#(Bit#(PicWidthSz)) picWidth <- mkReg(maxPicWidthInMB);
|
153 |
|
|
Reg#(Bit#(PicHeightSz)) picHeight <- mkReg(0);
|
154 |
|
|
Reg#(Bit#(PicAreaSz)) firstMb <- mkReg(0);
|
155 |
|
|
Reg#(Bit#(PicAreaSz)) currMb <- mkReg(0);
|
156 |
|
|
Reg#(Bit#(PicAreaSz)) currMbHor <- mkReg(0);//horizontal position of currMb
|
157 |
|
|
Reg#(Bit#(PicHeightSz)) currMbVer <- mkReg(0);//vertical position of currMb
|
158 |
|
|
|
159 |
|
|
FIFOF#(OutState) outstatefifo <- mkFIFOF;
|
160 |
|
|
FIFOF#(NextOutput) nextoutputfifo <- mkFIFOF;
|
161 |
|
|
Reg#(Bit#(4)) outBlockNum <- mkReg(0);
|
162 |
|
|
Reg#(Bit#(4)) outPixelNum <- mkReg(0);
|
163 |
|
|
FIFO#(Vector#(4,Bit#(8))) predictedfifo <- mkSizedFIFO(prediction_predictedfifo_size);
|
164 |
|
|
Reg#(Bit#(1)) outChromaFlag <- mkReg(0);
|
165 |
|
|
Reg#(Bool) outFirstQPFlag <- mkReg(False);
|
166 |
|
|
|
167 |
|
|
DoNotFire donotfire <- mkDoNotFire();
|
168 |
|
|
|
169 |
|
|
//Reg#(Vector#(16,Bit#(8))) workVector <- mkRegU();
|
170 |
|
|
|
171 |
|
|
//Inter state
|
172 |
|
|
Interpolator interpolator <- mkInterpolator();
|
173 |
|
|
Reg#(InterState) interstate <- mkReg(Start);
|
174 |
|
|
Reg#(Bit#(PicAreaSz)) interPskipCount <- mkReg(0);
|
175 |
|
|
Reg#(Vector#(5,InterBlockMv)) interTopVal <- mkRegU();
|
176 |
|
|
Reg#(Vector#(4,InterBlockMv)) interLeftVal <- mkRegU();
|
177 |
|
|
Reg#(Vector#(4,InterBlockMv)) interTopLeftVal <- mkRegU();
|
178 |
|
|
FIFO#(MemReq#(TAdd#(PicWidthSz,2),32)) interMemReqQ <- mkFIFO;
|
179 |
|
|
Reg#(MemReq#(TAdd#(PicWidthSz,2),32)) interMemReqQdelay <- mkRegU();
|
180 |
|
|
FIFO#(MemResp#(32)) interMemRespQ <- mkFIFO;
|
181 |
|
|
Reg#(Bit#(3)) interReqCount <- mkReg(0);
|
182 |
|
|
Reg#(Bit#(3)) interRespCount <- mkReg(0);
|
183 |
|
|
|
184 |
|
|
Reg#(Bit#(1)) interStepCount <- mkReg(0);
|
185 |
|
|
Reg#(Bit#(2)) interMbPartNum <- mkReg(0);
|
186 |
|
|
Reg#(Bit#(2)) interSubMbPartNum <- mkReg(0);
|
187 |
|
|
Reg#(Bit#(2)) interPassingCount <- mkReg(0);
|
188 |
|
|
Reg#(Vector#(4,Bit#(4))) interRefIdxVector <- mkRegU();
|
189 |
|
|
Reg#(Vector#(4,Bit#(2))) interSubMbTypeVector <- mkRegU();
|
190 |
|
|
RFile1#(Bit#(4),Tuple2#(Bit#(14),Bit#(12))) interMvFile <- mkRFile1Full();
|
191 |
|
|
Reg#(Bit#(15)) interMvDiffTemp <- mkReg(0);
|
192 |
|
|
FIFO#(Tuple2#(Bit#(15),Bit#(13))) interMvDiff <- mkFIFO;
|
193 |
|
|
Reg#(Bit#(5)) interNewestMv <- mkReg(0);
|
194 |
|
|
|
195 |
|
|
Reg#(Bit#(2)) interIPStepCount <- mkReg(0);
|
196 |
|
|
Reg#(Bit#(2)) interIPMbPartNum <- mkReg(0);
|
197 |
|
|
Reg#(Bit#(2)) interIPSubMbPartNum <- mkReg(0);
|
198 |
|
|
|
199 |
|
|
Reg#(Bit#(PicWidthSz)) interCurrMbDiff <- mkReg(0);
|
200 |
|
|
|
201 |
|
|
Reg#(Vector#(4,Bool)) interTopNonZeroTransCoeff <- mkRegU();
|
202 |
|
|
Reg#(Vector#(4,Bool)) interLeftNonZeroTransCoeff <- mkRegU();
|
203 |
|
|
FIFO#(Tuple2#(Bit#(2),Bit#(2))) interBSfifo <- mkSizedFIFO(32);
|
204 |
|
|
Reg#(Bool) interBSoutput <- mkReg(True);
|
205 |
|
|
FIFO#(InterBlockMv) interOutBlockMvfifo <- mkSizedFIFO(8);
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
//Intra state
|
209 |
|
|
Reg#(IntraState) intrastate <- mkReg(Start);
|
210 |
|
|
Reg#(Bit#(1)) intraChromaFlag <- mkReg(0);
|
211 |
|
|
FIFO#(MemReq#(TAdd#(PicWidthSz,2),68)) intraMemReqQ <- mkFIFO;
|
212 |
|
|
Reg#(MemReq#(TAdd#(PicWidthSz,2),68)) intraMemReqQdelay <- mkRegU;
|
213 |
|
|
FIFO#(MemResp#(68)) intraMemRespQ <- mkFIFO;
|
214 |
|
|
Reg#(Vector#(4,Bit#(4))) intra4x4typeLeft <- mkRegU();//15=unavailable, 14=inter-MB, 13=intra-non-4x4
|
215 |
|
|
Reg#(Vector#(4,Bit#(4))) intra4x4typeTop <- mkRegU();//15=unavailable, 14=inter-MB, 13=intra-non-4x4
|
216 |
|
|
Reg#(Bit#(1)) ppsconstrained_intra_pred_flag <- mkReg(0);
|
217 |
|
|
Reg#(Vector#(4,Bit#(40))) intraLeftVal <- mkRegU();
|
218 |
|
|
Reg#(Vector#(9,Bit#(8))) intraLeftValChroma0 <- mkRegU();
|
219 |
|
|
Reg#(Vector#(9,Bit#(8))) intraLeftValChroma1 <- mkRegU();
|
220 |
|
|
Reg#(Vector#(5,Bit#(32))) intraTopVal <- mkRegU();
|
221 |
|
|
Reg#(Vector#(4,Bit#(16))) intraTopValChroma0 <- mkRegU();
|
222 |
|
|
Reg#(Vector#(4,Bit#(16))) intraTopValChroma1 <- mkRegU();
|
223 |
|
|
Reg#(Bit#(32)) intraLeftValNext <- mkReg(0);
|
224 |
|
|
Reg#(Bit#(2)) intra16x16_pred_mode <- mkReg(0);
|
225 |
|
|
FIFO#(Bit#(4)) rem_intra4x4_pred_mode <- mkSizedFIFO(16);
|
226 |
|
|
FIFO#(Bit#(2)) intra_chroma_pred_mode <- mkFIFO;
|
227 |
|
|
Reg#(Bit#(4)) cur_intra4x4_pred_mode <- mkReg(0);
|
228 |
|
|
Reg#(Bit#(1)) intraChromaTopAvailable <- mkReg(0);
|
229 |
|
|
Reg#(Bit#(1)) intraChromaLeftAvailable <- mkReg(0);
|
230 |
|
|
|
231 |
|
|
Reg#(Bit#(3)) intraReqCount <- mkReg(0);
|
232 |
|
|
Reg#(Bit#(3)) intraRespCount <- mkReg(0);
|
233 |
|
|
Reg#(Bit#(4)) intraStepCount <- mkReg(0);
|
234 |
|
|
Reg#(Bit#(13)) intraSumA <- mkReg(0);
|
235 |
|
|
Reg#(Bit#(15)) intraSumB <- mkReg(0);
|
236 |
|
|
Reg#(Bit#(15)) intraSumC <- mkReg(0);
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
//-----------------------------------------------------------
|
241 |
|
|
// Rules
|
242 |
|
|
|
243 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
244 |
|
|
// rule stateMonitor ( True );
|
245 |
|
|
// if(predictedfifo.notEmpty())
|
246 |
|
|
// $display( "TRACE Prediction: stateMonitor predictedfifo.first() %0d", predictedfifo.first());////////////////////
|
247 |
|
|
// if(infifo.first() matches tagged ITBresidual .xdata)
|
248 |
|
|
// $display( "TRACE Prediction: stateMonitor infifo.first() %0d", xdata);////////////////////
|
249 |
|
|
// if(infifo.first() matches tagged ITBresidual .xdata)
|
250 |
|
|
// $display( "TRACE Prediction: stateMonitor outBlockNum outPixelNum outChromaFlag %0d %0d", outBlockNum, outPixelNum, outChromaFlag);////////////////////
|
251 |
|
|
// endrule
|
252 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
rule checkFIFO ( True );
|
256 |
|
|
$display( "Trace Prediction: checkFIFO %h", infifo_ITB.first() );
|
257 |
|
|
endrule
|
258 |
|
|
|
259 |
|
|
rule passing ( passFlag && !outstatefifo.notEmpty() && currMbHor
|
260 |
|
|
$display( "Trace Prediction: passing infifo packed %h", pack(infifo.first()));
|
261 |
|
|
case (infifo.first()) matches
|
262 |
|
|
tagged NewUnit . xdata :
|
263 |
|
|
begin
|
264 |
|
|
infifo.deq();
|
265 |
|
|
outfifo.enq(infifo.first());
|
266 |
|
|
$display("ccl4newunit");
|
267 |
|
|
$display("ccl4rbspbyte %h", xdata);
|
268 |
|
|
end
|
269 |
|
|
tagged SPSpic_width_in_mbs .xdata :
|
270 |
|
|
begin
|
271 |
|
|
infifo.deq();
|
272 |
|
|
outfifo.enq(infifo.first());
|
273 |
|
|
picWidth <= xdata;
|
274 |
|
|
interpolator.setPicWidth(xdata);
|
275 |
|
|
end
|
276 |
|
|
tagged SPSpic_height_in_map_units .xdata :
|
277 |
|
|
begin
|
278 |
|
|
infifo.deq();
|
279 |
|
|
outfifo.enq(infifo.first());
|
280 |
|
|
picHeight <= xdata;
|
281 |
|
|
interpolator.setPicHeight(xdata);
|
282 |
|
|
end
|
283 |
|
|
tagged PPSconstrained_intra_pred_flag .xdata :
|
284 |
|
|
begin
|
285 |
|
|
infifo.deq();
|
286 |
|
|
////outfifo.enq(infifo.first());
|
287 |
|
|
ppsconstrained_intra_pred_flag <= xdata;
|
288 |
|
|
end
|
289 |
|
|
tagged SHfirst_mb_in_slice .xdata :
|
290 |
|
|
begin
|
291 |
|
|
infifo.deq();
|
292 |
|
|
outfifo.enq(infifo.first());
|
293 |
|
|
firstMb <= xdata;
|
294 |
|
|
currMb <= xdata;
|
295 |
|
|
currMbHor <= xdata;
|
296 |
|
|
currMbVer <= 0;
|
297 |
|
|
intra4x4typeLeft <= replicate(15);
|
298 |
|
|
interTopLeftVal <= replicate(NotInter 0);
|
299 |
|
|
if(xdata==0)
|
300 |
|
|
interLeftVal <= replicate(NotInter 0);
|
301 |
|
|
outFirstQPFlag <= True;
|
302 |
|
|
end
|
303 |
|
|
tagged SDmb_skip_run .xdata : passFlag <= False;
|
304 |
|
|
tagged SDMmbtype .xdata : passFlag <= False;
|
305 |
|
|
tagged EndOfFile :
|
306 |
|
|
begin
|
307 |
|
|
infifo.deq();
|
308 |
|
|
outfifo.enq(infifo.first());
|
309 |
|
|
$display( "INFO Prediction: EndOfFile reached" );
|
310 |
|
|
//$finish(0);////////////////////////////////
|
311 |
|
|
end
|
312 |
|
|
default:
|
313 |
|
|
begin
|
314 |
|
|
infifo.deq();
|
315 |
|
|
outfifo.enq(infifo.first());
|
316 |
|
|
end
|
317 |
|
|
endcase
|
318 |
|
|
endrule
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
rule inputing ( !passFlag );
|
322 |
|
|
$display( "Trace Prediction: inputing infifo packed %h", pack(infifo.first()));
|
323 |
|
|
case (infifo.first()) matches
|
324 |
|
|
tagged SDmb_skip_run .xdata :
|
325 |
|
|
begin
|
326 |
|
|
if(interstate==Start && intrastate==Start)
|
327 |
|
|
begin
|
328 |
|
|
if(interPskipCount < xdata)
|
329 |
|
|
begin
|
330 |
|
|
if(!outstatefifo.notEmpty() || interCurrMbDiff
|
331 |
|
|
begin
|
332 |
|
|
$display( "Trace Prediction: passing SDmb_skip_run %0d", xdata);
|
333 |
|
|
outstatefifo.enq(Inter);
|
334 |
|
|
interstate <= InterPskip;
|
335 |
|
|
interReqCount <= 1;
|
336 |
|
|
interRespCount <= 1;
|
337 |
|
|
intra4x4typeLeft <= replicate(14);
|
338 |
|
|
intra4x4typeTop <= replicate(14);
|
339 |
|
|
interTopLeftVal <= update(interTopLeftVal , 0, (NotInter 0));
|
340 |
|
|
interTopVal <= replicate(NotInter 0);
|
341 |
|
|
interPskipCount <= interPskipCount+1;
|
342 |
|
|
interNewestMv <= 0;
|
343 |
|
|
interRefIdxVector <= replicate(0);
|
344 |
|
|
interCurrMbDiff <= interCurrMbDiff+1;
|
345 |
|
|
nextoutputfifo.enq(SkipMB);
|
346 |
|
|
end
|
347 |
|
|
else
|
348 |
|
|
donotfire.doNotFire();
|
349 |
|
|
end
|
350 |
|
|
else
|
351 |
|
|
begin
|
352 |
|
|
$display( "Trace Prediction: passing no SDmb_skip_run");
|
353 |
|
|
interPskipCount <= 0;
|
354 |
|
|
infifo.deq();
|
355 |
|
|
end
|
356 |
|
|
end
|
357 |
|
|
else
|
358 |
|
|
donotfire.doNotFire();
|
359 |
|
|
end
|
360 |
|
|
tagged SDMmbtype .xdata :
|
361 |
|
|
begin
|
362 |
|
|
if(interstate==Start && intrastate==Start)//not necessary (just need to keep inter from feeding predictedfifo or change intra state until intrastate==Start)
|
363 |
|
|
begin
|
364 |
|
|
infifo.deq();
|
365 |
|
|
$display( "INFO Prediction: SDMmbtype %0d", xdata);
|
366 |
|
|
if(mbPartPredMode(xdata,0)==Intra_16x16)
|
367 |
|
|
begin
|
368 |
|
|
if(!outstatefifo.notEmpty())
|
369 |
|
|
begin
|
370 |
|
|
outstatefifo.enq(Intra);
|
371 |
|
|
intrastate <= Intra16x16;
|
372 |
|
|
if(xdata matches tagged I_16x16 {intra16x16PredMode:.tempv1, codedBlockPatternChroma:.tempv2, codedBlockPatternLuma:.tempv3})
|
373 |
|
|
intra16x16_pred_mode <= tempv1;
|
374 |
|
|
else
|
375 |
|
|
$display( "ERROR Prediction: MacroblockLayer 5 sdmmbtype not I_16x16" );
|
376 |
|
|
intraReqCount <= 1;
|
377 |
|
|
intraRespCount <= 1;
|
378 |
|
|
interTopLeftVal <= replicate(NotInter 1);
|
379 |
|
|
interLeftVal <= replicate(NotInter 1);
|
380 |
|
|
interTopVal <= replicate(NotInter 1);
|
381 |
|
|
end
|
382 |
|
|
else
|
383 |
|
|
donotfire.doNotFire();
|
384 |
|
|
end
|
385 |
|
|
else if(xdata==I_NxN)
|
386 |
|
|
begin
|
387 |
|
|
if(!outstatefifo.notEmpty())
|
388 |
|
|
begin
|
389 |
|
|
outstatefifo.enq(Intra4x4);
|
390 |
|
|
intrastate <= Intra4x4;
|
391 |
|
|
intraReqCount <= 1;
|
392 |
|
|
intraRespCount <= 1;
|
393 |
|
|
interTopLeftVal <= replicate(NotInter 1);
|
394 |
|
|
interLeftVal <= replicate(NotInter 1);
|
395 |
|
|
interTopVal <= replicate(NotInter 1);
|
396 |
|
|
end
|
397 |
|
|
else
|
398 |
|
|
donotfire.doNotFire();
|
399 |
|
|
end
|
400 |
|
|
else if(xdata==I_PCM)
|
401 |
|
|
begin
|
402 |
|
|
$display( "ERROR Prediction: I_PCM not implemented yet");
|
403 |
|
|
$finish;////////////////////////////////////////////////////////////////////////////////////////
|
404 |
|
|
intra4x4typeLeft <= replicate(13);
|
405 |
|
|
intra4x4typeTop <= replicate(13);
|
406 |
|
|
interTopLeftVal <= replicate(NotInter 1);
|
407 |
|
|
interLeftVal <= replicate(NotInter 1);
|
408 |
|
|
interTopVal <= replicate(NotInter 1);
|
409 |
|
|
end
|
410 |
|
|
else
|
411 |
|
|
begin
|
412 |
|
|
if(!outstatefifo.notEmpty() || interCurrMbDiff
|
413 |
|
|
begin
|
414 |
|
|
outstatefifo.enq(Inter);
|
415 |
|
|
case(xdata)
|
416 |
|
|
P_L0_16x16: interstate <= InterP16x16;
|
417 |
|
|
P_L0_L0_16x8: interstate <= InterP16x8;
|
418 |
|
|
P_L0_L0_8x16: interstate <= InterP8x16;
|
419 |
|
|
P_8x8: interstate <= InterP8x8;
|
420 |
|
|
P_8x8ref0: interstate <= InterP8x8ref0;
|
421 |
|
|
default: $display( "ERROR Prediction: passing SDMmbtype inter prediction unknown mbtype");
|
422 |
|
|
endcase
|
423 |
|
|
interReqCount <= 1;
|
424 |
|
|
interRespCount <= 1;
|
425 |
|
|
intra4x4typeLeft <= replicate(14);/////////////////////////////////////////////////////////////////////////////
|
426 |
|
|
intra4x4typeTop <= replicate(14);
|
427 |
|
|
interTopLeftVal <= update(interTopLeftVal , 0, (NotInter 0));
|
428 |
|
|
interTopVal <= replicate(NotInter 0);
|
429 |
|
|
interNewestMv <= 0;
|
430 |
|
|
interRefIdxVector <= replicate(0);
|
431 |
|
|
nextoutputfifo.enq(NonSkipMB);
|
432 |
|
|
end
|
433 |
|
|
else
|
434 |
|
|
donotfire.doNotFire();
|
435 |
|
|
end
|
436 |
|
|
interCurrMbDiff <= interCurrMbDiff+1;
|
437 |
|
|
end
|
438 |
|
|
else
|
439 |
|
|
donotfire.doNotFire();
|
440 |
|
|
end
|
441 |
|
|
tagged SDMMrem_intra4x4_pred_mode .xdata :
|
442 |
|
|
begin
|
443 |
|
|
infifo.deq();
|
444 |
|
|
////outfifo.enq(infifo.first());
|
445 |
|
|
rem_intra4x4_pred_mode.enq(xdata);
|
446 |
|
|
end
|
447 |
|
|
tagged SDMMintra_chroma_pred_mode .xdata :
|
448 |
|
|
begin
|
449 |
|
|
infifo.deq();
|
450 |
|
|
////outfifo.enq(infifo.first());
|
451 |
|
|
intra_chroma_pred_mode.enq(xdata);
|
452 |
|
|
end
|
453 |
|
|
tagged SDMMref_idx_l0 .xdata :
|
454 |
|
|
begin
|
455 |
|
|
infifo.deq();
|
456 |
|
|
////outfifo.enq(infifo.first());
|
457 |
|
|
interRefIdxVector <= update(interRefIdxVector,interPassingCount,xdata[3:0]);
|
458 |
|
|
if(interstate==InterP16x16 || interPassingCount==1)
|
459 |
|
|
interPassingCount <= 0;
|
460 |
|
|
else
|
461 |
|
|
interPassingCount <= interPassingCount+1;
|
462 |
|
|
end
|
463 |
|
|
tagged SDMMmvd_l0 .xdata :
|
464 |
|
|
begin
|
465 |
|
|
infifo.deq();
|
466 |
|
|
////outfifo.enq(infifo.first());
|
467 |
|
|
if(interPassingCount==1)
|
468 |
|
|
begin
|
469 |
|
|
Bit#(13) interMvDiffTemp2 = truncate(xdata);
|
470 |
|
|
interMvDiff.enq(tuple2(interMvDiffTemp,interMvDiffTemp2));
|
471 |
|
|
interPassingCount <= 0;
|
472 |
|
|
end
|
473 |
|
|
else
|
474 |
|
|
begin
|
475 |
|
|
interMvDiffTemp <= truncate(xdata);
|
476 |
|
|
interPassingCount <= interPassingCount+1;
|
477 |
|
|
end
|
478 |
|
|
end
|
479 |
|
|
tagged SDMSsub_mb_type .xdata :
|
480 |
|
|
begin
|
481 |
|
|
infifo.deq();
|
482 |
|
|
////outfifo.enq(infifo.first());
|
483 |
|
|
interSubMbTypeVector <= update(interSubMbTypeVector,interPassingCount,xdata);
|
484 |
|
|
interPassingCount <= interPassingCount+1;
|
485 |
|
|
end
|
486 |
|
|
tagged SDMSref_idx_l0 .xdata :
|
487 |
|
|
begin
|
488 |
|
|
infifo.deq();
|
489 |
|
|
////outfifo.enq(infifo.first());
|
490 |
|
|
interRefIdxVector <= update(interRefIdxVector,interPassingCount,xdata[3:0]);
|
491 |
|
|
interPassingCount <= interPassingCount+1;
|
492 |
|
|
end
|
493 |
|
|
tagged SDMSmvd_l0 .xdata :
|
494 |
|
|
begin
|
495 |
|
|
infifo.deq();
|
496 |
|
|
////outfifo.enq(infifo.first());
|
497 |
|
|
if(interPassingCount==1)
|
498 |
|
|
begin
|
499 |
|
|
Bit#(13) interMvDiffTemp2 = truncate(xdata);
|
500 |
|
|
interMvDiff.enq(tuple2(interMvDiffTemp,interMvDiffTemp2));
|
501 |
|
|
interPassingCount <= 0;
|
502 |
|
|
end
|
503 |
|
|
else
|
504 |
|
|
begin
|
505 |
|
|
interMvDiffTemp <= truncate(xdata);
|
506 |
|
|
interPassingCount <= interPassingCount+1;
|
507 |
|
|
end
|
508 |
|
|
end
|
509 |
|
|
default: passFlag <= True;
|
510 |
|
|
endcase
|
511 |
|
|
endrule
|
512 |
|
|
|
513 |
|
|
|
514 |
|
|
rule outputing ( currMbHor
|
515 |
|
|
Bit#(1) outputFlag = 0;
|
516 |
|
|
Vector#(4,Bit#(8)) outputVector = replicate(0);
|
517 |
|
|
Bit#(2) blockHor = {outBlockNum[2],outBlockNum[0]};
|
518 |
|
|
Bit#(2) blockVer = {outBlockNum[3],outBlockNum[1]};
|
519 |
|
|
Bit#(2) pixelVer = {outPixelNum[3],outPixelNum[2]};
|
520 |
|
|
Bit#(4) totalVer = {blockVer,pixelVer};
|
521 |
|
|
//$display( "Trace Prediction: outputing" );
|
522 |
|
|
if(outFirstQPFlag)
|
523 |
|
|
begin
|
524 |
|
|
if(infifo_ITB.first() matches tagged IBTmb_qp .xdata)
|
525 |
|
|
begin
|
526 |
|
|
infifo_ITB.deq();
|
527 |
|
|
outfifo.enq(IBTmb_qp {qpy:xdata.qpy,qpc:xdata.qpc});
|
528 |
|
|
outFirstQPFlag <= False;
|
529 |
|
|
$display( "Trace Prediction: outputing outFirstQP %h %h %h", outBlockNum, outPixelNum, xdata);
|
530 |
|
|
end
|
531 |
|
|
else
|
532 |
|
|
$display( "ERROR Prediction: outputing unexpected infifo_ITB.first()");
|
533 |
|
|
end
|
534 |
|
|
else if(nextoutputfifo.first() == SkipMB)
|
535 |
|
|
begin
|
536 |
|
|
if(interBSoutput && outChromaFlag==0 && outPixelNum==0)
|
537 |
|
|
begin
|
538 |
|
|
interBSoutput <= False;
|
539 |
|
|
interBSfifo.deq();
|
540 |
|
|
Bit#(2) tempHorBS = tpl_1(interBSfifo.first());
|
541 |
|
|
Bit#(2) tempVerBS = tpl_2(interBSfifo.first());
|
542 |
|
|
Bit#(3) horBS = (tempHorBS==3 ? 4 : (interLeftNonZeroTransCoeff[blockVer] ? 2 : zeroExtend(tempHorBS)));
|
543 |
|
|
Bit#(3) verBS = (tempVerBS==3 ? 4 : (interTopNonZeroTransCoeff[blockHor]&&blockVer!=0 ? 2 : zeroExtend(tempVerBS)));
|
544 |
|
|
outfifo.enq(PBbS {bShor:horBS,bSver:verBS});
|
545 |
|
|
interLeftNonZeroTransCoeff <= update(interLeftNonZeroTransCoeff, blockVer, False);
|
546 |
|
|
interTopNonZeroTransCoeff <= update(interTopNonZeroTransCoeff, blockHor, False);
|
547 |
|
|
$display( "Trace Prediction: outputing SkipMB bS %h %h %h %h", outBlockNum, outPixelNum, currMbHor, currMbVer);
|
548 |
|
|
end
|
549 |
|
|
else
|
550 |
|
|
begin
|
551 |
|
|
interBSoutput <= True;
|
552 |
|
|
outputVector = predictedfifo.first();
|
553 |
|
|
outfifo.enq(PBoutput outputVector);
|
554 |
|
|
outputFlag = 1;
|
555 |
|
|
predictedfifo.deq();
|
556 |
|
|
$display( "Trace Prediction: outputing SkipMB out %h %h %h", outBlockNum, outPixelNum, outputVector);
|
557 |
|
|
end
|
558 |
|
|
end
|
559 |
|
|
else
|
560 |
|
|
begin
|
561 |
|
|
case ( infifo_ITB.first() ) matches
|
562 |
|
|
tagged IBTmb_qp .xdata :
|
563 |
|
|
begin
|
564 |
|
|
infifo_ITB.deq();
|
565 |
|
|
outfifo.enq(IBTmb_qp {qpy:xdata.qpy,qpc:xdata.qpc});
|
566 |
|
|
outFirstQPFlag <= False;
|
567 |
|
|
$display( "Trace Prediction: outputing ITBmb_qp %h %h %h", outBlockNum, outPixelNum, xdata);
|
568 |
|
|
end
|
569 |
|
|
tagged ITBresidual .xdata :
|
570 |
|
|
begin
|
571 |
|
|
if(interBSoutput && outChromaFlag==0 && outPixelNum==0)
|
572 |
|
|
begin
|
573 |
|
|
interBSoutput <= False;
|
574 |
|
|
if(outstatefifo.first() != Inter)
|
575 |
|
|
outfifo.enq(PBbS {bShor:(blockHor==0 ? 4 : 3),bSver:(blockVer==0 ? 4 : 3)});
|
576 |
|
|
else
|
577 |
|
|
begin
|
578 |
|
|
interBSfifo.deq();
|
579 |
|
|
Bit#(2) tempHorBS = tpl_1(interBSfifo.first());
|
580 |
|
|
Bit#(2) tempVerBS = tpl_2(interBSfifo.first());
|
581 |
|
|
Bit#(3) horBS = (tempHorBS==3 ? 4 : 2);
|
582 |
|
|
Bit#(3) verBS = (tempVerBS==3 ? 4 : 2);
|
583 |
|
|
outfifo.enq(PBbS {bShor:horBS,bSver:verBS});
|
584 |
|
|
end
|
585 |
|
|
interLeftNonZeroTransCoeff <= update(interLeftNonZeroTransCoeff, blockVer, True);
|
586 |
|
|
interTopNonZeroTransCoeff <= update(interTopNonZeroTransCoeff, blockHor, True);
|
587 |
|
|
$display( "Trace Prediction: outputing ITBresidual bS %h %h %h %h %h", outChromaFlag, outBlockNum, outPixelNum, currMbHor, currMbVer);
|
588 |
|
|
end
|
589 |
|
|
else
|
590 |
|
|
begin
|
591 |
|
|
interBSoutput <= True;
|
592 |
|
|
Bit#(11) tempOutputValue = 0;
|
593 |
|
|
for(Integer ii=0; ii<4; ii=ii+1)
|
594 |
|
|
begin
|
595 |
|
|
tempOutputValue = signExtend(xdata[ii]) + zeroExtend((predictedfifo.first())[ii]);
|
596 |
|
|
if(tempOutputValue[10]==1)
|
597 |
|
|
outputVector[ii] = 0;
|
598 |
|
|
else if(tempOutputValue[9:0] > 255)
|
599 |
|
|
outputVector[ii] = 255;
|
600 |
|
|
else
|
601 |
|
|
outputVector[ii] = tempOutputValue[7:0];
|
602 |
|
|
end
|
603 |
|
|
outfifo.enq(PBoutput outputVector);
|
604 |
|
|
infifo_ITB.deq();
|
605 |
|
|
predictedfifo.deq();
|
606 |
|
|
outputFlag = 1;
|
607 |
|
|
$display( "Trace Prediction: outputing ITBresidual out %h %h %h %h %h %h", outChromaFlag, outBlockNum, outPixelNum, predictedfifo.first(), xdata, outputVector);
|
608 |
|
|
end
|
609 |
|
|
end
|
610 |
|
|
tagged ITBcoeffLevelZeros :
|
611 |
|
|
begin
|
612 |
|
|
if(interBSoutput && outChromaFlag==0 && outPixelNum==0)
|
613 |
|
|
begin
|
614 |
|
|
interBSoutput <= False;
|
615 |
|
|
if(outstatefifo.first() != Inter)
|
616 |
|
|
outfifo.enq(PBbS {bShor:(blockHor==0 ? 4 : 3),bSver:(blockVer==0 ? 4 : 3)});
|
617 |
|
|
else
|
618 |
|
|
begin
|
619 |
|
|
interBSfifo.deq();
|
620 |
|
|
Bit#(2) tempHorBS = tpl_1(interBSfifo.first());
|
621 |
|
|
Bit#(2) tempVerBS = tpl_2(interBSfifo.first());
|
622 |
|
|
Bit#(3) horBS = (tempHorBS==3 ? 4 : (interLeftNonZeroTransCoeff[blockVer] ? 2 : zeroExtend(tempHorBS)));
|
623 |
|
|
Bit#(3) verBS = (tempVerBS==3 ? 4 : (interTopNonZeroTransCoeff[blockHor]&&blockVer!=0 ? 2 : zeroExtend(tempVerBS)));
|
624 |
|
|
outfifo.enq(PBbS {bShor:horBS,bSver:verBS});
|
625 |
|
|
end
|
626 |
|
|
interLeftNonZeroTransCoeff <= update(interLeftNonZeroTransCoeff, blockVer, False);
|
627 |
|
|
interTopNonZeroTransCoeff <= update(interTopNonZeroTransCoeff, blockHor, False);
|
628 |
|
|
$display( "Trace Prediction: outputing ITBcoeffLevelZeros bS %h %h %h %h %h", outChromaFlag, outBlockNum, outPixelNum, currMbHor, currMbVer);
|
629 |
|
|
end
|
630 |
|
|
else
|
631 |
|
|
begin
|
632 |
|
|
interBSoutput <= True;
|
633 |
|
|
if(outPixelNum == 12)
|
634 |
|
|
infifo_ITB.deq();
|
635 |
|
|
outputVector = predictedfifo.first();
|
636 |
|
|
outfifo.enq(PBoutput outputVector);
|
637 |
|
|
outputFlag = 1;
|
638 |
|
|
predictedfifo.deq();
|
639 |
|
|
$display( "Trace Prediction: outputing ITBcoeffLevelZeros out %h %h %h %h %h", outChromaFlag, outBlockNum, outPixelNum, predictedfifo.first(), outputVector);
|
640 |
|
|
end
|
641 |
|
|
end
|
642 |
|
|
default: $display( "ERROR Prediction: outputing unknown infifo_ITB input" );
|
643 |
|
|
endcase
|
644 |
|
|
end
|
645 |
|
|
|
646 |
|
|
if(outputFlag == 1)
|
647 |
|
|
begin
|
648 |
|
|
$display("ccl4PBoutput %0d", outputVector[0]);
|
649 |
|
|
$display("ccl4PBoutput %0d", outputVector[1]);
|
650 |
|
|
$display("ccl4PBoutput %0d", outputVector[2]);
|
651 |
|
|
$display("ccl4PBoutput %0d", outputVector[3]);
|
652 |
|
|
|
653 |
|
|
if(outBlockNum==0 && pixelVer==0 && outChromaFlag==0 && currMb!=firstMb && picWidth>1)
|
654 |
|
|
begin
|
655 |
|
|
intraMemReqQ.enq(intraMemReqQdelay);
|
656 |
|
|
interMemReqQ.enq(interMemReqQdelay);
|
657 |
|
|
//$display( "TRACE Prediction: passing storing addr data");//////////////////
|
658 |
|
|
end
|
659 |
|
|
|
660 |
|
|
if(blockHor==3 || (blockHor[0]==1 && outChromaFlag==1) || (outstatefifo.first()==Intra4x4 && outChromaFlag==0))
|
661 |
|
|
begin
|
662 |
|
|
if(outChromaFlag==0)
|
663 |
|
|
begin
|
664 |
|
|
Bit#(32) intraLeftValNextTemp = intraLeftValNext;
|
665 |
|
|
if(totalVer==0 || (outstatefifo.first()==Intra4x4 && pixelVer==0))
|
666 |
|
|
begin
|
667 |
|
|
Bit#(32) tempValSet = select(intraTopVal,zeroExtend(blockHor));
|
668 |
|
|
intraLeftValNextTemp = zeroExtend(tempValSet[31:24]);
|
669 |
|
|
end
|
670 |
|
|
case(pixelVer)
|
671 |
|
|
0:intraLeftValNext <= {intraLeftValNextTemp[31:16],outputVector[3],intraLeftValNextTemp[7:0]};
|
672 |
|
|
1:intraLeftValNext <= {intraLeftValNextTemp[31:24],outputVector[3],intraLeftValNextTemp[15:0]};
|
673 |
|
|
2:intraLeftValNext <= {outputVector[3],intraLeftValNextTemp[23:0]};
|
674 |
|
|
3:
|
675 |
|
|
begin
|
676 |
|
|
intraLeftVal <= update(intraLeftVal,blockVer,{outputVector[3],intraLeftValNextTemp});
|
677 |
|
|
intraLeftValNext <= zeroExtend(outputVector[3]);
|
678 |
|
|
if(outstatefifo.first()==Intra4x4)
|
679 |
|
|
intra4x4typeLeft <= update(intra4x4typeLeft,blockVer,cur_intra4x4_pred_mode);
|
680 |
|
|
else if(outstatefifo.first()==Intra)
|
681 |
|
|
intra4x4typeLeft <= update(intra4x4typeLeft,blockVer,13);
|
682 |
|
|
else
|
683 |
|
|
intra4x4typeLeft <= update(intra4x4typeLeft,blockVer,14);
|
684 |
|
|
end
|
685 |
|
|
endcase
|
686 |
|
|
end
|
687 |
|
|
else
|
688 |
|
|
begin
|
689 |
|
|
if(outBlockNum[2]==0)
|
690 |
|
|
intraLeftValChroma0 <= update(intraLeftValChroma0,totalVer+1,outputVector[3]);
|
691 |
|
|
else
|
692 |
|
|
intraLeftValChroma1 <= update(intraLeftValChroma1,totalVer+1,outputVector[3]);
|
693 |
|
|
end
|
694 |
|
|
end
|
695 |
|
|
|
696 |
|
|
if(pixelVer==3 && (blockVer==3 || (blockVer[0]==1 && outChromaFlag==1) || (outstatefifo.first()==Intra4x4 && outChromaFlag==0)))
|
697 |
|
|
begin
|
698 |
|
|
if(outChromaFlag==0)
|
699 |
|
|
begin
|
700 |
|
|
intraTopVal <= update(intraTopVal,zeroExtend(blockHor),{outputVector[3],outputVector[2],outputVector[1],outputVector[0]});
|
701 |
|
|
if(outstatefifo.first()==Intra4x4)
|
702 |
|
|
intra4x4typeTop <= update(intra4x4typeTop,blockHor,cur_intra4x4_pred_mode);
|
703 |
|
|
else if(outstatefifo.first()==Intra)
|
704 |
|
|
intra4x4typeTop <= update(intra4x4typeTop,blockHor,13);
|
705 |
|
|
else
|
706 |
|
|
intra4x4typeTop <= update(intra4x4typeTop,blockHor,14);
|
707 |
|
|
end
|
708 |
|
|
else
|
709 |
|
|
begin
|
710 |
|
|
if(outBlockNum[2]==0)
|
711 |
|
|
begin
|
712 |
|
|
Vector#(4,Bit#(16)) intraTopValChroma0Next = intraTopValChroma0;
|
713 |
|
|
intraTopValChroma0Next[{blockHor[0],1'b0}] = {outputVector[1],outputVector[0]};
|
714 |
|
|
intraTopValChroma0Next[{blockHor[0],1'b1}] = {outputVector[3],outputVector[2]};
|
715 |
|
|
intraTopValChroma0 <= intraTopValChroma0Next;
|
716 |
|
|
end
|
717 |
|
|
else
|
718 |
|
|
begin
|
719 |
|
|
Vector#(4,Bit#(16)) intraTopValChroma1Next = intraTopValChroma1;
|
720 |
|
|
intraTopValChroma1Next[{blockHor[0],1'b0}] = {outputVector[1],outputVector[0]};
|
721 |
|
|
intraTopValChroma1Next[{blockHor[0],1'b1}] = {outputVector[3],outputVector[2]};
|
722 |
|
|
intraTopValChroma1 <= intraTopValChroma1Next;
|
723 |
|
|
end
|
724 |
|
|
end
|
725 |
|
|
end
|
726 |
|
|
|
727 |
|
|
if(outChromaFlag==1 && outBlockNum==7)
|
728 |
|
|
begin
|
729 |
|
|
Bit#(PicWidthSz) tempStoreAddr = truncate(currMbHor);
|
730 |
|
|
InterBlockMv outBlockMv = interOutBlockMvfifo.first();
|
731 |
|
|
if(outBlockMv matches tagged BlockMv .bdata)
|
732 |
|
|
begin
|
733 |
|
|
outBlockMv = (BlockMv {refIdx:bdata.refIdx,mvhor:bdata.mvhor,mvver:bdata.mvver,nonZeroTransCoeff:(interTopNonZeroTransCoeff[pixelVer]?1:0)});
|
734 |
|
|
interOutBlockMvfifo.deq();
|
735 |
|
|
end
|
736 |
|
|
else if(pixelVer==3)
|
737 |
|
|
interOutBlockMvfifo.deq();
|
738 |
|
|
if(pixelVer==3 && picWidth>1)
|
739 |
|
|
interMemReqQdelay <= StoreReq {addr:{tempStoreAddr,pixelVer},data:pack(outBlockMv)};
|
740 |
|
|
else
|
741 |
|
|
interMemReqQ.enq(StoreReq {addr:{tempStoreAddr,pixelVer},data:pack(outBlockMv)});
|
742 |
|
|
if(pixelVer>0)
|
743 |
|
|
begin
|
744 |
|
|
Bit#(4) intra4x4typeTopStore = ((outstatefifo.first()==Inter) ? 14 : ((outstatefifo.first()!=Intra4x4) ? 13: intra4x4typeTop[(pixelVer-1)]));
|
745 |
|
|
Bit#(32) intraTopValStore = intraTopVal[(pixelVer-1)];
|
746 |
|
|
Bit#(16) intraTopValChroma0Store = intraTopValChroma0[(pixelVer-1)];
|
747 |
|
|
Bit#(16) intraTopValChroma1Store = (pixelVer<3 ? intraTopValChroma1[(pixelVer-1)] : {outputVector[1],outputVector[0]});
|
748 |
|
|
Bit#(68) intraStore = {intra4x4typeTopStore,intraTopValChroma1Store,intraTopValChroma0Store,intraTopValStore};
|
749 |
|
|
intraMemReqQ.enq(StoreReq {addr:{tempStoreAddr,(pixelVer-1)},data:intraStore});
|
750 |
|
|
if(pixelVer==3)
|
751 |
|
|
begin
|
752 |
|
|
intra4x4typeTopStore = ((outstatefifo.first()==Inter) ? 14 : ((outstatefifo.first()!=Intra4x4) ? 13: intra4x4typeTop[3]));
|
753 |
|
|
intraTopValStore = intraTopVal[3];
|
754 |
|
|
intraTopValChroma0Store = intraTopValChroma0[3];
|
755 |
|
|
intraTopValChroma1Store = {outputVector[3],outputVector[2]};
|
756 |
|
|
intraStore = {intra4x4typeTopStore,intraTopValChroma1Store,intraTopValChroma0Store,intraTopValStore};
|
757 |
|
|
intraMemReqQdelay <= StoreReq {addr:{tempStoreAddr,2'b11},data:intraStore};
|
758 |
|
|
end
|
759 |
|
|
end
|
760 |
|
|
end
|
761 |
|
|
outPixelNum <= outPixelNum+4;
|
762 |
|
|
if(outPixelNum == 12)
|
763 |
|
|
begin
|
764 |
|
|
if(outChromaFlag==0)
|
765 |
|
|
begin
|
766 |
|
|
outBlockNum <= outBlockNum+1;
|
767 |
|
|
if(outBlockNum == 15)
|
768 |
|
|
outChromaFlag <= 1;
|
769 |
|
|
if(nextoutputfifo.first() == Intra4x4)
|
770 |
|
|
nextoutputfifo.deq();
|
771 |
|
|
end
|
772 |
|
|
else
|
773 |
|
|
begin
|
774 |
|
|
if(outBlockNum == 7)
|
775 |
|
|
begin
|
776 |
|
|
outBlockNum <= 0;
|
777 |
|
|
outChromaFlag <= 0;
|
778 |
|
|
currMb <= currMb+1;
|
779 |
|
|
currMbHor <= currMbHor+1;
|
780 |
|
|
interCurrMbDiff <= interCurrMbDiff-1;
|
781 |
|
|
outstatefifo.deq;
|
782 |
|
|
intrastate <= Start;
|
783 |
|
|
if(truncate(currMbHor)==picWidth-1 && currMbVer==picHeight-1)
|
784 |
|
|
interpolator.endOfFrame();
|
785 |
|
|
nextoutputfifo.deq();
|
786 |
|
|
end
|
787 |
|
|
else
|
788 |
|
|
outBlockNum <= outBlockNum+1;
|
789 |
|
|
end
|
790 |
|
|
end
|
791 |
|
|
end
|
792 |
|
|
endrule
|
793 |
|
|
|
794 |
|
|
|
795 |
|
|
rule currMbHorUpdate( !(currMbHor
|
796 |
|
|
Bit#(PicAreaSz) temp = zeroExtend(picWidth);
|
797 |
|
|
if((currMbHor >> 3) >= temp)
|
798 |
|
|
begin
|
799 |
|
|
currMbHor <= currMbHor - (temp << 3);
|
800 |
|
|
currMbVer <= currMbVer + 8;
|
801 |
|
|
end
|
802 |
|
|
else
|
803 |
|
|
begin
|
804 |
|
|
currMbHor <= currMbHor - temp;
|
805 |
|
|
currMbVer <= currMbVer + 1;
|
806 |
|
|
end
|
807 |
|
|
//$display( "Trace Prediction: currMbHorUpdate %h %h", currMbHor, currMbVer);
|
808 |
|
|
endrule
|
809 |
|
|
|
810 |
|
|
|
811 |
|
|
// inter prediction rules
|
812 |
|
|
|
813 |
|
|
rule interSendReq ( interReqCount>0 && currMbHor
|
814 |
|
|
Bit#(PicAreaSz) currMbHorTemp = currMbHor+zeroExtend(interCurrMbDiff)-1;
|
815 |
|
|
Bit#(PicAreaSz) currMbTemp = currMb+zeroExtend(interCurrMbDiff)-1;
|
816 |
|
|
if( currMbHorTemp >= zeroExtend(picWidth) )
|
817 |
|
|
currMbHorTemp = currMbHorTemp-zeroExtend(picWidth);
|
818 |
|
|
Bit#(PicWidthSz) temp2 = truncate(currMbHorTemp);
|
819 |
|
|
Bit#(TAdd#(PicWidthSz,2)) temp = 0;
|
820 |
|
|
Bool noMoreReq = False;
|
821 |
|
|
if( currMbTemp < zeroExtend(picWidth) )
|
822 |
|
|
noMoreReq = True;
|
823 |
|
|
else
|
824 |
|
|
begin
|
825 |
|
|
if(interReqCount<5)
|
826 |
|
|
begin
|
827 |
|
|
Bit#(2) temp3 = truncate(interReqCount-1);
|
828 |
|
|
temp = {temp2,temp3};
|
829 |
|
|
end
|
830 |
|
|
else if(interReqCount==5)
|
831 |
|
|
begin
|
832 |
|
|
if((currMbHorTemp+1)
|
833 |
|
|
temp = {(temp2+1),2'b00};
|
834 |
|
|
else if(currMbHorTemp>0 && currMbTemp-firstMb>zeroExtend(picWidth))
|
835 |
|
|
temp = {(temp2-1),2'b11};
|
836 |
|
|
else
|
837 |
|
|
noMoreReq = True;
|
838 |
|
|
end
|
839 |
|
|
else if(interReqCount==6)
|
840 |
|
|
begin
|
841 |
|
|
if((currMbHorTemp+1)0 && currMbTemp-firstMb>zeroExtend(picWidth))
|
842 |
|
|
temp = {(temp2-1),2'b11};
|
843 |
|
|
else
|
844 |
|
|
noMoreReq = True;
|
845 |
|
|
end
|
846 |
|
|
else
|
847 |
|
|
noMoreReq = True;
|
848 |
|
|
end
|
849 |
|
|
if(!noMoreReq)
|
850 |
|
|
begin
|
851 |
|
|
interMemReqQ.enq(LoadReq temp);
|
852 |
|
|
interReqCount <= interReqCount+1;
|
853 |
|
|
//$display( "TRACE Prediction: interSendReq addr %0d",temp);///////////////////////
|
854 |
|
|
end
|
855 |
|
|
else
|
856 |
|
|
interReqCount <= 0;
|
857 |
|
|
$display( "Trace Prediction: interSendReq %h %h %h", interstate, interReqCount, temp);
|
858 |
|
|
endrule
|
859 |
|
|
|
860 |
|
|
|
861 |
|
|
rule interReceiveNoResp ( interRespCount>0 && currMbHor
|
862 |
|
|
Bit#(PicAreaSz) currMbHorTemp = currMbHor+zeroExtend(interCurrMbDiff)-1;
|
863 |
|
|
if( currMbHorTemp >= zeroExtend(picWidth) )
|
864 |
|
|
currMbHorTemp = currMbHorTemp-zeroExtend(picWidth);
|
865 |
|
|
interRespCount <= 0;
|
866 |
|
|
interStepCount <= 1;
|
867 |
|
|
interIPStepCount <= 1;
|
868 |
|
|
if(currMbHorTemp == 0)
|
869 |
|
|
begin
|
870 |
|
|
interLeftVal <= replicate(NotInter 0);
|
871 |
|
|
interTopLeftVal <= replicate(NotInter 0);
|
872 |
|
|
end
|
873 |
|
|
$display( "Trace Prediction: interReceiveNoResp %h %h", interstate, interRespCount);
|
874 |
|
|
endrule
|
875 |
|
|
|
876 |
|
|
|
877 |
|
|
rule interReceiveResp ( interRespCount>0 && interRespCount<7 && currMbHor
|
878 |
|
|
Bit#(PicAreaSz) currMbHorTemp = currMbHor+zeroExtend(interCurrMbDiff)-1;
|
879 |
|
|
Bit#(PicAreaSz) currMbTemp = currMb+zeroExtend(interCurrMbDiff)-1;
|
880 |
|
|
if( currMbHorTemp >= zeroExtend(picWidth) )
|
881 |
|
|
currMbHorTemp = currMbHorTemp-zeroExtend(picWidth);
|
882 |
|
|
Bool noMoreResp = False;
|
883 |
|
|
Bit#(2) temp2bit = 0;
|
884 |
|
|
InterBlockMv unpackedData = unpack(data);
|
885 |
|
|
Vector#(5,InterBlockMv) interTopValNext = interTopVal;
|
886 |
|
|
Vector#(4,InterBlockMv) interTopLeftValNext = interTopLeftVal;
|
887 |
|
|
if(interRespCount<5)
|
888 |
|
|
begin
|
889 |
|
|
temp2bit = truncate(interRespCount-1);
|
890 |
|
|
interTopValNext[temp2bit] = unpackedData;
|
891 |
|
|
if((interRespCount==4 || (interRespCount==1 && (interstate==InterPskip || interstate==InterP16x16 || interstate==InterP16x8)))
|
892 |
|
|
&& (!((currMbHorTemp+1)0 && currMbTemp-firstMb>zeroExtend(picWidth))))
|
893 |
|
|
noMoreResp = True;
|
894 |
|
|
end
|
895 |
|
|
else if(interRespCount==5)
|
896 |
|
|
begin
|
897 |
|
|
if((currMbHorTemp+1)
|
898 |
|
|
begin
|
899 |
|
|
interTopValNext[4] = unpackedData;
|
900 |
|
|
if(!(currMbHorTemp>0 && currMbTemp-firstMb>zeroExtend(picWidth)))
|
901 |
|
|
noMoreResp = True;
|
902 |
|
|
end
|
903 |
|
|
else
|
904 |
|
|
begin
|
905 |
|
|
interTopLeftValNext[0] = unpackedData;
|
906 |
|
|
noMoreResp = True;
|
907 |
|
|
end
|
908 |
|
|
end
|
909 |
|
|
else
|
910 |
|
|
begin
|
911 |
|
|
interTopLeftValNext[0] = unpackedData;
|
912 |
|
|
noMoreResp = True;
|
913 |
|
|
end
|
914 |
|
|
interMemRespQ.deq();
|
915 |
|
|
//$display( "TRACE Prediction: interReceiveResp data %h",data);///////////////////////
|
916 |
|
|
if(!noMoreResp)
|
917 |
|
|
interRespCount <= interRespCount+1;
|
918 |
|
|
else
|
919 |
|
|
begin
|
920 |
|
|
interRespCount <= 0;
|
921 |
|
|
interStepCount <= 1;
|
922 |
|
|
interIPStepCount <= 1;
|
923 |
|
|
if(currMbHorTemp == 0)
|
924 |
|
|
begin
|
925 |
|
|
interLeftVal <= replicate(NotInter 0);
|
926 |
|
|
interTopLeftValNext = replicate(NotInter 0);
|
927 |
|
|
end
|
928 |
|
|
end
|
929 |
|
|
interTopVal <= interTopValNext;
|
930 |
|
|
interTopLeftVal <= interTopLeftValNext;
|
931 |
|
|
$display( "Trace Prediction: interReceiveResp %h %h %h", interstate, interRespCount, data);
|
932 |
|
|
endrule
|
933 |
|
|
|
934 |
|
|
|
935 |
|
|
rule interProcessStep ( interStepCount>0 && currMbHor
|
936 |
|
|
Bit#(PicAreaSz) currMbTemp = currMb+zeroExtend(interCurrMbDiff)-1;
|
937 |
|
|
Bit#(2) blockHor = {interMbPartNum[0],interSubMbPartNum[0]};
|
938 |
|
|
Bit#(2) blockVer = {interMbPartNum[1],interSubMbPartNum[1]};
|
939 |
|
|
Bit#(3) partWidth = 0;
|
940 |
|
|
Bit#(3) partHeight = 0;
|
941 |
|
|
Bit#(3) numPart = 1;
|
942 |
|
|
Bit#(3) numSubPart = 1;
|
943 |
|
|
Bit#(2) subMbType = 0;
|
944 |
|
|
Bool noBlockC = False;
|
945 |
|
|
Bool calcmv = False;
|
946 |
|
|
Bool leftmv = False;
|
947 |
|
|
if(interstate==InterPskip || interstate==InterP16x16)
|
948 |
|
|
begin
|
949 |
|
|
partWidth = 4;
|
950 |
|
|
partHeight = 4;
|
951 |
|
|
numPart = 1;
|
952 |
|
|
calcmv = (interMbPartNum==0 && interSubMbPartNum==0);
|
953 |
|
|
leftmv = (blockHor>0);
|
954 |
|
|
end
|
955 |
|
|
else if(interstate==InterP16x8)
|
956 |
|
|
begin
|
957 |
|
|
partWidth = 4;
|
958 |
|
|
partHeight = 2;
|
959 |
|
|
numPart = 2;
|
960 |
|
|
if(interMbPartNum==2)
|
961 |
|
|
noBlockC = True;
|
962 |
|
|
calcmv = (interMbPartNum[0]==0 && interSubMbPartNum==0);
|
963 |
|
|
leftmv = (blockHor>0);
|
964 |
|
|
end
|
965 |
|
|
else if(interstate==InterP8x16)
|
966 |
|
|
begin
|
967 |
|
|
partWidth = 2;
|
968 |
|
|
partHeight = 4;
|
969 |
|
|
numPart = 2;
|
970 |
|
|
calcmv = (interMbPartNum[1]==0 && interSubMbPartNum==0);
|
971 |
|
|
leftmv = !(blockVer>0);
|
972 |
|
|
end
|
973 |
|
|
else if(interstate==InterP8x8 || interstate==InterP8x8ref0)
|
974 |
|
|
begin
|
975 |
|
|
numPart = 4;
|
976 |
|
|
subMbType = interSubMbTypeVector[interMbPartNum];
|
977 |
|
|
numSubPart = numSubMbPart(subMbType);
|
978 |
|
|
case(subMbType)
|
979 |
|
|
0:
|
980 |
|
|
begin
|
981 |
|
|
partWidth = 2;
|
982 |
|
|
partHeight = 2;
|
983 |
|
|
if(interMbPartNum==3)
|
984 |
|
|
noBlockC = True;
|
985 |
|
|
calcmv = (interSubMbPartNum==0);
|
986 |
|
|
leftmv = (blockHor[0]>0);
|
987 |
|
|
end
|
988 |
|
|
1:
|
989 |
|
|
begin
|
990 |
|
|
partWidth = 2;
|
991 |
|
|
partHeight = 1;
|
992 |
|
|
if(interSubMbPartNum==2)
|
993 |
|
|
noBlockC = True;
|
994 |
|
|
calcmv = (interSubMbPartNum[0]==0);
|
995 |
|
|
leftmv = True;
|
996 |
|
|
end
|
997 |
|
|
2:
|
998 |
|
|
begin
|
999 |
|
|
partWidth = 1;
|
1000 |
|
|
partHeight = 2;
|
1001 |
|
|
calcmv = (interSubMbPartNum[1]==0);
|
1002 |
|
|
leftmv = False;
|
1003 |
|
|
end
|
1004 |
|
|
3:
|
1005 |
|
|
begin
|
1006 |
|
|
partWidth = 1;
|
1007 |
|
|
partHeight = 1;
|
1008 |
|
|
if(interSubMbPartNum==3)
|
1009 |
|
|
noBlockC = True;
|
1010 |
|
|
calcmv = True;
|
1011 |
|
|
end
|
1012 |
|
|
endcase
|
1013 |
|
|
end
|
1014 |
|
|
else
|
1015 |
|
|
$display( "ERROR Prediction: interProcessStep unexpected interstate");
|
1016 |
|
|
Bit#(4) refIndex = ((interstate==InterPskip||interstate==InterP8x8ref0) ? 0 : interRefIdxVector[interMbPartNum]);
|
1017 |
|
|
Vector#(3,InterBlockMv) blockABC = replicate(NotInter 0);
|
1018 |
|
|
if( currMbTemp-firstMb==0 && blockHor==0 )
|
1019 |
|
|
blockABC[0] = (NotInter 0);
|
1020 |
|
|
else
|
1021 |
|
|
blockABC[0] = interLeftVal[blockVer];
|
1022 |
|
|
if( currMbTemp-firstMb
|
1023 |
|
|
blockABC[1] = (NotInter 0);
|
1024 |
|
|
else
|
1025 |
|
|
blockABC[1] = interTopVal[blockHor];
|
1026 |
|
|
blockABC[2] = interTopVal[{1'b0,blockHor}+partWidth];
|
1027 |
|
|
if(noBlockC || blockABC[2]==(NotInter 0))
|
1028 |
|
|
blockABC[2] = interTopLeftVal[blockVer];
|
1029 |
|
|
Bit#(14) mvhorfinal = 0;
|
1030 |
|
|
Bit#(12) mvverfinal = 0;
|
1031 |
|
|
Bit#(5) interNewestMvNext = 0;
|
1032 |
|
|
if(calcmv)//motion vector caculation
|
1033 |
|
|
begin
|
1034 |
|
|
Vector#(3,Int#(14)) mvhorABC = replicate(0);
|
1035 |
|
|
Vector#(3,Int#(12)) mvverABC = replicate(0);
|
1036 |
|
|
Bit#(2) validCount = 0;
|
1037 |
|
|
Bit#(14) mvhorPred = 0;
|
1038 |
|
|
Bit#(12) mvverPred = 0;
|
1039 |
|
|
for(Integer ii=0; ii<3; ii=ii+1)
|
1040 |
|
|
begin
|
1041 |
|
|
if(blockABC[ii] matches tagged BlockMv .xdata)
|
1042 |
|
|
begin
|
1043 |
|
|
mvhorABC[ii] = unpack(xdata.mvhor);
|
1044 |
|
|
mvverABC[ii] = unpack(xdata.mvver);
|
1045 |
|
|
if(xdata.refIdx == refIndex)
|
1046 |
|
|
begin
|
1047 |
|
|
validCount = validCount+1;
|
1048 |
|
|
mvhorPred = xdata.mvhor;
|
1049 |
|
|
mvverPred = xdata.mvver;
|
1050 |
|
|
end
|
1051 |
|
|
end
|
1052 |
|
|
else
|
1053 |
|
|
begin
|
1054 |
|
|
mvhorABC[ii] = 0;
|
1055 |
|
|
mvverABC[ii] = 0;
|
1056 |
|
|
end
|
1057 |
|
|
end
|
1058 |
|
|
if(validCount != 1)//median
|
1059 |
|
|
begin
|
1060 |
|
|
if(mvhorABC[0]>mvhorABC[1] && mvhorABC[0]>mvhorABC[2])
|
1061 |
|
|
mvhorPred = pack((mvhorABC[1]>mvhorABC[2]) ? mvhorABC[1] : mvhorABC[2]);
|
1062 |
|
|
else if(mvhorABC[0]
|
1063 |
|
|
mvhorPred = pack((mvhorABC[1]
|
1064 |
|
|
else
|
1065 |
|
|
mvhorPred = pack(mvhorABC[0]);
|
1066 |
|
|
if(mvverABC[0]>mvverABC[1] && mvverABC[0]>mvverABC[2])
|
1067 |
|
|
mvverPred = pack((mvverABC[1]>mvverABC[2]) ? mvverABC[1] : mvverABC[2]);
|
1068 |
|
|
else if(mvverABC[0]
|
1069 |
|
|
mvverPred = pack((mvverABC[1]
|
1070 |
|
|
else
|
1071 |
|
|
mvverPred = pack(mvverABC[0]);
|
1072 |
|
|
end
|
1073 |
|
|
if(interstate==InterPskip)
|
1074 |
|
|
begin
|
1075 |
|
|
for(Integer ii=0; ii<2; ii=ii+1)
|
1076 |
|
|
begin
|
1077 |
|
|
if(blockABC[ii] matches tagged BlockMv .xdata)
|
1078 |
|
|
begin
|
1079 |
|
|
if(xdata.refIdx==0 && xdata.mvhor==0 && xdata.mvver==0)
|
1080 |
|
|
begin
|
1081 |
|
|
mvhorPred = 0;
|
1082 |
|
|
mvverPred = 0;
|
1083 |
|
|
end
|
1084 |
|
|
end
|
1085 |
|
|
else if(blockABC[ii] matches tagged NotInter 0)
|
1086 |
|
|
begin
|
1087 |
|
|
mvhorPred = 0;
|
1088 |
|
|
mvverPred = 0;
|
1089 |
|
|
end
|
1090 |
|
|
end
|
1091 |
|
|
end
|
1092 |
|
|
else if(interstate==InterP16x8 || interstate==InterP8x16)
|
1093 |
|
|
begin
|
1094 |
|
|
InterBlockMv blockCheck;
|
1095 |
|
|
if(interstate==InterP16x8)
|
1096 |
|
|
begin
|
1097 |
|
|
if(interMbPartNum==0)
|
1098 |
|
|
blockCheck = blockABC[1];
|
1099 |
|
|
else
|
1100 |
|
|
blockCheck = blockABC[0];
|
1101 |
|
|
end
|
1102 |
|
|
else
|
1103 |
|
|
begin
|
1104 |
|
|
if(interMbPartNum==0)
|
1105 |
|
|
blockCheck = blockABC[0];
|
1106 |
|
|
else
|
1107 |
|
|
blockCheck = blockABC[2];
|
1108 |
|
|
end
|
1109 |
|
|
if(blockCheck matches tagged BlockMv .xdata &&& xdata.refIdx==refIndex)
|
1110 |
|
|
begin
|
1111 |
|
|
mvhorPred = xdata.mvhor;
|
1112 |
|
|
mvverPred = xdata.mvver;
|
1113 |
|
|
end
|
1114 |
|
|
end
|
1115 |
|
|
mvhorfinal = mvhorPred;
|
1116 |
|
|
mvverfinal = mvverPred;
|
1117 |
|
|
if(interstate!=InterPskip)
|
1118 |
|
|
begin
|
1119 |
|
|
mvhorfinal = truncate(tpl_1(interMvDiff.first()) + signExtend(mvhorPred));
|
1120 |
|
|
mvverfinal = truncate(tpl_2(interMvDiff.first()) + signExtend(mvverPred));
|
1121 |
|
|
interMvDiff.deq();
|
1122 |
|
|
end
|
1123 |
|
|
interMvFile.upd({interMbPartNum,interSubMbPartNum},tuple2(mvhorfinal,mvverfinal));
|
1124 |
|
|
interNewestMvNext = zeroExtend({interMbPartNum,interSubMbPartNum})+1;
|
1125 |
|
|
$display( "Trace Prediction: interProcessStep %h %h %h %h %h %h %h %h %h", interstate, interStepCount, interMbPartNum, interSubMbPartNum, pack(blockABC[0]), pack(blockABC[1]), pack(blockABC[2]), mvhorPred, mvverPred);
|
1126 |
|
|
end
|
1127 |
|
|
else
|
1128 |
|
|
begin
|
1129 |
|
|
if(leftmv)
|
1130 |
|
|
begin
|
1131 |
|
|
if(blockABC[0] matches tagged BlockMv .xdata)
|
1132 |
|
|
begin
|
1133 |
|
|
mvhorfinal = unpack(xdata.mvhor);
|
1134 |
|
|
mvverfinal = unpack(xdata.mvver);
|
1135 |
|
|
end
|
1136 |
|
|
else
|
1137 |
|
|
$display( "ERROR Prediction: interProcessStep unexpected blockABC[0]");
|
1138 |
|
|
end
|
1139 |
|
|
else
|
1140 |
|
|
begin
|
1141 |
|
|
if(blockABC[1] matches tagged BlockMv .xdata)
|
1142 |
|
|
begin
|
1143 |
|
|
mvhorfinal = unpack(xdata.mvhor);
|
1144 |
|
|
mvverfinal = unpack(xdata.mvver);
|
1145 |
|
|
end
|
1146 |
|
|
else
|
1147 |
|
|
$display( "ERROR Prediction: interProcessStep unexpected blockABC[1]");
|
1148 |
|
|
end
|
1149 |
|
|
end
|
1150 |
|
|
Bit#(2) tempBShor = 0;//bS calculation
|
1151 |
|
|
Bit#(2) tempBSver = 0;
|
1152 |
|
|
if(interLeftVal[blockVer] matches tagged BlockMv .xdata)
|
1153 |
|
|
begin
|
1154 |
|
|
if(xdata.nonZeroTransCoeff == 1)
|
1155 |
|
|
tempBShor = 2;
|
1156 |
|
|
else
|
1157 |
|
|
begin
|
1158 |
|
|
if(xdata.refIdx!=refIndex || absDiffGEFour14(mvhorfinal,xdata.mvhor) || absDiffGEFour12(mvverfinal,xdata.mvver))
|
1159 |
|
|
tempBShor = 1;
|
1160 |
|
|
else
|
1161 |
|
|
tempBShor = 0;
|
1162 |
|
|
end
|
1163 |
|
|
end
|
1164 |
|
|
else
|
1165 |
|
|
tempBShor = 3;
|
1166 |
|
|
if(interTopVal[blockHor] matches tagged BlockMv .xdata)
|
1167 |
|
|
begin
|
1168 |
|
|
if(xdata.nonZeroTransCoeff == 1)
|
1169 |
|
|
tempBSver = 2;
|
1170 |
|
|
else
|
1171 |
|
|
begin
|
1172 |
|
|
if(xdata.refIdx!=refIndex || absDiffGEFour14(mvhorfinal,xdata.mvhor) || absDiffGEFour12(mvverfinal,xdata.mvver))
|
1173 |
|
|
tempBSver = 1;
|
1174 |
|
|
else
|
1175 |
|
|
tempBSver = 0;
|
1176 |
|
|
end
|
1177 |
|
|
end
|
1178 |
|
|
else
|
1179 |
|
|
tempBSver = 3;
|
1180 |
|
|
interBSfifo.enq(tuple2(tempBShor,tempBSver));
|
1181 |
|
|
Vector#(5,InterBlockMv) interTopValNext = interTopVal;//update inter*Val
|
1182 |
|
|
Vector#(4,InterBlockMv) interLeftValNext = interLeftVal;
|
1183 |
|
|
Vector#(4,InterBlockMv) interTopLeftValNext = interTopLeftVal;
|
1184 |
|
|
interLeftValNext[blockVer] = (BlockMv {refIdx:refIndex,mvhor:mvhorfinal,mvver:mvverfinal,nonZeroTransCoeff:0});
|
1185 |
|
|
interTopValNext[blockHor] = (BlockMv {refIdx:refIndex,mvhor:mvhorfinal,mvver:mvverfinal,nonZeroTransCoeff:0});
|
1186 |
|
|
interTopLeftValNext[blockVer] = interTopVal[blockHor];
|
1187 |
|
|
interTopVal <= interTopValNext;
|
1188 |
|
|
interLeftVal <= interLeftValNext;
|
1189 |
|
|
interTopLeftVal <= interTopLeftValNext;
|
1190 |
|
|
if(blockVer == 3)
|
1191 |
|
|
interOutBlockMvfifo.enq(BlockMv {refIdx:refIndex,mvhor:mvhorfinal,mvver:mvverfinal,nonZeroTransCoeff:0});
|
1192 |
|
|
if(interSubMbPartNum == 3)//next step
|
1193 |
|
|
begin
|
1194 |
|
|
interSubMbPartNum <= 0;
|
1195 |
|
|
if(interMbPartNum == 3)
|
1196 |
|
|
begin
|
1197 |
|
|
interMbPartNum <= 0;
|
1198 |
|
|
interStepCount <= 0;
|
1199 |
|
|
interNewestMvNext = 16;
|
1200 |
|
|
end
|
1201 |
|
|
else
|
1202 |
|
|
interMbPartNum <= interMbPartNum+1;
|
1203 |
|
|
end
|
1204 |
|
|
else
|
1205 |
|
|
interSubMbPartNum <= interSubMbPartNum+1;
|
1206 |
|
|
if(interNewestMvNext > 0)
|
1207 |
|
|
interNewestMv <= interNewestMvNext;
|
1208 |
|
|
endrule
|
1209 |
|
|
|
1210 |
|
|
|
1211 |
|
|
rule interIPProcessStep ( interIPStepCount>0 && currMbHorzeroExtend({interIPMbPartNum,interIPSubMbPartNum}) );
|
1212 |
|
|
Bit#(PicAreaSz) currMbHorTemp = currMbHor+zeroExtend(interCurrMbDiff)-1;
|
1213 |
|
|
Bit#(PicHeightSz) currMbVerTemp = currMbVer;
|
1214 |
|
|
if( currMbHorTemp >= zeroExtend(picWidth) )
|
1215 |
|
|
begin
|
1216 |
|
|
currMbHorTemp = currMbHorTemp-zeroExtend(picWidth);
|
1217 |
|
|
currMbVerTemp = currMbVerTemp+1;
|
1218 |
|
|
end
|
1219 |
|
|
Bit#(2) blockHor = {interIPMbPartNum[0],interIPSubMbPartNum[0]};
|
1220 |
|
|
Bit#(2) blockVer = {interIPMbPartNum[1],interIPSubMbPartNum[1]};
|
1221 |
|
|
Bit#(3) numPart = 1;
|
1222 |
|
|
Bit#(3) numSubPart = 1;
|
1223 |
|
|
Bit#(2) subMbType = 0;
|
1224 |
|
|
if(interstate==InterPskip || interstate==InterP16x16)
|
1225 |
|
|
numPart = 1;
|
1226 |
|
|
else if(interstate==InterP16x8)
|
1227 |
|
|
numPart = 2;
|
1228 |
|
|
else if(interstate==InterP8x16)
|
1229 |
|
|
numPart = 2;
|
1230 |
|
|
else if(interstate==InterP8x8 || interstate==InterP8x8ref0)
|
1231 |
|
|
begin
|
1232 |
|
|
numPart = 4;
|
1233 |
|
|
subMbType = interSubMbTypeVector[interIPMbPartNum];
|
1234 |
|
|
numSubPart = numSubMbPart(subMbType);
|
1235 |
|
|
end
|
1236 |
|
|
else
|
1237 |
|
|
$display( "ERROR Prediction: interIPProcessStep unexpected interstate");
|
1238 |
|
|
Bit#(4) refIndex = ((interstate==InterPskip||interstate==InterP8x8ref0) ? 0 : interRefIdxVector[interIPMbPartNum]);
|
1239 |
|
|
Bit#(PicWidthSz) currMbHorT = truncate(currMbHorTemp);
|
1240 |
|
|
Bit#(TAdd#(PicWidthSz,2)) horTemp = {currMbHorT,blockHor};
|
1241 |
|
|
Bit#(TAdd#(PicHeightSz,4)) verTemp = {currMbVerTemp,blockVer,2'b00};
|
1242 |
|
|
IPBlockType btTemp = IP16x16;
|
1243 |
|
|
if(interstate==InterPskip || interstate==InterP16x16)
|
1244 |
|
|
btTemp = IP16x16;
|
1245 |
|
|
else if(interstate==InterP16x8)
|
1246 |
|
|
btTemp = IP16x8;
|
1247 |
|
|
else if(interstate==InterP8x16)
|
1248 |
|
|
btTemp = IP8x16;
|
1249 |
|
|
else
|
1250 |
|
|
begin
|
1251 |
|
|
case(subMbType)
|
1252 |
|
|
0: btTemp = IP8x8;
|
1253 |
|
|
1: btTemp = IP8x4;
|
1254 |
|
|
2: btTemp = IP4x8;
|
1255 |
|
|
3: btTemp = IP4x4;
|
1256 |
|
|
endcase
|
1257 |
|
|
end
|
1258 |
|
|
Bit#(14) mvhorTemp = tpl_1(interMvFile.sub({interIPMbPartNum,interIPSubMbPartNum}));
|
1259 |
|
|
Bit#(12) mvverTemp = tpl_2(interMvFile.sub({interIPMbPartNum,interIPSubMbPartNum}));
|
1260 |
|
|
if(interIPStepCount == 1)
|
1261 |
|
|
begin
|
1262 |
|
|
if(!(interstate==InterP8x8 || interstate==InterP8x8ref0))
|
1263 |
|
|
begin
|
1264 |
|
|
numPart = 4;
|
1265 |
|
|
Bit#(2) interIPMbPartNumTemp = interIPMbPartNum;
|
1266 |
|
|
if(btTemp==IP16x16)
|
1267 |
|
|
interIPMbPartNumTemp = 0;
|
1268 |
|
|
else if(btTemp==IP16x8 && interIPMbPartNumTemp[0]==1)
|
1269 |
|
|
interIPMbPartNumTemp = interIPMbPartNumTemp-1;
|
1270 |
|
|
else if(btTemp==IP8x16 && interIPMbPartNumTemp[1]==1)
|
1271 |
|
|
interIPMbPartNumTemp = interIPMbPartNumTemp-2;
|
1272 |
|
|
refIndex = ((interstate==InterPskip||interstate==InterP8x8ref0) ? 0 : interRefIdxVector[interIPMbPartNumTemp]);
|
1273 |
|
|
btTemp = IP8x8;
|
1274 |
|
|
mvhorTemp = tpl_1(interMvFile.sub({interIPMbPartNumTemp,2'b00}));
|
1275 |
|
|
mvverTemp = tpl_2(interMvFile.sub({interIPMbPartNumTemp,2'b00}));
|
1276 |
|
|
interpolator.request(IPLuma {refIdx:refIndex,hor:horTemp,ver:verTemp,mvhor:mvhorTemp,mvver:mvverTemp,bt:btTemp});
|
1277 |
|
|
end
|
1278 |
|
|
else
|
1279 |
|
|
interpolator.request(IPLuma {refIdx:refIndex,hor:horTemp,ver:verTemp,mvhor:mvhorTemp,mvver:mvverTemp,bt:btTemp});
|
1280 |
|
|
end
|
1281 |
|
|
else
|
1282 |
|
|
interpolator.request(IPChroma {refIdx:refIndex,uv:interIPStepCount[0],hor:horTemp,ver:truncate(verTemp>>1),mvhor:mvhorTemp,mvver:mvverTemp,bt:btTemp});
|
1283 |
|
|
if(interIPSubMbPartNum >= truncate(numSubPart-1))
|
1284 |
|
|
begin
|
1285 |
|
|
interIPSubMbPartNum <= 0;
|
1286 |
|
|
if(interIPMbPartNum >= truncate(numPart-1))
|
1287 |
|
|
begin
|
1288 |
|
|
interIPMbPartNum <= 0;
|
1289 |
|
|
interIPStepCount <= interIPStepCount+1;
|
1290 |
|
|
end
|
1291 |
|
|
else
|
1292 |
|
|
begin
|
1293 |
|
|
if(btTemp == IP16x8)
|
1294 |
|
|
interIPMbPartNum <= 2;
|
1295 |
|
|
else
|
1296 |
|
|
interIPMbPartNum <= interIPMbPartNum+1;
|
1297 |
|
|
end
|
1298 |
|
|
end
|
1299 |
|
|
else
|
1300 |
|
|
begin
|
1301 |
|
|
if(subMbType == 1)
|
1302 |
|
|
interIPSubMbPartNum <= 2;
|
1303 |
|
|
else
|
1304 |
|
|
interIPSubMbPartNum <= interIPSubMbPartNum+1;
|
1305 |
|
|
end
|
1306 |
|
|
$display( "Trace Prediction: interIPProcessStep %h %h %h %h %h %h %h %h %h %h", interstate, interIPStepCount, interIPMbPartNum, interIPSubMbPartNum, refIndex, horTemp, verTemp, mvhorTemp, mvverTemp, pack(btTemp));
|
1307 |
|
|
endrule
|
1308 |
|
|
|
1309 |
|
|
|
1310 |
|
|
rule interDone ( interstate!=Start && interReqCount==0 && interRespCount==0 && interStepCount==0 && interIPStepCount==0 );
|
1311 |
|
|
interstate <= Start;
|
1312 |
|
|
//$display( "Trace Prediction: interOutputTransfer %h %h", interstate, interOutputCount);
|
1313 |
|
|
endrule
|
1314 |
|
|
|
1315 |
|
|
|
1316 |
|
|
rule interOutputTransfer ( True );
|
1317 |
|
|
predictedfifo.enq(interpolator.first());
|
1318 |
|
|
interpolator.deq();
|
1319 |
|
|
//$display( "Trace Prediction: interOutputTransfer %h %h", interstate, interOutputCount);
|
1320 |
|
|
endrule
|
1321 |
|
|
|
1322 |
|
|
|
1323 |
|
|
|
1324 |
|
|
// intra prediction rules
|
1325 |
|
|
|
1326 |
|
|
rule intraSendReq ( intraReqCount>0 && currMbHor
|
1327 |
|
|
Bit#(PicWidthSz) temp2 = truncate(currMbHor);
|
1328 |
|
|
Bit#(TAdd#(PicWidthSz,2)) temp = 0;
|
1329 |
|
|
Bit#(1) noMoreReq = 0;
|
1330 |
|
|
if( currMb-firstMb < zeroExtend(picWidth) )
|
1331 |
|
|
noMoreReq = 1;
|
1332 |
|
|
else
|
1333 |
|
|
begin
|
1334 |
|
|
if(intraReqCount<5)
|
1335 |
|
|
begin
|
1336 |
|
|
Bit#(2) temp3 = truncate(intraReqCount-1);
|
1337 |
|
|
temp = {temp2,temp3};
|
1338 |
|
|
end
|
1339 |
|
|
else if(intraReqCount==5)
|
1340 |
|
|
begin
|
1341 |
|
|
if((currMbHor+1)
|
1342 |
|
|
temp = {(temp2+1),2'b00};
|
1343 |
|
|
else if(currMbHor>0 && currMb-firstMb>zeroExtend(picWidth))
|
1344 |
|
|
temp = {(temp2-1),2'b11};
|
1345 |
|
|
else
|
1346 |
|
|
noMoreReq = 1;
|
1347 |
|
|
end
|
1348 |
|
|
else if(intraReqCount==6)
|
1349 |
|
|
begin
|
1350 |
|
|
if((currMbHor+1)0 && currMb-firstMb>zeroExtend(picWidth))
|
1351 |
|
|
temp = {(temp2-1),2'b11};
|
1352 |
|
|
else
|
1353 |
|
|
noMoreReq = 1;
|
1354 |
|
|
end
|
1355 |
|
|
else
|
1356 |
|
|
noMoreReq = 1;
|
1357 |
|
|
end
|
1358 |
|
|
if(noMoreReq == 0)
|
1359 |
|
|
begin
|
1360 |
|
|
intraMemReqQ.enq(LoadReq temp);
|
1361 |
|
|
intraReqCount <= intraReqCount+1;
|
1362 |
|
|
//$display( "TRACE Prediction: intraSendReq addr %0d",temp);///////////////////////
|
1363 |
|
|
end
|
1364 |
|
|
else
|
1365 |
|
|
intraReqCount <= 0;
|
1366 |
|
|
$display( "Trace Prediction: intraSendReq");
|
1367 |
|
|
endrule
|
1368 |
|
|
|
1369 |
|
|
|
1370 |
|
|
rule intraReceiveNoResp ( intraRespCount>0 && currMbHor
|
1371 |
|
|
intra4x4typeTop <= replicate(15);
|
1372 |
|
|
intraRespCount <= 0;
|
1373 |
|
|
intraStepCount <= 1;
|
1374 |
|
|
blockNum <= 0;
|
1375 |
|
|
pixelNum <= 0;
|
1376 |
|
|
interOutBlockMvfifo.enq(NotInter 1);
|
1377 |
|
|
$display( "Trace Prediction: intraReceiveNoResp");
|
1378 |
|
|
endrule
|
1379 |
|
|
|
1380 |
|
|
|
1381 |
|
|
rule intraReceiveResp ( intraRespCount>0 && intraRespCount<7 && currMbHor
|
1382 |
|
|
Bit#(1) noMoreResp = 0;
|
1383 |
|
|
Bit#(2) temp2bit = 0;
|
1384 |
|
|
if(intraRespCount<5)
|
1385 |
|
|
begin
|
1386 |
|
|
temp2bit = truncate(intraRespCount-1);
|
1387 |
|
|
intra4x4typeTop <= update(intra4x4typeTop, temp2bit, data[67:64]);
|
1388 |
|
|
if(intraRespCount==4)
|
1389 |
|
|
begin
|
1390 |
|
|
Vector#(5,Bit#(32)) intraTopValTemp = intraTopVal;
|
1391 |
|
|
intraTopValTemp[3] = data[31:0];
|
1392 |
|
|
intraTopValTemp[4] = {data[31:24],data[31:24],data[31:24],data[31:24]};
|
1393 |
|
|
intraTopVal <= intraTopValTemp;
|
1394 |
|
|
if(!((currMbHor+1)0 && currMb-firstMb>zeroExtend(picWidth)))
|
1395 |
|
|
noMoreResp = 1;
|
1396 |
|
|
end
|
1397 |
|
|
else
|
1398 |
|
|
intraTopVal <= update(intraTopVal, intraRespCount-1, data[31:0]);
|
1399 |
|
|
intraTopValChroma0 <= update(intraTopValChroma0, temp2bit, data[47:32]);
|
1400 |
|
|
intraTopValChroma1 <= update(intraTopValChroma1, temp2bit, data[63:48]);
|
1401 |
|
|
end
|
1402 |
|
|
else if(intraRespCount==5)
|
1403 |
|
|
begin
|
1404 |
|
|
if((currMbHor+1)
|
1405 |
|
|
begin
|
1406 |
|
|
if(!(data[67:64]==15 || (data[67:64]==14 && ppsconstrained_intra_pred_flag==1)))
|
1407 |
|
|
intraTopVal <= update(intraTopVal, 4, data[31:0]);
|
1408 |
|
|
if(!(currMbHor>0 && currMb-firstMb>zeroExtend(picWidth)))
|
1409 |
|
|
noMoreResp = 1;
|
1410 |
|
|
end
|
1411 |
|
|
else
|
1412 |
|
|
begin
|
1413 |
|
|
Bit#(40) temp2 = intraLeftVal[0];
|
1414 |
|
|
intraLeftVal <= update(intraLeftVal, 0, {temp2[39:8],data[31:24]});
|
1415 |
|
|
intraLeftValChroma0 <= update(intraLeftValChroma0, 0, data[47:40]);
|
1416 |
|
|
intraLeftValChroma1 <= update(intraLeftValChroma1, 0, data[63:56]);
|
1417 |
|
|
noMoreResp = 1;
|
1418 |
|
|
end
|
1419 |
|
|
end
|
1420 |
|
|
else
|
1421 |
|
|
begin
|
1422 |
|
|
Bit#(40) temp2 = intraLeftVal[0];
|
1423 |
|
|
intraLeftVal <= update(intraLeftVal, 0, {temp2[39:8],data[31:24]});
|
1424 |
|
|
intraLeftValChroma0 <= update(intraLeftValChroma0, 0, data[47:40]);
|
1425 |
|
|
intraLeftValChroma1 <= update(intraLeftValChroma1, 0, data[63:56]);
|
1426 |
|
|
noMoreResp = 1;
|
1427 |
|
|
end
|
1428 |
|
|
intraMemRespQ.deq();
|
1429 |
|
|
//$display( "TRACE Prediction: intraReceiveResp data %h",data);///////////////////////
|
1430 |
|
|
if(noMoreResp == 0)
|
1431 |
|
|
intraRespCount <= intraRespCount+1;
|
1432 |
|
|
else
|
1433 |
|
|
begin
|
1434 |
|
|
intraRespCount <= 0;
|
1435 |
|
|
intraStepCount <= 1;
|
1436 |
|
|
blockNum <= 0;
|
1437 |
|
|
pixelNum <= 0;
|
1438 |
|
|
interOutBlockMvfifo.enq(NotInter 1);
|
1439 |
|
|
end
|
1440 |
|
|
$display( "Trace Prediction: intraReceiveResp");
|
1441 |
|
|
endrule
|
1442 |
|
|
|
1443 |
|
|
|
1444 |
|
|
rule intraPredTypeStep ( intraStepCount==1 && !nextoutputfifo.notEmpty());
|
1445 |
|
|
Bit#(2) blockHor = {blockNum[2],blockNum[0]};
|
1446 |
|
|
Bit#(2) blockVer = {blockNum[3],blockNum[1]};
|
1447 |
|
|
Bit#(4) topType = select(intra4x4typeTop, blockHor);
|
1448 |
|
|
Bit#(4) leftType;
|
1449 |
|
|
if(currMbHor!=0 || blockNum!=0)
|
1450 |
|
|
leftType = select(intra4x4typeLeft, blockVer);
|
1451 |
|
|
else
|
1452 |
|
|
begin
|
1453 |
|
|
leftType = 15;
|
1454 |
|
|
intra4x4typeLeft <= replicate(15);
|
1455 |
|
|
end
|
1456 |
|
|
if(intrastate!=Intra4x4)
|
1457 |
|
|
begin
|
1458 |
|
|
intraStepCount <= intraStepCount+1;
|
1459 |
|
|
nextoutputfifo.enq(NonSkipMB);
|
1460 |
|
|
end
|
1461 |
|
|
else
|
1462 |
|
|
begin
|
1463 |
|
|
Bit#(1) topAvailable;
|
1464 |
|
|
Bit#(1) leftAvailable;
|
1465 |
|
|
if(topType==15 || (topType==14 && ppsconstrained_intra_pred_flag==1))
|
1466 |
|
|
topAvailable = 0;
|
1467 |
|
|
else
|
1468 |
|
|
topAvailable = 1;
|
1469 |
|
|
if(leftType==15 || (leftType==14 && ppsconstrained_intra_pred_flag==1))
|
1470 |
|
|
leftAvailable = 0;
|
1471 |
|
|
else
|
1472 |
|
|
leftAvailable = 1;
|
1473 |
|
|
Bit#(4) predType = 0;
|
1474 |
|
|
Bit#(4) remType = rem_intra4x4_pred_mode.first();
|
1475 |
|
|
Bit#(4) curType = 0;
|
1476 |
|
|
rem_intra4x4_pred_mode.deq();
|
1477 |
|
|
if(topAvailable==0 || leftAvailable==0)
|
1478 |
|
|
predType = 2;
|
1479 |
|
|
else
|
1480 |
|
|
begin
|
1481 |
|
|
Bit#(4) topType2 = topType;
|
1482 |
|
|
Bit#(4) leftType2 = leftType;
|
1483 |
|
|
if(topType>8)
|
1484 |
|
|
topType2 = 2;
|
1485 |
|
|
if(leftType>8)
|
1486 |
|
|
leftType2 = 2;
|
1487 |
|
|
if(topType2 > leftType2)
|
1488 |
|
|
predType = leftType2;
|
1489 |
|
|
else
|
1490 |
|
|
predType = topType2;
|
1491 |
|
|
end
|
1492 |
|
|
if(remType[3] == 1)
|
1493 |
|
|
curType = predType;
|
1494 |
|
|
else if(remType < predType)
|
1495 |
|
|
curType = remType;
|
1496 |
|
|
else
|
1497 |
|
|
curType = remType+1;
|
1498 |
|
|
cur_intra4x4_pred_mode <= curType;
|
1499 |
|
|
intraStepCount <= intraStepCount+1;
|
1500 |
|
|
if(blockNum == 15)
|
1501 |
|
|
nextoutputfifo.enq(Intra4x4PlusChroma);
|
1502 |
|
|
else
|
1503 |
|
|
nextoutputfifo.enq(Intra4x4);
|
1504 |
|
|
$display( "TRACE Prediction: intraPredTypeStep currMbHor currMbVer blockNum topType leftType predType remType curType %0d %0d %0d %0d %0d %0d %0d %0d",currMbHor,currMbVer,blockNum,topType,leftType,predType,remType,curType);//////////////////
|
1505 |
|
|
end
|
1506 |
|
|
//$display( "Trace Prediction: intraPredTypeStep");
|
1507 |
|
|
endrule
|
1508 |
|
|
|
1509 |
|
|
|
1510 |
|
|
rule intraProcessStep ( intraStepCount>1 );
|
1511 |
|
|
$display( "TRACE Prediction: intraProcessStep %0d %0d", blockNum, pixelNum);////////////////////
|
1512 |
|
|
//$display( "TRACE Prediction: intraProcessStep intraTopVal %h %h %h %h %h",intraTopVal[4],intraTopVal[3],intraTopVal[2],intraTopVal[1],intraTopVal[0]);/////////////////
|
1513 |
|
|
Bit#(1) outFlag = 0;
|
1514 |
|
|
Bit#(4) nextIntraStepCount = intraStepCount+1;
|
1515 |
|
|
Bit#(2) blockHor = {blockNum[2],blockNum[0]};
|
1516 |
|
|
Bit#(2) blockVer = {blockNum[3],blockNum[1]};
|
1517 |
|
|
Bit#(2) pixelVer = {pixelNum[3],pixelNum[2]};
|
1518 |
|
|
Vector#(4,Bit#(8)) predVector = replicate(0);
|
1519 |
|
|
|
1520 |
|
|
Bit#(4) topType = select(intra4x4typeTop, blockHor);
|
1521 |
|
|
Bit#(4) leftType = select(intra4x4typeLeft, blockVer);
|
1522 |
|
|
Bit#(1) topAvailable;
|
1523 |
|
|
Bit#(1) leftAvailable;
|
1524 |
|
|
if(topType==15 || (topType==14 && ppsconstrained_intra_pred_flag==1))
|
1525 |
|
|
topAvailable = 0;
|
1526 |
|
|
else
|
1527 |
|
|
topAvailable = 1;
|
1528 |
|
|
if(leftType==15 || (leftType==14 && ppsconstrained_intra_pred_flag==1))
|
1529 |
|
|
leftAvailable = 0;
|
1530 |
|
|
else
|
1531 |
|
|
leftAvailable = 1;
|
1532 |
|
|
if(blockNum==0 && pixelNum==0 && intraChromaFlag==0)
|
1533 |
|
|
begin
|
1534 |
|
|
intraChromaTopAvailable <= topAvailable;
|
1535 |
|
|
intraChromaLeftAvailable <= leftAvailable;
|
1536 |
|
|
end
|
1537 |
|
|
if(intrastate==Intra4x4 && intraChromaFlag==0)
|
1538 |
|
|
begin
|
1539 |
|
|
if(intraStepCount==2)
|
1540 |
|
|
begin
|
1541 |
|
|
outFlag = 1;
|
1542 |
|
|
Bit#(40) leftValSet = select(intraLeftVal,blockVer);
|
1543 |
|
|
Bit#(32) topMidValSet = select(intraTopVal,zeroExtend(blockHor));
|
1544 |
|
|
Bit#(32) topRightValSet = select(intraTopVal,{1'b0,blockHor}+1);
|
1545 |
|
|
Bit#(72) topValSet;
|
1546 |
|
|
if((blockNum[3:2]==3 && blockNum[0]==1) || blockNum[1:0]==3)
|
1547 |
|
|
topValSet = {topMidValSet[31:24],topMidValSet[31:24],topMidValSet[31:24],topMidValSet[31:24],topMidValSet,leftValSet[7:0]};
|
1548 |
|
|
else
|
1549 |
|
|
topValSet = {topRightValSet,topMidValSet,leftValSet[7:0]};
|
1550 |
|
|
$display( "TRACE Prediction: intraProcessStep intra4x4 %0d %0d %h %h", cur_intra4x4_pred_mode, blockNum, leftValSet, topValSet);////////////////////
|
1551 |
|
|
Bit#(4) topSelect1 = 0;
|
1552 |
|
|
Bit#(4) topSelect2 = 0;
|
1553 |
|
|
Bit#(4) topSelect3 = 0;
|
1554 |
|
|
Bit#(3) leftSelect1 = 0;
|
1555 |
|
|
Bit#(3) leftSelect2 = 0;
|
1556 |
|
|
Bit#(3) leftSelect3 = 0;
|
1557 |
|
|
Bit#(10) tempVal1 = 0;
|
1558 |
|
|
Bit#(10) tempVal2 = 0;
|
1559 |
|
|
Bit#(10) tempVal3 = 0;
|
1560 |
|
|
case(cur_intra4x4_pred_mode)
|
1561 |
|
|
0://vertical
|
1562 |
|
|
begin
|
1563 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1564 |
|
|
begin
|
1565 |
|
|
topSelect1 = fromInteger(pixelHor);
|
1566 |
|
|
Bit#(8) topVal = intra4x4SelectTop(topValSet,topSelect1);
|
1567 |
|
|
predVector[pixelHor] = topVal;
|
1568 |
|
|
end
|
1569 |
|
|
end
|
1570 |
|
|
1://horizontal
|
1571 |
|
|
begin
|
1572 |
|
|
leftSelect1 = zeroExtend(pixelVer);
|
1573 |
|
|
Bit#(8) leftVal = intra4x4SelectLeft(leftValSet,leftSelect1);
|
1574 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1575 |
|
|
predVector[pixelHor] = leftVal;
|
1576 |
|
|
end
|
1577 |
|
|
2://dc
|
1578 |
|
|
begin
|
1579 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1580 |
|
|
begin
|
1581 |
|
|
Bit#(10) tempTopSum = zeroExtend(topValSet[15:8])+zeroExtend(topValSet[23:16])+zeroExtend(topValSet[31:24])+zeroExtend(topValSet[39:32]) + 2;
|
1582 |
|
|
Bit#(10) tempLeftSum = zeroExtend(leftValSet[15:8])+zeroExtend(leftValSet[23:16])+zeroExtend(leftValSet[31:24])+zeroExtend(leftValSet[39:32]) + 2;
|
1583 |
|
|
Bit#(11) tempTotalSum = zeroExtend(tempTopSum)+zeroExtend(tempLeftSum);
|
1584 |
|
|
Bit#(8) topSum = tempTopSum[9:2];
|
1585 |
|
|
Bit#(8) leftSum = tempLeftSum[9:2];
|
1586 |
|
|
Bit#(8) totalSum = tempTotalSum[10:3];
|
1587 |
|
|
if(topAvailable==1 && leftAvailable==1)
|
1588 |
|
|
predVector[pixelHor] = totalSum;
|
1589 |
|
|
else if(topAvailable==1)
|
1590 |
|
|
predVector[pixelHor] = topSum;
|
1591 |
|
|
else if(leftAvailable==1)
|
1592 |
|
|
predVector[pixelHor] = leftSum;
|
1593 |
|
|
else
|
1594 |
|
|
predVector[pixelHor] = 8'b10000000;
|
1595 |
|
|
end
|
1596 |
|
|
end
|
1597 |
|
|
3://diagonal down left
|
1598 |
|
|
begin
|
1599 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1600 |
|
|
begin
|
1601 |
|
|
Bit#(4) selectNum = fromInteger(pixelHor)+zeroExtend(pixelVer);
|
1602 |
|
|
if(pixelHor==3 && pixelVer==3)
|
1603 |
|
|
begin
|
1604 |
|
|
topSelect1 = 6;
|
1605 |
|
|
topSelect2 = 7;
|
1606 |
|
|
topSelect3 = 7;
|
1607 |
|
|
end
|
1608 |
|
|
else
|
1609 |
|
|
begin
|
1610 |
|
|
topSelect1 = selectNum;
|
1611 |
|
|
topSelect2 = selectNum+1;
|
1612 |
|
|
topSelect3 = selectNum+2;
|
1613 |
|
|
end
|
1614 |
|
|
tempVal1 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1615 |
|
|
tempVal2 = zeroExtend(intra4x4SelectTop(topValSet,topSelect2));
|
1616 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect3));
|
1617 |
|
|
Bit#(10) predVal = tempVal1 + (tempVal2<<1) + tempVal3 + 2;
|
1618 |
|
|
predVector[pixelHor] = predVal[9:2];
|
1619 |
|
|
end
|
1620 |
|
|
end
|
1621 |
|
|
4://diagonal down right
|
1622 |
|
|
begin
|
1623 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1624 |
|
|
begin
|
1625 |
|
|
if(fromInteger(pixelHor) > pixelVer)
|
1626 |
|
|
begin
|
1627 |
|
|
topSelect3 = fromInteger(pixelHor)-zeroExtend(pixelVer);
|
1628 |
|
|
topSelect2 = topSelect3-1;
|
1629 |
|
|
topSelect1 = topSelect3-2;
|
1630 |
|
|
tempVal1 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1631 |
|
|
tempVal2 = zeroExtend(intra4x4SelectTop(topValSet,topSelect2));
|
1632 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect3));
|
1633 |
|
|
end
|
1634 |
|
|
else if(fromInteger(pixelHor) < pixelVer)
|
1635 |
|
|
begin
|
1636 |
|
|
leftSelect3 = zeroExtend(pixelVer)-fromInteger(pixelHor);
|
1637 |
|
|
leftSelect2 = leftSelect3-1;
|
1638 |
|
|
leftSelect1 = leftSelect3-2;
|
1639 |
|
|
tempVal1 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect1));
|
1640 |
|
|
tempVal2 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect2));
|
1641 |
|
|
tempVal3 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect3));
|
1642 |
|
|
end
|
1643 |
|
|
else
|
1644 |
|
|
begin
|
1645 |
|
|
leftSelect1 = 0;
|
1646 |
|
|
leftSelect2 = -1;
|
1647 |
|
|
topSelect1 = 0;
|
1648 |
|
|
tempVal1 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect1));
|
1649 |
|
|
tempVal2 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect2));
|
1650 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1651 |
|
|
end
|
1652 |
|
|
Bit#(10) predVal = tempVal1 + (tempVal2<<1) + tempVal3 + 2;
|
1653 |
|
|
predVector[pixelHor] = predVal[9:2];
|
1654 |
|
|
end
|
1655 |
|
|
end
|
1656 |
|
|
5://vertical right
|
1657 |
|
|
begin
|
1658 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1659 |
|
|
begin
|
1660 |
|
|
Bit#(4) tempPixelHor = fromInteger(pixelHor);
|
1661 |
|
|
Bit#(4) zVR = (tempPixelHor<<1)-zeroExtend(pixelVer);
|
1662 |
|
|
if(zVR<=6 && zVR>=0)
|
1663 |
|
|
begin
|
1664 |
|
|
topSelect3 = fromInteger(pixelHor)-zeroExtend(pixelVer>>1);
|
1665 |
|
|
topSelect2 = topSelect3-1;
|
1666 |
|
|
if(zVR==1 || zVR==3 || zVR==5)
|
1667 |
|
|
topSelect1 = topSelect3-2;
|
1668 |
|
|
else
|
1669 |
|
|
topSelect1 = topSelect3;
|
1670 |
|
|
tempVal1 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1671 |
|
|
tempVal2 = zeroExtend(intra4x4SelectTop(topValSet,topSelect2));
|
1672 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect3));
|
1673 |
|
|
end
|
1674 |
|
|
else if(zVR==-1)
|
1675 |
|
|
begin
|
1676 |
|
|
leftSelect1 = 0;
|
1677 |
|
|
leftSelect2 = -1;
|
1678 |
|
|
topSelect1 = 0;
|
1679 |
|
|
tempVal1 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect1));
|
1680 |
|
|
tempVal2 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect2));
|
1681 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1682 |
|
|
end
|
1683 |
|
|
else
|
1684 |
|
|
begin
|
1685 |
|
|
leftSelect1 = zeroExtend(pixelVer)-1;
|
1686 |
|
|
leftSelect2 = leftSelect1-1;
|
1687 |
|
|
leftSelect3 = leftSelect1-2;
|
1688 |
|
|
tempVal1 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect1));
|
1689 |
|
|
tempVal2 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect2));
|
1690 |
|
|
tempVal3 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect3));
|
1691 |
|
|
end
|
1692 |
|
|
Bit#(10) predVal = tempVal1 + (tempVal2<<1) + tempVal3 + 2;
|
1693 |
|
|
predVector[pixelHor] = predVal[9:2];
|
1694 |
|
|
end
|
1695 |
|
|
end
|
1696 |
|
|
6://horizontal down
|
1697 |
|
|
begin
|
1698 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1699 |
|
|
begin
|
1700 |
|
|
Bit#(4) tempPixelVer = zeroExtend(pixelVer);
|
1701 |
|
|
Bit#(4) zHD = (tempPixelVer<<1)-fromInteger(pixelHor);
|
1702 |
|
|
if(zHD<=6 && zHD>=0)
|
1703 |
|
|
begin
|
1704 |
|
|
leftSelect3 = zeroExtend(pixelVer)-fromInteger(pixelHor/2);
|
1705 |
|
|
leftSelect2 = leftSelect3-1;
|
1706 |
|
|
if(zHD==1 || zHD==3 || zHD==5)
|
1707 |
|
|
leftSelect1 = leftSelect3-2;
|
1708 |
|
|
else
|
1709 |
|
|
leftSelect1 = leftSelect3;
|
1710 |
|
|
tempVal1 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect1));
|
1711 |
|
|
tempVal2 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect2));
|
1712 |
|
|
tempVal3 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect3));
|
1713 |
|
|
end
|
1714 |
|
|
else if(zHD==-1)
|
1715 |
|
|
begin
|
1716 |
|
|
leftSelect1 = 0;
|
1717 |
|
|
leftSelect2 = -1;
|
1718 |
|
|
topSelect1 = 0;
|
1719 |
|
|
tempVal1 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect1));
|
1720 |
|
|
tempVal2 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect2));
|
1721 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1722 |
|
|
end
|
1723 |
|
|
else
|
1724 |
|
|
begin
|
1725 |
|
|
topSelect1 = fromInteger(pixelHor)-1;
|
1726 |
|
|
topSelect2 = topSelect1-1;
|
1727 |
|
|
topSelect3 = topSelect1-2;
|
1728 |
|
|
tempVal1 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1729 |
|
|
tempVal2 = zeroExtend(intra4x4SelectTop(topValSet,topSelect2));
|
1730 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect3));
|
1731 |
|
|
end
|
1732 |
|
|
Bit#(10) predVal = tempVal1 + (tempVal2<<1) + tempVal3 + 2;
|
1733 |
|
|
predVector[pixelHor] = predVal[9:2];
|
1734 |
|
|
end
|
1735 |
|
|
end
|
1736 |
|
|
7://vertical left
|
1737 |
|
|
begin
|
1738 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1739 |
|
|
begin
|
1740 |
|
|
topSelect1 = fromInteger(pixelHor)+zeroExtend(pixelVer>>1);
|
1741 |
|
|
topSelect2 = topSelect1+1;
|
1742 |
|
|
if(pixelVer==1 || pixelVer==3)
|
1743 |
|
|
topSelect3 = topSelect1+2;
|
1744 |
|
|
else
|
1745 |
|
|
topSelect3 = topSelect1;
|
1746 |
|
|
tempVal1 = zeroExtend(intra4x4SelectTop(topValSet,topSelect1));
|
1747 |
|
|
tempVal2 = zeroExtend(intra4x4SelectTop(topValSet,topSelect2));
|
1748 |
|
|
tempVal3 = zeroExtend(intra4x4SelectTop(topValSet,topSelect3));
|
1749 |
|
|
Bit#(10) predVal = tempVal1 + (tempVal2<<1) + tempVal3 + 2;
|
1750 |
|
|
predVector[pixelHor] = predVal[9:2];
|
1751 |
|
|
end
|
1752 |
|
|
end
|
1753 |
|
|
8://horizontal up
|
1754 |
|
|
begin
|
1755 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1756 |
|
|
begin
|
1757 |
|
|
Bit#(4) tempPixelVer = zeroExtend(pixelVer);
|
1758 |
|
|
Bit#(4) zHU = (tempPixelVer<<1)+fromInteger(pixelHor);
|
1759 |
|
|
if(zHU<=4)
|
1760 |
|
|
begin
|
1761 |
|
|
leftSelect1 = zeroExtend(pixelVer)+fromInteger(pixelHor/2);
|
1762 |
|
|
leftSelect2 = leftSelect1+1;
|
1763 |
|
|
if(zHU==1 || zHU==3)
|
1764 |
|
|
leftSelect3 = leftSelect1+2;
|
1765 |
|
|
else
|
1766 |
|
|
leftSelect3 = leftSelect1;
|
1767 |
|
|
end
|
1768 |
|
|
else
|
1769 |
|
|
begin
|
1770 |
|
|
if(zHU==5)
|
1771 |
|
|
leftSelect1 = 2;
|
1772 |
|
|
else
|
1773 |
|
|
leftSelect1 = 3;
|
1774 |
|
|
leftSelect2 = 3;
|
1775 |
|
|
leftSelect3 = 3;
|
1776 |
|
|
end
|
1777 |
|
|
tempVal1 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect1));
|
1778 |
|
|
tempVal2 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect2));
|
1779 |
|
|
tempVal3 = zeroExtend(intra4x4SelectLeft(leftValSet,leftSelect3));
|
1780 |
|
|
Bit#(10) predVal = tempVal1 + (tempVal2<<1) + tempVal3 + 2;
|
1781 |
|
|
predVector[pixelHor] = predVal[9:2];
|
1782 |
|
|
end
|
1783 |
|
|
end
|
1784 |
|
|
default: $display( "ERROR Prediction: intraProcessStep intra4x4 unknown cur_intra4x4_pred_mode");
|
1785 |
|
|
endcase
|
1786 |
|
|
end
|
1787 |
|
|
else
|
1788 |
|
|
$display( "ERROR Prediction: intraProcessStep intra4x4 unknown intraStepCount");
|
1789 |
|
|
end
|
1790 |
|
|
else if(intrastate==Intra16x16 && intraChromaFlag==0)
|
1791 |
|
|
begin
|
1792 |
|
|
//$display( "TRACE Prediction: intraProcessStep intra16x16 %0d %0d %0d %h", intra16x16_pred_mode, currMb, blockNum, select(intraTopVal,blockHor));/////////////////
|
1793 |
|
|
case(intra16x16_pred_mode)
|
1794 |
|
|
0://vertical
|
1795 |
|
|
begin
|
1796 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1797 |
|
|
begin
|
1798 |
|
|
Bit#(32) topValSet = select(intraTopVal,blockHor);
|
1799 |
|
|
Bit#(8) topVal = select32to8(topValSet,fromInteger(pixelHor));
|
1800 |
|
|
predVector[pixelHor] = topVal;
|
1801 |
|
|
end
|
1802 |
|
|
outFlag = 1;
|
1803 |
|
|
end
|
1804 |
|
|
1://horizontal
|
1805 |
|
|
begin
|
1806 |
|
|
Bit#(40) leftValSet = select(intraLeftVal,blockVer);
|
1807 |
|
|
Bit#(8) leftVal = intra4x4SelectLeft(leftValSet,zeroExtend(pixelVer));
|
1808 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1809 |
|
|
predVector[pixelHor] = leftVal;
|
1810 |
|
|
outFlag = 1;
|
1811 |
|
|
end
|
1812 |
|
|
2://dc
|
1813 |
|
|
begin
|
1814 |
|
|
case(intraStepCount)
|
1815 |
|
|
2:
|
1816 |
|
|
begin
|
1817 |
|
|
if(topAvailable == 1)
|
1818 |
|
|
begin
|
1819 |
|
|
Bit#(32) topValSet = select(intraTopVal,0);
|
1820 |
|
|
intraSumA <= zeroExtend(topValSet[7:0])+zeroExtend(topValSet[15:8])+zeroExtend(topValSet[23:16])+zeroExtend(topValSet[31:24]);
|
1821 |
|
|
end
|
1822 |
|
|
else
|
1823 |
|
|
begin
|
1824 |
|
|
intraSumA <= 0;
|
1825 |
|
|
nextIntraStepCount = 6;
|
1826 |
|
|
end
|
1827 |
|
|
end
|
1828 |
|
|
3:
|
1829 |
|
|
begin
|
1830 |
|
|
Bit#(32) topValSet = select(intraTopVal,1);
|
1831 |
|
|
intraSumA <= intraSumA+zeroExtend(topValSet[7:0])+zeroExtend(topValSet[15:8])+zeroExtend(topValSet[23:16])+zeroExtend(topValSet[31:24]);
|
1832 |
|
|
end
|
1833 |
|
|
4:
|
1834 |
|
|
begin
|
1835 |
|
|
Bit#(32) topValSet = select(intraTopVal,2);
|
1836 |
|
|
intraSumA <= intraSumA+zeroExtend(topValSet[7:0])+zeroExtend(topValSet[15:8])+zeroExtend(topValSet[23:16])+zeroExtend(topValSet[31:24]);
|
1837 |
|
|
end
|
1838 |
|
|
5:
|
1839 |
|
|
begin
|
1840 |
|
|
Bit#(32) topValSet = select(intraTopVal,3);
|
1841 |
|
|
intraSumA <= intraSumA+zeroExtend(topValSet[7:0])+zeroExtend(topValSet[15:8])+zeroExtend(topValSet[23:16])+zeroExtend(topValSet[31:24])+8;
|
1842 |
|
|
end
|
1843 |
|
|
6:
|
1844 |
|
|
begin
|
1845 |
|
|
if(leftAvailable == 1)
|
1846 |
|
|
begin
|
1847 |
|
|
Bit#(40) leftValSet = select(intraLeftVal,0);
|
1848 |
|
|
intraSumA <= intraSumA+zeroExtend(leftValSet[15:8])+zeroExtend(leftValSet[23:16])+zeroExtend(leftValSet[31:24])+zeroExtend(leftValSet[39:32]);
|
1849 |
|
|
end
|
1850 |
|
|
else
|
1851 |
|
|
nextIntraStepCount = 10;
|
1852 |
|
|
end
|
1853 |
|
|
7:
|
1854 |
|
|
begin
|
1855 |
|
|
Bit#(40) leftValSet = select(intraLeftVal,1);
|
1856 |
|
|
intraSumA <= intraSumA+zeroExtend(leftValSet[15:8])+zeroExtend(leftValSet[23:16])+zeroExtend(leftValSet[31:24])+zeroExtend(leftValSet[39:32]);
|
1857 |
|
|
end
|
1858 |
|
|
8:
|
1859 |
|
|
begin
|
1860 |
|
|
Bit#(40) leftValSet = select(intraLeftVal,2);
|
1861 |
|
|
intraSumA <= intraSumA+zeroExtend(leftValSet[15:8])+zeroExtend(leftValSet[23:16])+zeroExtend(leftValSet[31:24])+zeroExtend(leftValSet[39:32]);
|
1862 |
|
|
end
|
1863 |
|
|
9:
|
1864 |
|
|
begin
|
1865 |
|
|
Bit#(40) leftValSet = select(intraLeftVal,3);
|
1866 |
|
|
intraSumA <= intraSumA+zeroExtend(leftValSet[15:8])+zeroExtend(leftValSet[23:16])+zeroExtend(leftValSet[31:24])+zeroExtend(leftValSet[39:32])+8;
|
1867 |
|
|
end
|
1868 |
|
|
10:
|
1869 |
|
|
begin
|
1870 |
|
|
if(leftAvailable == 1 && topAvailable == 1)
|
1871 |
|
|
intraSumA <= intraSumA >> 5;
|
1872 |
|
|
else if(leftAvailable == 1 || topAvailable == 1)
|
1873 |
|
|
intraSumA <= intraSumA >> 4;
|
1874 |
|
|
else
|
1875 |
|
|
intraSumA <= 128;
|
1876 |
|
|
end
|
1877 |
|
|
11:
|
1878 |
|
|
begin
|
1879 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1880 |
|
|
predVector[pixelHor] = intraSumA[7:0];
|
1881 |
|
|
outFlag = 1;
|
1882 |
|
|
end
|
1883 |
|
|
default: $display( "ERROR Prediction: intraProcessStep intra16x16 DC unknown intraStepCount");
|
1884 |
|
|
endcase
|
1885 |
|
|
end
|
1886 |
|
|
3://plane
|
1887 |
|
|
begin
|
1888 |
|
|
if(intraStepCount == 2)
|
1889 |
|
|
begin
|
1890 |
|
|
Bit#(32) topValSet = select(intraTopVal,3);
|
1891 |
|
|
Bit#(8) topVal = select32to8(topValSet,3);
|
1892 |
|
|
Bit#(40) leftValSet = select(intraLeftVal,3);
|
1893 |
|
|
Bit#(8) leftVal = intra4x4SelectLeft(leftValSet,3);
|
1894 |
|
|
Bit#(13) tempVal = zeroExtend(topVal) + zeroExtend(leftVal);
|
1895 |
|
|
intraSumA <= tempVal << 4;
|
1896 |
|
|
intraSumB <= 0;
|
1897 |
|
|
intraSumC <= 0;
|
1898 |
|
|
end
|
1899 |
|
|
else if(intraStepCount < 11)
|
1900 |
|
|
begin
|
1901 |
|
|
Bit#(4) xyPlusOne = intraStepCount-2;
|
1902 |
|
|
Bit#(4) xyPlusEight = intraStepCount+5;
|
1903 |
|
|
Bit#(4) sixMinusXY = 9-intraStepCount;
|
1904 |
|
|
Bit#(32) topValSet1 = select(intraTopVal,xyPlusEight[3:2]);
|
1905 |
|
|
Bit#(8) topVal1 = select32to8(topValSet1,xyPlusEight[1:0]);
|
1906 |
|
|
Bit#(40) leftValSet1 = select(intraLeftVal,xyPlusEight[3:2]);
|
1907 |
|
|
Bit#(8) leftVal1 = intra4x4SelectLeft(leftValSet1,zeroExtend(xyPlusEight[1:0]));
|
1908 |
|
|
Bit#(32) topValSet2=0;
|
1909 |
|
|
Bit#(8) topVal2;
|
1910 |
|
|
Bit#(40) leftValSet2;
|
1911 |
|
|
Bit#(8) leftVal2;
|
1912 |
|
|
if(intraStepCount==10)
|
1913 |
|
|
begin
|
1914 |
|
|
leftValSet2 = select(intraLeftVal,0);
|
1915 |
|
|
leftVal2 = intra4x4SelectLeft(leftValSet2,-1);
|
1916 |
|
|
topVal2 = leftVal2;
|
1917 |
|
|
end
|
1918 |
|
|
else
|
1919 |
|
|
begin
|
1920 |
|
|
topValSet2 = select(intraTopVal,sixMinusXY[3:2]);
|
1921 |
|
|
topVal2 = select32to8(topValSet2,sixMinusXY[1:0]);
|
1922 |
|
|
leftValSet2 = select(intraLeftVal,sixMinusXY[3:2]);
|
1923 |
|
|
leftVal2 = intra4x4SelectLeft(leftValSet2,zeroExtend(sixMinusXY[1:0]));
|
1924 |
|
|
end
|
1925 |
|
|
Bit#(15) diffH = zeroExtend(topVal1) - zeroExtend(topVal2);
|
1926 |
|
|
Bit#(15) diffV = zeroExtend(leftVal1) - zeroExtend(leftVal2);
|
1927 |
|
|
intraSumB <= intraSumB + (zeroExtend(xyPlusOne) * diffH);
|
1928 |
|
|
intraSumC <= intraSumC + (zeroExtend(xyPlusOne) * diffV);
|
1929 |
|
|
end
|
1930 |
|
|
else if(intraStepCount == 11)
|
1931 |
|
|
begin
|
1932 |
|
|
Bit#(18) tempSumB = (5*signExtend(intraSumB)) + 32;
|
1933 |
|
|
Bit#(18) tempSumC = (5*signExtend(intraSumC)) + 32;
|
1934 |
|
|
intraSumB <= signExtend(tempSumB[17:6]);
|
1935 |
|
|
intraSumC <= signExtend(tempSumC[17:6]);
|
1936 |
|
|
end
|
1937 |
|
|
else if(intraStepCount == 12)
|
1938 |
|
|
begin
|
1939 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
1940 |
|
|
begin
|
1941 |
|
|
Bit#(5) positionHor = {1'b0,blockHor,fromInteger(pixelHor)};
|
1942 |
|
|
Bit#(5) positionVer = {1'b0,blockVer,pixelVer};
|
1943 |
|
|
Bit#(16) tempProductB = signExtend(intraSumB) * signExtend(positionHor-7);
|
1944 |
|
|
Bit#(16) tempProductC = signExtend(intraSumC) * signExtend(positionVer-7);
|
1945 |
|
|
Bit#(16) tempTotal = tempProductB + tempProductC + zeroExtend(intraSumA) + 16;
|
1946 |
|
|
if(tempTotal[15]==1)
|
1947 |
|
|
predVector[pixelHor] = 0;
|
1948 |
|
|
else if(tempTotal[14:5] > 255)
|
1949 |
|
|
predVector[pixelHor] = 255;
|
1950 |
|
|
else
|
1951 |
|
|
predVector[pixelHor] = tempTotal[12:5];
|
1952 |
|
|
end
|
1953 |
|
|
outFlag = 1;
|
1954 |
|
|
end
|
1955 |
|
|
else
|
1956 |
|
|
$display( "ERROR Prediction: intraProcessStep intra16x16 plane unknown intraStepCount");
|
1957 |
|
|
end
|
1958 |
|
|
endcase
|
1959 |
|
|
end
|
1960 |
|
|
else if(intraChromaFlag==1)
|
1961 |
|
|
begin
|
1962 |
|
|
//$display( "TRACE Prediction: intraProcessStep intraChroma %0d %0d %0d %0d %0d %0d %h %h %h %h %h %h %h %h",intra_chroma_pred_mode.first(),intraChromaTopAvailable,intraChromaLeftAvailable,currMb,blockNum,pixelNum,pack(intraLeftValChroma0),pack(intraTopValChroma0),pack(intraLeftValChroma1),pack(intraTopValChroma1),intraLeftValChroma0[0],intraTopValChroma0[3][15:8],intraLeftValChroma1[0],intraTopValChroma1[3][15:8]);///////////////////
|
1963 |
|
|
Vector#(9,Bit#(8)) tempLeftVec;
|
1964 |
|
|
Vector#(4,Bit#(16)) tempTopVec;
|
1965 |
|
|
if(blockNum[2] == 0)
|
1966 |
|
|
begin
|
1967 |
|
|
tempLeftVec = intraLeftValChroma0;
|
1968 |
|
|
tempTopVec = intraTopValChroma0;
|
1969 |
|
|
end
|
1970 |
|
|
else
|
1971 |
|
|
begin
|
1972 |
|
|
tempLeftVec = intraLeftValChroma1;
|
1973 |
|
|
tempTopVec = intraTopValChroma1;
|
1974 |
|
|
end
|
1975 |
|
|
case(intra_chroma_pred_mode.first())
|
1976 |
|
|
0://dc
|
1977 |
|
|
begin
|
1978 |
|
|
if(intraStepCount == 2)
|
1979 |
|
|
begin
|
1980 |
|
|
Bit#(1) useTop=0;
|
1981 |
|
|
Bit#(1) useLeft=0;
|
1982 |
|
|
if(blockNum[1:0] == 0 || blockNum[1:0] == 3)
|
1983 |
|
|
begin
|
1984 |
|
|
useTop = intraChromaTopAvailable;
|
1985 |
|
|
useLeft = intraChromaLeftAvailable;
|
1986 |
|
|
end
|
1987 |
|
|
else if(blockNum[1:0] == 1)
|
1988 |
|
|
begin
|
1989 |
|
|
if(intraChromaTopAvailable == 1)
|
1990 |
|
|
useTop = 1;
|
1991 |
|
|
else if(intraChromaLeftAvailable == 1)
|
1992 |
|
|
useLeft = 1;
|
1993 |
|
|
end
|
1994 |
|
|
else if(blockNum[1:0] == 2)
|
1995 |
|
|
begin
|
1996 |
|
|
if(intraChromaLeftAvailable == 1)
|
1997 |
|
|
useLeft = 1;
|
1998 |
|
|
else if(intraChromaTopAvailable == 1)
|
1999 |
|
|
useTop = 1;
|
2000 |
|
|
end
|
2001 |
|
|
else
|
2002 |
|
|
$display( "ERROR Prediction: intraProcessStep intraChroma dc unknown blockNum");
|
2003 |
|
|
Bit#(10) topSum;
|
2004 |
|
|
Bit#(10) leftSum;
|
2005 |
|
|
Bit#(11) totalSum;
|
2006 |
|
|
if(blockHor[0] == 0)
|
2007 |
|
|
topSum = zeroExtend(tempTopVec[0][15:8])+zeroExtend(tempTopVec[0][7:0])+zeroExtend(tempTopVec[1][15:8])+zeroExtend(tempTopVec[1][7:0])+2;
|
2008 |
|
|
else
|
2009 |
|
|
topSum = zeroExtend(tempTopVec[2][15:8])+zeroExtend(tempTopVec[2][7:0])+zeroExtend(tempTopVec[3][15:8])+zeroExtend(tempTopVec[3][7:0])+2;
|
2010 |
|
|
if(blockVer[0] == 0)
|
2011 |
|
|
leftSum = zeroExtend(tempLeftVec[1])+zeroExtend(tempLeftVec[2])+zeroExtend(tempLeftVec[3])+zeroExtend(tempLeftVec[4])+2;
|
2012 |
|
|
else
|
2013 |
|
|
leftSum = zeroExtend(tempLeftVec[5])+zeroExtend(tempLeftVec[6])+zeroExtend(tempLeftVec[7])+zeroExtend(tempLeftVec[8])+2;
|
2014 |
|
|
totalSum = zeroExtend(topSum) + zeroExtend(leftSum);
|
2015 |
|
|
if(useTop==1 && useLeft==1)
|
2016 |
|
|
intraSumA <= zeroExtend(totalSum[10:3]);
|
2017 |
|
|
else if(useTop==1)
|
2018 |
|
|
intraSumA <= zeroExtend(topSum[9:2]);
|
2019 |
|
|
else if(useLeft==1)
|
2020 |
|
|
intraSumA <= zeroExtend(leftSum[9:2]);
|
2021 |
|
|
else
|
2022 |
|
|
intraSumA <= zeroExtend(8'b10000000);
|
2023 |
|
|
end
|
2024 |
|
|
else if(intraStepCount == 3)
|
2025 |
|
|
begin
|
2026 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
2027 |
|
|
predVector[pixelHor] = intraSumA[7:0];
|
2028 |
|
|
outFlag = 1;
|
2029 |
|
|
end
|
2030 |
|
|
else
|
2031 |
|
|
$display( "ERROR Prediction: intraProcessStep intraChroma dc unknown intraStepCount");
|
2032 |
|
|
end
|
2033 |
|
|
1://horizontal
|
2034 |
|
|
begin
|
2035 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
2036 |
|
|
begin
|
2037 |
|
|
Bit#(4) tempLeftIdx = {1'b0,blockVer[0],pixelVer} + 1;
|
2038 |
|
|
predVector[pixelHor] = select(tempLeftVec,tempLeftIdx);
|
2039 |
|
|
end
|
2040 |
|
|
outFlag = 1;
|
2041 |
|
|
end
|
2042 |
|
|
2://vertical
|
2043 |
|
|
begin
|
2044 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
2045 |
|
|
begin
|
2046 |
|
|
Bit#(2) pixelHorTemp = fromInteger(pixelHor);
|
2047 |
|
|
Bit#(16) tempTopVal = select(tempTopVec,{blockHor[0],pixelHorTemp[1]});
|
2048 |
|
|
if(pixelHorTemp[0] == 0)
|
2049 |
|
|
predVector[pixelHor] = tempTopVal[7:0];
|
2050 |
|
|
else
|
2051 |
|
|
predVector[pixelHor] = tempTopVal[15:8];
|
2052 |
|
|
end
|
2053 |
|
|
outFlag = 1;
|
2054 |
|
|
end
|
2055 |
|
|
3://plane
|
2056 |
|
|
begin
|
2057 |
|
|
if(intraStepCount == 2)
|
2058 |
|
|
begin
|
2059 |
|
|
Bit#(16) topValSet = tempTopVec[3];
|
2060 |
|
|
Bit#(8) topVal = topValSet[15:8];
|
2061 |
|
|
Bit#(8) leftVal = tempLeftVec[8];
|
2062 |
|
|
Bit#(13) tempVal = zeroExtend(topVal) + zeroExtend(leftVal);
|
2063 |
|
|
intraSumA <= tempVal << 4;
|
2064 |
|
|
intraSumB <= 0;
|
2065 |
|
|
intraSumC <= 0;
|
2066 |
|
|
end
|
2067 |
|
|
else if(intraStepCount < 7)
|
2068 |
|
|
begin
|
2069 |
|
|
Bit#(3) xyPlusOne = truncate(intraStepCount)-2;
|
2070 |
|
|
Bit#(3) xyPlusFour = truncate(intraStepCount)+1;
|
2071 |
|
|
Bit#(4) twoMinusXY = 5-intraStepCount;
|
2072 |
|
|
Bit#(16) topValSet1 = select(tempTopVec,xyPlusFour[2:1]);
|
2073 |
|
|
Bit#(8) topVal1 = select16to8(topValSet1,xyPlusFour[0]);
|
2074 |
|
|
Bit#(4) tempLeftIdx1 = {1'b0,xyPlusFour} + 1;
|
2075 |
|
|
Bit#(8) leftVal1 = select(tempLeftVec,tempLeftIdx1);
|
2076 |
|
|
|
2077 |
|
|
Bit#(16) topValSet2 = select(tempTopVec,twoMinusXY[2:1]);
|
2078 |
|
|
Bit#(8) topVal2;
|
2079 |
|
|
Bit#(8) leftVal2 = select(tempLeftVec,twoMinusXY+1);
|
2080 |
|
|
if(intraStepCount==6)
|
2081 |
|
|
topVal2 = leftVal2;
|
2082 |
|
|
else
|
2083 |
|
|
topVal2 = select16to8(topValSet2,twoMinusXY[0]);
|
2084 |
|
|
Bit#(15) diffH = zeroExtend(topVal1) - zeroExtend(topVal2);
|
2085 |
|
|
Bit#(15) diffV = zeroExtend(leftVal1) - zeroExtend(leftVal2);
|
2086 |
|
|
intraSumB <= intraSumB + (zeroExtend(xyPlusOne) * diffH);
|
2087 |
|
|
intraSumC <= intraSumC + (zeroExtend(xyPlusOne) * diffV);
|
2088 |
|
|
Int#(15) tempDisplayH = unpack(zeroExtend(xyPlusOne) * diffH);
|
2089 |
|
|
Int#(15) tempDisplayV = unpack(zeroExtend(xyPlusOne) * diffV);
|
2090 |
|
|
//$display( "TRACE Prediction: intraProcessStep intraChroma plane partH partV %0d %0d",tempDisplayH,tempDisplayV);////////////////////
|
2091 |
|
|
end
|
2092 |
|
|
else if(intraStepCount == 7)
|
2093 |
|
|
begin
|
2094 |
|
|
Int#(15) tempDisplayH = unpack(intraSumB);
|
2095 |
|
|
Int#(15) tempDisplayV = unpack(intraSumC);
|
2096 |
|
|
//$display( "TRACE Prediction: intraProcessStep intraChroma plane H V %0d %0d",tempDisplayH,tempDisplayV);////////////////////
|
2097 |
|
|
Bit#(19) tempSumB = (34*signExtend(intraSumB)) + 32;
|
2098 |
|
|
Bit#(19) tempSumC = (34*signExtend(intraSumC)) + 32;
|
2099 |
|
|
intraSumB <= signExtend(tempSumB[18:6]);
|
2100 |
|
|
intraSumC <= signExtend(tempSumC[18:6]);
|
2101 |
|
|
end
|
2102 |
|
|
else if(intraStepCount == 8)
|
2103 |
|
|
begin
|
2104 |
|
|
for(Integer pixelHor=0; pixelHor<4; pixelHor=pixelHor+1)
|
2105 |
|
|
begin
|
2106 |
|
|
Bit#(4) positionHor = {1'b0,blockHor[0],fromInteger(pixelHor)};
|
2107 |
|
|
Bit#(4) positionVer = {1'b0,blockVer[0],pixelVer};
|
2108 |
|
|
Bit#(17) tempProductB = signExtend(intraSumB) * signExtend(positionHor-3);
|
2109 |
|
|
Bit#(17) tempProductC = signExtend(intraSumC) * signExtend(positionVer-3);
|
2110 |
|
|
Bit#(17) tempTotal = tempProductB + tempProductC + zeroExtend(intraSumA) + 16;
|
2111 |
|
|
if(tempTotal[16]==1)
|
2112 |
|
|
predVector[pixelHor] = 0;
|
2113 |
|
|
else if(tempTotal[15:5] > 255)
|
2114 |
|
|
predVector[pixelHor] = 255;
|
2115 |
|
|
else
|
2116 |
|
|
predVector[pixelHor] = tempTotal[12:5];
|
2117 |
|
|
end
|
2118 |
|
|
outFlag = 1;
|
2119 |
|
|
end
|
2120 |
|
|
else
|
2121 |
|
|
$display( "ERROR Prediction: intraProcessStep intraChroma plane unknown intraStepCount");
|
2122 |
|
|
end
|
2123 |
|
|
endcase
|
2124 |
|
|
end
|
2125 |
|
|
else
|
2126 |
|
|
$display( "ERROR Prediction: intraProcessStep unknown intrastate");
|
2127 |
|
|
|
2128 |
|
|
if(outFlag==1)
|
2129 |
|
|
begin
|
2130 |
|
|
predictedfifo.enq(predVector);
|
2131 |
|
|
pixelNum <= pixelNum+4;
|
2132 |
|
|
if(pixelNum == 12)
|
2133 |
|
|
begin
|
2134 |
|
|
if(intraChromaFlag==0)
|
2135 |
|
|
begin
|
2136 |
|
|
blockNum <= blockNum+1;
|
2137 |
|
|
if(blockNum == 15)
|
2138 |
|
|
begin
|
2139 |
|
|
intraChromaFlag <= 1;
|
2140 |
|
|
intraStepCount <= 2;
|
2141 |
|
|
end
|
2142 |
|
|
else if(intrastate==Intra4x4)
|
2143 |
|
|
intraStepCount <= 1;
|
2144 |
|
|
end
|
2145 |
|
|
else
|
2146 |
|
|
begin
|
2147 |
|
|
if(blockNum == 7)
|
2148 |
|
|
begin
|
2149 |
|
|
blockNum <= 0;
|
2150 |
|
|
intraChromaFlag <= 0;
|
2151 |
|
|
intraStepCount <= 0;
|
2152 |
|
|
intra_chroma_pred_mode.deq();
|
2153 |
|
|
end
|
2154 |
|
|
else
|
2155 |
|
|
begin
|
2156 |
|
|
blockNum <= blockNum+1;
|
2157 |
|
|
if(intra_chroma_pred_mode.first()==0)
|
2158 |
|
|
intraStepCount <= 2;
|
2159 |
|
|
else if(blockNum==3)
|
2160 |
|
|
intraStepCount <= 2;
|
2161 |
|
|
end
|
2162 |
|
|
end
|
2163 |
|
|
end
|
2164 |
|
|
end
|
2165 |
|
|
else
|
2166 |
|
|
intraStepCount <= nextIntraStepCount;
|
2167 |
|
|
//$display( "Trace Prediction: intraProcessStep");
|
2168 |
|
|
endrule
|
2169 |
|
|
|
2170 |
|
|
|
2171 |
|
|
|
2172 |
|
|
interface Client mem_client_intra;
|
2173 |
|
|
interface Get request = fifoToGet(intraMemReqQ);
|
2174 |
|
|
interface Put response = fifoToPut(intraMemRespQ);
|
2175 |
|
|
endinterface
|
2176 |
|
|
interface Client mem_client_inter;
|
2177 |
|
|
interface Get request = fifoToGet(interMemReqQ);
|
2178 |
|
|
interface Put response = fifoToPut(interMemRespQ);
|
2179 |
|
|
endinterface
|
2180 |
|
|
interface Client mem_client_buffer = interpolator.mem_client;
|
2181 |
|
|
|
2182 |
|
|
interface Put ioin = fifoToPut(infifo);
|
2183 |
|
|
interface Put ioin_InverseTrans = fifoToPut(infifo_ITB);
|
2184 |
|
|
interface Get ioout = fifoToGet(outfifo);
|
2185 |
|
|
|
2186 |
|
|
|
2187 |
|
|
endmodule
|
2188 |
|
|
|
2189 |
|
|
endpackage
|