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

Subversion Repositories bluespec-h264

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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