1 |
10 |
eexuke |
//--------------------------------------------------------------------------------------------------
|
2 |
|
|
// Design : nova
|
3 |
|
|
// Author(s) : Ke Xu
|
4 |
|
|
// Email : eexuke@yahoo.com
|
5 |
|
|
// File : Inter_pred_pipeline.v
|
6 |
|
|
// Generated : Oct 4, 2005
|
7 |
|
|
// Copyright (C) 2008 Ke Xu
|
8 |
|
|
//-------------------------------------------------------------------------------------------------
|
9 |
|
|
// Description
|
10 |
|
|
// Inter prediction pipeline
|
11 |
|
|
//-------------------------------------------------------------------------------------------------
|
12 |
|
|
// Revise log
|
13 |
|
|
// 1.July 23,2006
|
14 |
|
|
// Change the ext_frame_RAM from async read to sync read.Therefore,blk4x4_inter_preload_counter has to +1 for all the cases
|
15 |
|
|
//-------------------------------------------------------------------------------------------------
|
16 |
|
|
|
17 |
|
|
// synopsys translate_off
|
18 |
|
|
`include "timescale.v"
|
19 |
|
|
// synopsys translate_on
|
20 |
|
|
`include "nova_defines.v"
|
21 |
|
|
|
22 |
|
|
module Inter_pred_pipeline (clk,reset_n,
|
23 |
|
|
mb_num_h,mb_num_v,trigger_blk4x4_inter_pred,blk4x4_rec_counter,mb_type_general_bit3,
|
24 |
|
|
mv_is16x16,mv_below8x8,
|
25 |
|
|
mvx_CurrMb0,mvx_CurrMb1,mvx_CurrMb2,mvx_CurrMb3,
|
26 |
|
|
mvy_CurrMb0,mvy_CurrMb1,mvy_CurrMb2,mvy_CurrMb3,
|
27 |
|
|
Inter_pix_copy0,Inter_pix_copy1,Inter_pix_copy2,Inter_pix_copy3,
|
28 |
|
|
LPE0_out,LPE1_out,LPE2_out,LPE3_out,
|
29 |
|
|
CPE0_out,CPE1_out,CPE2_out,CPE3_out,
|
30 |
|
|
|
31 |
|
|
mv_below8x8_curr,blk4x4_inter_preload_counter,blk4x4_inter_calculate_counter,Inter_chroma2x2_counter,
|
32 |
|
|
end_of_one_blk4x4_inter,IsInterLuma,IsInterChroma,Is_InterChromaCopy,
|
33 |
|
|
xInt_addr_unclip,xInt_org_unclip_1to0,pos_FracL,xFracC,yFracC,
|
34 |
|
|
Inter_pred_out0,Inter_pred_out1,Inter_pred_out2,Inter_pred_out3,Inter_blk4x4_pred_output_valid,
|
35 |
|
|
ref_frame_RAM_rd,ref_frame_RAM_rd_addr);
|
36 |
|
|
input clk;
|
37 |
|
|
input reset_n;
|
38 |
|
|
input [3:0] mb_num_h,mb_num_v;
|
39 |
|
|
input trigger_blk4x4_inter_pred;
|
40 |
|
|
input [4:0] blk4x4_rec_counter;
|
41 |
|
|
input mb_type_general_bit3;
|
42 |
|
|
input mv_is16x16;
|
43 |
|
|
input [3:0] mv_below8x8;
|
44 |
|
|
input [31:0] mvx_CurrMb0,mvx_CurrMb1,mvx_CurrMb2,mvx_CurrMb3;
|
45 |
|
|
input [31:0] mvy_CurrMb0,mvy_CurrMb1,mvy_CurrMb2,mvy_CurrMb3;
|
46 |
|
|
input [7:0] Inter_pix_copy0,Inter_pix_copy1,Inter_pix_copy2,Inter_pix_copy3;
|
47 |
|
|
input [7:0] LPE0_out,LPE1_out,LPE2_out,LPE3_out;
|
48 |
|
|
input [7:0] CPE0_out,CPE1_out,CPE2_out,CPE3_out;
|
49 |
|
|
|
50 |
|
|
output mv_below8x8_curr;
|
51 |
|
|
output [5:0] blk4x4_inter_preload_counter;
|
52 |
|
|
output [3:0] blk4x4_inter_calculate_counter;
|
53 |
|
|
output [1:0] Inter_chroma2x2_counter;
|
54 |
|
|
output end_of_one_blk4x4_inter;
|
55 |
|
|
output IsInterLuma,IsInterChroma;
|
56 |
|
|
output Is_InterChromaCopy;
|
57 |
|
|
output [8:0] xInt_addr_unclip;
|
58 |
|
|
output [1:0] xInt_org_unclip_1to0;
|
59 |
|
|
output [3:0] pos_FracL;
|
60 |
|
|
output [2:0] xFracC,yFracC;
|
61 |
|
|
output [7:0] Inter_pred_out0,Inter_pred_out1,Inter_pred_out2,Inter_pred_out3;
|
62 |
|
|
output [1:0] Inter_blk4x4_pred_output_valid; //2'b01:luma output valid 2'b10:chroma output valid
|
63 |
|
|
output ref_frame_RAM_rd;
|
64 |
|
|
output [13:0] ref_frame_RAM_rd_addr;
|
65 |
|
|
|
66 |
|
|
reg [5:0] blk4x4_inter_preload_counter;
|
67 |
|
|
reg [3:0] blk4x4_inter_calculate_counter;
|
68 |
|
|
reg mv_below8x8_curr;
|
69 |
|
|
reg [7:0] Inter_pred_out0,Inter_pred_out1,Inter_pred_out2,Inter_pred_out3;
|
70 |
|
|
reg [1:0] Inter_blk4x4_pred_output_valid;
|
71 |
|
|
wire ref_frame_RAM_rd;
|
72 |
|
|
wire IsInterLuma;
|
73 |
|
|
wire IsInterChroma;
|
74 |
|
|
wire [1:0] xFracL;
|
75 |
|
|
wire [1:0] yFracL;
|
76 |
|
|
wire [2:0] xFracC;
|
77 |
|
|
wire [2:0] yFracC;
|
78 |
|
|
wire [13:0] ref_frame_RAM_rd_addr;
|
79 |
|
|
|
80 |
|
|
assign IsInterLuma = (!mb_type_general_bit3 && blk4x4_rec_counter < 16)? 1'b1:1'b0;
|
81 |
|
|
assign IsInterChroma = (!mb_type_general_bit3 && blk4x4_rec_counter > 15)? 1'b1:1'b0;
|
82 |
|
|
//-------------------------------------------------------------------------
|
83 |
|
|
//mv_below8x8_curr for each 2x2 Inter Chroma prediction
|
84 |
|
|
//-------------------------------------------------------------------------
|
85 |
|
|
always @ (IsInterLuma or IsInterChroma or blk4x4_rec_counter[3:0] or mv_below8x8)
|
86 |
|
|
if (IsInterLuma)
|
87 |
|
|
case (blk4x4_rec_counter[3:2])
|
88 |
|
|
2'b00:mv_below8x8_curr <= mv_below8x8[0];
|
89 |
|
|
2'b01:mv_below8x8_curr <= mv_below8x8[1];
|
90 |
|
|
2'b10:mv_below8x8_curr <= mv_below8x8[2];
|
91 |
|
|
2'b11:mv_below8x8_curr <= mv_below8x8[3];
|
92 |
|
|
endcase
|
93 |
|
|
else if (IsInterChroma)
|
94 |
|
|
case (blk4x4_rec_counter[1:0])
|
95 |
|
|
2'b00:mv_below8x8_curr <= mv_below8x8[0];
|
96 |
|
|
2'b01:mv_below8x8_curr <= mv_below8x8[1];
|
97 |
|
|
2'b10:mv_below8x8_curr <= mv_below8x8[2];
|
98 |
|
|
2'b11:mv_below8x8_curr <= mv_below8x8[3];
|
99 |
|
|
endcase
|
100 |
|
|
else
|
101 |
|
|
mv_below8x8_curr <= 0;
|
102 |
|
|
//----------------------------------------------------------------------------------------
|
103 |
|
|
//Inter_chroma2x2_counter to guide the prediction of 2x2 chroma blocks
|
104 |
|
|
//2'b11 -> 2'b10 -> 2'b01 -> 2'b00
|
105 |
|
|
//----------------------------------------------------------------------------------------
|
106 |
|
|
reg [1:0] Inter_chroma2x2_counter;
|
107 |
|
|
always @ (posedge clk)
|
108 |
|
|
if (reset_n == 1'b0)
|
109 |
|
|
Inter_chroma2x2_counter <= 0;
|
110 |
|
|
//mv_below8x8_curr == 1'b1 includes the condition that "blk4x4_rec_counter > 15"
|
111 |
|
|
else if (IsInterChroma && trigger_blk4x4_inter_pred && mv_below8x8_curr)
|
112 |
|
|
Inter_chroma2x2_counter <= 2'b11;
|
113 |
|
|
else if (blk4x4_inter_calculate_counter == 4'd1 && Inter_chroma2x2_counter != 0)
|
114 |
|
|
Inter_chroma2x2_counter <= Inter_chroma2x2_counter - 1;
|
115 |
|
|
|
116 |
|
|
//----------------------------------------------------------------------------------------
|
117 |
|
|
//trigger_blk2x2_inter_pred:only for chroma 2x2 decoding
|
118 |
|
|
//We introduce this additional signal since we need Inter_chroma2x2_counter to update
|
119 |
|
|
//one cycle before blk4x4_inter_calculate_counter
|
120 |
|
|
//----------------------------------------------------------------------------------------
|
121 |
|
|
reg trigger_blk2x2_inter_pred;
|
122 |
|
|
always @ (posedge clk)
|
123 |
|
|
if (reset_n == 1'b0)
|
124 |
|
|
trigger_blk2x2_inter_pred <= 0;
|
125 |
|
|
else if ((IsInterChroma && trigger_blk4x4_inter_pred && mv_below8x8_curr) ||
|
126 |
|
|
(blk4x4_inter_calculate_counter == 4'd1 && Inter_chroma2x2_counter != 0))
|
127 |
|
|
trigger_blk2x2_inter_pred <= 1'b1;
|
128 |
|
|
else
|
129 |
|
|
trigger_blk2x2_inter_pred <= 1'b0;
|
130 |
|
|
//----------------------------------------------------------------------------------------
|
131 |
|
|
//Inter motion vector for current 4x4 luma/chroma block or 2x2 chroma block
|
132 |
|
|
// Inter_blk_mvx,Inter_blk_mvy
|
133 |
|
|
//----------------------------------------------------------------------------------------
|
134 |
|
|
reg [7:0] Inter_blk_mvx,Inter_blk_mvy;
|
135 |
|
|
always @ (blk4x4_rec_counter or mv_below8x8_curr or Inter_chroma2x2_counter
|
136 |
|
|
or IsInterLuma or IsInterChroma or mv_is16x16
|
137 |
|
|
or mvx_CurrMb0 or mvx_CurrMb1 or mvx_CurrMb2 or mvx_CurrMb3
|
138 |
|
|
or mvy_CurrMb0 or mvy_CurrMb1 or mvy_CurrMb2 or mvy_CurrMb3)
|
139 |
|
|
//Inter luma
|
140 |
|
|
if (IsInterLuma)
|
141 |
|
|
begin
|
142 |
|
|
if (mv_is16x16)
|
143 |
|
|
begin Inter_blk_mvx <= mvx_CurrMb0[7:0]; Inter_blk_mvy <= mvy_CurrMb0[7:0]; end
|
144 |
|
|
else
|
145 |
|
|
case (mv_below8x8_curr)
|
146 |
|
|
1'b0:
|
147 |
|
|
case (blk4x4_rec_counter[3:2])
|
148 |
|
|
2'b00:begin Inter_blk_mvx <= mvx_CurrMb0[7:0]; Inter_blk_mvy <= mvy_CurrMb0[7:0]; end
|
149 |
|
|
2'b01:begin Inter_blk_mvx <= mvx_CurrMb1[7:0]; Inter_blk_mvy <= mvy_CurrMb1[7:0]; end
|
150 |
|
|
2'b10:begin Inter_blk_mvx <= mvx_CurrMb2[7:0]; Inter_blk_mvy <= mvy_CurrMb2[7:0]; end
|
151 |
|
|
2'b11:begin Inter_blk_mvx <= mvx_CurrMb3[7:0]; Inter_blk_mvy <= mvy_CurrMb3[7:0]; end
|
152 |
|
|
endcase
|
153 |
|
|
1'b1:
|
154 |
|
|
case (blk4x4_rec_counter)
|
155 |
|
|
|
156 |
|
|
1 :begin Inter_blk_mvx <= mvx_CurrMb0[15:8]; Inter_blk_mvy <= mvy_CurrMb0[15:8]; end
|
157 |
|
|
2 :begin Inter_blk_mvx <= mvx_CurrMb0[23:16];Inter_blk_mvy <= mvy_CurrMb0[23:16]; end
|
158 |
|
|
3 :begin Inter_blk_mvx <= mvx_CurrMb0[31:24];Inter_blk_mvy <= mvy_CurrMb0[31:24]; end
|
159 |
|
|
4 :begin Inter_blk_mvx <= mvx_CurrMb1[7:0]; Inter_blk_mvy <= mvy_CurrMb1[7:0]; end
|
160 |
|
|
5 :begin Inter_blk_mvx <= mvx_CurrMb1[15:8]; Inter_blk_mvy <= mvy_CurrMb1[15:8]; end
|
161 |
|
|
6 :begin Inter_blk_mvx <= mvx_CurrMb1[23:16];Inter_blk_mvy <= mvy_CurrMb1[23:16]; end
|
162 |
|
|
7 :begin Inter_blk_mvx <= mvx_CurrMb1[31:24];Inter_blk_mvy <= mvy_CurrMb1[31:24]; end
|
163 |
|
|
8 :begin Inter_blk_mvx <= mvx_CurrMb2[7:0]; Inter_blk_mvy <= mvy_CurrMb2[7:0]; end
|
164 |
|
|
9 :begin Inter_blk_mvx <= mvx_CurrMb2[15:8]; Inter_blk_mvy <= mvy_CurrMb2[15:8]; end
|
165 |
|
|
10:begin Inter_blk_mvx <= mvx_CurrMb2[23:16];Inter_blk_mvy <= mvy_CurrMb2[23:16]; end
|
166 |
|
|
11:begin Inter_blk_mvx <= mvx_CurrMb2[31:24];Inter_blk_mvy <= mvy_CurrMb2[31:24]; end
|
167 |
|
|
12:begin Inter_blk_mvx <= mvx_CurrMb3[7:0]; Inter_blk_mvy <= mvy_CurrMb3[7:0]; end
|
168 |
|
|
13:begin Inter_blk_mvx <= mvx_CurrMb3[15:8]; Inter_blk_mvy <= mvy_CurrMb3[15:8]; end
|
169 |
|
|
14:begin Inter_blk_mvx <= mvx_CurrMb3[23:16];Inter_blk_mvy <= mvy_CurrMb3[23:16]; end
|
170 |
|
|
15:begin Inter_blk_mvx <= mvx_CurrMb3[31:24];Inter_blk_mvy <= mvy_CurrMb3[31:24]; end
|
171 |
|
|
default:begin Inter_blk_mvx <= 0;Inter_blk_mvy <= 0; end
|
172 |
|
|
endcase
|
173 |
|
|
endcase
|
174 |
|
|
end
|
175 |
|
|
//Inter chroma
|
176 |
|
|
else if (IsInterChroma)
|
177 |
|
|
begin
|
178 |
|
|
if (mv_is16x16)
|
179 |
|
|
begin Inter_blk_mvx <= mvx_CurrMb0[7:0]; Inter_blk_mvy <= mvy_CurrMb0[7:0]; end
|
180 |
|
|
else
|
181 |
|
|
case (blk4x4_rec_counter[1:0])
|
182 |
|
|
2'b00:
|
183 |
|
|
if (mv_below8x8_curr) //chroma2x2 prediction
|
184 |
|
|
case (Inter_chroma2x2_counter)
|
185 |
|
|
3:begin Inter_blk_mvx <= mvx_CurrMb0[7:0]; Inter_blk_mvy <= mvy_CurrMb0[7:0]; end
|
186 |
|
|
2:begin Inter_blk_mvx <= mvx_CurrMb0[15:8]; Inter_blk_mvy <= mvy_CurrMb0[15:8]; end
|
187 |
|
|
1:begin Inter_blk_mvx <= mvx_CurrMb0[23:16];Inter_blk_mvy <= mvy_CurrMb0[23:16]; end
|
188 |
|
|
0:begin Inter_blk_mvx <= mvx_CurrMb0[31:24];Inter_blk_mvy <= mvy_CurrMb0[31:24]; end
|
189 |
|
|
endcase
|
190 |
|
|
else //chroma 4x4 prediction
|
191 |
|
|
begin Inter_blk_mvx <= mvx_CurrMb0[7:0]; Inter_blk_mvy <= mvy_CurrMb0[7:0]; end
|
192 |
|
|
2'b01:
|
193 |
|
|
if (mv_below8x8_curr) //need chroma2x2 prediction
|
194 |
|
|
case (Inter_chroma2x2_counter)
|
195 |
|
|
3:begin Inter_blk_mvx <= mvx_CurrMb1[7:0]; Inter_blk_mvy <= mvy_CurrMb1[7:0]; end
|
196 |
|
|
2:begin Inter_blk_mvx <= mvx_CurrMb1[15:8]; Inter_blk_mvy <= mvy_CurrMb1[15:8]; end
|
197 |
|
|
1:begin Inter_blk_mvx <= mvx_CurrMb1[23:16];Inter_blk_mvy <= mvy_CurrMb1[23:16]; end
|
198 |
|
|
0:begin Inter_blk_mvx <= mvx_CurrMb1[31:24];Inter_blk_mvy <= mvy_CurrMb1[31:24]; end
|
199 |
|
|
endcase
|
200 |
|
|
else //chroma 4x4 prediction
|
201 |
|
|
begin Inter_blk_mvx <= mvx_CurrMb1[7:0]; Inter_blk_mvy <= mvy_CurrMb1[7:0]; end
|
202 |
|
|
2'b10:
|
203 |
|
|
if (mv_below8x8_curr) //chroma2x2 prediction
|
204 |
|
|
case (Inter_chroma2x2_counter)
|
205 |
|
|
3:begin Inter_blk_mvx <= mvx_CurrMb2[7:0]; Inter_blk_mvy <= mvy_CurrMb2[7:0]; end
|
206 |
|
|
2:begin Inter_blk_mvx <= mvx_CurrMb2[15:8]; Inter_blk_mvy <= mvy_CurrMb2[15:8]; end
|
207 |
|
|
1:begin Inter_blk_mvx <= mvx_CurrMb2[23:16];Inter_blk_mvy <= mvy_CurrMb2[23:16]; end
|
208 |
|
|
0:begin Inter_blk_mvx <= mvx_CurrMb2[31:24];Inter_blk_mvy <= mvy_CurrMb2[31:24]; end
|
209 |
|
|
endcase
|
210 |
|
|
else //chroma 4x4 prediction
|
211 |
|
|
begin Inter_blk_mvx <= mvx_CurrMb2[7:0]; Inter_blk_mvy <= mvy_CurrMb2[7:0]; end
|
212 |
|
|
2'b11:
|
213 |
|
|
if (mv_below8x8_curr) //chroma2x2 prediction
|
214 |
|
|
case (Inter_chroma2x2_counter)
|
215 |
|
|
3:begin Inter_blk_mvx <= mvx_CurrMb3[7:0]; Inter_blk_mvy <= mvy_CurrMb3[7:0]; end
|
216 |
|
|
2:begin Inter_blk_mvx <= mvx_CurrMb3[15:8]; Inter_blk_mvy <= mvy_CurrMb3[15:8]; end
|
217 |
|
|
1:begin Inter_blk_mvx <= mvx_CurrMb3[23:16];Inter_blk_mvy <= mvy_CurrMb3[23:16]; end
|
218 |
|
|
0:begin Inter_blk_mvx <= mvx_CurrMb3[31:24];Inter_blk_mvy <= mvy_CurrMb3[31:24]; end
|
219 |
|
|
endcase
|
220 |
|
|
else //chroma 4x4 prediction
|
221 |
|
|
begin Inter_blk_mvx <= mvx_CurrMb3[7:0]; Inter_blk_mvy <= mvy_CurrMb3[7:0]; end
|
222 |
|
|
endcase
|
223 |
|
|
end
|
224 |
|
|
else
|
225 |
|
|
begin Inter_blk_mvx <= 0; Inter_blk_mvy <= 0; end
|
226 |
|
|
//----------------------------------------------------------------------------------------
|
227 |
|
|
//Describes the offset of each blk4x4 inside a MB
|
228 |
|
|
//----------------------------------------------------------------------------------------
|
229 |
|
|
// xOffset = 0 for 0,2,8, 10 yOffset = 0 for 0, 1, 4, 5
|
230 |
|
|
// xOffset = 4 for 1,3,9, 11 yOffset = 4 for 2, 3, 6, 7
|
231 |
|
|
// xOffset = 8 for 4,6,12,14 yOffset = 8 for 8, 9, 12,13
|
232 |
|
|
// xOffset = 12 for 5,7,13,15 yOffset = 12 for 10,11,14,15
|
233 |
|
|
reg [3:0] xOffsetL,yOffsetL;
|
234 |
|
|
always @ (IsInterLuma or mv_below8x8_curr or blk4x4_rec_counter[2] or blk4x4_rec_counter[0])
|
235 |
|
|
if (IsInterLuma)
|
236 |
|
|
begin
|
237 |
|
|
if (!mv_below8x8_curr)
|
238 |
|
|
xOffsetL <= (blk4x4_rec_counter[2])? 4'd8:4'd0;
|
239 |
|
|
else
|
240 |
|
|
case ({blk4x4_rec_counter[2],blk4x4_rec_counter[0]})
|
241 |
|
|
2'b00:xOffsetL <= 4'd0;
|
242 |
|
|
2'b01:xOffsetL <= 4'd4;
|
243 |
|
|
2'b10:xOffsetL <= 4'd8;
|
244 |
|
|
2'b11:xOffsetL <= 4'd12;
|
245 |
|
|
endcase
|
246 |
|
|
end
|
247 |
|
|
else
|
248 |
|
|
xOffsetL <= 0;
|
249 |
|
|
|
250 |
|
|
always @ (IsInterLuma or mv_below8x8_curr or blk4x4_rec_counter[3] or blk4x4_rec_counter[1])
|
251 |
|
|
if (IsInterLuma)
|
252 |
|
|
begin
|
253 |
|
|
if (!mv_below8x8_curr)
|
254 |
|
|
yOffsetL <= (blk4x4_rec_counter[3])? 4'd8:4'd0;
|
255 |
|
|
else
|
256 |
|
|
case ({blk4x4_rec_counter[3],blk4x4_rec_counter[1]})
|
257 |
|
|
2'b00:yOffsetL <= 4'd0;
|
258 |
|
|
2'b01:yOffsetL <= 4'd4;
|
259 |
|
|
2'b10:yOffsetL <= 4'd8;
|
260 |
|
|
2'b11:yOffsetL <= 4'd12;
|
261 |
|
|
endcase
|
262 |
|
|
end
|
263 |
|
|
else
|
264 |
|
|
yOffsetL <= 0;
|
265 |
|
|
|
266 |
|
|
reg [2:0] xOffsetC,yOffsetC;
|
267 |
|
|
always @ (IsInterChroma or mv_below8x8_curr or blk4x4_rec_counter[0] or Inter_chroma2x2_counter[0])
|
268 |
|
|
if (IsInterChroma)
|
269 |
|
|
begin
|
270 |
|
|
if (mv_below8x8_curr == 1'b0)
|
271 |
|
|
xOffsetC <= (blk4x4_rec_counter[0] == 1'b0)? 3'd0:3'd4;
|
272 |
|
|
else
|
273 |
|
|
case (blk4x4_rec_counter[0])
|
274 |
|
|
1'b0:xOffsetC <= (Inter_chroma2x2_counter[0] == 1'b1)? 3'd0:3'd2;
|
275 |
|
|
1'b1:xOffsetC <= (Inter_chroma2x2_counter[0] == 1'b1)? 3'd4:3'd6;
|
276 |
|
|
endcase
|
277 |
|
|
end
|
278 |
|
|
else
|
279 |
|
|
xOffsetC <= 0;
|
280 |
|
|
|
281 |
|
|
always @ (IsInterChroma or mv_below8x8_curr or blk4x4_rec_counter[1] or Inter_chroma2x2_counter[1])
|
282 |
|
|
if (IsInterChroma)
|
283 |
|
|
begin
|
284 |
|
|
if (mv_below8x8_curr == 1'b0)
|
285 |
|
|
yOffsetC <= (blk4x4_rec_counter[1] == 1'b0)? 3'd0:3'd4;
|
286 |
|
|
else
|
287 |
|
|
case (blk4x4_rec_counter[1])
|
288 |
|
|
1'b0:yOffsetC <= (Inter_chroma2x2_counter[1] == 1'b1)? 3'd0:3'd2;
|
289 |
|
|
1'b1:yOffsetC <= (Inter_chroma2x2_counter[1] == 1'b1)? 3'd4:3'd6;
|
290 |
|
|
endcase
|
291 |
|
|
end
|
292 |
|
|
else
|
293 |
|
|
yOffsetC <= 3'd0;
|
294 |
|
|
//----------------------------------------------------------------------------------------
|
295 |
|
|
//Integer position of each left-up-most pixel of a 8x8/4x4/2x2 blk
|
296 |
|
|
//----------------------------------------------------------------------------------------
|
297 |
|
|
wire [8:0] xIntL_unclip,yIntL_unclip; // 2's complement,bit[8] is the sign bit
|
298 |
|
|
wire [7:0] xIntC_unclip,yIntC_unclip; // 2's complement,bit[7] is the sign bit
|
299 |
|
|
assign xIntL_unclip = (IsInterLuma)? ({1'b0,mb_num_h,4'b0} + xOffsetL + {{3{Inter_blk_mvx[7]}},Inter_blk_mvx[7:2]}):0;
|
300 |
|
|
assign yIntL_unclip = (IsInterLuma)? ({1'b0,mb_num_v,4'b0} + yOffsetL + {{3{Inter_blk_mvy[7]}},Inter_blk_mvy[7:2]}):0;
|
301 |
|
|
assign xIntC_unclip = (IsInterChroma)? ({1'b0,mb_num_h,3'b0} + xOffsetC + {{3{Inter_blk_mvx[7]}},Inter_blk_mvx[7:3]}):0;
|
302 |
|
|
assign yIntC_unclip = (IsInterChroma)? ({1'b0,mb_num_v,3'b0} + yOffsetC + {{3{Inter_blk_mvy[7]}},Inter_blk_mvy[7:3]}):0;
|
303 |
|
|
|
304 |
|
|
wire [8:0] xInt_org_unclip;
|
305 |
|
|
wire [8:0] yInt_org_unclip;
|
306 |
|
|
assign xInt_org_unclip = (IsInterLuma)? xIntL_unclip:{xIntC_unclip[7],xIntC_unclip};
|
307 |
|
|
assign yInt_org_unclip = (IsInterLuma)? yIntL_unclip:{yIntC_unclip[7],yIntC_unclip};
|
308 |
|
|
assign xInt_org_unclip_1to0 = xInt_org_unclip[1:0];
|
309 |
|
|
//----------------------------------------------------------------------------------------
|
310 |
|
|
//Fractional motion vector for both luma and chroma
|
311 |
|
|
//----------------------------------------------------------------------------------------
|
312 |
|
|
wire [3:0] pos_FracL;
|
313 |
|
|
wire Is_InterChromaCopy;//If chroma is predicted by direct copy,calculate cycle would reduce
|
314 |
|
|
//from 16 cycles to 4 cycles
|
315 |
|
|
|
316 |
|
|
assign xFracL = (IsInterLuma)? Inter_blk_mvx[1:0]:0;
|
317 |
|
|
assign yFracL = (IsInterLuma)? Inter_blk_mvy[1:0]:0;
|
318 |
|
|
assign xFracC = (IsInterChroma)? Inter_blk_mvx[2:0]:0;
|
319 |
|
|
assign yFracC = (IsInterChroma)? Inter_blk_mvy[2:0]:0;
|
320 |
|
|
assign pos_FracL = {xFracL,yFracL};
|
321 |
|
|
assign Is_InterChromaCopy = (IsInterChroma && xFracC == 0 && yFracC == 0)? 1'b1:1'b0;
|
322 |
|
|
|
323 |
|
|
//----------------------------------------------------------------------------------------
|
324 |
|
|
//Inter prediction step control counter
|
325 |
|
|
//----------------------------------------------------------------------------------------
|
326 |
|
|
//1.Preload integer pels counter
|
327 |
|
|
// If block partition equals 8x8 or above,preload only at first 4x4 block of each 8x8block
|
328 |
|
|
// If block partition is 8x4,4x8 or 4x4, preload at each 4x4 block
|
329 |
|
|
always @ (posedge clk)
|
330 |
|
|
if (reset_n == 1'b0)
|
331 |
|
|
blk4x4_inter_preload_counter <= 0;
|
332 |
|
|
//luma
|
333 |
|
|
else if (trigger_blk4x4_inter_pred && IsInterLuma)
|
334 |
|
|
begin
|
335 |
|
|
if (!mv_below8x8_curr && blk4x4_rec_counter[1:0] == 2'b00)
|
336 |
|
|
case (pos_FracL)
|
337 |
|
|
`pos_Int :blk4x4_inter_preload_counter <= (xInt_org_unclip[1:0] == 2'b00)? 6'd17:6'd25;
|
338 |
|
|
`pos_f,`pos_q,`pos_i,`pos_k,`pos_j:blk4x4_inter_preload_counter <= 6'd53;
|
339 |
|
|
`pos_d,`pos_h,`pos_n :blk4x4_inter_preload_counter <= (xInt_org_unclip[1:0] == 2'b00)? 6'd27:6'd40;
|
340 |
|
|
`pos_a,`pos_b,`pos_c :blk4x4_inter_preload_counter <= 6'd33;
|
341 |
|
|
`pos_e,`pos_g,`pos_p,`pos_r :blk4x4_inter_preload_counter <= 6'd49;
|
342 |
|
|
endcase
|
343 |
|
|
else if (mv_below8x8_curr) //partition below 8x8block
|
344 |
|
|
case (pos_FracL)
|
345 |
|
|
`pos_Int :blk4x4_inter_preload_counter <= (xInt_org_unclip[1:0] == 2'b00)? 6'd5:6'd9;
|
346 |
|
|
`pos_f,`pos_q,`pos_i,`pos_k,`pos_j:blk4x4_inter_preload_counter <= 6'd28;
|
347 |
|
|
`pos_d,`pos_h,`pos_n :blk4x4_inter_preload_counter <= (xInt_org_unclip[1:0] == 2'b00)? 6'd10:6'd19;
|
348 |
|
|
`pos_a,`pos_b,`pos_c :blk4x4_inter_preload_counter <= 6'd13;
|
349 |
|
|
`pos_e,`pos_g,`pos_p,`pos_r :blk4x4_inter_preload_counter <= 6'd24;
|
350 |
|
|
endcase
|
351 |
|
|
end
|
352 |
|
|
//chroma
|
353 |
|
|
else if (trigger_blk4x4_inter_pred && IsInterChroma && mv_below8x8_curr == 1'b0)
|
354 |
|
|
begin
|
355 |
|
|
if (xFracC == 0 && yFracC == 0)
|
356 |
|
|
blk4x4_inter_preload_counter <= (xInt_org_unclip[1:0] == 2'b00)? 6'd5:6'd9;
|
357 |
|
|
else
|
358 |
|
|
blk4x4_inter_preload_counter <= 6'd11;
|
359 |
|
|
end
|
360 |
|
|
else if (trigger_blk2x2_inter_pred && IsInterChroma && mv_below8x8_curr == 1'b1)
|
361 |
|
|
begin
|
362 |
|
|
if (xFracC == 0 && yFracC == 0)
|
363 |
|
|
blk4x4_inter_preload_counter <= (xInt_org_unclip[1:0] == 2'b11)? 6'd5:6'd3;
|
364 |
|
|
else
|
365 |
|
|
blk4x4_inter_preload_counter <= (xInt_org_unclip[1] == 1'b0 )? 6'd4:6'd7;
|
366 |
|
|
end
|
367 |
|
|
else if (blk4x4_inter_preload_counter != 0)
|
368 |
|
|
blk4x4_inter_preload_counter <= blk4x4_inter_preload_counter - 1;
|
369 |
|
|
|
370 |
|
|
//2.Calculate counter
|
371 |
|
|
always @ (posedge clk)
|
372 |
|
|
if (reset_n == 1'b0)
|
373 |
|
|
blk4x4_inter_calculate_counter <= 0;
|
374 |
|
|
//luma
|
375 |
|
|
else if (IsInterLuma && ((!mv_below8x8_curr && (
|
376 |
|
|
(blk4x4_rec_counter[1:0] == 2'b00 && blk4x4_inter_preload_counter == 1) ||
|
377 |
|
|
(blk4x4_rec_counter[1:0] != 2'b00 && trigger_blk4x4_inter_pred))) ||
|
378 |
|
|
(mv_below8x8_curr && blk4x4_inter_preload_counter == 1)))
|
379 |
|
|
case (pos_FracL)
|
380 |
|
|
`pos_j,`pos_f,`pos_q:blk4x4_inter_calculate_counter <= 4'd5;
|
381 |
|
|
`pos_i,`pos_k :blk4x4_inter_calculate_counter <= 4'd8;
|
382 |
|
|
default :blk4x4_inter_calculate_counter <= 4'd4;
|
383 |
|
|
endcase
|
384 |
|
|
//chroma
|
385 |
|
|
else if (blk4x4_inter_preload_counter == 1 && IsInterChroma == 1'b1)
|
386 |
|
|
case (mv_below8x8_curr)
|
387 |
|
|
1'b0:blk4x4_inter_calculate_counter <= 4'd4;
|
388 |
|
|
1'b1:blk4x4_inter_calculate_counter <= 4'd1;
|
389 |
|
|
endcase
|
390 |
|
|
else if (blk4x4_inter_calculate_counter != 0)
|
391 |
|
|
blk4x4_inter_calculate_counter <= blk4x4_inter_calculate_counter - 1;
|
392 |
|
|
|
393 |
|
|
assign end_of_one_blk4x4_inter = (blk4x4_inter_calculate_counter == 4'd1 &&
|
394 |
|
|
((IsInterChroma && mv_below8x8_curr && Inter_chroma2x2_counter == 2'b00) ||
|
395 |
|
|
!(IsInterChroma && mv_below8x8_curr)));
|
396 |
|
|
//----------------------------------------------------------------------------------------
|
397 |
|
|
//Inter prediction reference frame RAM read control
|
398 |
|
|
//----------------------------------------------------------------------------------------
|
399 |
|
|
assign ref_frame_RAM_rd = ((IsInterLuma || IsInterChroma) && blk4x4_inter_preload_counter != 6'd0 && blk4x4_inter_preload_counter != 6'd1);
|
400 |
|
|
|
401 |
|
|
//compared with blk4x4_inter_preload_counter,blk4x4_inter_preload_counter_m2 has some advantages
|
402 |
|
|
//during some pos_FracL for vertical memory address decoding
|
403 |
|
|
wire [5:0] blk4x4_inter_preload_counter_m2;
|
404 |
|
|
assign blk4x4_inter_preload_counter_m2 = (blk4x4_inter_preload_counter == 6'd0 || blk4x4_inter_preload_counter == 6'd1)?
|
405 |
|
|
6'd0:(blk4x4_inter_preload_counter - 2);
|
406 |
|
|
|
407 |
|
|
//xInt_curr_offset: offset from the left-upper most pixel of current block,ranging -2 ~ +10.
|
408 |
|
|
//After each preload cycle,xInt_curr_offset will increase 4
|
409 |
|
|
reg [4:0] xInt_curr_offset;
|
410 |
|
|
always @ (IsInterLuma or mv_below8x8_curr or pos_FracL or xFracC or yFracC
|
411 |
|
|
or xInt_org_unclip[1:0] or blk4x4_inter_preload_counter_m2 or blk4x4_inter_preload_counter)
|
412 |
|
|
if (blk4x4_inter_preload_counter != 6'd0 && blk4x4_inter_preload_counter != 6'd1)
|
413 |
|
|
begin
|
414 |
|
|
if (IsInterLuma)
|
415 |
|
|
begin
|
416 |
|
|
if (!mv_below8x8_curr)
|
417 |
|
|
case (pos_FracL)
|
418 |
|
|
`pos_f,`pos_q,`pos_i,`pos_k,`pos_j:
|
419 |
|
|
case (blk4x4_inter_preload_counter_m2[1:0])
|
420 |
|
|
2'b00:xInt_curr_offset <= 5'b01010; //+10
|
421 |
|
|
2'b01:xInt_curr_offset <= 5'b00110; //+6
|
422 |
|
|
2'b10:xInt_curr_offset <= 5'b00010; //+2
|
423 |
|
|
2'b11:xInt_curr_offset <= 5'b11110; //-2
|
424 |
|
|
endcase
|
425 |
|
|
`pos_d,`pos_h,`pos_n:
|
426 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
427 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0])? 4'b0:4'b0100; //+0 or +4
|
428 |
|
|
else
|
429 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
430 |
|
|
6'd38,6'd35,6'd32,6'd29,6'd26,6'd23,6'd20,6'd17,6'd14,6'd11,6'd8,6'd5,6'd2:
|
431 |
|
|
xInt_curr_offset <= 5'b0; //+0
|
432 |
|
|
6'd37,6'd34,6'd31,6'd28,6'd25,6'd22,6'd19,6'd16,6'd13,6'd10,6'd7,6'd4,6'd1:
|
433 |
|
|
xInt_curr_offset <= 5'b00100; //+4
|
434 |
|
|
default:xInt_curr_offset <= 5'b01000;//+8
|
435 |
|
|
endcase
|
436 |
|
|
`pos_a,`pos_b,`pos_c:
|
437 |
|
|
case (blk4x4_inter_preload_counter_m2[1:0])
|
438 |
|
|
2'b00:xInt_curr_offset <= 5'b01010; //+10
|
439 |
|
|
2'b01:xInt_curr_offset <= 5'b00110; //+6
|
440 |
|
|
2'b10:xInt_curr_offset <= 5'b00010; //+2
|
441 |
|
|
2'b11:xInt_curr_offset <= 5'b11110; //-2
|
442 |
|
|
endcase
|
443 |
|
|
`pos_Int:
|
444 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
445 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0])? 5'b0:5'b0100; //+0 or +4
|
446 |
|
|
else
|
447 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
448 |
|
|
6'd23,6'd20,6'd17,6'd14,6'd11,6'd8,6'd5,6'd2:
|
449 |
|
|
xInt_curr_offset <= 5'b00000; //+0
|
450 |
|
|
6'd22,6'd19,6'd16,6'd13,6'd10,6'd7,6'd4,6'd1:
|
451 |
|
|
xInt_curr_offset <= 5'b00100; //+4
|
452 |
|
|
default:xInt_curr_offset <= 5'b01000;//+8
|
453 |
|
|
endcase
|
454 |
|
|
`pos_e,`pos_g,`pos_p,`pos_r:
|
455 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
456 |
|
|
6'd47,6'd44,6'd5,6'd2:
|
457 |
|
|
xInt_curr_offset <= 5'b00000; //+0
|
458 |
|
|
6'd46,6'd43,6'd4,6'd1:
|
459 |
|
|
xInt_curr_offset <= 5'b00100; //+4
|
460 |
|
|
6'd45,6'd42,6'd3,6'd0:
|
461 |
|
|
xInt_curr_offset <= 5'b01000; //+8
|
462 |
|
|
default:
|
463 |
|
|
case (blk4x4_inter_preload_counter_m2[1:0])
|
464 |
|
|
2'b00:xInt_curr_offset <= 5'b00010; //+2
|
465 |
|
|
2'b01:xInt_curr_offset <= 5'b11110; //-2
|
466 |
|
|
2'b10:xInt_curr_offset <= 5'b01010; //+10
|
467 |
|
|
2'b11:xInt_curr_offset <= 5'b00110; //+6
|
468 |
|
|
endcase
|
469 |
|
|
endcase
|
470 |
|
|
endcase
|
471 |
|
|
else //block partition below 8x8
|
472 |
|
|
case (pos_FracL)
|
473 |
|
|
`pos_f,`pos_q,`pos_i,`pos_k,`pos_j:
|
474 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
475 |
|
|
6'd26,6'd23,6'd20,6'd17,6'd14,6'd11,6'd8,6'd5,6'd2:xInt_curr_offset <= 5'b11110;//-2
|
476 |
|
|
6'd25,6'd22,6'd19,6'd16,6'd13,6'd10,6'd7,6'd4,6'd1:xInt_curr_offset <= 5'b00010;//+2
|
477 |
|
|
default:xInt_curr_offset <= 5'b00110; //+6
|
478 |
|
|
endcase
|
479 |
|
|
`pos_d,`pos_h,`pos_n:
|
480 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
481 |
|
|
xInt_curr_offset <= 5'b0; //+0
|
482 |
|
|
else
|
483 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0])? 5'b0:5'b00100;//+0 or +4
|
484 |
|
|
`pos_a,`pos_b,`pos_c:
|
485 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
486 |
|
|
6'd11,6'd8,6'd5,6'd2:xInt_curr_offset <= 5'b11110; //-2
|
487 |
|
|
6'd10,6'd7,6'd4,6'd1:xInt_curr_offset <= 5'b00010; //+2
|
488 |
|
|
default:xInt_curr_offset <= 5'b00110; //+6
|
489 |
|
|
endcase
|
490 |
|
|
`pos_Int:
|
491 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
492 |
|
|
xInt_curr_offset <= 5'b0; //+0
|
493 |
|
|
else
|
494 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0])? 5'b0:5'b00100; //+0 or +4
|
495 |
|
|
`pos_e,`pos_g,`pos_p,`pos_r:
|
496 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
497 |
|
|
6'd22,6'd20,6'd3,6'd1:xInt_curr_offset <= 5'b0; //+0
|
498 |
|
|
6'd21,6'd19,6'd2,6'd0:xInt_curr_offset <= 5'b00100; //+4
|
499 |
|
|
6'd18,6'd15,6'd12,6'd9,6'd6:xInt_curr_offset <= 5'b11110;//-2
|
500 |
|
|
6'd17,6'd14,6'd11,6'd8,6'd5:xInt_curr_offset <= 5'b00010;//+2
|
501 |
|
|
6'd16,6'd13,6'd10,6'd7,6'd4:xInt_curr_offset <= 5'b00110;//+6
|
502 |
|
|
default:xInt_curr_offset <= 5'b0;
|
503 |
|
|
endcase
|
504 |
|
|
endcase
|
505 |
|
|
end
|
506 |
|
|
else //IsInterChroma
|
507 |
|
|
begin
|
508 |
|
|
if (!mv_below8x8_curr)
|
509 |
|
|
begin
|
510 |
|
|
if (xFracC == 0 && yFracC == 0)
|
511 |
|
|
begin
|
512 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
513 |
|
|
xInt_curr_offset <= 5'b0;
|
514 |
|
|
else
|
515 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0] == 1'b1)? 5'b0:5'b0100;
|
516 |
|
|
end
|
517 |
|
|
else
|
518 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0] == 1'b1)? 5'b0:5'b0100;
|
519 |
|
|
end
|
520 |
|
|
else //mv_below8x8_curr == 1'b1
|
521 |
|
|
begin
|
522 |
|
|
if (xFracC == 0 && yFracC == 0)
|
523 |
|
|
begin
|
524 |
|
|
if (xInt_org_unclip[1:0] == 2'b11) // 4 preload cycles
|
525 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0] == 1'b1)? 5'b0:5'b0100;
|
526 |
|
|
else
|
527 |
|
|
xInt_curr_offset <= 0;
|
528 |
|
|
end
|
529 |
|
|
else
|
530 |
|
|
begin
|
531 |
|
|
if (xInt_org_unclip[1] == 1'b0)
|
532 |
|
|
xInt_curr_offset <= 0;
|
533 |
|
|
else
|
534 |
|
|
xInt_curr_offset <= (blk4x4_inter_preload_counter_m2[0] == 1'b1)? 5'b0:5'b0100;
|
535 |
|
|
end
|
536 |
|
|
end
|
537 |
|
|
end
|
538 |
|
|
end
|
539 |
|
|
else //blk4x4_inter_preload_counter == 0 || blk4x4_inter_preload_counter == 1
|
540 |
|
|
xInt_curr_offset <= 5'b0;
|
541 |
|
|
|
542 |
|
|
//Derive unclipped x pos for each preload cycle
|
543 |
|
|
wire [8:0] xInt_addr_unclip;
|
544 |
|
|
assign xInt_addr_unclip = xInt_org_unclip + {{4{xInt_curr_offset[4]}},xInt_curr_offset};
|
545 |
|
|
|
546 |
|
|
//x addr clipped:x address in pixels
|
547 |
|
|
reg [7:0] xInt_addr;
|
548 |
|
|
always @ (xInt_addr_unclip or IsInterLuma or IsInterChroma)
|
549 |
|
|
if (xInt_addr_unclip[8] == 1'b1) //negative
|
550 |
|
|
xInt_addr <= 0;
|
551 |
|
|
else if (IsInterLuma)
|
552 |
|
|
xInt_addr <= (xInt_addr_unclip[7:0] > (`pic_width - 4))? 8'd172:xInt_addr_unclip[7:0];
|
553 |
|
|
else if (IsInterChroma)
|
554 |
|
|
xInt_addr <= (xInt_addr_unclip[7:0] > (`half_pic_width - 4))? 8'd84:xInt_addr_unclip[7:0];
|
555 |
|
|
else
|
556 |
|
|
xInt_addr <= 0;
|
557 |
|
|
|
558 |
|
|
//yInt_p1:when loading from Xth line to (X-1)th line,yInt_p1 is set to 1'b1 at the last
|
559 |
|
|
//loading cycle of current Xth line
|
560 |
|
|
reg yInt_p1;
|
561 |
|
|
always @ (IsInterLuma or mv_below8x8_curr or pos_FracL or xFracC or yFracC
|
562 |
|
|
or blk4x4_inter_preload_counter or blk4x4_inter_preload_counter_m2 or xInt_org_unclip[1:0] or xInt_org_unclip[1])
|
563 |
|
|
if (blk4x4_inter_preload_counter != 6'd0 && blk4x4_inter_preload_counter != 6'd1)
|
564 |
|
|
begin
|
565 |
|
|
if (IsInterLuma)
|
566 |
|
|
case (mv_below8x8_curr)
|
567 |
|
|
1'b0:
|
568 |
|
|
case (pos_FracL)
|
569 |
|
|
`pos_f,`pos_q,`pos_i,`pos_k,`pos_j:
|
570 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[1:0] == 2'b00)? 1'b1:1'b0;
|
571 |
|
|
`pos_d,`pos_h,`pos_n:
|
572 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
573 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
574 |
|
|
else
|
575 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
576 |
|
|
6'd36,6'd33,6'd30,6'd27,6'd24,6'd21,6'd18,6'd15,6'd12,6'd9,6'd6,6'd3,6'd0:
|
577 |
|
|
yInt_p1 <= 1'b1;
|
578 |
|
|
default:yInt_p1 <= 1'b0;
|
579 |
|
|
endcase
|
580 |
|
|
`pos_a,`pos_b,`pos_c:
|
581 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[1:0] == 2'b00)? 1'b1:1'b0;
|
582 |
|
|
`pos_Int:
|
583 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
584 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
585 |
|
|
else
|
586 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
587 |
|
|
6'd21,6'd18,6'd15,6'd12,6'd9,6'd6,6'd3,6'd0:yInt_p1 <= 1'b1;
|
588 |
|
|
default: yInt_p1 <= 1'b0;
|
589 |
|
|
endcase
|
590 |
|
|
`pos_e,`pos_g,`pos_p,`pos_r:
|
591 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
592 |
|
|
6'd45,6'd42,6'd3,6'd0:yInt_p1 <= 1'b1;
|
593 |
|
|
6'd6,6'd10,6'd14,6'd18,6'd22,6'd26,6'd30,6'd34,6'd38:yInt_p1 <= 1'b1;
|
594 |
|
|
default:yInt_p1 <= 1'b0;
|
595 |
|
|
endcase
|
596 |
|
|
endcase
|
597 |
|
|
1'b1: //block partition below 8x8
|
598 |
|
|
case (pos_FracL)
|
599 |
|
|
`pos_f,`pos_q,`pos_i,`pos_k,`pos_j:
|
600 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
601 |
|
|
6'd24,6'd21,6'd18,6'd15,6'd12,6'd9,6'd6,6'd3,6'd0:yInt_p1 <= 1'b1;
|
602 |
|
|
default:yInt_p1 <= 1'b0;
|
603 |
|
|
endcase
|
604 |
|
|
`pos_d,`pos_h,`pos_n:
|
605 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
606 |
|
|
yInt_p1 <= 1'b1;
|
607 |
|
|
else
|
608 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
609 |
|
|
`pos_a,`pos_b,`pos_c:
|
610 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
611 |
|
|
5'd9,5'd6,5'd3,5'd0 :yInt_p1 <= 1'b1;
|
612 |
|
|
default :yInt_p1 <= 1'b0;
|
613 |
|
|
endcase
|
614 |
|
|
`pos_Int:
|
615 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
616 |
|
|
yInt_p1 <= 1'b1;
|
617 |
|
|
else
|
618 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
619 |
|
|
`pos_e,`pos_g,`pos_p,`pos_r:
|
620 |
|
|
case (blk4x4_inter_preload_counter_m2)
|
621 |
|
|
6'd21,6'd19,6'd2,6'd0 :yInt_p1 <= 1'b1;
|
622 |
|
|
6'd4,6'd7,6'd10,6'd13,6'd16 :yInt_p1 <= 1'b1;
|
623 |
|
|
default :yInt_p1 <= 1'b0;
|
624 |
|
|
endcase
|
625 |
|
|
endcase
|
626 |
|
|
endcase
|
627 |
|
|
else //IsInterChroma
|
628 |
|
|
case (mv_below8x8_curr)
|
629 |
|
|
1'b0:
|
630 |
|
|
if (xFracC == 0 && yFracC == 0)
|
631 |
|
|
begin
|
632 |
|
|
if (xInt_org_unclip[1:0] == 2'b00)
|
633 |
|
|
yInt_p1 <= 1'b1;
|
634 |
|
|
else
|
635 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
636 |
|
|
end
|
637 |
|
|
else
|
638 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
639 |
|
|
1'b1:
|
640 |
|
|
if (xFracC == 0 && yFracC == 0)
|
641 |
|
|
begin
|
642 |
|
|
if (xInt_org_unclip[1:0] != 2'b11)
|
643 |
|
|
yInt_p1 <= 1'b1;
|
644 |
|
|
else
|
645 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
646 |
|
|
end
|
647 |
|
|
else
|
648 |
|
|
begin
|
649 |
|
|
if (xInt_org_unclip[1] == 1'b0)
|
650 |
|
|
yInt_p1 <= 1'b1;
|
651 |
|
|
else
|
652 |
|
|
yInt_p1 <= (blk4x4_inter_preload_counter_m2[0] == 1'b0)? 1'b1:1'b0;
|
653 |
|
|
end
|
654 |
|
|
endcase
|
655 |
|
|
end
|
656 |
|
|
else // blk4x4_inter_preload_counter == 0 || blk4x4_inter_preload_counter == 1
|
657 |
|
|
yInt_p1 <= 1'b0;
|
658 |
|
|
|
659 |
|
|
//Derive unclipped y pos for each preload cycle
|
660 |
|
|
reg [8:0] yInt_addr_unclip;
|
661 |
|
|
always @ (posedge clk)
|
662 |
|
|
if (reset_n == 1'b0)
|
663 |
|
|
yInt_addr_unclip <= 0;
|
664 |
|
|
else if ((IsInterLuma && (trigger_blk4x4_inter_pred && (mv_below8x8_curr ||
|
665 |
|
|
(!mv_below8x8_curr && blk4x4_rec_counter[1:0] == 2'b00)))) ||
|
666 |
|
|
(IsInterChroma && (!mv_below8x8_curr && trigger_blk4x4_inter_pred) ||
|
667 |
|
|
(mv_below8x8_curr && trigger_blk2x2_inter_pred)))
|
668 |
|
|
begin
|
669 |
|
|
if (IsInterLuma) //Luma
|
670 |
|
|
case (pos_FracL)
|
671 |
|
|
`pos_a,`pos_b,`pos_c,`pos_Int:
|
672 |
|
|
yInt_addr_unclip <= yInt_org_unclip;
|
673 |
|
|
default: //need -2 here
|
674 |
|
|
yInt_addr_unclip <= yInt_org_unclip + 9'b111111110;
|
675 |
|
|
endcase
|
676 |
|
|
else //Chroma
|
677 |
|
|
yInt_addr_unclip <= yInt_org_unclip;
|
678 |
|
|
end
|
679 |
|
|
else if (blk4x4_inter_preload_counter_m2 != 0 && yInt_p1 == 1'b1)
|
680 |
|
|
yInt_addr_unclip <= yInt_addr_unclip + 1;
|
681 |
|
|
|
682 |
|
|
//y addr clipped
|
683 |
|
|
reg [7:0] yInt_addr;
|
684 |
|
|
always @ (yInt_addr_unclip or IsInterLuma or IsInterChroma)
|
685 |
|
|
if (yInt_addr_unclip[8] == 1'b1) //negative
|
686 |
|
|
yInt_addr <= 0;
|
687 |
|
|
else if (IsInterLuma)
|
688 |
|
|
yInt_addr <= (yInt_addr_unclip[7:0] > (`pic_height - 1))? 8'd143:yInt_addr_unclip[7:0];
|
689 |
|
|
else if (IsInterChroma)
|
690 |
|
|
yInt_addr <= (yInt_addr_unclip[7:0] > (`half_pic_height - 1))? 8'd71:yInt_addr_unclip[7:0];
|
691 |
|
|
else
|
692 |
|
|
yInt_addr <= 0;
|
693 |
|
|
|
694 |
|
|
wire [12:0] offset_constant;
|
695 |
|
|
wire [10:0] yInt_addr_x11;
|
696 |
|
|
wire [12:0] offset_yInt_addr;
|
697 |
|
|
assign offset_constant = (IsInterLuma)? 0:((IsInterChroma)? ((blk4x4_rec_counter < 5'd20)? 13'd6336:13'd7920):0);
|
698 |
|
|
assign yInt_addr_x11 = {yInt_addr,3'b0} + {2'b0,yInt_addr,1'b0} + {3'b0,yInt_addr};
|
699 |
|
|
assign offset_yInt_addr = (IsInterLuma)? {yInt_addr_x11,2'b0}:{1'b0,yInt_addr_x11,1'b0};
|
700 |
|
|
assign ref_frame_RAM_rd_addr = (offset_constant + {8'b0,xInt_addr[7:2]}) + {1'b0,offset_yInt_addr};
|
701 |
|
|
|
702 |
|
|
//----------------------------------------------------------------------------------------
|
703 |
|
|
//Inter prediction output control: from LPE or from CPE
|
704 |
|
|
//----------------------------------------------------------------------------------------
|
705 |
|
|
always @ (IsInterLuma or IsInterChroma or Is_InterChromaCopy
|
706 |
|
|
or blk4x4_inter_calculate_counter or pos_FracL
|
707 |
|
|
or Inter_pix_copy0 or Inter_pix_copy1 or Inter_pix_copy2 or Inter_pix_copy3
|
708 |
|
|
or LPE0_out or LPE1_out or LPE2_out or LPE3_out
|
709 |
|
|
or CPE0_out or CPE1_out or CPE2_out or CPE3_out)
|
710 |
|
|
if (IsInterLuma && blk4x4_inter_calculate_counter != 0)
|
711 |
|
|
begin
|
712 |
|
|
Inter_blk4x4_pred_output_valid <= 2'b01;
|
713 |
|
|
case (pos_FracL)
|
714 |
|
|
`pos_Int:
|
715 |
|
|
begin
|
716 |
|
|
Inter_pred_out0 <= Inter_pix_copy0;Inter_pred_out1 <= Inter_pix_copy1;
|
717 |
|
|
Inter_pred_out2 <= Inter_pix_copy2;Inter_pred_out3 <= Inter_pix_copy3;
|
718 |
|
|
end
|
719 |
|
|
`pos_i,`pos_k:
|
720 |
|
|
if (blk4x4_inter_calculate_counter == 4'd7 || blk4x4_inter_calculate_counter == 4'd5 ||
|
721 |
|
|
blk4x4_inter_calculate_counter == 4'd3 || blk4x4_inter_calculate_counter == 4'd1)
|
722 |
|
|
begin
|
723 |
|
|
Inter_pred_out0 <= LPE0_out;Inter_pred_out1 <= LPE1_out;
|
724 |
|
|
Inter_pred_out2 <= LPE2_out;Inter_pred_out3 <= LPE3_out;
|
725 |
|
|
end
|
726 |
|
|
else
|
727 |
|
|
begin
|
728 |
|
|
Inter_pred_out0 <= 0;Inter_pred_out1 <= 0;Inter_pred_out2 <= 0;Inter_pred_out3 <= 0;
|
729 |
|
|
end
|
730 |
|
|
default:
|
731 |
|
|
if (blk4x4_inter_calculate_counter == 4'd4 || blk4x4_inter_calculate_counter == 4'd3 ||
|
732 |
|
|
blk4x4_inter_calculate_counter == 4'd2 || blk4x4_inter_calculate_counter == 4'd1)
|
733 |
|
|
begin
|
734 |
|
|
Inter_pred_out0 <= LPE0_out;Inter_pred_out1 <= LPE1_out;
|
735 |
|
|
Inter_pred_out2 <= LPE2_out;Inter_pred_out3 <= LPE3_out;
|
736 |
|
|
end
|
737 |
|
|
else
|
738 |
|
|
begin
|
739 |
|
|
Inter_pred_out0 <= 0;Inter_pred_out1 <= 0;Inter_pred_out2 <= 0;Inter_pred_out3 <= 0;
|
740 |
|
|
end
|
741 |
|
|
endcase
|
742 |
|
|
end
|
743 |
|
|
else if (IsInterChroma && blk4x4_inter_calculate_counter != 0)
|
744 |
|
|
begin
|
745 |
|
|
Inter_pred_out0 <= (Is_InterChromaCopy)? Inter_pix_copy0:CPE0_out;
|
746 |
|
|
Inter_pred_out1 <= (Is_InterChromaCopy)? Inter_pix_copy1:CPE1_out;
|
747 |
|
|
Inter_pred_out2 <= (Is_InterChromaCopy)? Inter_pix_copy2:CPE2_out;
|
748 |
|
|
Inter_pred_out3 <= (Is_InterChromaCopy)? Inter_pix_copy3:CPE3_out;
|
749 |
|
|
Inter_blk4x4_pred_output_valid <= 2'b10;
|
750 |
|
|
end
|
751 |
|
|
else
|
752 |
|
|
begin
|
753 |
|
|
Inter_pred_out0 <= 0;Inter_pred_out1 <= 0;Inter_pred_out2 <= 0;Inter_pred_out3 <= 0;
|
754 |
|
|
Inter_blk4x4_pred_output_valid <= 2'b00;
|
755 |
|
|
end
|
756 |
|
|
endmodule
|
757 |
|
|
|
758 |
|
|
|
759 |
|
|
|
760 |
|
|
|
761 |
|
|
|
762 |
|
|
|
763 |
|
|
|
764 |
|
|
|
765 |
|
|
|
766 |
|
|
|
767 |
|
|
|
768 |
|
|
|
769 |
|
|
|
770 |
|
|
|
771 |
|
|
|
772 |
|
|
|
773 |
|
|
|
774 |
|
|
|
775 |
|
|
|
776 |
|
|
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
|
780 |
|
|
|
781 |
|
|
|
782 |
|
|
|