OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [LumaChromaParallel/] [mkPrediction.bsv] - Blame information for rev 100

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.