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

Subversion Repositories bluespec-h264

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

powered by: WebSVN 2.1.0

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