OpenCores
URL https://opencores.org/ocsvn/nova/nova/trunk

Subversion Repositories nova

[/] [nova/] [trunk/] [src/] [syntax_decoding.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 eexuke
//--------------------------------------------------------------------------------------------------
2
// Design    : nova
3
// Author(s) : Ke Xu
4
// Email           : eexuke@yahoo.com
5
// File      : syntax_decoding.v
6
// Generated : May 23, 2005
7
// Copyright (C) 2008 Ke Xu                
8
//-------------------------------------------------------------------------------------------------
9
// Description 
10
// Decoding each sytax inside the bitstream
11
//-------------------------------------------------------------------------------------------------
12
 
13
// synopsys translate_off
14
`include "timescale.v"
15
// synopsys translate_on
16
`include "nova_defines.v"
17
 
18
module syntax_decoding (clk,reset_n,mb_num_h,mb_num_v,end_of_MB_DEC,pin_disable_DF,
19
        parser_state,nal_unit_state,seq_parameter_set_state,pic_parameter_set_state,
20
        slice_header_state,slice_data_state,mb_pred_state,sub_mb_pred_state,
21
        exp_golomb_decoding_output,BitStream_buffer_output,dependent_variable_decoding_output,mbPartIdx,
22
 
23
        nal_unit_type,start_code_prefix_found,
24
        deblocking_filter_control_present_flag,disable_deblocking_filter_idc,disable_DF,
25
        slice_alpha_c0_offset_div2,slice_beta_offset_div2,
26
        mb_skip_run,NumMbPart,NumSubMbPart,
27
        MBTypeGen_mbAddrA,MBTypeGen_mbAddrD,MBTypeGen_mbAddrB_reg,
28
        log2_max_frame_num_minus4,log2_max_pic_order_cnt_lsb_minus4,constrained_intra_pred_flag,
29
        num_ref_idx_active_override_flag,num_ref_idx_l0_active_minus1,
30
        slice_type,mb_type,mb_type_general,sub_mb_type,Intra16x16_predmode,intra_chroma_pred_mode,
31
        pic_init_qp_minus26,chroma_qp_index_offset,
32
        rem_intra4x4_pred_mode,prev_intra4x4_pred_mode_flag,mvd,mv_below8x8);
33
        input clk,reset_n;
34
        input [3:0] mb_num_h,mb_num_v;
35
        input end_of_MB_DEC;
36
        input pin_disable_DF;
37
        input [1:0] parser_state;
38
        input [2:0] nal_unit_state;
39
        input [3:0] seq_parameter_set_state;
40
        input [3:0] pic_parameter_set_state;
41
        input [3:0] slice_header_state;
42
        input [3:0] slice_data_state;
43
        input [2:0] mb_pred_state;
44
        input [1:0] sub_mb_pred_state;
45
        input [15:0] BitStream_buffer_output;
46
        input [7:0] exp_golomb_decoding_output;
47
        input [9:0] dependent_variable_decoding_output;
48
        input [1:0] mbPartIdx;
49
 
50
        output [4:0] nal_unit_type;
51
        output start_code_prefix_found;
52
        output deblocking_filter_control_present_flag;
53
        output [1:0] disable_deblocking_filter_idc;
54
        output disable_DF;
55
        output [3:0] slice_alpha_c0_offset_div2;
56
        output [3:0] slice_beta_offset_div2;
57
        output [6:0] mb_skip_run;
58
        output [2:0] NumMbPart;
59
        output [2:0] NumSubMbPart;
60
        output [1:0] MBTypeGen_mbAddrA;
61
        output MBTypeGen_mbAddrD;
62
        output [21:0] MBTypeGen_mbAddrB_reg;
63
        output [3:0] log2_max_frame_num_minus4;
64
        output [3:0] log2_max_pic_order_cnt_lsb_minus4;
65
        output constrained_intra_pred_flag;
66
        output num_ref_idx_active_override_flag;
67
        output [2:0] num_ref_idx_l0_active_minus1;
68
        output [2:0] slice_type;
69
        output [4:0] mb_type;
70
        output [3:0] mb_type_general;
71
        output [1:0] Intra16x16_predmode;
72
        output [1:0] intra_chroma_pred_mode;
73
        output [1:0] sub_mb_type;
74
        output [5:0] pic_init_qp_minus26;
75
        output [4:0] chroma_qp_index_offset;
76
        output [2:0] rem_intra4x4_pred_mode;
77
        output prev_intra4x4_pred_mode_flag;
78
        output [7:0] mvd;
79
        output [3:0] mv_below8x8;
80
        //--------------------------
81
        //start_code_prefix
82
        //--------------------------
83
        reg start_code_prefix_found;
84
        always @ (parser_state or BitStream_buffer_output)
85
                if (parser_state == `start_code_prefix)
86
                        begin
87
                                if (BitStream_buffer_output == 16'b0000000000000001)
88
                                        start_code_prefix_found <= 1;
89
                                else
90
                                        start_code_prefix_found <= 0;
91
                        end
92
                else
93
                        start_code_prefix_found <= 0;
94
        //--------------------------
95
        //nal_unit
96
        //--------------------------
97
        reg forbidden_zero_bit;
98
        reg [1:0] nal_ref_idc;
99
        reg [4:0] nal_unit_type_reg;
100
        wire [4:0] nal_unit_type;
101
        assign nal_unit_type = (nal_unit_state == `forbidden_zero_bit_2_nal_unit_type)? BitStream_buffer_output[12:8]:nal_unit_type_reg;
102
        always @ (posedge clk)
103
                if (reset_n == 0)
104
                        begin
105
                                forbidden_zero_bit <= 0;
106
                                nal_ref_idc        <= 0;
107
                                nal_unit_type_reg  <= 0;
108
                        end
109
                else if (nal_unit_state == `forbidden_zero_bit_2_nal_unit_type)
110
                        begin
111
                                forbidden_zero_bit <= BitStream_buffer_output[15];
112
                                nal_ref_idc        <= BitStream_buffer_output[14:13];
113
                                nal_unit_type_reg  <= nal_unit_type;
114
                        end
115
        //--------------------------
116
        //seq_parameter_set
117
        //--------------------------
118
        reg [7:0] profile_idc;
119
        reg constraint_set0_flag,constraint_set1_flag,constraint_set2_flag,constraint_set3_flag;
120
        reg [3:0] reserved_zero_4bits;
121
        reg [7:0] level_idc;
122
        reg [4:0] seq_parameter_set_id_sps;
123
        reg [3:0] log2_max_frame_num_minus4;
124
        reg [1:0] pic_order_cnt_type;
125
        reg [3:0] log2_max_pic_order_cnt_lsb_minus4;
126
        reg [2:0] num_ref_frames; //however,we only support 1 reference frame currently
127
        reg gaps_in_frame_num_value_allowed_flag;
128
        reg [3:0] pic_width_in_mbs_minus1;
129
        reg [3:0] pic_height_in_map_units_minus1;
130
        reg frame_mbs_only_flag;
131
        reg direct_8x8_inference_flag;
132
        reg frame_cropping_flag;
133
        reg vui_parameter_present_flag;
134
        always @ (posedge clk)
135
                if (reset_n == 0)
136
                        begin
137
                                profile_idc                          <= 0;
138
                                constraint_set0_flag                 <= 0;
139
                                constraint_set1_flag                 <= 0;
140
                                constraint_set2_flag                 <= 0;
141
                                constraint_set3_flag                 <= 0;
142
                                reserved_zero_4bits                      <= 0;
143
                                level_idc                            <= 0;
144
                                seq_parameter_set_id_sps             <= 0;
145
                                log2_max_frame_num_minus4            <= 0;
146
                                pic_order_cnt_type                   <= 0;
147
                                log2_max_pic_order_cnt_lsb_minus4    <= 0;
148
                                num_ref_frames                       <= 0;
149
                                gaps_in_frame_num_value_allowed_flag <= 0;
150
                                pic_width_in_mbs_minus1              <= 0;
151
                                pic_height_in_map_units_minus1       <= 0;
152
                                frame_mbs_only_flag                  <= 0;
153
                                direct_8x8_inference_flag            <= 0;
154
                                frame_cropping_flag                  <= 0;
155
                                vui_parameter_present_flag           <= 0;
156
                        end
157
                else
158
                        case (seq_parameter_set_state)
159
                                `fixed_header:
160
                                begin
161
                                        profile_idc <= BitStream_buffer_output[15:8];
162
                                        constraint_set0_flag <= BitStream_buffer_output[7];
163
                                        constraint_set1_flag <= BitStream_buffer_output[6];
164
                                        constraint_set2_flag <= BitStream_buffer_output[5];
165
                                        constraint_set3_flag <= BitStream_buffer_output[4];
166
                                        reserved_zero_4bits  <= BitStream_buffer_output[3:0];
167
                                end
168
                                `level_idc_s                           :level_idc                            <= BitStream_buffer_output[15:8];
169
                                `seq_parameter_set_id_sps_s            :seq_parameter_set_id_sps             <= exp_golomb_decoding_output[4:0];
170
                                `log2_max_frame_num_minus4_s           :log2_max_frame_num_minus4            <= exp_golomb_decoding_output[3:0];
171
                                `pic_order_cnt_type_s                  :pic_order_cnt_type                   <= exp_golomb_decoding_output[1:0];
172
                                `log2_max_pic_order_cnt_lsb_minus4_s   :log2_max_pic_order_cnt_lsb_minus4    <= exp_golomb_decoding_output[3:0];
173
                                `num_ref_frames_s                      :num_ref_frames                       <= exp_golomb_decoding_output[0];
174
                                `gaps_in_frame_num_value_allowed_flag_s:gaps_in_frame_num_value_allowed_flag <= BitStream_buffer_output[15];
175
                                `pic_width_in_mbs_minus1_s             :pic_width_in_mbs_minus1              <= exp_golomb_decoding_output[3:0];
176
                                `pic_height_in_map_units_minus1_s      :pic_height_in_map_units_minus1       <= exp_golomb_decoding_output[3:0];
177
                                `frame_mbs_only_flag_2_frame_cropping_flag:
178
                                begin
179
                                        frame_mbs_only_flag       <= BitStream_buffer_output[15];
180
                                        direct_8x8_inference_flag <= BitStream_buffer_output[14];
181
                                        frame_cropping_flag       <= BitStream_buffer_output[13];
182
                                end
183
                                `vui_parameter_present_flag_s:vui_parameter_present_flag <= BitStream_buffer_output[15];
184
                        endcase
185
        //--------------------------
186
        //pic_parameter_set
187
        //--------------------------
188
        reg [7:0] pic_parameter_set_id_pps;
189
        reg [4:0] seq_parameter_set_id_pps;
190
        reg entropy_coding_mode_flag;
191
        reg pic_order_present_flag;
192
        reg [2:0] num_slice_groups_minus1;
193
        reg [2:0] num_ref_idx_l0_active_minus1;
194
        reg [2:0] num_ref_idx_l1_active_minus1;
195
        reg weighted_pred_flag;
196
        reg [1:0] weighted_bipred_idc;
197
        reg [5:0] pic_init_qp_minus26,pic_init_qs_minus26;
198
        reg [4:0] chroma_qp_index_offset;
199
        reg deblocking_filter_control_present_flag;
200
        reg constrained_intra_pred_flag;
201
        reg redundant_pic_cnt_present_flag;
202
        always @ (posedge clk)
203
                if (reset_n == 0)
204
                        begin
205
                                pic_parameter_set_id_pps               <= 0;
206
                                seq_parameter_set_id_pps               <= 0;
207
                                entropy_coding_mode_flag               <= 0;
208
                                pic_order_present_flag                 <= 0;
209
                                num_slice_groups_minus1                <= 0;
210
                                num_ref_idx_l0_active_minus1           <= 0;
211
                                num_ref_idx_l1_active_minus1           <= 0;
212
                                weighted_pred_flag                     <= 0;
213
                                weighted_bipred_idc                    <= 0;
214
                                pic_init_qp_minus26                    <= 0;
215
                                pic_init_qs_minus26                    <= 0;
216
                                chroma_qp_index_offset                 <= 0;
217
                                deblocking_filter_control_present_flag <= 0;
218
                                constrained_intra_pred_flag            <= 0;
219
                                redundant_pic_cnt_present_flag         <= 0;
220
                        end
221
                else
222
                        case (pic_parameter_set_state)
223
                                `pic_parameter_set_id_pps_s:pic_parameter_set_id_pps <= exp_golomb_decoding_output[7:0];
224
                                `seq_parameter_set_id_pps_s:seq_parameter_set_id_pps <= exp_golomb_decoding_output[4:0];
225
                                `entropy_coding_mode_flag_2_pic_order_present_flag:
226
                                begin
227
                                        entropy_coding_mode_flag <= BitStream_buffer_output[15];
228
                                        pic_order_present_flag   <= BitStream_buffer_output[14];
229
                                end
230
                                `num_slice_groups_minus1_s         :num_slice_groups_minus1 <= exp_golomb_decoding_output[2:0];
231
                                `num_ref_idx_l0_active_minus1_pps_s:num_ref_idx_l0_active_minus1 <= exp_golomb_decoding_output[2:0];
232
                                `num_ref_idx_l1_active_minus1_pps_s:num_ref_idx_l1_active_minus1 <= exp_golomb_decoding_output[2:0];
233
                                `weighted_pred_flag_2_weighted_bipred_idc:
234
                                begin
235
                                        weighted_pred_flag  <= BitStream_buffer_output[15];
236
                                        weighted_bipred_idc <= BitStream_buffer_output[14:13];
237
                                end
238
                                `pic_init_qp_minus26_s   :pic_init_qp_minus26 <= exp_golomb_decoding_output[5:0];
239
                                `pic_init_qs_minus26_s   :pic_init_qs_minus26 <= exp_golomb_decoding_output[5:0];
240
                                `chroma_qp_index_offset_s:chroma_qp_index_offset <= exp_golomb_decoding_output[4:0];
241
                                `deblocking_filter_control_2_redundant_pic_cnt_present_flag:
242
                                begin
243
                                        deblocking_filter_control_present_flag <= BitStream_buffer_output[15];
244
                                        constrained_intra_pred_flag            <= BitStream_buffer_output[14];
245
                                        redundant_pic_cnt_present_flag         <= BitStream_buffer_output[13];
246
                                end
247
                        endcase
248
        //--------------------------
249
        //slice_header
250
        //--------------------------
251
        reg first_mb_in_slice;
252
        reg [2:0] slice_type;
253
        reg [7:0] pic_parameter_set_id_slice_header;
254
        reg [3:0] frame_num;
255
        reg idr_pic_id;
256
        reg [9:0] pic_order_cnt_lsb;
257
        reg num_ref_idx_active_override_flag;
258
        reg [1:0] disable_deblocking_filter_idc;
259
        reg [3:0] slice_alpha_c0_offset_div2_dec;
260
        reg [3:0] slice_beta_offset_div2_dec;
261
        always @ (posedge clk)
262
                if (reset_n == 0)
263
                        begin
264
                                first_mb_in_slice                 <= 0;
265
                                slice_type                        <= 0;
266
                                pic_parameter_set_id_slice_header <= 0;
267
                                frame_num                         <= 0;
268
                                idr_pic_id                        <= 0;
269
                                pic_order_cnt_lsb                 <= 0;
270
                                num_ref_idx_active_override_flag  <= 0;
271
                                disable_deblocking_filter_idc     <= 0;
272
                                slice_alpha_c0_offset_div2_dec    <= 0;
273
                                slice_beta_offset_div2_dec        <= 0;
274
                        end
275
                else
276
                        case (slice_header_state)
277
                                `first_mb_in_slice_s                :first_mb_in_slice                 <= exp_golomb_decoding_output[0];
278
                                `slice_type_s                       :slice_type                        <= exp_golomb_decoding_output[2:0];
279
                                `pic_parameter_set_id_slice_header_s:pic_parameter_set_id_slice_header <= exp_golomb_decoding_output;
280
                                `frame_num_s                        :frame_num                         <= dependent_variable_decoding_output[3:0];
281
                                `idr_pic_id_s                       :idr_pic_id                        <= exp_golomb_decoding_output[0];
282
                                `pic_order_cnt_lsb_s                :pic_order_cnt_lsb                 <= dependent_variable_decoding_output[9:0];
283
                                `num_ref_idx_active_override_flag_s :num_ref_idx_active_override_flag  <= BitStream_buffer_output[15];
284
                                //num_ref_idx_l0_active_minus1_slice_header_s:
285
                                //slice_qp_delta_s:slice_qp_delta <= exp_golomb_decoding_output[5:0];
286
                                `disable_deblocking_filter_idc_s    :disable_deblocking_filter_idc     <= exp_golomb_decoding_output[1:0];
287
                                `slice_alpha_c0_offset_div2_s       :slice_alpha_c0_offset_div2_dec    <= exp_golomb_decoding_output[3:0];
288
                                `slice_beta_offset_div2_s           :slice_beta_offset_div2_dec              <= exp_golomb_decoding_output[3:0];
289
                                //slice_group_change_cycle_s:
290
                        endcase
291
 
292
        wire [3:0] slice_alpha_c0_offset_div2;
293
        wire [3:0] slice_beta_offset_div2;
294
        assign slice_alpha_c0_offset_div2 = {4{deblocking_filter_control_present_flag}} & slice_alpha_c0_offset_div2_dec;
295
        assign slice_beta_offset_div2     = {4{deblocking_filter_control_present_flag}} & slice_beta_offset_div2_dec;
296
 
297
        reg sw_disable_DF;
298
        always @ (posedge clk)
299
                if (reset_n == 0)
300
                        sw_disable_DF <= 0;
301
                else if (slice_header_state == `disable_deblocking_filter_idc_s && disable_deblocking_filter_idc == 1)
302
                        sw_disable_DF <= 1;
303
                else
304
                        sw_disable_DF <= 0;
305
 
306
        assign disable_DF = sw_disable_DF | pin_disable_DF;
307
        //--------------------------
308
        //slice_data
309
        //--------------------------
310
        wire [6:0] mb_skip_run;
311
        reg [6:0] mb_skip_run_reg;
312
        reg [4:0] mb_type;
313
        reg [3:0] mb_type_general;
314
        reg [3:0] mb_type_general_reg;
315
        reg [1:0] Intra16x16_predmode;
316
 
317
        //mb_type_general
318
        assign mb_skip_run = (slice_data_state == `mb_skip_run_s)? exp_golomb_decoding_output[6:0]:mb_skip_run_reg;
319
        always @ (slice_data_state or slice_type or exp_golomb_decoding_output or mb_type_general_reg)
320
                if (slice_data_state == `skip_run_duration)
321
                        mb_type_general <= `MB_P_skip;
322
                else if (slice_data_state == `mb_type_s)
323
                        begin
324
                                if (slice_type == 2 || slice_type == 7) //I slice
325
                                        case (exp_golomb_decoding_output)
326
                                                0:                      mb_type_general <= `MB_Intra4x4;
327
                                                1,2,3,4,13,14,15,16:    mb_type_general <= `MB_Intra16x16_CBPChroma0;
328
                                                5,6,7,8,17,18,19,20:    mb_type_general <= `MB_Intra16x16_CBPChroma1;
329
                                                9,10,11,12,21,22,23,24: mb_type_general <= `MB_Intra16x16_CBPChroma2;
330
                                                default:                mb_type_general <= `MB_Inter16x16;
331
                                        endcase
332
                                else                                    //P slice
333
                                        case (exp_golomb_decoding_output)
334
                                                0:                      mb_type_general <= `MB_Inter16x16;
335
                                                1:                      mb_type_general <= `MB_Inter16x8;
336
                                                2:                      mb_type_general <= `MB_Inter8x16;
337
                                                3:                      mb_type_general <= `MB_P_8x8;
338
                                                4:                      mb_type_general <= `MB_P_8x8ref0;
339
                                                5:                      mb_type_general <= `MB_Intra4x4;
340
                                                6,7,8,9,18,19,20,21:    mb_type_general <= `MB_Intra16x16_CBPChroma0;
341
                                                10,11,12,13,22,23,24,25:mb_type_general <= `MB_Intra16x16_CBPChroma1;
342
                                                14,15,16,17,26,27,28,29:mb_type_general <= `MB_Intra16x16_CBPChroma0;
343
                                                default:                mb_type_general <= `MB_Inter16x8;
344
                                        endcase
345
                        end
346
                else
347
                        mb_type_general <= mb_type_general_reg;
348
 
349
        //Intra16x16_predmode
350
        always @ (posedge clk)
351
                if (reset_n == 0)
352
                        Intra16x16_predmode <= 2'b0;
353
                else if (slice_data_state == `mb_type_s)
354
                        begin
355
                                if (slice_type == 2 || slice_type == 7) //I slice
356
                                        begin
357
                                                if (exp_golomb_decoding_output != 0)
358
                                                        case (exp_golomb_decoding_output[1:0])
359
                                                                2'b00:Intra16x16_predmode <= 2'b11;
360
                                                                2'b01:Intra16x16_predmode <= 2'b00;
361
                                                                2'b10:Intra16x16_predmode <= 2'b01;
362
                                                                2'b11:Intra16x16_predmode <= 2'b10;
363
                                                        endcase
364
                                        end
365
                                else if (exp_golomb_decoding_output[4:0] > 5) //P slice
366
                                        case (exp_golomb_decoding_output[1:0])
367
                                                2'b00:Intra16x16_predmode <= 2'b10;
368
                                                2'b01:Intra16x16_predmode <= 2'b11;
369
                                                2'b10:Intra16x16_predmode <= 2'b00;
370
                                                2'b11:Intra16x16_predmode <= 2'b01;
371
                                        endcase
372
                        end
373
 
374
        always @ (posedge clk)
375
                if (reset_n == 0)
376
                        begin
377
                                mb_skip_run_reg <= 0;
378
                                mb_type <= 0;
379
                                mb_type_general_reg <= `MB_type_rst;
380
                        end
381
                else
382
                        case (slice_data_state)
383
                                `mb_skip_run_s:mb_skip_run_reg <= mb_skip_run;
384
                                `skip_run_duration:
385
                                begin
386
                                        mb_type <= 5'd31;
387
                                        mb_type_general_reg <= mb_type_general;
388
                                end
389
                                `mb_type_s:
390
                                begin
391
                                        mb_type <= exp_golomb_decoding_output[4:0];
392
                                        mb_type_general_reg <= mb_type_general;
393
                                end
394
                                //pcm_byte_s: --> Currently no deal with it
395
                                //coded_block_pattern_s: --> See CodedBlockPattern_decoding.v
396
                                //mb_qp_delta_s:mb_qp_delta <= exp_golomb_decoding_output;
397
                        endcase
398
        //Update MBTypeGen information
399
        reg [1:0] MBTypeGen_mbAddrA;
400
        reg MBTypeGen_mbAddrD_tmp;
401
        reg MBTypeGen_mbAddrD;
402
        reg [21:0] MBTypeGen_mbAddrB_reg;
403
        always @ (posedge clk)
404
                if (reset_n == 0)
405
                        begin
406
                                MBTypeGen_mbAddrA <= 0;
407
                                MBTypeGen_mbAddrD_tmp <= 0;
408
                                MBTypeGen_mbAddrB_reg <= 0;
409
                        end
410
                else if (slice_data_state == `skip_run_duration && end_of_MB_DEC)//for P_skip
411
                        begin
412
                                if (mb_num_h != 10)
413
                                        MBTypeGen_mbAddrA <= `MB_addrA_addrB_P_skip;
414
                                if (mb_num_h == 9)
415
                                        MBTypeGen_mbAddrD_tmp <= 1'b0;
416
                                if (mb_num_v != 8)
417
                                        case (mb_num_h)
418
                                                0:MBTypeGen_mbAddrB_reg[1:0]    <= `MB_addrA_addrB_P_skip;1:MBTypeGen_mbAddrB_reg[3:2]     <= `MB_addrA_addrB_P_skip;
419
                                                2:MBTypeGen_mbAddrB_reg[5:4]    <= `MB_addrA_addrB_P_skip;3:MBTypeGen_mbAddrB_reg[7:6]   <= `MB_addrA_addrB_P_skip;
420
                                                4:MBTypeGen_mbAddrB_reg[9:8]    <= `MB_addrA_addrB_P_skip;5:MBTypeGen_mbAddrB_reg[11:10] <= `MB_addrA_addrB_P_skip;
421
                                                6:MBTypeGen_mbAddrB_reg[13:12]  <= `MB_addrA_addrB_P_skip;7:MBTypeGen_mbAddrB_reg[15:14] <= `MB_addrA_addrB_P_skip;
422
                                                8:MBTypeGen_mbAddrB_reg[17:16]  <= `MB_addrA_addrB_P_skip;9:MBTypeGen_mbAddrB_reg[19:18] <= `MB_addrA_addrB_P_skip;
423
                                                10:MBTypeGen_mbAddrB_reg[21:20] <= `MB_addrA_addrB_P_skip;
424
                                        endcase
425
                        end
426
                else if (slice_data_state == `mb_num_update)
427
                        begin
428
                                if (mb_num_h != 10)
429
                                        begin
430
                                                if (mb_type_general[3] == 1'b0)
431
                                                        MBTypeGen_mbAddrA <= `MB_addrA_addrB_Inter;
432
                                                else if (mb_type_general[3:2] == 2'b10)
433
                                                        MBTypeGen_mbAddrA <= `MB_addrA_addrB_Intra16x16;
434
                                                else if (mb_type_general == `MB_Intra4x4)
435
                                                        MBTypeGen_mbAddrA <= `MB_addrA_addrB_Intra4x4;
436
                                        end
437
                                if (mb_num_h == 9)
438
                                        MBTypeGen_mbAddrD_tmp <= mb_type_general[3];
439
                                if (mb_num_v != 8)
440
                                        begin
441
                                                if (mb_type_general[3] == 1'b0)
442
                                                        case (mb_num_h)
443
                                                                0:MBTypeGen_mbAddrB_reg[1:0]   <= `MB_addrA_addrB_Inter; 1:MBTypeGen_mbAddrB_reg[3:2]   <= `MB_addrA_addrB_Inter;
444
                                                                2:MBTypeGen_mbAddrB_reg[5:4]   <= `MB_addrA_addrB_Inter; 3:MBTypeGen_mbAddrB_reg[7:6]   <= `MB_addrA_addrB_Inter;
445
                                                                4:MBTypeGen_mbAddrB_reg[9:8]   <= `MB_addrA_addrB_Inter; 5:MBTypeGen_mbAddrB_reg[11:10] <= `MB_addrA_addrB_Inter;
446
                                                                6:MBTypeGen_mbAddrB_reg[13:12] <= `MB_addrA_addrB_Inter; 7:MBTypeGen_mbAddrB_reg[15:14] <= `MB_addrA_addrB_Inter;
447
                                                                8:MBTypeGen_mbAddrB_reg[17:16] <= `MB_addrA_addrB_Inter; 9:MBTypeGen_mbAddrB_reg[19:18] <= `MB_addrA_addrB_Inter;
448
                                                                10:MBTypeGen_mbAddrB_reg[21:20]<= `MB_addrA_addrB_Inter;
449
                                                        endcase
450
                                                else if (mb_type_general[3:2] == 2'b10)
451
                                                        case (mb_num_h)
452
                                                                0:MBTypeGen_mbAddrB_reg[1:0]   <= `MB_addrA_addrB_Intra16x16; 1:MBTypeGen_mbAddrB_reg[3:2]   <= `MB_addrA_addrB_Intra16x16;
453
                                                                2:MBTypeGen_mbAddrB_reg[5:4]   <= `MB_addrA_addrB_Intra16x16; 3:MBTypeGen_mbAddrB_reg[7:6]   <= `MB_addrA_addrB_Intra16x16;
454
                                                                4:MBTypeGen_mbAddrB_reg[9:8]   <= `MB_addrA_addrB_Intra16x16; 5:MBTypeGen_mbAddrB_reg[11:10] <= `MB_addrA_addrB_Intra16x16;
455
                                                                6:MBTypeGen_mbAddrB_reg[13:12] <= `MB_addrA_addrB_Intra16x16; 7:MBTypeGen_mbAddrB_reg[15:14] <= `MB_addrA_addrB_Intra16x16;
456
                                                                8:MBTypeGen_mbAddrB_reg[17:16] <= `MB_addrA_addrB_Intra16x16; 9:MBTypeGen_mbAddrB_reg[19:18] <= `MB_addrA_addrB_Intra16x16;
457
                                                                10:MBTypeGen_mbAddrB_reg[21:20]<= `MB_addrA_addrB_Intra16x16;
458
                                                        endcase
459
                                                else if (mb_type_general == `MB_Intra4x4)
460
                                                        case (mb_num_h)
461
                                                                0:MBTypeGen_mbAddrB_reg[1:0]   <= `MB_addrA_addrB_Intra4x4;       1:MBTypeGen_mbAddrB_reg[3:2]   <= `MB_addrA_addrB_Intra4x4;
462
                                                                2:MBTypeGen_mbAddrB_reg[5:4]   <= `MB_addrA_addrB_Intra4x4;     3:MBTypeGen_mbAddrB_reg[7:6]   <= `MB_addrA_addrB_Intra4x4;
463
                                                                4:MBTypeGen_mbAddrB_reg[9:8]   <= `MB_addrA_addrB_Intra4x4;     5:MBTypeGen_mbAddrB_reg[11:10] <= `MB_addrA_addrB_Intra4x4;
464
                                                                6:MBTypeGen_mbAddrB_reg[13:12] <= `MB_addrA_addrB_Intra4x4; 7:MBTypeGen_mbAddrB_reg[15:14] <= `MB_addrA_addrB_Intra4x4;
465
                                                                8:MBTypeGen_mbAddrB_reg[17:16] <= `MB_addrA_addrB_Intra4x4; 9:MBTypeGen_mbAddrB_reg[19:18] <= `MB_addrA_addrB_Intra4x4;
466
                                                                10:MBTypeGen_mbAddrB_reg[21:20]<= `MB_addrA_addrB_Intra4x4;
467
                                                        endcase
468
                                        end
469
                        end
470
 
471
        always @ (posedge clk)
472
                if (reset_n == 1'b0)
473
                        MBTypeGen_mbAddrD <= 0;
474
                else if (mb_num_h == 0)
475
                        MBTypeGen_mbAddrD <= MBTypeGen_mbAddrD_tmp;
476
 
477
        //----------------------------------------------------------------------
478
        //mb_pred & sub_mb_pred 
479
        //      --> Also refer to Intra4x4_PredMode_decoding.v & Inter_mv_decoding.v
480
        //----------------------------------------------------------------------
481
        wire prev_intra4x4_pred_mode_flag;
482
        reg prev_intra4x4_pred_mode_flag_reg;
483
        wire [2:0] rem_intra4x4_pred_mode;
484
        reg [2:0] rem_intra4x4_pred_mode_reg;
485
        reg [1:0] intra_chroma_pred_mode;
486
        wire [7:0] mvd;
487
        reg [7:0] mvd_reg;
488
        reg [7:0] sub_mb_type_reg;
489
        assign prev_intra4x4_pred_mode_flag = (mb_pred_state == `prev_intra4x4_pred_mode_flag_s)? BitStream_buffer_output[15]:prev_intra4x4_pred_mode_flag_reg;
490
        assign rem_intra4x4_pred_mode = (mb_pred_state == `rem_intra4x4_pred_mode_s)? BitStream_buffer_output[15:13]:rem_intra4x4_pred_mode_reg;
491
        assign mvd = ((mb_pred_state == `mvd_l0_s) || (sub_mb_pred_state == `sub_mvd_l0_s))? exp_golomb_decoding_output[7:0]:mvd_reg;
492
        always @ (posedge clk)
493
                if (reset_n == 0)
494
                        begin
495
                                prev_intra4x4_pred_mode_flag_reg <= 0;
496
                                rem_intra4x4_pred_mode_reg       <= 0;
497
                                intra_chroma_pred_mode           <= 0;
498
                                mvd_reg                          <= 0;
499
                                sub_mb_type_reg                  <= 0;
500
                        end
501
                else
502
                        begin
503
                                case (mb_pred_state)
504
                                        `prev_intra4x4_pred_mode_flag_s:prev_intra4x4_pred_mode_flag_reg <= prev_intra4x4_pred_mode_flag;
505
                                        `rem_intra4x4_pred_mode_s      :rem_intra4x4_pred_mode_reg       <= rem_intra4x4_pred_mode;
506
                                        `intra_chroma_pred_mode_s      :intra_chroma_pred_mode           <= exp_golomb_decoding_output[1:0];
507
                                        //ref_idx_l0_s: --> only 1 reference frame,so never jump into this state
508
                                        `mvd_l0_s:      mvd_reg <= mvd;
509
                                endcase
510
                                case (sub_mb_pred_state)
511
                                        `sub_mb_type_s:
512
                                        case (mbPartIdx)
513
                                                0:sub_mb_type_reg[1:0] <= exp_golomb_decoding_output[1:0];
514
                                                1:sub_mb_type_reg[3:2] <= exp_golomb_decoding_output[1:0];
515
                                                2:sub_mb_type_reg[5:4] <= exp_golomb_decoding_output[1:0];
516
                                                3:sub_mb_type_reg[7:6] <= exp_golomb_decoding_output[1:0];
517
                                        endcase
518
                                        //sub_ref_idx_l0_s: --> only 1 reference frame,so never jump into this state
519
                                        `sub_mvd_l0_s: mvd_reg <= mvd;
520
                                endcase
521
                        end
522
        reg [2:0] NumMbPart;
523
        reg [2:0] NumSubMbPart;
524
        reg [1:0] sub_mb_type;
525
        always @ (sub_mb_pred_state or sub_mb_type_reg or mbPartIdx)
526
                if (sub_mb_pred_state == `sub_mvd_l0_s)
527
                        case (mbPartIdx)
528
                                0:sub_mb_type <= sub_mb_type_reg[1:0];
529
                                1:sub_mb_type <= sub_mb_type_reg[3:2];
530
                                2:sub_mb_type <= sub_mb_type_reg[5:4];
531
                                3:sub_mb_type <= sub_mb_type_reg[7:6];
532
                        endcase
533
                else
534
                        sub_mb_type <= 0;
535
        always @ (mb_pred_state or mb_type_general or sub_mb_pred_state)
536
                if (mb_pred_state == `mvd_l0_s)
537
                        case (mb_type_general)
538
                                0:NumMbPart <= 3'd1;
539
                                default:NumMbPart <= 3'd2;
540
                        endcase
541
                else if (sub_mb_pred_state == `sub_mvd_l0_s)
542
                        NumMbPart <= 3'd4;
543
                else
544
                        NumMbPart <= 3'd0;
545
        always @ (sub_mb_pred_state or mbPartIdx or sub_mb_type_reg)
546
                if (sub_mb_pred_state == `sub_mvd_l0_s)
547
                        case (mbPartIdx)
548
                                0:
549
                                case (sub_mb_type_reg[1:0])
550
                                        2'b00      :NumSubMbPart <= 3'd1;
551
                                        2'b01,2'b10:NumSubMbPart <= 3'd2;
552
                                        2'b11      :NumSubMbPart <= 3'd4;
553
                                endcase
554
                                1:
555
                                case (sub_mb_type_reg[3:2])
556
                                        2'b00      :NumSubMbPart <= 3'd1;
557
                                        2'b01,2'b10:NumSubMbPart <= 3'd2;
558
                                        2'b11      :NumSubMbPart <= 3'd4;
559
                                endcase
560
                                2:
561
                                case (sub_mb_type_reg[5:4])
562
                                        2'b00      :NumSubMbPart <= 3'd1;
563
                                        2'b01,2'b10:NumSubMbPart <= 3'd2;
564
                                        2'b11      :NumSubMbPart <= 3'd4;
565
                                endcase
566
                                3:
567
                                case (sub_mb_type_reg[7:6])
568
                                        2'b00      :NumSubMbPart <= 3'd1;
569
                                        2'b01,2'b10:NumSubMbPart <= 3'd2;
570
                                        2'b11      :NumSubMbPart <= 3'd4;
571
                                endcase
572
                        endcase
573
                else
574
                        NumSubMbPart <= 0;
575
 
576
        //mv_below8x8
577
        reg [3:0] mv_below8x8;
578
        always @ (posedge clk)
579
                if (reset_n == 1'b0)
580
                        mv_below8x8 <= 4'b0;
581
                else if (sub_mb_pred_state == `sub_mb_type_s)
582
                        case (mbPartIdx)
583
                                0:mv_below8x8[0] <= (exp_golomb_decoding_output[1:0] == 2'b00)? 1'b0:1'b1;
584
                                1:mv_below8x8[1] <= (exp_golomb_decoding_output[1:0] == 2'b00)? 1'b0:1'b1;
585
                                2:mv_below8x8[2] <= (exp_golomb_decoding_output[1:0] == 2'b00)? 1'b0:1'b1;
586
                                3:mv_below8x8[3] <= (exp_golomb_decoding_output[1:0] == 2'b00)? 1'b0:1'b1;
587
                        endcase
588
                else if (slice_data_state == `mb_pred || slice_data_state == `skip_run_duration)
589
                        mv_below8x8 <= 4'b0;
590
 
591
endmodule
592
 
593
 
594
 
595
 
596
 
597
 
598
 
599
 
600
 
601
 
602
 
603
 
604
 
605
 
606
 
607
 
608
 
609
 
610
 
611
 
612
 
613
 
614
 
615
 
616
 
617
 
618
 
619
 
620
 
621
 
622
 

powered by: WebSVN 2.1.0

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