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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [release/] [mkInverseTrans.bsv] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 85 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 84 jamey.hick
//**********************************************************************
23
// Inverse Quantizer and Inverse Transformer implementation
24
//----------------------------------------------------------------------
25
//
26
//
27
 
28
package mkInverseTrans;
29
 
30
import H264Types::*;
31
 
32
import IInverseTrans::*;
33
import FIFO::*;
34
import Vector::*;
35
 
36
import Connectable::*;
37
import GetPut::*;
38
import ClientServer::*;
39
 
40
 
41
//-----------------------------------------------------------
42
// Local Datatypes
43
//-----------------------------------------------------------
44
 
45
typedef union tagged
46
{
47
 void     Start;            //not working on anything in particular
48
 void     Intra16x16DC;
49
 void     Intra16x16;
50
 void     ChromaDC;
51
 void     Chroma;
52
 void     Regular4x4;
53
}
54
State deriving(Eq,Bits);
55
 
56
typedef union tagged
57
{
58
 void     Passing;          //not working on anything in particular
59
 void     LoadingDC;
60
 void     Scaling;          //does not include scaling for DC (just loading in that case)
61
 void     TransformingDC;
62
 void     ScalingDC;
63
}
64
Process deriving(Eq,Bits);
65
 
66
typedef union tagged
67
{
68
 void     Invalid;
69
 void     Zeros;
70
 Vector#(16,Bit#(16)) Values;
71
}
72
PipeType deriving(Eq,Bits);
73
 
74
 
75
//-----------------------------------------------------------
76
// Helper functions
77
 
78
function Bit#(6) qpi_to_qpc( Bit#(6) qpi );//mapping from qpi to qpc
79
   case ( qpi )
80
      30: return 29;
81
      31: return 30;
82
      32: return 31;
83
      33: return 32;
84
      34: return 32;
85
      35: return 33;
86
      36: return 34;
87
      37: return 34;
88
      38: return 35;
89
      39: return 35;
90
      40: return 36;
91
      41: return 36;
92
      42: return 37;
93
      43: return 37;
94
      44: return 37;
95
      45: return 38;
96
      46: return 38;
97
      47: return 38;
98
      48: return 39;
99
      49: return 39;
100
      50: return 39;
101
      51: return 39;
102
      default: return qpi;
103
   endcase
104
endfunction
105
 
106
 
107
function Bit#(4) reverseInverseZigZagScan( Bit#(4) idx );
108
   case ( idx )
109
      0: return 15;
110
      1: return 14;
111
      2: return 11;
112
      3: return 7;
113
      4: return 10;
114
      5: return 13;
115
      6: return 12;
116
      7: return 9;
117
      8: return 6;
118
      9: return 3;
119
      10: return 2;
120
      11: return 5;
121
      12: return 8;
122
      13: return 4;
123
      14: return 1;
124
      15: return 0;
125
   endcase
126
endfunction
127
 
128
 
129
function Tuple2#(Bit#(4),Bit#(3)) qpdivmod6( Bit#(6) qp );
130
   Bit#(6) tempqp = qp;
131
   Bit#(4) tempdiv = 0;
132
   for(Integer ii=5; ii>=2; ii=ii-1)
133
      begin
