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