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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src/] [mkInterpolator.bsv] - Blame information for rev 70

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamey.hick
//**********************************************************************
2
// interpolator implementation
3
//----------------------------------------------------------------------
4
//
5
//
6
 
7
 
8
import H264Types::*;
9
import IInterpolator::*;
10
import FIFO::*;
11
import Vector::*;
12
 
13
import Connectable::*;
14
import GetPut::*;
15
import ClientServer::*;
16
 
17
 
18
//-----------------------------------------------------------
19
// Local Datatypes
20
//-----------------------------------------------------------
21
 
22
typedef union tagged
23
{
24
 struct { Bit#(2) xFracL; Bit#(2) yFracL; Bit#(2) offset; IPBlockType bt; } IPWLuma;
25
 struct { Bit#(3) xFracC; Bit#(3) yFracC; Bit#(2) offset; IPBlockType bt; } IPWChroma;
26
}
27
InterpolatorWT deriving(Eq,Bits);
28
 
29
 
30 60 jamey.hick
 
31
 
32 2 jamey.hick
//-----------------------------------------------------------
33
// Helper functions
34
 
35
function Bit#(8) clip1y10to8( Bit#(10) innum );
36
   if(innum[9] == 1)
37
      return 0;
38
   else if(innum[8] == 1)
39
      return 255;
40
   else
41
      return truncate(innum);
42
endfunction
43
 
44 70 jamey.hick
interface Interpolate8to15;
45
  method Bit#(15) interpolate(Bit#(8) in0, Bit#(8) in1, Bit#(8) in2, Bit#(8) in3, Bit#(8) in4, Bit#(8) in5);
46
endinterface
47 2 jamey.hick
 
48 70 jamey.hick
module mkInterpolate8to15 (Interpolate8to15);
49
   method Bit#(15) interpolate( Bit#(8) in0, Bit#(8) in1, Bit#(8) in2, Bit#(8) in3, Bit#(8) in4, Bit#(8) in5 );
50
     return zeroExtend(in0) - 5*zeroExtend(in1) + 20*zeroExtend(in2) + 20*zeroExtend(in3) - 5*zeroExtend(in4) + zeroExtend(in5);
51
   endmethod
52
endmodule
53 2 jamey.hick
 
54
 
55 70 jamey.hick
interface Interpolate15to8;
56
  method Bit#(8) interpolate( Bit#(15) in0, Bit#(15) in1, Bit#(15) in2, Bit#(15) in3, Bit#(15) in4, Bit#(15) in5 );
57
endinterface
58 2 jamey.hick
 
59 70 jamey.hick
module mkInterpolate15to8 (Interpolate15to8);
60
  method Bit#(8) interpolate( Bit#(15) in0, Bit#(15) in1, Bit#(15) in2, Bit#(15) in3, Bit#(15) in4, Bit#(15) in5 );
61
    Bit#(20) temp = signExtend(in0) - 5*signExtend(in1) + 20*signExtend(in2) + 20*signExtend(in3) - 5*signExtend(in4) + signExtend(in5) + 512;
62
    return clip1y10to8(truncate(temp>>10));
63
  endmethod
64
endmodule
65
 
66
 
67
 
68 2 jamey.hick
//-----------------------------------------------------------
69
// Interpolation Module
70
//-----------------------------------------------------------
71
 
72
 
73
(* synthesize *)
74
module mkInterpolator( Interpolator );
75
 
76 60 jamey.hick
   FIFO#(InterpolatorIT) reqfifoLoad <- mkSizedFIFO(interpolator_reqfifoLoad_size);  // This fifo takes in motion vector
77
                                                                                     // pixel requests.
78
   FIFO#(InterpolatorWT) reqfifoWork1 <- mkSizedFIFO(interpolator_reqfifoWork_size); // This is where the memory responses
79
                                                                                     // come from
80 70 jamey.hick
 
81
   Interpolate15to8 interpolate15to8 <- mkInterpolate15to8();
82
   Interpolate8to15 interpolate8to15 <- mkInterpolate8to15();
83 2 jamey.hick
   Reg#(Maybe#(InterpolatorWT)) reqregWork2 <- mkReg(Invalid);
84
   FIFO#(Vector#(4,Bit#(8))) outfifo <- mkFIFO;
85
   Reg#(Bool) endOfFrameFlag <- mkReg(False);
86
   FIFO#(InterpolatorLoadReq)  memReqQ  <- mkFIFO;
87
   FIFO#(InterpolatorLoadResp) memRespQ <- mkSizedFIFO(interpolator_memRespQ_size);
88
 
89
   Reg#(Bit#(PicWidthSz))  picWidth  <- mkReg(maxPicWidthInMB);
90
   Reg#(Bit#(PicHeightSz)) picHeight <- mkReg(0);
91
 
92
   RFile1#(Bit#(6),Vector#(4,Bit#(15))) workFile  <- mkRFile1Full();
93
   RFile1#(Bit#(6),Vector#(4,Bit#(8)))  storeFile <- mkRFile1Full();
94
   Reg#(Bit#(1)) workFileFlag <- mkReg(0);
95
   RFile1#(Bit#(4),Vector#(4,Bit#(8))) resultFile <- mkRFile1Full();
96
 
97
   Reg#(Bit#(1)) loadStage  <- mkReg(0);
98
   Reg#(Bit#(2)) loadHorNum <- mkReg(0);
99
   Reg#(Bit#(4)) loadVerNum <- mkReg(0);
100
 
101
   Reg#(Bit#(2)) work1MbPart    <- mkReg(0);//only for Chroma
102
   Reg#(Bit#(2)) work1SubMbPart <- mkReg(0);//only for Chroma
103
   Reg#(Bit#(1)) work1Stage     <- mkReg(0);
104
   Reg#(Bit#(2)) work1HorNum    <- mkReg(0);
105
   Reg#(Bit#(4)) work1VerNum    <- mkReg(0);
106
   Reg#(Vector#(20,Bit#(8))) work1Vector8 <- mkRegU;
107
   Reg#(Bool) work1Done <- mkReg(False);
108
 
109
   Reg#(Bit#(2)) work2SubMbPart <- mkReg(0);
110
   Reg#(Bit#(2)) work2HorNum    <- mkReg(0);
111
   Reg#(Bit#(4)) work2VerNum    <- mkReg(0);
112
   Reg#(Vector#(20,Bit#(8))) work2Vector8 <- mkRegU;
113
   Reg#(Vector#(20,Bit#(15))) work2Vector15 <- mkRegU;
114
   Reg#(Vector#(16,Bit#(1))) resultReady <- mkReg(replicate(0));
115
   Reg#(Bool) work2Done <- mkReg(False);
116
   Reg#(Bool) work8x8Done <- mkReg(False);
117
 
118
   Reg#(Bit#(2)) outBlockNum <- mkReg(0);
119
   Reg#(Bit#(2)) outPixelNum <- mkReg(0);
120
   Reg#(Bool) outDone <- mkReg(False);
121
 
122
 
123
   rule sendEndOfFrameReq( endOfFrameFlag );
124
      endOfFrameFlag <= False;
125
      memReqQ.enq(IPLoadEndFrame);
126
   endrule
127
 
128
 
129
   rule loadLuma( reqfifoLoad.first() matches tagged IPLuma .reqdata &&& !endOfFrameFlag );
130
      Bit#(2) xfracl = reqdata.mvhor[1:0];
131
      Bit#(2) yfracl = reqdata.mvver[1:0];
132
      Bit#(2) offset = reqdata.mvhor[3:2];
133
      Bool twoStage = (xfracl==1||xfracl==3) && (yfracl==1||yfracl==3);
134
      Bool horInter = (twoStage ? loadStage==1 : xfracl!=0);
135
      Bool verInter = (twoStage ? loadStage==0 : yfracl!=0);
136
      Bit#(2) offset2 = reqdata.mvhor[3:2] + ((twoStage&&verInter&&xfracl==3) ? 1 : 0);
137
      Bit#(1) horOut = 0;
138
      Bit#(TAdd#(PicWidthSz,2)) horAddr;
139
      Bit#(TAdd#(PicHeightSz,4)) verAddr;
140
      Bit#(TAdd#(PicWidthSz,12)) horTemp = zeroExtend({reqdata.hor,2'b00}) + zeroExtend({loadHorNum,2'b00}) + (xfracl==3&&(yfracl==1||yfracl==3)&&loadStage==0 ? 1 : 0);
141
      Bit#(TAdd#(PicHeightSz,10)) verTemp = zeroExtend(reqdata.ver) + zeroExtend(loadVerNum) + (yfracl==3&&(xfracl==1||xfracl==3)&&loadStage==1 ? 1 : 0);
142
      Bit#(13) mvhortemp = signExtend(reqdata.mvhor[13:2])-(horInter?2:0);
143
      Bit#(11) mvvertemp = signExtend(reqdata.mvver[11:2])-(verInter?2:0);
144
      if(mvhortemp[12]==1 && zeroExtend(0-mvhortemp)>horTemp)
145
         begin
146
            horAddr = 0;
147
            horOut = 1;
148
         end
149
      else
150
         begin
151
            horTemp = horTemp + signExtend(mvhortemp);
152
            if(horTemp>=zeroExtend({picWidth,4'b0000}))
153
               begin
154
                  horAddr = {picWidth-1,2'b11};
155
                  horOut = 1;
156
               end
157
            else
158
               horAddr = truncate(horTemp>>2);
159
         end
160
      if(mvvertemp[10]==1 && zeroExtend(0-mvvertemp)>verTemp)
161
         verAddr = 0;
162
      else
163
         begin
164
            verTemp = verTemp + signExtend(mvvertemp);
165
            if(verTemp>=zeroExtend({picHeight,4'b0000}))
166
               verAddr = {picHeight-1,4'b1111};
167
            else
168
               verAddr = truncate(verTemp);
169
         end
170
      memReqQ.enq(IPLoadLuma {refIdx:reqdata.refIdx,horOutOfBounds:horOut,hor:horAddr,ver:verAddr});
171
      Bool verFirst = twoStage || (yfracl==2&&(xfracl==1||xfracl==3));
172
      Bit#(2) loadHorNumMax = (reqdata.bt==IP8x8||reqdata.bt==IP8x4 ? 1 : 0) + (horInter ? 2 : (offset2==0 ? 0 : 1));
173
      Bit#(4) loadVerNumMax = (reqdata.bt==IP8x8||reqdata.bt==IP4x8 ? 7 : 3) + (verInter ? 5 : 0);
174 60 jamey.hick
      // It would appear that we are collecting memory requests here, or at least we're adjusting
175
      // the memory addresses.
176 2 jamey.hick
      if(verFirst)
177
         begin
178
            if(loadVerNum < loadVerNumMax)
179
               loadVerNum <= loadVerNum+1;
180
            else
181
               begin
182
                  loadVerNum <= 0;
183
                  if(loadHorNum < loadHorNumMax)
184
                     begin
185
                        if(loadStage == 1)
186
                           begin
187
                              offset = offset + (xfracl==3 ? 1 : 0);
188
                              if(!(offset==1 || (xfracl==3 && offset==2)))
189
                                 loadHorNum <= loadHorNumMax;
190
                              else
191
                                 begin
192
                                    loadHorNum <= 0;
193
                                    loadStage <= 0;
194
                                    reqfifoLoad.deq();
195
                                 end
196
                           end
197
                        else
198
                           loadHorNum <= loadHorNum+1;
199
                     end
200
                  else
201
                     begin
202
                        if(twoStage && loadStage==0)
203
                           begin
204
                              offset = offset + (xfracl==3 ? 1 : 0);
205
                              if((xfracl==3 ? offset<3 : offset<2))
206
                                 loadHorNum <= 0;
207
                              else
208
                                 loadHorNum <= loadHorNumMax+1;
209
                              loadStage <= 1;
210
                           end
211
                        else
212
                           begin
213
                              loadHorNum <= 0;
214
                              loadStage <= 0;
215
                              reqfifoLoad.deq();
216
                           end
217
                     end
218
               end
219
         end
220
      else
221
         begin
222
            if(loadHorNum < loadHorNumMax)
223
               loadHorNum <= loadHorNum+1;
224
            else
225
               begin
226
                  loadHorNum <= 0;
227
                  if(loadVerNum < loadVerNumMax)
228
                     loadVerNum <= loadVerNum+1;
229
                  else
230
                     begin
231
                        loadVerNum <= 0;
232
                        reqfifoLoad.deq();
233
                     end
234
               end
235
         end
236
      if(reqdata.bt==IP16x16 || reqdata.bt==IP16x8 || reqdata.bt==IP8x16)
237
         $display( "ERROR Interpolation: loadLuma block sizes > 8x8 not supported");
238 70 jamey.hick
      $display( "Trace interpolator: loadLuma xfrac: %h yfrac: %h Hor: %h Ver: %h refIdx: %h HorAddr:%h VerAddr%h", xfracl, yfracl, loadHorNum, loadVerNum, reqdata.refIdx, horAddr, verAddr);
239 2 jamey.hick
   endrule
240
 
241
 
242
   rule loadChroma( reqfifoLoad.first() matches tagged IPChroma .reqdata &&& !endOfFrameFlag );
243
      Bit#(3) xfracc = reqdata.mvhor[2:0];
244
      Bit#(3) yfracc = reqdata.mvver[2:0];
245
      Bit#(2) offset = reqdata.mvhor[4:3]+{reqdata.hor[0],1'b0};
246
      Bit#(1) horOut = 0;
247
      Bit#(TAdd#(PicWidthSz,1)) horAddr;
248
      Bit#(TAdd#(PicHeightSz,3)) verAddr;
249
      Bit#(TAdd#(PicWidthSz,11)) horTemp = zeroExtend({reqdata.hor,1'b0}) + zeroExtend({loadHorNum,2'b00});
250
      Bit#(TAdd#(PicHeightSz,9)) verTemp = zeroExtend(reqdata.ver) + zeroExtend(loadVerNum);
251
      if(reqdata.mvhor[13]==1 && zeroExtend(0-reqdata.mvhor[13:3])>horTemp)
252
         begin
253
            horAddr = 0;
254
            horOut = 1;
255
         end
256
      else
257
         begin
258
            horTemp = horTemp + signExtend(reqdata.mvhor[13:3]);
259
            if(horTemp>=zeroExtend({picWidth,3'b000}))
260
               begin
261
                  horAddr = {picWidth-1,1'b1};
262
                  horOut = 1;
263
               end
264
            else
265
               horAddr = truncate(horTemp>>2);
266
         end
267 60 jamey.hick
 
268 2 jamey.hick
      if(reqdata.mvver[11]==1 && zeroExtend(0-reqdata.mvver[11:3])>verTemp)
269
         verAddr = 0;
270
      else
271
         begin
272
            verTemp = verTemp + signExtend(reqdata.mvver[11:3]);
273
            if(verTemp>=zeroExtend({picHeight,3'b000}))
274
               verAddr = {picHeight-1,3'b111};
275
            else
276
               verAddr = truncate(verTemp);
277
         end
278 60 jamey.hick
 
279 2 jamey.hick
      memReqQ.enq(IPLoadChroma {refIdx:reqdata.refIdx,uv:reqdata.uv,horOutOfBounds:horOut,hor:horAddr,ver:verAddr});
280
      Bit#(2) loadHorNumMax = (reqdata.bt==IP4x8||reqdata.bt==IP4x4 ? (offset[1]==0||(xfracc==0&&offset!=3) ? 0 : 1) : ((reqdata.bt==IP16x16||reqdata.bt==IP16x8 ? 1 : 0) + (xfracc==0&&offset==0 ? 0 : 1)));
281
      Bit#(4) loadVerNumMax = (reqdata.bt==IP16x16||reqdata.bt==IP8x16 ? 7 : (reqdata.bt==IP16x8||reqdata.bt==IP8x8||reqdata.bt==IP4x8 ? 3 : 1)) + (yfracc==0 ? 0 : 1);
282
      if(loadHorNum < loadHorNumMax)
283
         loadHorNum <= loadHorNum+1;
284
      else
285
         begin
286
            loadHorNum <= 0;
287
            if(loadVerNum < loadVerNumMax)
288
               loadVerNum <= loadVerNum+1;
289
            else
290
               begin
291
                  loadVerNum <= 0;
292
                  reqfifoLoad.deq();
293
               end
294
         end
295 70 jamey.hick
      $display( "Trace interpolator: loadChroma xfrac: %h yfrac: %h Hor: %h Ver: %h refIdx: %h horAddr: %h verAddr: %h", xfracc, yfracc, loadHorNum, loadVerNum, reqdata.refIdx, horAddr, verAddr);
296 2 jamey.hick
   endrule
297
 
298
 
299
   rule work1Luma ( reqfifoWork1.first() matches tagged IPWLuma .reqdata &&& !work1Done );
300
      let xfracl = reqdata.xFracL;
301
      let yfracl = reqdata.yFracL;
302
      let offset = reqdata.offset;
303
      let blockT = reqdata.bt;
304 60 jamey.hick
      Bool twoStage = (xfracl==1||xfracl==3) && (yfracl==1||yfracl==3); // are we dealing with a quarter sample
305
      Vector#(20,Bit#(8)) work1Vector8Next = work1Vector8; // This must die.
306 2 jamey.hick
      if(memRespQ.first() matches tagged IPLoadResp .tempreaddata)
307
         begin
308
            memRespQ.deq();
309
            Vector#(4,Bit#(8)) readdata = replicate(0);
310
            readdata[0] = tempreaddata[7:0];
311
            readdata[1] = tempreaddata[15:8];
312
            readdata[2] = tempreaddata[23:16];
313
            readdata[3] = tempreaddata[31:24];
314
            //$display( "Trace interpolator: workLuma stage 0 readdata %h %h %h %h %h %h", workHorNum, workVerNum, readdata[3], readdata[2], readdata[1], readdata[0] );
315
            Vector#(4,Bit#(8)) tempResult8 = replicate(0);
316
            Vector#(4,Bit#(15)) tempResult15 = replicate(0);
317
            if(xfracl==0 || yfracl==0 || xfracl==2)
318
               begin
319
                  if(xfracl==0)//reorder
320
                     begin
321
                        for(Integer ii=0; ii<4; ii=ii+1)
322
                           begin
323
                              Bit#(2) offsetplusii = offset+fromInteger(ii);
324
                              if(offset <= 3-fromInteger(ii) && offset!=0)
325
                                 tempResult8[ii] = work1Vector8[offsetplusii];
326
                              else
327
                                 tempResult8[ii] = readdata[offsetplusii];
328
                              work1Vector8Next[ii] = readdata[ii];
329
                           end
330
                        for(Integer ii=0; ii<4; ii=ii+1)
331
                           tempResult15[ii] = zeroExtend({tempResult8[ii],5'b00000});
332
                     end
333
                  else//horizontal interpolation
334
                     begin
335
                        offset = offset-2;
336
                        for(Integer ii=0; ii<8; ii=ii+1)
337
                           work1Vector8Next[ii] = work1Vector8[ii+4];
338
                        for(Integer ii=0; ii<4; ii=ii+1)
339
                           begin
340
                              Bit#(4) tempIndex = fromInteger(ii) + 8 - zeroExtend(offset);
341
                              work1Vector8Next[tempIndex] = readdata[ii];
342
                           end
343 60 jamey.hick
                        for(Integer ii=0; ii<4; ii=ii+1) // horizontal filtration step.
344 2 jamey.hick
                           begin
345 70 jamey.hick
                              tempResult15[ii] = interpolate8to15.interpolate(work1Vector8Next[ii],work1Vector8Next[ii+1],work1Vector8Next[ii+2],work1Vector8Next[ii+3],work1Vector8Next[ii+4],work1Vector8Next[ii+5]);
346 2 jamey.hick
                              tempResult8[ii] = clip1y10to8(truncate((tempResult15[ii]+16)>>5));
347 60 jamey.hick
                              if(xfracl == 1) // Seems to be averaging the quarter samples.
348 2 jamey.hick
                                 tempResult8[ii] = truncate(({1'b0,tempResult8[ii]} + {1'b0,work1Vector8Next[ii+2]} + 1) >> 1);
349
                              else if(xfracl == 3)
350
                                 tempResult8[ii] = truncate(({1'b0,tempResult8[ii]} + {1'b0,work1Vector8Next[ii+3]} + 1) >> 1);
351
                           end
352
                     end
353
                  Bit#(2) workHorNumOffset = (xfracl!=0 ? 2 : (reqdata.offset==0 ? 0 : 1));
354
                  if(work1HorNum >= workHorNumOffset)
355
                     begin
356
                        Bit#(1) horAddr = truncate(work1HorNum-workHorNumOffset);
357
                        if(yfracl == 0)
358
                           begin
359
                              for(Integer ii=0; ii<4; ii=ii+1)
360
                                 tempResult15[ii] = zeroExtend({tempResult8[ii],5'b00000});
361
                           end
362
                        workFile.upd({workFileFlag,work1VerNum,horAddr},tempResult15);
363
                     end
364
                  Bit#(2) workHorNumMax = (blockT==IP8x8||blockT==IP8x4 ? 1 : 0) + workHorNumOffset;
365
                  Bit#(4) workVerNumMax = (blockT==IP8x8||blockT==IP4x8 ? 7 : 3) + (yfracl!=0 ? 5 : 0);
366
                  if(work1HorNum < workHorNumMax)
367
                     work1HorNum <= work1HorNum+1;
368
                  else
369
                     begin
370
                        work1HorNum <= 0;
371
                        if(work1VerNum < workVerNumMax)
372
                           work1VerNum <= work1VerNum+1;
373
                        else
374
                           begin
375
                              work1VerNum <= 0;
376
                              work1Done <= True;
377
                           end
378
                     end
379
               end
380
            else if(work1Stage == 0)//vertical interpolation
381
               begin
382
                  offset = offset + (xfracl==3&&(yfracl==1||yfracl==3) ? 1 : 0);
383 60 jamey.hick
                  for(Integer ii=0; ii<4; ii=ii+1) // apply the horizontal filtration step.
384 70 jamey.hick
                     tempResult15[ii] = interpolate8to15.interpolate(work1Vector8[ii],work1Vector8[ii+4],work1Vector8[ii+8],work1Vector8[ii+12],work1Vector8[ii+16],readdata[ii]);
385 60 jamey.hick
                  for(Integer ii=0; ii<16; ii=ii+1) // advances the work vector
386
                     work1Vector8Next[ii] = work1Vector8[ii+4];
387
                  for(Integer ii=0; ii<4; ii=ii+1) // assigns the new work vector value
388 2 jamey.hick
                     work1Vector8Next[ii+16] = readdata[ii];
389
                  Bit#(2) workHorNumMax = (blockT==IP8x8||blockT==IP8x4 ? 1 : 0) + (yfracl==2 ? 2 : (offset==0 ? 0 : 1));
390
                  Bit#(4) workVerNumMax = (blockT==IP8x8||blockT==IP4x8 ? 7 : 3) + 5;
391
                  Bit#(2) horAddr = work1HorNum;
392
                  Bit#(3) verAddr = truncate(work1VerNum-5);
393
                  if(work1VerNum > 4)
394
                     begin
395
                        workFile.upd({workFileFlag,verAddr,horAddr},tempResult15);
396
                        //$display( "Trace interpolator: workLuma stage 0 result %h %h %h %h %h %h %h", workHorNum, workVerNum, {verAddr,horAddr}, tempResult15[3], tempResult15[2], tempResult15[1], tempResult15[0]);
397
                     end
398
                  if(twoStage)
399
                     begin
400
                        Bit#(2) storeHorAddr = work1HorNum;
401
                        Bit#(4) storeVerAddr = work1VerNum;
402
                        if((xfracl==3 ? offset<3 : offset<2))
403
                           storeHorAddr = storeHorAddr+1;
404
                        if(yfracl==3)
405
                           storeVerAddr = storeVerAddr-3;
406
                        else
407
                           storeVerAddr = storeVerAddr-2;
408
                        if(storeVerAddr < 8)
409
                           storeFile.upd({workFileFlag,storeVerAddr[2:0],storeHorAddr},readdata);
410
                     end
411
                  if(work1VerNum < workVerNumMax)
412
                     work1VerNum <= work1VerNum+1;
413
                  else
414
                     begin
415
                        work1VerNum <= 0;
416
                        if(work1HorNum < workHorNumMax)
417
                           work1HorNum <= work1HorNum+1;
418
                        else
419
                           begin
420
                              if(twoStage)
421
                                 begin
422
                                    work1Stage <= 1;
423
                                    if((xfracl==3 ? offset<3 : offset<2))
424
                                       work1HorNum <= 0;
425
                                    else
426
                                       work1HorNum <= workHorNumMax+1;
427
                                 end
428
                              else
429
                                 begin
430
                                    work1HorNum <= 0;
431
                                    work1Done <= True;
432
                                 end
433
                           end
434
                     end
435
               end
436
            else//second stage of twoStage
437
               begin
438
                  storeFile.upd({workFileFlag,work1VerNum[2:0],work1HorNum},readdata);
439
                  Bit#(2) workHorNumMax = (blockT==IP8x8||blockT==IP8x4 ? 1 : 0) + 2;
440
                  Bit#(4) workVerNumMax = (blockT==IP8x8||blockT==IP4x8 ? 7 : 3);
441
                  if(work1VerNum < workVerNumMax)
442
                     work1VerNum <= work1VerNum+1;
443
                  else
444
                     begin
445
                        work1VerNum <= 0;
446
                        offset = offset + (xfracl==3 ? 1 : 0);
447
                        if(work1HorNum
448
                           work1HorNum <= workHorNumMax;
449
                        else
450
                           begin
451
                              work1HorNum <= 0;
452
                              work1Stage <= 0;
453
                              work1Done <= True;
454
                           end
455
                     end
456
               end
457
         end
458
      work1Vector8 <= work1Vector8Next;
459 70 jamey.hick
      $display( "Trace interpolator: work1Luma xfrac: %h yfrac: %h horNum: %h verNum: %h offset: %h workStage: %h", xfracl, yfracl, work1HorNum, work1VerNum, offset, work1Stage);
460 2 jamey.hick
   endrule
461
 
462
 
463
   rule work2Luma ( reqregWork2 matches tagged Valid .vdata &&& vdata matches tagged IPWLuma .reqdata &&& !work2Done &&& !work8x8Done );
464
      let xfracl = reqdata.xFracL;
465
      let yfracl = reqdata.yFracL;
466
      let offset = reqdata.offset;
467
      let blockT = reqdata.bt;
468
      Vector#(20,Bit#(8)) work2Vector8Next = work2Vector8;
469
      Vector#(20,Bit#(15)) work2Vector15Next = work2Vector15;
470
      Vector#(16,Bit#(1)) resultReadyNext = resultReady;
471
      Vector#(4,Bit#(8)) tempResult8 = replicate(0);
472
      Vector#(4,Bit#(15)) readdata = replicate(0);
473
      if(yfracl==0)
474
         begin
475 19 jamey.hick
            readdata = workFile.sub({(1-workFileFlag),1'b0,work2VerNum[1],work2HorNum,work2VerNum[0]});
476 2 jamey.hick
            for(Integer ii=0; ii<4; ii=ii+1)
477
               tempResult8[ii] = (readdata[ii])[12:5];
478
            resultFile.upd({work2VerNum[1],work2HorNum,work2VerNum[0]},tempResult8);
479
            resultReadyNext[{work2VerNum[1],work2HorNum,work2VerNum[0]}] = 1;
480
            work2HorNum <= work2HorNum+1;
481
            if(work2HorNum == 3)
482
               begin
483
                  if(work2VerNum == 3)
484
                     begin
485
                        work2VerNum <= 0;
486
                        work2Done <= True;
487
                        if(((blockT==IP4x8 || blockT==IP8x4) && work2SubMbPart==0) || (blockT==IP4x4 && work2SubMbPart<3))
488
                           work2SubMbPart <= work2SubMbPart+1;
489
                        else
490
                           begin
491
                              work2SubMbPart <= 0;
492
                              work8x8Done <= True;
493
                           end
494
                     end
495
                  else
496
                     work2VerNum <= work2VerNum+1;
497
               end
498
         end
499
      else if(xfracl==0 || xfracl==2)//vertical interpolation
500
         begin
501 19 jamey.hick
            readdata = workFile.sub({(1-workFileFlag),work2VerNum,work2HorNum[0]});
502 2 jamey.hick
            for(Integer ii=0; ii<4; ii=ii+1)
503
               begin
504 70 jamey.hick
                  tempResult8[ii] = interpolate15to8.interpolate(work2Vector15[ii],work2Vector15[ii+4],work2Vector15[ii+8],work2Vector15[ii+12],work2Vector15[ii+16],readdata[ii]);
505 2 jamey.hick
                  if(yfracl == 1)
506
                     tempResult8[ii] = truncate(({1'b0,tempResult8[ii]} + {1'b0,clip1y10to8(truncate((work2Vector15[ii+8]+16)>>5))} + 1) >> 1);
507
                  else if(yfracl == 3)
508
                     tempResult8[ii] = truncate(({1'b0,tempResult8[ii]} + {1'b0,clip1y10to8(truncate((work2Vector15[ii+12]+16)>>5))} + 1) >> 1);
509
               end
510
            for(Integer ii=0; ii<16; ii=ii+1)
511
               work2Vector15Next[ii] = work2Vector15[ii+4];
512
            for(Integer ii=0; ii<4; ii=ii+1)
513
               work2Vector15Next[ii+16] = readdata[ii];
514
            Bit#(2) workHorNumMax = 1;
515
            Bit#(4) workVerNumMax = (blockT==IP8x8||blockT==IP4x8 ? 7 : 3) + 5;
516
            if(work2VerNum > 4)
517
               begin
518
                  Bit#(1) horAddr = truncate(work2HorNum);
519
                  Bit#(3) verAddr = truncate(work2VerNum-5);
520
                  horAddr = horAddr + ((blockT==IP4x8&&work2SubMbPart==1)||(blockT==IP4x4&&work2SubMbPart[0]==1) ? 1 : 0);
521
                  verAddr = verAddr + ((blockT==IP8x4&&work2SubMbPart==1)||(blockT==IP4x4&&work2SubMbPart[1]==1) ? 4 : 0);
522
                  resultFile.upd({verAddr,horAddr},tempResult8);
523
                  resultReadyNext[{verAddr,horAddr}] = 1;
524
               end
525
            if(work2VerNum < workVerNumMax)
526
               work2VerNum <= work2VerNum+1;
527
            else
528
               begin
529
                  work2VerNum <= 0;
530
                  if(work2HorNum < workHorNumMax)
531
                     work2HorNum <= work2HorNum+1;
532
                  else
533
                     begin
534
                        work2HorNum <= 0;
535
                        work2Done <= True;
536
                        if(((blockT==IP4x8 || blockT==IP8x4) && work2SubMbPart==0) || (blockT==IP4x4 && work2SubMbPart<3))
537
                           work2SubMbPart <= work2SubMbPart+1;
538
                        else
539
                           begin
540
                              work2SubMbPart <= 0;
541
                              work8x8Done <= True;
542
                           end
543
                     end
544
               end
545
         end
546
      else//horizontal interpolation
547
         begin
548
            offset = offset-2;
549
            if(yfracl == 2)
550
               begin
551 19 jamey.hick
                  readdata = workFile.sub({(1-workFileFlag),work2VerNum[2:0],work2HorNum});
552 2 jamey.hick
                  for(Integer ii=0; ii<8; ii=ii+1)
553
                     work2Vector15Next[ii] = work2Vector15[ii+4];
554
                  for(Integer ii=0; ii<4; ii=ii+1)
555
                     begin
556
                        Bit#(4) tempIndex = fromInteger(ii) + 8 - zeroExtend(offset);
557
                        work2Vector15Next[tempIndex] = readdata[ii];
558
                     end
559
                  for(Integer ii=0; ii<4; ii=ii+1)
560
                     begin
561 70 jamey.hick
                        tempResult8[ii] = interpolate15to8.interpolate(work2Vector15Next[ii],work2Vector15Next[ii+1],work2Vector15Next[ii+2],work2Vector15Next[ii+3],work2Vector15Next[ii+4],work2Vector15Next[ii+5]);
562 2 jamey.hick
                        if(xfracl == 1)
563
                           tempResult8[ii] = truncate(({1'b0,tempResult8[ii]} + {1'b0,clip1y10to8(truncate((work2Vector15Next[ii+2]+16)>>5))} + 1) >> 1);
564
                        else if(xfracl == 3)
565
                           tempResult8[ii] = truncate(({1'b0,tempResult8[ii]} + {1'b0,clip1y10to8(truncate((work2Vector15Next[ii+3]+16)>>5))} + 1) >> 1);
566
                     end
567
               end
568
            else
569 19 jamey.hick
               begin
570
                  Vector#(4,Bit#(8)) readdata8 = storeFile.sub({(1-workFileFlag),work2VerNum[2:0],work2HorNum});
571 2 jamey.hick
                  for(Integer ii=0; ii<8; ii=ii+1)
572
                     work2Vector8Next[ii] = work2Vector8[ii+4];
573
                  for(Integer ii=0; ii<4; ii=ii+1)
574
                     begin
575
                        Bit#(4) tempIndex = fromInteger(ii) + 8 - zeroExtend(offset);
576
                        work2Vector8Next[tempIndex] = readdata8[ii];
577
                     end
578
                  Vector#(4,Bit#(15)) tempResult15 = replicate(0);
579
                  for(Integer ii=0; ii<4; ii=ii+1)
580
                     begin
581 70 jamey.hick
                        tempResult15[ii] = interpolate8to15.interpolate(work2Vector8Next[ii],work2Vector8Next[ii+1],work2Vector8Next[ii+2],work2Vector8Next[ii+3],work2Vector8Next[ii+4],work2Vector8Next[ii+5]);
582 2 jamey.hick
                        tempResult8[ii] = clip1y10to8(truncate((tempResult15[ii]+16)>>5));
583
                     end
584
                  Bit#(2) verOffset;
585
                  Vector#(4,Bit#(15)) verResult15 = replicate(0);
586
                  if(xfracl == 1)
587
                     verOffset = reqdata.offset;
588
                  else
589
                     verOffset = reqdata.offset+1;
590 19 jamey.hick
                  readdata = workFile.sub({(1-workFileFlag),work2VerNum[2:0],(work2HorNum-2+(verOffset==0?0:1))});
591 2 jamey.hick
                  for(Integer ii=0; ii<4; ii=ii+1)
592
                     begin
593
                        Bit#(2) offsetplusii = verOffset+fromInteger(ii);
594
                        if(verOffset <= 3-fromInteger(ii) && verOffset!=0)
595
                           verResult15[ii] = work2Vector15[offsetplusii];
596
                        else
597
                           verResult15[ii] = readdata[offsetplusii];
598
                        work2Vector15Next[ii] = readdata[ii];
599
                     end
600
                  for(Integer ii=0; ii<4; ii=ii+1)
601
                     begin
602
                        Bit#(9) tempVal = zeroExtend(clip1y10to8(truncate((verResult15[ii]+16)>>5)));
603
                        tempResult8[ii] = truncate((tempVal+zeroExtend(tempResult8[ii])+1)>>1);
604
                     end
605
               end
606
            if(work2HorNum >= 2)
607
               begin
608
                  Bit#(1) horAddr = truncate(work2HorNum-2);
609
                  Bit#(3) verAddr = truncate(work2VerNum);
610
                  horAddr = horAddr + ((blockT==IP4x8&&work2SubMbPart==1)||(blockT==IP4x4&&work2SubMbPart[0]==1) ? 1 : 0);
611
                  verAddr = verAddr + ((blockT==IP8x4&&work2SubMbPart==1)||(blockT==IP4x4&&work2SubMbPart[1]==1) ? 4 : 0);
612
                  resultFile.upd({verAddr,horAddr},tempResult8);
613
                  resultReadyNext[{verAddr,horAddr}] = 1;
614
                  //$display( "Trace interpolator: workLuma stage 1 result %h %h %h %h %h %h %h %h", workHorNum, workVerNum, {verAddr,horAddr}, tempResult8[3], tempResult8[2], tempResult8[1], tempResult8[0], pack(resultReadyNext));
615
               end
616
            Bit#(2) workHorNumMax = (blockT==IP8x8||blockT==IP8x4 ? 1 : 0) + 2;
617
            Bit#(4) workVerNumMax = (blockT==IP8x8||blockT==IP4x8 ? 7 : 3);
618
            if(work2HorNum < workHorNumMax)
619
               work2HorNum <= work2HorNum+1;
620
            else
621
               begin
622
                  work2HorNum <= 0;
623
                  if(work2VerNum < workVerNumMax)
624
                     work2VerNum <= work2VerNum+1;
625
                  else
626
                     begin
627
                        work2VerNum <= 0;
628
                        work2Done <= True;
629
                        if(((blockT==IP4x8 || blockT==IP8x4) && work2SubMbPart==0) || (blockT==IP4x4 && work2SubMbPart<3))
630
                           work2SubMbPart <= work2SubMbPart+1;
631
                        else
632
                           begin
633
                              work2SubMbPart <= 0;
634
                              work8x8Done <= True;
635
                           end
636
                     end
637
               end
638
         end
639
      work2Vector8 <= work2Vector8Next;
640
      work2Vector15 <= work2Vector15Next;
641
      resultReady <= resultReadyNext;
642 70 jamey.hick
      $display( "Trace interpolator: work2Luma xfrac: %h yfrac: %h horNum: %h verNum: %h offset: %h", xfracl, yfracl, work2HorNum, work2VerNum, offset);
643 2 jamey.hick
   endrule
644
 
645
 
646
   rule work1Chroma ( reqfifoWork1.first() matches tagged IPWChroma .reqdata &&& !work1Done );
647
      Bit#(4) xfracc = zeroExtend(reqdata.xFracC);
648
      Bit#(4) yfracc = zeroExtend(reqdata.yFracC);
649
      let offset = reqdata.offset;
650
      let blockT = reqdata.bt;
651
      Vector#(20,Bit#(8)) work1Vector8Next = work1Vector8;
652
      if(memRespQ.first() matches tagged IPLoadResp .tempreaddata)
653
         begin
654
            memRespQ.deq();
655
            Vector#(4,Bit#(8)) readdata = replicate(0);
656
            readdata[0] = tempreaddata[7:0];
657
            readdata[1] = tempreaddata[15:8];
658
            readdata[2] = tempreaddata[23:16];
659
            readdata[3] = tempreaddata[31:24];
660
            Vector#(5,Bit#(8)) tempWork8 = replicate(0);
661
            Vector#(5,Bit#(8)) tempPrev8 = replicate(0);
662
            Vector#(4,Bit#(8)) tempResult8 = replicate(0);
663
            Bool resultReadyFlag = False;
664
            for(Integer ii=0; ii<4; ii=ii+1)
665
               begin
666
                  Bit#(2) offsetplusii = offset+fromInteger(ii);
667
                  if(offset <= 3-fromInteger(ii) && !((blockT==IP4x8||blockT==IP4x4)&&(offset[1]==0||(xfracc==0&&offset!=3))) && !(xfracc==0&&offset==0))
668
                     tempWork8[ii] = work1Vector8[offsetplusii];
669
                  else
670
                     tempWork8[ii] = readdata[offsetplusii];
671
                  work1Vector8Next[ii] = readdata[ii];
672
               end
673
            tempWork8[4] = readdata[offset];
674 60 jamey.hick
 
675
            // deals with the row major offsets
676 2 jamey.hick
            if((blockT==IP16x8 || blockT==IP16x16) && work1HorNum==(xfracc==0&&offset==0 ? 1 : 2))
677
               begin
678
                  for(Integer ii=0; ii<5; ii=ii+1)
679
                     begin
680
                        tempPrev8[ii] = work1Vector8[ii+9];
681
                        work1Vector8Next[ii+9] = tempWork8[ii];
682
                     end
683
               end
684
            else
685
               begin
686
                  for(Integer ii=0; ii<5; ii=ii+1)
687
                     tempPrev8[ii] = work1Vector8[ii+4];
688
                  if(work1HorNum==(xfracc==0&&offset==0 ? 0 : 1) || ((blockT==IP4x8||blockT==IP4x4)&&(offset[1]==0||(xfracc==0&&offset!=3))))
689
                     begin
690
                        for(Integer ii=0; ii<5; ii=ii+1)
691
                           work1Vector8Next[ii+4] = tempWork8[ii];
692
                     end
693
               end
694
            if(yfracc==0)
695
               begin
696
                  for(Integer ii=0; ii<5; ii=ii+1)
697
                     tempPrev8[ii] = tempWork8[ii];
698
               end
699 60 jamey.hick
            // Apply filter?
700 2 jamey.hick
            for(Integer ii=0; ii<4; ii=ii+1)
701
               begin
702 70 jamey.hick
                  $display("Trace interpolator: Applying filter");
703 2 jamey.hick
                  Bit#(14) tempVal = zeroExtend((8-xfracc))*zeroExtend((8-yfracc))*zeroExtend(tempPrev8[ii]);
704
                  tempVal = tempVal + zeroExtend(xfracc)*zeroExtend((8-yfracc))*zeroExtend(tempPrev8[ii+1]);
705
                  tempVal = tempVal + zeroExtend((8-xfracc))*zeroExtend(yfracc)*zeroExtend(tempWork8[ii]);
706
                  tempVal = tempVal + zeroExtend(xfracc)*zeroExtend(yfracc)*zeroExtend(tempWork8[ii+1]);
707
                  tempResult8[ii] = truncate((tempVal+32)>>6);
708
               end
709 60 jamey.hick
 
710 2 jamey.hick
            if(work1VerNum > 0 || yfracc==0)
711
               begin
712
                  if(blockT==IP4x8 || blockT==IP4x4)
713
                     begin
714
                        Bit#(5) tempIndex = 10 + zeroExtend(work1VerNum<<1);
715
                        work1Vector8Next[tempIndex] = tempResult8[0];
716
                        work1Vector8Next[tempIndex+1] = tempResult8[1];
717
                        tempResult8[2] = tempResult8[0];
718
                        tempResult8[3] = tempResult8[1];
719
                        tempResult8[0] = work1Vector8[tempIndex];
720
                        tempResult8[1] = work1Vector8[tempIndex+1];
721
                        if((work1HorNum>0 || offset[1]==0) && work1SubMbPart[0]==1)
722
                           resultReadyFlag = True;
723
                     end
724
                  else
725
                     begin
726
                        if(work1HorNum>0 || (xfracc==0 && offset==0))
727
                           resultReadyFlag = True;
728
                     end
729
               end
730
            if(resultReadyFlag)
731
               begin
732
                  Bit#(1) horAddr = ((blockT==IP4x8 || blockT==IP4x4) ? 0 : truncate(((xfracc==0 && offset==0) ? work1HorNum : work1HorNum-1)));
733
                  Bit#(3) verAddr = truncate((yfracc==0 ? work1VerNum : work1VerNum-1));
734
                  horAddr = horAddr + ((blockT==IP16x8||blockT==IP16x16) ? 0 : work1MbPart[0]);
735
                  verAddr = verAddr + ((blockT==IP8x16||blockT==IP16x16) ? 0 : ((blockT==IP16x8) ? {work1MbPart[0],2'b00} : {work1MbPart[1],2'b00}));
736
                  verAddr = verAddr + ((blockT==IP8x4&&work1SubMbPart==1)||(blockT==IP4x4&&work1SubMbPart[1]==1) ? 2 : 0);
737
                  storeFile.upd({workFileFlag,1'b0,verAddr,horAddr},tempResult8);
738
               end
739
            Bit#(2) workHorNumMax = (blockT==IP4x8||blockT==IP4x4 ? (offset[1]==0||(xfracc==0&&offset!=3) ? 0 : 1) : ((blockT==IP16x16||blockT==IP16x8 ? 1 : 0) + (xfracc==0&&offset==0 ? 0 : 1)));
740
            Bit#(4) workVerNumMax = (blockT==IP16x16||blockT==IP8x16 ? 7 : (blockT==IP16x8||blockT==IP8x8||blockT==IP4x8 ? 3 : 1)) + (yfracc==0 ? 0 : 1);
741
            if(work1HorNum < workHorNumMax)
742
               work1HorNum <= work1HorNum+1;
743
            else
744
               begin
745
                  work1HorNum <= 0;
746
                  if(work1VerNum < workVerNumMax)
747
                     work1VerNum <= work1VerNum+1;
748
                  else
749
                     begin
750
                        Bool allDone = False;
751
                        work1VerNum <= 0;
752
                        if(((blockT==IP4x8 || blockT==IP8x4) && work1SubMbPart==0) || (blockT==IP4x4 && work1SubMbPart<3))
753
                           work1SubMbPart <= work1SubMbPart+1;
754
                        else
755
                           begin
756
                              work1SubMbPart <= 0;
757
                              if(((blockT==IP16x8 || blockT==IP8x16) && work1MbPart==0) || (!(blockT==IP16x8 || blockT==IP8x16 || blockT==IP16x16) && work1MbPart<3))
758
                                 work1MbPart <= work1MbPart+1;
759
                              else
760
                                 begin
761
                                    work1MbPart <= 0;
762
                                    work1Done <= True;
763
                                    allDone = True;
764
                                 end
765
                           end
766
                        if(!allDone)
767 70 jamey.hick
                          begin
768
                            reqfifoWork1.deq();
769
                            $display("Trace Interpolator: work1Chroma finished");
770
                          end
771 2 jamey.hick
                     end
772
               end
773
         end
774
      work1Vector8 <= work1Vector8Next;
775 70 jamey.hick
 
776
      case (blockT)
777
         IP16x16: $display("Trace Interpolator: chroma 16x16");
778
         IP16x8:  $display("Trace Interpolator: chroma 16x8");
779
         IP8x16:  $display("Trace Interpolator: chroma 8x16");
780
         IP8x8:   $display("Trace Interpolator: chroma 8x8");
781
         IP8x4:   $display("Trace Interpolator: chroma 8x4");
782
         IP4x8:   $display("Trace Interpolator: chroma 4x8");
783
         IP4x4:   $display("Trace Interpolator: chroma 4x4");
784
      endcase
785
 
786
      $display( "Trace interpolator: work1Chroma xfracc: %h yfracc: %h Hor: %h Ver: %h offset: %h",
787
                xfracc, yfracc, work1HorNum, work1VerNum, offset);
788 2 jamey.hick
   endrule
789
 
790
 
791
   rule work2Chroma ( reqregWork2 matches tagged Valid .vdata &&& vdata matches tagged IPWChroma .reqdata &&& !work2Done &&& !work8x8Done );
792
      Vector#(16,Bit#(1)) resultReadyNext = resultReady;
793 19 jamey.hick
      resultFile.upd({work2VerNum[1],work2HorNum,work2VerNum[0]},storeFile.sub({(1-workFileFlag),1'b0,work2VerNum[1],work2HorNum,work2VerNum[0]}));
794 2 jamey.hick
      resultReadyNext[{work2VerNum[1],work2HorNum,work2VerNum[0]}] = 1;
795
      work2HorNum <= work2HorNum+1;
796
      if(work2HorNum == 3)
797
         begin
798
            if(work2VerNum == 3)
799
               begin
800
                  work2VerNum <= 0;
801
                  work2Done <= True;
802
                  work8x8Done <= True;
803
               end
804
            else
805
               work2VerNum <= work2VerNum+1;
806
         end
807
      resultReady <= resultReadyNext;
808 70 jamey.hick
      $display( "Trace interpolator: work2Chroma Hor: %h Ver: %h", work2HorNum, work2VerNum);
809 2 jamey.hick
   endrule
810
 
811
 
812
  rule outputing( !outDone && resultReady[{outBlockNum[1],outPixelNum,outBlockNum[0]}]==1 );
813 19 jamey.hick
      outfifo.enq(resultFile.sub({outBlockNum[1],outPixelNum,outBlockNum[0]}));
814 2 jamey.hick
      outPixelNum <= outPixelNum+1;
815
      if(outPixelNum == 3)
816
         begin
817
            outBlockNum <= outBlockNum+1;
818
            if(outBlockNum == 3)
819
               outDone <= True;
820
         end
821 70 jamey.hick
      $display( "Trace interpolator: outputing BlockNum: %h pixelNum: %h", outBlockNum, outPixelNum);
822 2 jamey.hick
   endrule
823
 
824
 
825 60 jamey.hick
   // These two rules complete the processing step, and
826 2 jamey.hick
   rule switching( work1Done && (work2Done || reqregWork2==Invalid) && !work8x8Done);
827
      work1Done <= False;
828
      work2Done <= False;
829 62 jamey.hick
      reqregWork2 <= (tagged Valid reqfifoWork1.first());
830 2 jamey.hick
      workFileFlag <= 1-workFileFlag;
831 70 jamey.hick
      $display("Trace Interpolator: work1 finished");
832 2 jamey.hick
      reqfifoWork1.deq();
833 70 jamey.hick
      $display( "Trace interpolator: switching blockNum: %h pixelNum: %h", outBlockNum, outPixelNum);
834 2 jamey.hick
   endrule
835
 
836
 
837 60 jamey.hick
   // this rule is kind of one of the last to run
838 2 jamey.hick
   rule switching8x8( work1Done && (work2Done || reqregWork2==Invalid) && work8x8Done && outDone);
839
      outDone <= False;
840
      work8x8Done <= False;
841
      resultReady <= replicate(0);
842
      work1Done <= False;
843
      work2Done <= False;
844 62 jamey.hick
      reqregWork2 <= (tagged Valid reqfifoWork1.first());
845 2 jamey.hick
      workFileFlag <= 1-workFileFlag;
846
      reqfifoWork1.deq();
847 70 jamey.hick
      $display("Trace Interpolator: work1 finished");
848
      $display( "Trace interpolator: switching8x8 blockNum: %h pixelNum: %h", outBlockNum, outPixelNum);
849 2 jamey.hick
   endrule
850
 
851
 
852
 
853
   method Action   setPicWidth( Bit#(PicWidthSz) newPicWidth );
854
      picWidth <= newPicWidth;
855
   endmethod
856
 
857
   method Action   setPicHeight( Bit#(PicHeightSz) newPicHeight );
858
      picHeight <= newPicHeight;
859
   endmethod
860
 
861
   method Action request( InterpolatorIT inputdata );
862
      reqfifoLoad.enq(inputdata);
863
      if(inputdata matches tagged IPLuma .indata)
864
         reqfifoWork1.enq(IPWLuma {xFracL:indata.mvhor[1:0],yFracL:indata.mvver[1:0],offset:indata.mvhor[3:2],bt:indata.bt});
865
      else if(inputdata matches tagged IPChroma .indata)
866
         reqfifoWork1.enq(IPWChroma {xFracC:indata.mvhor[2:0],yFracC:indata.mvver[2:0],offset:indata.mvhor[4:3]+{indata.hor[0],1'b0},bt:indata.bt});
867
   endmethod
868
 
869
   method Vector#(4,Bit#(8)) first();
870
      return outfifo.first();
871
   endmethod
872
 
873
   method Action deq();
874
      outfifo.deq();
875
   endmethod
876
 
877
   method Action endOfFrame();
878
      endOfFrameFlag <= True;
879
   endmethod
880
 
881
   interface Client mem_client;
882
      interface Get request  = fifoToGet(memReqQ);
883
      interface Put response = fifoToPut(memRespQ);
884
   endinterface
885
 
886
 
887
endmodule
888
 
889
 

powered by: WebSVN 2.1.0

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