134
         if(tempqp >= (6'b000011 << (fromInteger(ii)-1)))
135
            begin
136
               tempqp = tempqp - (6'b000011 << (fromInteger(ii)-1));
137
               tempdiv = tempdiv | (4'b0001 << (fromInteger(ii)-2));
138
            end
139
      end
140
   return tuple2(tempdiv,truncate(tempqp));
141
endfunction
142
 
143
 
144
function Vector#(4,Bit#(16)) dcTransFunc( Bit#(16) in0, Bit#(16) in1, Bit#(16) in2, Bit#(16) in3 );
145
   Vector#(4,Bit#(16)) resultVector = replicate(0);
146
   resultVector[0] = in0 + in1 + in2 + in3;
147
   resultVector[1] = in0 + in1 - in2 - in3;
148
   resultVector[2] = in0 - in1 - in2 + in3;
149
   resultVector[3] = in0 - in1 + in2 - in3;
150
   return resultVector;
151
endfunction
152
 
153
 
154
function Vector#(4,Bit#(16)) transFunc( Bit#(16) in0, Bit#(16) in1, Bit#(16) in2, Bit#(16) in3 );
155
   Vector#(4,Bit#(16)) resultVector = replicate(0);
156
   Bit#(16) workValue0 = in0 + in2;
157
   Bit#(16) workValue1 = in0 - in2;
158
   Bit#(16) workValue2 = signedShiftRight(in1,1) - in3;
159
   Bit#(16) workValue3 = in1 + signedShiftRight(in3,1);
160
   resultVector[0] = workValue0 + workValue3;
161
   resultVector[1] = workValue1 + workValue2;
162
   resultVector[2] = workValue1 - workValue2;
163
   resultVector[3] = workValue0 - workValue3;
164
   return resultVector;
165
endfunction
166
 
167
 
168
//-----------------------------------------------------------
169
// Inverse Quantizer and Inverse Transformer Module
170
//-----------------------------------------------------------
171
 
172
 
173
(* synthesize *)
174
module mkInverseTrans( IInverseTrans );
175
 
176
   FIFO#(EntropyDecOT_InverseTrans) infifo  <- mkSizedFIFO(inverseTrans_infifo_size);
177
   FIFO#(InverseTransOT)            outfifo <- mkFIFO;
178
   Reg#(Bit#(4))       blockNum <- mkReg(0);
179
   Reg#(Bit#(4))       pixelNum <- mkReg(0);//also used as a regular counter during inverse transformation
180
   Reg#(State)         state    <- mkReg(Start);
181
   Reg#(Process)       process  <- mkReg(Passing);
182
 
183
   Reg#(Bit#(5))        chroma_qp_index_offset <- mkReg(0);
184
   Reg#(Bit#(6))        ppspic_init_qp <- mkReg(0);
185
   Reg#(Bit#(6))        slice_qp       <- mkReg(0);
186
   Reg#(Bit#(6))        qpy            <- mkReg(0);//Calculating it requires 8 bits, but value only 0 to 51
187
   Reg#(Bit#(6))        qpc            <- mkReg(0);
188
   Reg#(Bit#(3))        qpymod6        <- mkReg(0);
189
   Reg#(Bit#(3))        qpcmod6        <- mkReg(0);
190
   Reg#(Bit#(4))        qpydiv6        <- mkReg(0);
191
   Reg#(Bit#(4))        qpcdiv6        <- mkReg(0);
192
 
193
   Reg#(Vector#(16,Bit#(16))) storeVector <- mkRegU();
194
   Reg#(Vector#(16,Bit#(16))) workVector  <- mkRegU();
195
   Reg#(PipeType)             work2Vector <- mkReg(Invalid);
196
   Reg#(PipeType)             work3Vector <- mkReg(Invalid);
197
   Reg#(Bool)                 stage1Zeros <- mkReg(False);
198
   Reg#(Bool)                 stage1Done  <- mkReg(False);
199
   Reg#(Bool)                 stage2Done  <- mkReg(False);
200
   Reg#(Bool)                 stage3Done  <- mkReg(False);
201
   Reg#(Bit#(3))              stage2Step  <- mkReg(0);
202
   Reg#(Bit#(2))              stage3Step  <- mkReg(0);
203
 
204
 
205
 
206
   //-----------------------------------------------------------
207
   // Rules
208
 
209
 
210
   rule passing (process==Passing && work2Vector==Invalid && (stage3Done || work3Vector==Invalid) );
211
      //$display( "Trace Inverse Trans: passing infifo packed %h", pack(infifo.first()));
212
      case (infifo.first()) matches
213
         tagged NewUnit . xdata :
214
            begin
215
               infifo.deq();
216
               $display("ccl3newunit");
217
               $display("ccl3rbspbyte %h", xdata);
218
            end
219
         tagged SDMmbtype .xdata :
220
            begin
221
               infifo.deq();
222
               $display( "INFO InverseTrans: SDMmbtype %0d", xdata);
223
               if(mbPartPredMode(xdata,0) == Intra_16x16)
224
                  state <= Intra16x16DC;
225
               else
226
                  state <= Regular4x4;
227
            end
228
         tagged PPSpic_init_qp .xdata :
229
            begin
230
               infifo.deq();
231
               ppspic_init_qp <= truncate(xdata);
232
            end
233
         tagged SHslice_qp_delta .xdata :
234
            begin
235
               infifo.deq();
236
               slice_qp <= ppspic_init_qp+truncate(xdata);
237
               Bit#(6) qpynext = ppspic_init_qp+truncate(xdata);
238
               qpy <= qpynext;
239
               Bit#(7) qpitemp = zeroExtend(chroma_qp_index_offset+12) + zeroExtend(qpynext);
240
               Bit#(6) qpi;
241
               if(qpitemp < 12)
242
                  qpi = 0;
243
               else if(qpitemp > 63)
244
                  qpi = 51;
245
               else
246
                  qpi = truncate(qpitemp-12);
247
               qpc <= qpi_to_qpc(qpi);
248
               outfifo.enq(IBTmb_qp {qpy:qpynext,qpc:qpi_to_qpc(qpi)});
249
            end
250
         tagged SDMmb_qp_delta .xdata :
251
            begin
252
               infifo.deq();
253
               Bit#(8) qpytemp = zeroExtend(qpy) + zeroExtend(xdata+52);
254
               Bit#(6) qpynext;
255
               if(qpytemp >= 104)
256
                  qpynext = truncate(qpytemp - 104);
257
               else if(qpytemp >= 52)
258
                  qpynext = truncate(qpytemp - 52);
259
               else
260
                  qpynext = truncate(qpytemp);
261
               qpy <= qpynext;
262
 
263
               //$display( "TRACE InverseTrans: qpy %0d", qpynext );
264
               //$display( "TRACE InverseTrans: qpy %0d", qpynext );
265
               Tuple2#(Bit#(4),Bit#(3)) temptuple = qpdivmod6(qpynext);
266
               qpydiv6 <= tpl_1(temptuple);
267
               qpymod6 <= tpl_2(temptuple);
268
               //$display( "TRACE InverseTrans: qpydiv6 %0d", tpl_1(temptuple) );
269
               //$display( "TRACE InverseTrans: qpymod6 %0d", tpl_2(temptuple) );
270
 
271
               Bit#(7) qpitemp = zeroExtend(chroma_qp_index_offset+12) + zeroExtend(qpynext);
272
               Bit#(6) qpi;
273
               if(qpitemp < 12)
274
                  qpi = 0;
275
               else if(qpitemp > 63)
276
                  qpi = 51;
277
               else
278
                  qpi = truncate(qpitemp-12);
279
               qpc <= qpi_to_qpc(qpi);
280
               outfifo.enq(IBTmb_qp {qpy:qpynext,qpc:qpi_to_qpc(qpi)});
281
            end
282
         tagged PPSchroma_qp_index_offset .xdata :
283
            begin
284
               infifo.deq();
285
               chroma_qp_index_offset <= xdata;
286
            end
287
         tagged SDMRcoeffLevelPlusZeros .xdata :
288
            begin
289
               blockNum <= 0;
290
               pixelNum <= 0;
291
               if(state == Intra16x16DC)
292
                  begin
293
                     $display( "INFO InverseTrans: 16x16 MB" );
294
                     process <= LoadingDC;
295
                  end
296
               else
297
                  begin
298
                     $display( "INFO InverseTrans: Non-16x16 MB" );
299
                     process <= Scaling;
300
                  end
301
               workVector <= replicate(0);
302
               Tuple2#(Bit#(4),Bit#(3)) temptuple = qpdivmod6(qpc);
303
               qpcdiv6 <= tpl_1(temptuple);
304
               qpcmod6 <= tpl_2(temptuple);
305
            end
306
         tagged SDMRcoeffLevelZeros .xdata :
307
            begin
308
               blockNum <= 0;
309
               pixelNum <= 0;
310
               if(state == Intra16x16DC)
311
                  begin
312
                     $display( "INFO InverseTrans: 16x16 MB" );
313
                     process <= LoadingDC;
314
                  end
315
               else
316
                  begin
317
                     $display( "INFO InverseTrans: Non-16x16 MB" );
318
                     process <= Scaling;
319
                  end
320
               workVector <= replicate(0);
321
               Tuple2#(Bit#(4),Bit#(3)) temptuple = qpdivmod6(qpc);
322
               qpcdiv6 <= tpl_1(temptuple);
323
               qpcmod6 <= tpl_2(temptuple);
324
            end
325
         default: infifo.deq();
326
      endcase
327
   endrule
328
 
329
 
330
   rule loadingDC (process matches LoadingDC);
331
      Vector#(16,Bit#(16)) workVectorTemp = workVector;
332
 
333
      case (infifo.first()) matches
334
         tagged SDMRcoeffLevelZeros .xdata :
335
            begin
336
               infifo.deq();
337
               pixelNum <= pixelNum+truncate(xdata);
338
               if((state==ChromaDC && zeroExtend(pixelNum)+xdata==8) || zeroExtend(pixelNum)+xdata==16)
339
                  process <= TransformingDC;
340
               else if((state==ChromaDC && zeroExtend(pixelNum)+xdata>8) || zeroExtend(pixelNum)+xdata>16)
341
                  $display( "ERROR InverseTrans: loadingDC index overflow" );
342
            end
343
         tagged SDMRcoeffLevelPlusZeros .xdata :
344
            begin
345
               infifo.deq();
346
               Bit#(16) workValue = signExtend(xdata.level);
347
               if(state==ChromaDC)
348
                  begin
349
                     if(pixelNum<4)
350
                        workVector <= update(workVectorTemp, 3-pixelNum, workValue);
351
                     else
352
                        workVector <= update(workVectorTemp, 11-pixelNum, workValue);
353
                  end
354
               else
355
                  workVector <= update(workVectorTemp, reverseInverseZigZagScan(pixelNum), workValue);
356
               pixelNum <= pixelNum+1+truncate(xdata.zeros);
357
               if((state==ChromaDC && zeroExtend(pixelNum)+1+xdata.zeros==8) || zeroExtend(pixelNum)+1+xdata.zeros==16)
358
                  process <= TransformingDC;
359
               else if((state==ChromaDC && zeroExtend(pixelNum)+1+xdata.zeros>8) || zeroExtend(pixelNum)+1+xdata.zeros>16)
360
                  $display( "ERROR InverseTrans: loadingDC index overflow" );
361
            end
362
         default: process <= Passing;
363
      endcase
364
   endrule
365
 
366
 
367
   rule transformingDC (process matches TransformingDC);
368
      Vector#(16,Bit#(16)) workVectorTemp = workVector;
369
      Vector#(16,Bit#(16)) workVectorNew = workVector;
370
      Vector#(16,Bit#(16)) storeVectorTemp = storeVector;
371
 
372
      if(state == ChromaDC)
373
         begin
374
            case ( pixelNum )
375
               8:
376
               begin
377
                  workVectorNew[0] = workVectorTemp[0] + workVectorTemp[2];
378
                  workVectorNew[1] = workVectorTemp[1] + workVectorTemp[3];
379
                  workVectorNew[2] = workVectorTemp[0] - workVectorTemp[2];
380
                  workVectorNew[3] = workVectorTemp[1] - workVectorTemp[3];
381
                  pixelNum <= pixelNum+1;
382
               end
383
               9:
384
               begin
385
                  workVectorNew[0] = workVectorTemp[0] + workVectorTemp[1];
386
                  workVectorNew[1] = workVectorTemp[0] - workVectorTemp[1];
387
                  workVectorNew[2] = workVectorTemp[2] + workVectorTemp[3];
388
                  workVectorNew[3] = workVectorTemp[2] - workVectorTemp[3];
389
                  pixelNum <= pixelNum+1;
390
               end
391
               10:
392
               begin
393
                  workVectorNew[4] = workVectorTemp[4] + workVectorTemp[6];
394
                  workVectorNew[5] = workVectorTemp[5] + workVectorTemp[7];
395
                  workVectorNew[6] = workVectorTemp[4] - workVectorTemp[6];
396
                  workVectorNew[7] = workVectorTemp[5] - workVectorTemp[7];
397
                  pixelNum <= pixelNum+1;
398
               end
399
               11:
400
               begin
401
                  workVectorNew[4] = workVectorTemp[4] + workVectorTemp[5];
402
                  workVectorNew[5] = workVectorTemp[4] - workVectorTemp[5];
403
                  workVectorNew[6] = workVectorTemp[6] + workVectorTemp[7];
404
                  workVectorNew[7] = workVectorTemp[6] - workVectorTemp[7];
405
                  pixelNum <= 0;
406
                  process <= ScalingDC;
407
               end
408
               default:
409
                  $display( "ERROR InverseTrans: transformingDC ChromaDC unexpected pixelNum" );
410
            endcase
411
            workVector <= workVectorNew;
412
         end
413
      else if(state == Intra16x16DC)
414
         begin
415
            Vector#(4,Bit#(16)) resultVector = replicate(0);
416
            if(pixelNum < 4)
417
               begin
418
                  Bit#(4) tempIndex = zeroExtend(pixelNum[1:0]);
419
                  resultVector = dcTransFunc( workVectorTemp[tempIndex], workVectorTemp[tempIndex+4], workVectorTemp[tempIndex+8], workVectorTemp[tempIndex+12] );
420
                  for(Integer ii=0; ii<4; ii=ii+1)
421
                     workVectorNew[tempIndex+fromInteger(ii*4)] = resultVector[ii];
422
               end
423
            else if(pixelNum < 8)
424
               begin
425
                  Bit#(4) tempIndex = {pixelNum[1:0],2'b00};
426
                  resultVector = dcTransFunc( workVectorTemp[tempIndex], workVectorTemp[tempIndex+1], workVectorTemp[tempIndex+2], workVectorTemp[tempIndex+3] );
427
                  for(Integer ii=0; ii<4; ii=ii+1)
428
                     workVectorNew[tempIndex+fromInteger(ii)] = resultVector[ii];
429
               end
430
            else
431
               $display( "ERROR InverseTrans: transforming Intra16x16DC unexpected pixelNum" );
432
            workVector <= workVectorNew;
433
            if(pixelNum == 7)
434
               begin
435
                  pixelNum <= 0;
436
                  process <= ScalingDC;
437
               end
438
            else
439
               pixelNum <= pixelNum+1;
440
         end
441
      else
442
         $display( "ERROR InverseTrans: transformingDC unexpected state" );
443
   endrule
444
 
445
 
446
   rule scalingDC (process matches ScalingDC);
447
      Bit#(6)  qp;
448
      Bit#(4)  qpdiv6;
449
      Bit#(3)  qpmod6;
450
      Bit#(6)  workOne = 1;
451
      Bit#(16) workValue;
452
      Bit#(22) storeValueTemp;
453
      Bit#(16) storeValue;
454
      Vector#(16,Bit#(16)) workVectorTemp = workVector;
455
      Vector#(16,Bit#(16)) storeVectorTemp = storeVector;
456
 
457
      if(state==ChromaDC)
458
         begin
459
            qp = qpc;
460
            qpdiv6 = qpcdiv6;
461
            qpmod6 = qpcmod6;
462
         end
463
      else
464
         begin
465
            qp = qpy;
466
            qpdiv6 = qpydiv6;
467
            qpmod6 = qpymod6;
468
         end
469
      workValue = select(workVectorTemp, pixelNum);
470
      Bit#(5) levelScaleValue=0;
471
      case(qpmod6)
472
         0: levelScaleValue = 10;
473
         1: levelScaleValue = 11;
474
         2: levelScaleValue = 13;
475
         3: levelScaleValue = 14;
476
         4: levelScaleValue = 16;
477
         5: levelScaleValue = 18;
478
         default: $display( "ERROR InverseTrans: scalingDC levelScaleGen case default" );
479
      endcase
480
      storeValueTemp = zeroExtend(levelScaleValue)*signExtend(workValue);
481
      if(state==ChromaDC)
482
         storeValue = truncate( (storeValueTemp << zeroExtend(qpdiv6)) >> 1 );
483
      else
484
         begin
485
            if(qp >= 36)
486
               storeValue = truncate( storeValueTemp << zeroExtend(qpdiv6 - 2) );
487
            else
488
               storeValue = truncate( ((storeValueTemp << 4) + zeroExtend(workOne << zeroExtend(5-qpdiv6))) >> zeroExtend(6 - qpdiv6) );
489
         end
490
      storeVector <= update(storeVectorTemp, pixelNum, storeValue);
491
      if((state==ChromaDC && pixelNum==7) || pixelNum==15)
492
         begin
493
            blockNum <= 0;
494
            pixelNum <= 0;
495
            workVector <= replicate(0);
496
            if(state==ChromaDC)
497
               state <= Chroma;
498
            else
499
               state <= Intra16x16;
500
            process <= Scaling;
501
         end
502
      else if((state==ChromaDC && pixelNum>7) || pixelNum>15)
503
         $display( "ERROR InverseTrans: scalingDC index overflow" );
504
      else
505
         pixelNum <= pixelNum+1;
506
   endrule
507
 
508
 
509
   rule switching ( (stage1Done && work2Vector==Invalid) || (stage2Done && (stage3Done || work3Vector==Invalid)) );
510
      Bool switch2to3 = False;
511
      if(stage2Done && (stage3Done || work3Vector==Invalid))
512
         begin
513
            switch2to3 = True;
514
            work3Vector <= work2Vector;
515
            stage3Done <= False;
516
         end
517
      if(stage1Done && (switch2to3 || work2Vector==Invalid))
518
         begin
519
            Vector#(16,Bit#(16)) workVectorTemp = workVector;
520
            if(state==Intra16x16)
521
               workVectorTemp[0] = storeVector[{blockNum[3],blockNum[1],blockNum[2],blockNum[0]}];
522
            else if(state==Chroma)
523
               workVectorTemp[0] = storeVector[blockNum];
524
            if(stage1Zeros)
525
               work2Vector <= Zeros;
526
            else
527
               work2Vector <= (tagged Values workVectorTemp);
528
            stage1Zeros <= False;
529
            stage1Done <= False;
530
            workVector <= replicate(0);
531
            if(state==Chroma)
532
               begin
533
                  if(blockNum<7)
534
                     blockNum <= blockNum+1;
535
                  else if (blockNum==7)
536
                     begin
537
                        blockNum <= 0;
538
                        process <= Passing;
539
                     end
540
                  else
541
                     $display( "ERROR InverseTrans: switching chroma unexpected blockNum" );
542
               end
543
            else
544
               begin
545
                  blockNum <= blockNum+1;
546
                  if(blockNum==15)
547
                     begin
548
                        state <= ChromaDC;
549
                        process <= LoadingDC;
550
                     end
551
                  else
552
                     process <= Scaling;
553
               end
554
         end
555
      else //switch2to3==True
556
         work2Vector <= Invalid;
557
      stage2Done <= False;
558
   endrule
559
 
560
 
561
   rule scaling (process==Scaling && !stage1Done );
562
      Vector#(16,Bit#(16)) workVectorTemp = workVector;
563
      Vector#(16,Bit#(16)) storeVectorTemp = storeVector;
564
 
565
      case (infifo.first()) matches
566
         tagged SDMRcoeffLevelZeros .xdata :
567
            begin
568
               infifo.deq();
569
               if(zeroExtend(pixelNum)+xdata==16 || (zeroExtend(pixelNum)+xdata==15 && (state==Chroma || state==Intra16x16)))
570
                  begin
571
                     Bit#(16) prevValue0=0;
572
                     if(state==Intra16x16)
573
                        prevValue0 = select(storeVectorTemp, {blockNum[3],blockNum[1],blockNum[2],blockNum[0]});
574
                     else if(state==Chroma)
575
                        prevValue0 = select(storeVectorTemp, blockNum);
576
                     if(xdata==16 || (xdata==15 && (state==Chroma || state==Intra16x16) && prevValue0==0))
577
                        stage1Zeros <= True;
578
                     stage1Done <= True;
579
                     pixelNum <= 0;
580
                  end
581
               else if(zeroExtend(pixelNum)+xdata>16 || (zeroExtend(pixelNum)+xdata>15 && (state==Chroma || state==Intra16x16)))
582
                  $display( "ERROR InverseTrans: scaling index overflow" );
583
               else
584
                  pixelNum <= pixelNum+truncate(xdata);
585
               //$display( "TRACE InverseTrans: coeff zeros %0d", xdata );
586
            end
587
         tagged SDMRcoeffLevelPlusZeros .xdata :
588
            begin
589
               infifo.deq();
590
               Bit#(6)  qp;
591
               Bit#(4)  qpdiv6;
592
               Bit#(3)  qpmod6;
593
               if(state==Chroma)
594
                  begin
595
                     qp = qpc;
596
                     qpdiv6 = qpcdiv6;
597
                     qpmod6 = qpcmod6;
598
                  end
599
               else
600
                  begin
601
                     qp = qpy;
602
                     qpdiv6 = qpydiv6;
603
                     qpmod6 = qpymod6;
604
                  end
605
               Bit#(5) levelScaleValue=0;
606
               if(pixelNum==15 || pixelNum==12 || pixelNum==10 || pixelNum==4)
607
                  begin
608
                     case(qpmod6)
609
                        0: levelScaleValue = 10;
610
                        1: levelScaleValue = 11;
611
                        2: levelScaleValue = 13;
612
                        3: levelScaleValue = 14;
613
                        4: levelScaleValue = 16;
614
                        5: levelScaleValue = 18;
615
                        default: $display( "ERROR InverseTrans: levelScaleGen case default" );
616
                     endcase
617
                  end
618
               else if(pixelNum==11 || pixelNum==5 || pixelNum==3 || pixelNum==0)
619
                  begin
620
                     case(qpmod6)
621
                        0: levelScaleValue = 16;
622
                        1: levelScaleValue = 18;
623
                        2: levelScaleValue = 20;
624
                        3: levelScaleValue = 23;
625
                        4: levelScaleValue = 25;
626
                        5: levelScaleValue = 29;
627
                        default: $display( "ERROR InverseTrans: levelScaleGen case default" );
628
                     endcase
629
                  end
630
               else
631
                  begin
632
                     case(qpmod6)
633
                        0: levelScaleValue = 13;
634
                        1: levelScaleValue = 14;
635
                        2: levelScaleValue = 16;
636
                        3: levelScaleValue = 18;
637
                        4: levelScaleValue = 20;
638
                        5: levelScaleValue = 23;
639
                        default: $display( "ERROR InverseTrans: levelScaleGen case default" );
640
                     endcase
641
                  end
642
               Bit#(16) workValueTemp = zeroExtend(levelScaleValue)*signExtend(xdata.level);
643
               Bit#(16) workValue;
644
               workValue = workValueTemp << zeroExtend(qpdiv6);
645
               workVector <= update(workVectorTemp, reverseInverseZigZagScan(pixelNum), workValue);
646
               if(zeroExtend(pixelNum)+1+xdata.zeros==16 || (zeroExtend(pixelNum)+1+xdata.zeros==15 && (state==Chroma || state==Intra16x16)))
647
                  begin
648
                     stage1Done <= True;
649
                     pixelNum <= 0;
650
                  end
651
               else if(zeroExtend(pixelNum)+1+xdata.zeros>16 || (zeroExtend(pixelNum)+1+xdata.zeros>15 && (state==Chroma || state==Intra16x16)))
652
                  $display( "ERROR InverseTrans: scaling index overflow" );
653
               else
654
                  pixelNum <= pixelNum+1+truncate(xdata.zeros);
655
            end
656
         default: process <= Passing;
657
      endcase
658
   endrule
659
 
660
 
661
   rule transforming ( work2Vector!=Invalid && !stage2Done );
662
      if(work2Vector matches tagged Values .xdata)
663
         begin
664
            Vector#(16,Bit#(16)) work2VectorNew = xdata;
665
            if(stage2Step < 4)
666
               begin
667
                  Bit#(4) tempIndex = {stage2Step[1:0],2'b00};
668
                  Vector#(4,Bit#(16)) resultVector = transFunc( xdata[tempIndex], xdata[tempIndex+1], xdata[tempIndex+2], xdata[tempIndex+3] );
669
                  for(Integer ii=0; ii<4; ii=ii+1)
670
                     work2VectorNew[tempIndex+fromInteger(ii)] = resultVector[ii];
671
               end
672
            else
673
               begin
674
                  Bit#(4) tempIndex = zeroExtend(stage2Step[1:0]);
675
                  Vector#(4,Bit#(16)) resultVector = transFunc( xdata[tempIndex], xdata[tempIndex+4], xdata[tempIndex+8], xdata[tempIndex+12] );
676
                  for(Integer ii=0; ii<4; ii=ii+1)
677
                     work2VectorNew[tempIndex+fromInteger(ii*4)] = resultVector[ii];
678
               end
679
            work2Vector <= (tagged Values work2VectorNew);
680
            if(stage2Step == 7)
681
               stage2Done <= True;
682
            stage2Step <= stage2Step+1;
683
         end
684
      else //All Zeros
685
         stage2Done <= True;
686
   endrule
687
 
688
 
689
   rule outputing ( work3Vector!=Invalid && !stage3Done );
690
      if(work3Vector matches tagged Values .xdata)
691
         begin
692
            Vector#(4,Bit#(10)) outputVector = replicate(0);
693
            for(Integer ii=0; ii<4; ii=ii+1)
694
               outputVector[ii] = truncate((xdata[{stage3Step,2'b00}+fromInteger(ii)]+32) >> 6);
695
            outfifo.enq(tagged ITBresidual outputVector);
696
            Int#(10) tempint = unpack(outputVector[0]);
697
            $display("ccl3IBTresidual %0d", tempint);
698
            tempint = unpack(outputVector[1]);
699
            $display("ccl3IBTresidual %0d", tempint);
700
            tempint = unpack(outputVector[2]);
701
            $display("ccl3IBTresidual %0d", tempint);
702
            tempint = unpack(outputVector[3]);
703
            $display("ccl3IBTresidual %0d", tempint);
704
            if(stage3Step == 3)
705
               stage3Done <= True;
706
            stage3Step <= stage3Step+1;
707
         end
708
      else
709
         begin
710
            outfifo.enq(ITBcoeffLevelZeros);
711
            stage3Done <= True;
712
         end
713
   endrule
714
 
715
 
716
 
717
   interface Put ioin  = fifoToPut(infifo);
718
   interface Get ioout = fifoToGet(outfifo);
719
 
720
 
721
endmodule
722
 
723
endpackage

powered by: WebSVN 2.1.0

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