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 102

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

powered by: WebSVN 2.1.0

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