1 |
2 |
eexuke |
//--------------------------------------------------------------------------------------------------
|
2 |
|
|
// Design : nova
|
3 |
|
|
// Author(s) : Ke Xu
|
4 |
|
|
// Email : eexuke@yahoo.com
|
5 |
|
|
// File : NumCoeffTrailingOnes_decoding.v
|
6 |
|
|
// Generated : June 8, 2005
|
7 |
|
|
// Copyright (C) 2008 Ke Xu
|
8 |
|
|
//-------------------------------------------------------------------------------------------------
|
9 |
|
|
// Description
|
10 |
|
|
// Decoding for Table 9-5 on Page159 of H.264/AVC standard 2003
|
11 |
|
|
//-------------------------------------------------------------------------------------------------
|
12 |
|
|
|
13 |
|
|
// synopsys translate_off
|
14 |
|
|
`include "timescale.v"
|
15 |
|
|
// synopsys translate_on
|
16 |
|
|
`include "nova_defines.v"
|
17 |
|
|
|
18 |
|
|
module NumCoeffTrailingOnes_decoding (clk,reset_n,cavlc_decoder_state,heading_one_pos,BitStream_buffer_output,
|
19 |
|
|
nC,TrailingOnes,TotalCoeff,NumCoeffTrailingOnes_len);
|
20 |
|
|
input clk,reset_n;
|
21 |
|
|
input [3:0] cavlc_decoder_state;
|
22 |
|
|
input [3:0] heading_one_pos;
|
23 |
|
|
input [15:0] BitStream_buffer_output;
|
24 |
|
|
input [4:0] nC;
|
25 |
|
|
output [1:0] TrailingOnes;
|
26 |
|
|
output [4:0] TotalCoeff;
|
27 |
|
|
output [4:0] NumCoeffTrailingOnes_len;
|
28 |
|
|
reg [1:0] TrailingOnes;
|
29 |
|
|
reg [4:0] TotalCoeff;
|
30 |
|
|
reg [4:0] NumCoeffTrailingOnes_len;
|
31 |
|
|
|
32 |
|
|
reg [1:0] TrailingOnes_reg;
|
33 |
|
|
reg [4:0] TotalCoeff_reg;
|
34 |
|
|
|
35 |
|
|
wire nC_0to2,nC_2to4,nC_4to8,nC_n1,nC_GE8;
|
36 |
|
|
wire nC_0to2_t0,nC_0to2_t1,nC_0to2_t2,nC_0to2_t3;
|
37 |
|
|
wire nC_2to4_t0,nC_2to4_t1,nC_2to4_t2,nC_2to4_t3;
|
38 |
|
|
wire nC_4to8_t0,nC_4to8_t1;
|
39 |
|
|
wire nC_n1_t0;
|
40 |
|
|
//Select nC values to choose table
|
41 |
|
|
assign nC_0to2 = (cavlc_decoder_state == `NumCoeffTrailingOnes_LUT && (nC == 5'd0 || nC == 5'd1));
|
42 |
|
|
assign nC_2to4 = (cavlc_decoder_state == `NumCoeffTrailingOnes_LUT && (nC == 5'd2 || nC == 5'd3));
|
43 |
|
|
assign nC_4to8 = (cavlc_decoder_state == `NumCoeffTrailingOnes_LUT && (nC == 5'd4 || nC == 5'd5 || nC == 5'd6 || nC == 5'd7));
|
44 |
|
|
assign nC_n1 = (cavlc_decoder_state == `NumCoeffTrailingOnes_LUT && (nC == 5'd31));
|
45 |
|
|
assign nC_GE8 = (cavlc_decoder_state == `NumCoeffTrailingOnes_LUT && !nC_0to2 && !nC_2to4 && !nC_4to8 && !nC_n1);
|
46 |
|
|
|
47 |
|
|
//1.nC_0to2 t0 ~ t4 sub-table selection
|
48 |
|
|
assign nC_0to2_t0 = (nC_0to2 && (heading_one_pos == 4'd0 || heading_one_pos == 4'd1 || heading_one_pos == 4'd2));
|
49 |
|
|
assign nC_0to2_t1 = (nC_0to2 && (heading_one_pos == 4'd3 || heading_one_pos == 4'd4));
|
50 |
|
|
assign nC_0to2_t2 = (nC_0to2 && (heading_one_pos == 4'd5 || heading_one_pos == 4'd6 || heading_one_pos == 4'd7 || heading_one_pos == 4'd8));
|
51 |
|
|
assign nC_0to2_t3 = (nC_0to2 && (heading_one_pos == 4'd9 || heading_one_pos == 4'd10));
|
52 |
|
|
//2.nC_2to4 t0 ~ t4 sub-table selection
|
53 |
|
|
assign nC_2to4_t0 = (nC_2to4 && (heading_one_pos == 4'd0 || heading_one_pos == 4'd1));
|
54 |
|
|
assign nC_2to4_t1 = (nC_2to4 && (heading_one_pos == 4'd2 || heading_one_pos == 4'd3));
|
55 |
|
|
assign nC_2to4_t2 = (nC_2to4 && (heading_one_pos == 4'd4 || heading_one_pos == 4'd5 || heading_one_pos == 4'd6));
|
56 |
|
|
assign nC_2to4_t3 = (nC_2to4 && (heading_one_pos == 4'd7 || heading_one_pos == 4'd8));
|
57 |
|
|
//3.nC_4to8 t0 ~ t2 sub-table selection
|
58 |
|
|
assign nC_4to8_t0 = (nC_4to8 && heading_one_pos == 4'd0);
|
59 |
|
|
assign nC_4to8_t1 = (nC_4to8 && (heading_one_pos == 4'd1 || heading_one_pos == 4'd2 || heading_one_pos == 4'd3 || heading_one_pos == 4'd4));
|
60 |
|
|
//4.nC_GE8:single table, NO sub-table selection
|
61 |
|
|
//5.nC_n1 t0 ~ t1 sub-table selection
|
62 |
|
|
assign nC_n1_t0 = (nC_n1 && (heading_one_pos == 4'd0 || heading_one_pos == 4'd1 || heading_one_pos == 4'd2));
|
63 |
|
|
|
64 |
|
|
//NumCoeffTrailingOnes_len
|
65 |
|
|
always @ (nC_0to2 or nC_2to4 or nC_4to8 or nC_GE8 or nC_n1 or heading_one_pos or BitStream_buffer_output)
|
66 |
|
|
if (nC_0to2)
|
67 |
|
|
case (heading_one_pos)
|
68 |
|
|
|
69 |
|
|
1 :NumCoeffTrailingOnes_len <= 5'd2;
|
70 |
|
|
2 :NumCoeffTrailingOnes_len <= 5'd3;
|
71 |
|
|
3 :NumCoeffTrailingOnes_len <= (BitStream_buffer_output[11] == 1)? 5'd5:5'd6;
|
72 |
|
|
4 :NumCoeffTrailingOnes_len <= (BitStream_buffer_output[10] == 1)? 5'd6:5'd7;
|
73 |
|
|
5 :NumCoeffTrailingOnes_len <= 5'd8;
|
74 |
|
|
6 :NumCoeffTrailingOnes_len <= 5'd9;
|
75 |
|
|
7 :NumCoeffTrailingOnes_len <= 5'd10;
|
76 |
|
|
8 :NumCoeffTrailingOnes_len <= 5'd11;
|
77 |
|
|
9 :NumCoeffTrailingOnes_len <= 5'd13;
|
78 |
|
|
10:NumCoeffTrailingOnes_len <= 5'd14;
|
79 |
|
|
11:NumCoeffTrailingOnes_len <= 5'd15;
|
80 |
|
|
12:NumCoeffTrailingOnes_len <= 5'd16;
|
81 |
|
|
13:NumCoeffTrailingOnes_len <= 5'd16;
|
82 |
|
|
14:NumCoeffTrailingOnes_len <= 5'd15;
|
83 |
|
|
default:NumCoeffTrailingOnes_len <= 5'd0;
|
84 |
|
|
endcase
|
85 |
|
|
else if (nC_2to4)
|
86 |
|
|
case (heading_one_pos)
|
87 |
|
|
|
88 |
|
|
1 :NumCoeffTrailingOnes_len <= (BitStream_buffer_output[13] == 1)? 5'd3:5'd4;
|
89 |
|
|
2 :NumCoeffTrailingOnes_len <= (BitStream_buffer_output[12] == 1)? 5'd5:5'd6;
|
90 |
|
|
3 :NumCoeffTrailingOnes_len <= 5'd6;
|
91 |
|
|
4 :NumCoeffTrailingOnes_len <= 5'd7;
|
92 |
|
|
5 :NumCoeffTrailingOnes_len <= 5'd8;
|
93 |
|
|
6 :NumCoeffTrailingOnes_len <= 5'd9;
|
94 |
|
|
7 :NumCoeffTrailingOnes_len <= 5'd11;
|
95 |
|
|
8 :NumCoeffTrailingOnes_len <= 5'd12;
|
96 |
|
|
9 :NumCoeffTrailingOnes_len <= 5'd13;
|
97 |
|
|
10:NumCoeffTrailingOnes_len <= (BitStream_buffer_output[4] == 1)? 5'd13:5'd14;
|
98 |
|
|
11:NumCoeffTrailingOnes_len <= 5'd14;
|
99 |
|
|
12:NumCoeffTrailingOnes_len <= 5'd13;
|
100 |
|
|
default:NumCoeffTrailingOnes_len <= 5'd0;
|
101 |
|
|
endcase
|
102 |
|
|
else if (nC_n1)
|
103 |
|
|
case (heading_one_pos)
|
104 |
|
|
0:NumCoeffTrailingOnes_len <= 5'd1;
|
105 |
|
|
1:NumCoeffTrailingOnes_len <= 5'd2;
|
106 |
|
|
2:NumCoeffTrailingOnes_len <= 5'd3;
|
107 |
|
|
3:NumCoeffTrailingOnes_len <= 5'd6;
|
108 |
|
|
4:NumCoeffTrailingOnes_len <= 5'd6;
|
109 |
|
|
5:NumCoeffTrailingOnes_len <= 5'd7;
|
110 |
|
|
6:NumCoeffTrailingOnes_len <= 5'd8;
|
111 |
|
|
default:NumCoeffTrailingOnes_len <= 5'd7;
|
112 |
|
|
endcase
|
113 |
|
|
else if (nC_4to8)
|
114 |
|
|
case (heading_one_pos)
|
115 |
|
|
|
116 |
|
|
1 :NumCoeffTrailingOnes_len <= 5'd5;
|
117 |
|
|
2 :NumCoeffTrailingOnes_len <= 5'd6;
|
118 |
|
|
3 :NumCoeffTrailingOnes_len <= 5'd7;
|
119 |
|
|
4 :NumCoeffTrailingOnes_len <= 5'd8;
|
120 |
|
|
5 :NumCoeffTrailingOnes_len <= 5'd9;
|
121 |
|
|
6 :NumCoeffTrailingOnes_len <= (BitStream_buffer_output[8:7] == 2'b11)? 5'd9:5'd10;
|
122 |
|
|
7 :NumCoeffTrailingOnes_len <= 5'd10;
|
123 |
|
|
8 :NumCoeffTrailingOnes_len <= 5'd10;
|
124 |
|
|
9 :NumCoeffTrailingOnes_len <= 5'd10;
|
125 |
|
|
10:NumCoeffTrailingOnes_len <= 5'd10;
|
126 |
|
|
default:NumCoeffTrailingOnes_len <= 5'd0;
|
127 |
|
|
endcase
|
128 |
|
|
else if (nC_GE8)
|
129 |
|
|
NumCoeffTrailingOnes_len <= 5'd6;
|
130 |
|
|
else
|
131 |
|
|
NumCoeffTrailingOnes_len <= 0;
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
//TrailingOnes
|
135 |
|
|
always @ (posedge clk)
|
136 |
|
|
if (reset_n == 0)
|
137 |
|
|
TrailingOnes_reg <= 0;
|
138 |
|
|
else if (cavlc_decoder_state == `NumCoeffTrailingOnes_LUT)
|
139 |
|
|
TrailingOnes_reg <= TrailingOnes;
|
140 |
|
|
|
141 |
|
|
always @ (nC_0to2 or nC_2to4 or nC_4to8 or nC_n1 or nC_GE8
|
142 |
|
|
or nC_0to2_t0 or nC_0to2_t1 or nC_0to2_t2 or nC_0to2_t3
|
143 |
|
|
or nC_2to4_t0 or nC_2to4_t1 or nC_2to4_t2 or nC_2to4_t3
|
144 |
|
|
or nC_4to8_t0 or nC_4to8_t1 or nC_n1_t0
|
145 |
|
|
or TrailingOnes_reg or heading_one_pos or BitStream_buffer_output)
|
146 |
|
|
if (nC_0to2)
|
147 |
|
|
begin
|
148 |
|
|
if (nC_0to2_t0)
|
149 |
|
|
TrailingOnes <= heading_one_pos[1:0];
|
150 |
|
|
else if (nC_0to2_t1)
|
151 |
|
|
begin
|
152 |
|
|
if (heading_one_pos == 4'd3 && !BitStream_buffer_output[11])
|
153 |
|
|
TrailingOnes <= (BitStream_buffer_output[10])? 2'd0:2'd1;
|
154 |
|
|
else if (heading_one_pos == 4'd4 && BitStream_buffer_output[10:9] == 2'b01)
|
155 |
|
|
TrailingOnes <= 2'd2;
|
156 |
|
|
else
|
157 |
|
|
TrailingOnes <= 2'd3;
|
158 |
|
|
end
|
159 |
|
|
else if (nC_0to2_t2)
|
160 |
|
|
begin
|
161 |
|
|
if (heading_one_pos == 4'd5)
|
162 |
|
|
case (BitStream_buffer_output[9:8])
|
163 |
|
|
2'b00:TrailingOnes <= 2'd3;
|
164 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
165 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
166 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
167 |
|
|
endcase
|
168 |
|
|
else if (heading_one_pos == 4'd6)
|
169 |
|
|
case (BitStream_buffer_output[8:7])
|
170 |
|
|
2'b00:TrailingOnes <= 2'd3;
|
171 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
172 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
173 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
174 |
|
|
endcase
|
175 |
|
|
else if (heading_one_pos == 4'd7)
|
176 |
|
|
case (BitStream_buffer_output[7:6])
|
177 |
|
|
2'b00:TrailingOnes <= 2'd3;
|
178 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
179 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
180 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
181 |
|
|
endcase
|
182 |
|
|
else
|
183 |
|
|
case (BitStream_buffer_output[6:5])
|
184 |
|
|
2'b00:TrailingOnes <= 2'd3;
|
185 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
186 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
187 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
188 |
|
|
endcase
|
189 |
|
|
end
|
190 |
|
|
else if (nC_0to2_t3)
|
191 |
|
|
begin
|
192 |
|
|
if (heading_one_pos == 4'd9)
|
193 |
|
|
case (BitStream_buffer_output[4:3])
|
194 |
|
|
2'b00:TrailingOnes <= (BitStream_buffer_output[5])? 2'd3:2'd0;
|
195 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
196 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
197 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
198 |
|
|
endcase
|
199 |
|
|
else
|
200 |
|
|
case (BitStream_buffer_output[3:2])
|
201 |
|
|
2'b00:TrailingOnes <= 2'd3;
|
202 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
203 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
204 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
205 |
|
|
endcase
|
206 |
|
|
end
|
207 |
|
|
else
|
208 |
|
|
begin
|
209 |
|
|
if ((heading_one_pos == 4'd11 && BitStream_buffer_output[2:1] == 2'b11) ||
|
210 |
|
|
(heading_one_pos == 4'd12 && BitStream_buffer_output[1:0] == 2'b11) ||
|
211 |
|
|
(heading_one_pos == 4'd13 && (BitStream_buffer_output[1:0] == 2'b00 || BitStream_buffer_output[1:0] == 2'b11)))
|
212 |
|
|
TrailingOnes <= 2'd0;
|
213 |
|
|
else if ((heading_one_pos == 4'd11 && BitStream_buffer_output[2:1] == 2'b10) ||
|
214 |
|
|
(heading_one_pos == 4'd12 && BitStream_buffer_output[1:0] == 2'b10) ||
|
215 |
|
|
(heading_one_pos == 4'd13 && BitStream_buffer_output[1:0] == 2'b10) ||
|
216 |
|
|
heading_one_pos == 4'd14)
|
217 |
|
|
TrailingOnes <= 2'd1;
|
218 |
|
|
else if ((heading_one_pos == 4'd11 && BitStream_buffer_output[2:1] == 2'b01) ||
|
219 |
|
|
(heading_one_pos == 4'd12 && BitStream_buffer_output[1:0] == 2'b01) ||
|
220 |
|
|
(heading_one_pos == 4'd13 && BitStream_buffer_output[1:0] == 2'b01))
|
221 |
|
|
TrailingOnes <= 2'd2;
|
222 |
|
|
else
|
223 |
|
|
TrailingOnes <= 2'd3;
|
224 |
|
|
end
|
225 |
|
|
end
|
226 |
|
|
else if (nC_2to4)
|
227 |
|
|
begin
|
228 |
|
|
if (nC_2to4_t0)
|
229 |
|
|
begin
|
230 |
|
|
if (heading_one_pos == 4'd0)
|
231 |
|
|
TrailingOnes <= {1'b0,~BitStream_buffer_output[14]};
|
232 |
|
|
else
|
233 |
|
|
TrailingOnes <= (BitStream_buffer_output[13])? 2'd2:2'd3;
|
234 |
|
|
end
|
235 |
|
|
else if (nC_2to4_t1)
|
236 |
|
|
begin
|
237 |
|
|
if ((heading_one_pos == 4'd2 && BitStream_buffer_output[12:10] == 3'b011) ||
|
238 |
|
|
(heading_one_pos == 4'd3 && BitStream_buffer_output[11:10] == 2'b11))
|
239 |
|
|
TrailingOnes <= 2'd0;
|
240 |
|
|
else if ((heading_one_pos == 4'd2 && (BitStream_buffer_output[12:11] == 2'b11 || BitStream_buffer_output[12:10] == 3'b010)) ||
|
241 |
|
|
(heading_one_pos == 4'd3 && BitStream_buffer_output[11:10] == 2'b10))
|
242 |
|
|
TrailingOnes <= 2'd1;
|
243 |
|
|
else if ((heading_one_pos == 4'd2 && BitStream_buffer_output[12:10] == 3'b001) ||
|
244 |
|
|
(heading_one_pos == 4'd3 && BitStream_buffer_output[11:10] == 2'b01))
|
245 |
|
|
TrailingOnes <= 2'd2;
|
246 |
|
|
else
|
247 |
|
|
TrailingOnes <= 2'd3;
|
248 |
|
|
end
|
249 |
|
|
else if (nC_2to4_t2)
|
250 |
|
|
begin
|
251 |
|
|
if (heading_one_pos == 4'd4)
|
252 |
|
|
case (BitStream_buffer_output[10:9])
|
253 |
|
|
2'b00:TrailingOnes <= 2'd3;
|
254 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
255 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
256 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
257 |
|
|
endcase
|
258 |
|
|
else if (heading_one_pos == 4'd5)
|
259 |
|
|
case (BitStream_buffer_output[9:8])
|
260 |
|
|
2'b00:TrailingOnes <= 2'd0;
|
261 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
262 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
263 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
264 |
|
|
endcase
|
265 |
|
|
else
|
266 |
|
|
case (BitStream_buffer_output[8:7])
|
267 |
|
|
2'b00:TrailingOnes <= 2'd3;
|
268 |
|
|
2'b01:TrailingOnes <= 2'd2;
|
269 |
|
|
2'b10:TrailingOnes <= 2'd1;
|
270 |
|
|
2'b11:TrailingOnes <= 2'd0;
|
271 |
|
|
endcase
|
272 |
|
|
end
|
273 |
|
|
else if (nC_2to4_t3)
|
274 |
|
|
begin
|
275 |
|
|
if ((heading_one_pos == 4'd7 && BitStream_buffer_output[6:5] == 2'b11) ||
|
276 |
|
|
(heading_one_pos == 4'd8 && (BitStream_buffer_output[5:4] == 2'b11 || BitStream_buffer_output[6:4] == 3'b000)))
|
277 |
|
|
TrailingOnes <= 2'd0;
|
278 |
|
|
else if ((heading_one_pos == 4'd7 && BitStream_buffer_output[6:5] == 2'b10) ||
|
279 |
|
|
(heading_one_pos == 4'd8 && BitStream_buffer_output[5:4] == 2'b10))
|
280 |
|
|
TrailingOnes <= 2'd1;
|
281 |
|
|
else if ((heading_one_pos == 4'd7 && BitStream_buffer_output[6:5] == 2'b01) ||
|
282 |
|
|
(heading_one_pos == 4'd8 && BitStream_buffer_output[5:4] == 2'b01))
|
283 |
|
|
TrailingOnes <= 2'd2;
|
284 |
|
|
else
|
285 |
|
|
TrailingOnes <= 2'd3;
|
286 |
|
|
end
|
287 |
|
|
else
|
288 |
|
|
begin
|
289 |
|
|
if ((heading_one_pos == 4'd9 && BitStream_buffer_output[4:3] == 2'b11) ||
|
290 |
|
|
(heading_one_pos == 4'd10 && (BitStream_buffer_output[4:3] == 2'b11 || BitStream_buffer_output[4:2] == 3'b001)) ||
|
291 |
|
|
(heading_one_pos == 4'd11 && BitStream_buffer_output[3:2] == 2'b11))
|
292 |
|
|
TrailingOnes <= 2'd0;
|
293 |
|
|
else if ((heading_one_pos == 4'd9 && BitStream_buffer_output[4:3] == 2'b10) ||
|
294 |
|
|
(heading_one_pos == 4'd10 && (BitStream_buffer_output[4:2] == 3'b000 || BitStream_buffer_output[4:2] == 3'b011)) ||
|
295 |
|
|
(heading_one_pos == 4'd11 && BitStream_buffer_output[3:2] == 2'b10))
|
296 |
|
|
TrailingOnes <= 2'd1;
|
297 |
|
|
else if ((heading_one_pos == 4'd9 && BitStream_buffer_output[4:3] == 2'b01) ||
|
298 |
|
|
(heading_one_pos == 4'd10 && (BitStream_buffer_output[4:3] == 2'b10 || BitStream_buffer_output[4:2] == 3'b010)) ||
|
299 |
|
|
(heading_one_pos == 4'd11 && BitStream_buffer_output[3:2] == 2'b01))
|
300 |
|
|
TrailingOnes <= 2'd2;
|
301 |
|
|
else
|
302 |
|
|
TrailingOnes <= 2'd3;
|
303 |
|
|
end
|
304 |
|
|
end
|
305 |
|
|
else if (nC_n1)
|
306 |
|
|
begin
|
307 |
|
|
if (nC_n1_t0)
|
308 |
|
|
begin
|
309 |
|
|
if (BitStream_buffer_output[15]) TrailingOnes <= 2'd1;
|
310 |
|
|
else if (BitStream_buffer_output[14]) TrailingOnes <= 2'd0;
|
311 |
|
|
else TrailingOnes <= 2'd2;
|
312 |
|
|
end
|
313 |
|
|
else
|
314 |
|
|
begin
|
315 |
|
|
if ((heading_one_pos == 4'd3 && (BitStream_buffer_output[11:10] == 2'b00 || BitStream_buffer_output[11:10] == 2'b11)) ||
|
316 |
|
|
heading_one_pos == 4'd4)
|
317 |
|
|
TrailingOnes <= 2'd0;
|
318 |
|
|
else if ((heading_one_pos == 4'd3 && BitStream_buffer_output[11:10] == 2'b10) ||
|
319 |
|
|
(heading_one_pos == 4'd5 && BitStream_buffer_output[9]) ||
|
320 |
|
|
(heading_one_pos == 4'd6 && BitStream_buffer_output[8]))
|
321 |
|
|
TrailingOnes <= 2'd1;
|
322 |
|
|
else if ((heading_one_pos == 4'd5 && !BitStream_buffer_output[9]) ||
|
323 |
|
|
(heading_one_pos == 4'd6 && !BitStream_buffer_output[8]))
|
324 |
|
|
TrailingOnes <= 2'd2;
|
325 |
|
|
else
|
326 |
|
|
TrailingOnes <= 2'd3;
|
327 |
|
|
end
|
328 |
|
|
end
|
329 |
|
|
else if (nC_4to8)
|
330 |
|
|
begin
|
331 |
|
|
if (nC_4to8_t0)
|
332 |
|
|
begin
|
333 |
|
|
if (BitStream_buffer_output[14:12] == 3'b111) TrailingOnes <= 2'd0;
|
334 |
|
|
else if (BitStream_buffer_output[14:12] == 3'b110) TrailingOnes <= 2'd1;
|
335 |
|
|
else if (BitStream_buffer_output[14:12] == 3'b101) TrailingOnes <= 2'd2;
|
336 |
|
|
else TrailingOnes <= 2'd3;
|
337 |
|
|
end
|
338 |
|
|
else if (nC_4to8_t1)
|
339 |
|
|
begin
|
340 |
|
|
if ((heading_one_pos == 4'd1 &&
|
341 |
|
|
(BitStream_buffer_output[13:11] == 3'b000 || BitStream_buffer_output[13:11] == 3'b010 ||
|
342 |
|
|
BitStream_buffer_output[13:11] == 3'b100 || BitStream_buffer_output[13:11] == 3'b111)) ||
|
343 |
|
|
(heading_one_pos == 4'd2 && BitStream_buffer_output[11:10] == 2'b10 ) ||
|
344 |
|
|
(heading_one_pos == 4'd3 && BitStream_buffer_output[11:9] == 3'b110) ||
|
345 |
|
|
(heading_one_pos == 4'd4 && BitStream_buffer_output[9:8] == 2'b10 ))
|
346 |
|
|
TrailingOnes <= 2'd1;
|
347 |
|
|
else if (
|
348 |
|
|
(heading_one_pos == 4'd1 && (BitStream_buffer_output[13:11] == 3'b001 || BitStream_buffer_output[13:11] == 3'b011 || BitStream_buffer_output[13:11] == 3'b110))||
|
349 |
|
|
(heading_one_pos == 4'd2 && BitStream_buffer_output[11:10] == 2'b01) ||
|
350 |
|
|
(heading_one_pos == 4'd3 && (BitStream_buffer_output[11:9] == 3'b010 || BitStream_buffer_output[11:9] == 3'b101))||
|
351 |
|
|
(heading_one_pos == 4'd4 && BitStream_buffer_output[9:8] == 2'b01))
|
352 |
|
|
TrailingOnes <= 2'd2;
|
353 |
|
|
else if (
|
354 |
|
|
(heading_one_pos == 4'd1 && BitStream_buffer_output[13:11] == 3'b101) ||
|
355 |
|
|
(heading_one_pos == 4'd2 && BitStream_buffer_output[12:10] == 3'b100) ||
|
356 |
|
|
(heading_one_pos == 4'd3 && BitStream_buffer_output[11:9] == 3'b100) ||
|
357 |
|
|
(heading_one_pos == 4'd4 && BitStream_buffer_output[9:8] == 2'b00))
|
358 |
|
|
TrailingOnes <= 2'd3;
|
359 |
|
|
else
|
360 |
|
|
TrailingOnes <= 2'd0;
|
361 |
|
|
end
|
362 |
|
|
else
|
363 |
|
|
begin
|
364 |
|
|
if ((heading_one_pos == 4'd5 && BitStream_buffer_output[8:7] == 2'b10) ||
|
365 |
|
|
(heading_one_pos == 4'd6 && (BitStream_buffer_output[8:7] == 2'b11 || BitStream_buffer_output[7:6] == 2'b00)) ||
|
366 |
|
|
(heading_one_pos == 4'd7 && BitStream_buffer_output[7:6] == 2'b00))
|
367 |
|
|
TrailingOnes <= 2'd1;
|
368 |
|
|
else if (
|
369 |
|
|
(heading_one_pos == 4'd5 && BitStream_buffer_output[8:7] == 2'b01) ||
|
370 |
|
|
(heading_one_pos == 4'd6 && BitStream_buffer_output[8:6] == 3'b011) ||
|
371 |
|
|
(heading_one_pos == 4'd7 && BitStream_buffer_output[7:6] == 2'b11) ||
|
372 |
|
|
(heading_one_pos == 4'd8 && BitStream_buffer_output[6]))
|
373 |
|
|
TrailingOnes <= 2'd2;
|
374 |
|
|
else if (
|
375 |
|
|
(heading_one_pos == 4'd5 && BitStream_buffer_output[9:7] == 3'b100) ||
|
376 |
|
|
(heading_one_pos == 4'd6 && BitStream_buffer_output[8:6] == 3'b010) ||
|
377 |
|
|
(heading_one_pos == 4'd7 && BitStream_buffer_output[7:6] == 2'b10) ||
|
378 |
|
|
(heading_one_pos == 4'd8 && !BitStream_buffer_output[6]))
|
379 |
|
|
TrailingOnes <= 2'd3;
|
380 |
|
|
else
|
381 |
|
|
TrailingOnes <= 2'd0;
|
382 |
|
|
end
|
383 |
|
|
end
|
384 |
|
|
else if (nC_GE8)
|
385 |
|
|
begin
|
386 |
|
|
if (BitStream_buffer_output[15:10] == 6'b0 || heading_one_pos == 4'd4)
|
387 |
|
|
TrailingOnes <= 2'd0;
|
388 |
|
|
else if (heading_one_pos == 4'd5)
|
389 |
|
|
TrailingOnes <= 2'd1;
|
390 |
|
|
else
|
391 |
|
|
TrailingOnes <= BitStream_buffer_output[11:10];
|
392 |
|
|
end
|
393 |
|
|
else
|
394 |
|
|
TrailingOnes <= TrailingOnes_reg;
|
395 |
|
|
|
396 |
|
|
//TotalCoeff
|
397 |
|
|
always @ (posedge clk)
|
398 |
|
|
if (reset_n == 0)
|
399 |
|
|
TotalCoeff_reg <= 0;
|
400 |
|
|
else if (cavlc_decoder_state == `NumCoeffTrailingOnes_LUT)
|
401 |
|
|
TotalCoeff_reg <= TotalCoeff;
|
402 |
|
|
|
403 |
|
|
always @ (nC_0to2 or nC_2to4 or nC_4to8 or nC_n1 or nC_GE8
|
404 |
|
|
or nC_0to2_t0 or nC_0to2_t1 or nC_0to2_t2 or nC_0to2_t3
|
405 |
|
|
or nC_2to4_t0 or nC_2to4_t1 or nC_2to4_t2 or nC_2to4_t3
|
406 |
|
|
or nC_4to8_t0 or nC_4to8_t1 or nC_n1_t0
|
407 |
|
|
or TotalCoeff_reg or heading_one_pos or BitStream_buffer_output)
|
408 |
|
|
if (nC_0to2)
|
409 |
|
|
begin
|
410 |
|
|
if (nC_0to2_t0)
|
411 |
|
|
TotalCoeff <= {3'b0,heading_one_pos[1:0]};
|
412 |
|
|
else if (nC_0to2_t1)
|
413 |
|
|
begin
|
414 |
|
|
if (heading_one_pos == 4'd3)
|
415 |
|
|
case (BitStream_buffer_output[11:10])
|
416 |
|
|
2'b00 :TotalCoeff <= 5'd2;
|
417 |
|
|
2'b01 :TotalCoeff <= 5'd1;
|
418 |
|
|
default:TotalCoeff <= 5'd3;
|
419 |
|
|
endcase
|
420 |
|
|
else
|
421 |
|
|
case (BitStream_buffer_output[10:9])
|
422 |
|
|
2'b00 :TotalCoeff <= 5'd5;
|
423 |
|
|
2'b01 :TotalCoeff <= 5'd3;
|
424 |
|
|
default:TotalCoeff <= 5'd4;
|
425 |
|
|
endcase
|
426 |
|
|
end
|
427 |
|
|
else if (nC_0to2_t2)
|
428 |
|
|
begin
|
429 |
|
|
if (heading_one_pos == 4'd5)
|
430 |
|
|
case (BitStream_buffer_output[9:8])
|
431 |
|
|
2'b00:TotalCoeff <= 5'd6;
|
432 |
|
|
2'b01:TotalCoeff <= 5'd4;
|
433 |
|
|
2'b10:TotalCoeff <= 5'd3;
|
434 |
|
|
2'b11:TotalCoeff <= 5'd2;
|
435 |
|
|
endcase
|
436 |
|
|
else if (heading_one_pos == 4'd6)
|
437 |
|
|
case (BitStream_buffer_output[8:7])
|
438 |
|
|
2'b00:TotalCoeff <= 5'd7;
|
439 |
|
|
2'b01:TotalCoeff <= 5'd5;
|
440 |
|
|
2'b10:TotalCoeff <= 5'd4;
|
441 |
|
|
2'b11:TotalCoeff <= 5'd3;
|
442 |
|
|
endcase
|
443 |
|
|
else if (heading_one_pos == 4'd7)
|
444 |
|
|
case (BitStream_buffer_output[7:6])
|
445 |
|
|
2'b00:TotalCoeff <= 5'd8;
|
446 |
|
|
2'b01:TotalCoeff <= 5'd6;
|
447 |
|
|
2'b10:TotalCoeff <= 5'd5;
|
448 |
|
|
2'b11:TotalCoeff <= 5'd4;
|
449 |
|
|
endcase
|
450 |
|
|
else
|
451 |
|
|
case (BitStream_buffer_output[6:5])
|
452 |
|
|
2'b00:TotalCoeff <= 5'd9;
|
453 |
|
|
2'b01:TotalCoeff <= 5'd7;
|
454 |
|
|
2'b10:TotalCoeff <= 5'd6;
|
455 |
|
|
2'b11:TotalCoeff <= 5'd5;
|
456 |
|
|
endcase
|
457 |
|
|
end
|
458 |
|
|
else if (nC_0to2_t3)
|
459 |
|
|
begin
|
460 |
|
|
if (heading_one_pos == 4'd9)
|
461 |
|
|
case (BitStream_buffer_output[5:3])
|
462 |
|
|
3'b001 :TotalCoeff <= 5'd9;
|
463 |
|
|
3'b011,3'b110:TotalCoeff <= 5'd7;
|
464 |
|
|
3'b100 :TotalCoeff <= 5'd10;
|
465 |
|
|
3'b111 :TotalCoeff <= 5'd6;
|
466 |
|
|
default :TotalCoeff <= 5'd8;
|
467 |
|
|
endcase
|
468 |
|
|
else
|
469 |
|
|
case (BitStream_buffer_output[4:2])
|
470 |
|
|
3'b000 :TotalCoeff <= 5'd12;
|
471 |
|
|
3'b001,3'b100:TotalCoeff <= 5'd11;
|
472 |
|
|
3'b110,3'b111:TotalCoeff <= 5'd9;
|
473 |
|
|
default :TotalCoeff <= 5'd10;
|
474 |
|
|
endcase
|
475 |
|
|
end
|
476 |
|
|
else
|
477 |
|
|
begin
|
478 |
|
|
if (heading_one_pos == 4'd11)
|
479 |
|
|
case (BitStream_buffer_output[3:1])
|
480 |
|
|
3'b000 :TotalCoeff <= 5'd14;
|
481 |
|
|
3'b001,3'b100:TotalCoeff <= 5'd13;
|
482 |
|
|
3'b110,3'b111:TotalCoeff <= 5'd11;
|
483 |
|
|
default :TotalCoeff <= 5'd12;
|
484 |
|
|
endcase
|
485 |
|
|
else if (heading_one_pos == 4'd12)
|
486 |
|
|
case (BitStream_buffer_output[2:0])
|
487 |
|
|
3'b000 :TotalCoeff <= 5'd16;
|
488 |
|
|
3'b011,3'b101,3'b110:TotalCoeff <= 5'd14;
|
489 |
|
|
3'b111 :TotalCoeff <= 5'd13;
|
490 |
|
|
default :TotalCoeff <= 5'd15;
|
491 |
|
|
endcase
|
492 |
|
|
else if (heading_one_pos == 4'd13)
|
493 |
|
|
TotalCoeff <= (BitStream_buffer_output[1:0] == 2'b11)? 5'd15:5'd16;
|
494 |
|
|
else
|
495 |
|
|
TotalCoeff <= 5'd13;
|
496 |
|
|
end
|
497 |
|
|
end
|
498 |
|
|
else if (nC_2to4)
|
499 |
|
|
begin
|
500 |
|
|
if (nC_2to4_t0)
|
501 |
|
|
begin
|
502 |
|
|
if (heading_one_pos == 4'd0)
|
503 |
|
|
TotalCoeff <= {4'b0,~BitStream_buffer_output[14]};
|
504 |
|
|
else
|
505 |
|
|
case (BitStream_buffer_output[13:12])
|
506 |
|
|
2'b00 :TotalCoeff <= 5'd4;
|
507 |
|
|
2'b01 :TotalCoeff <= 5'd3;
|
508 |
|
|
default:TotalCoeff <= 5'd2;
|
509 |
|
|
endcase
|
510 |
|
|
end
|
511 |
|
|
else if (nC_2to4_t1)
|
512 |
|
|
begin
|
513 |
|
|
if (heading_one_pos == 4'd2)
|
514 |
|
|
case (BitStream_buffer_output[12:11])
|
515 |
|
|
2'b00:TotalCoeff <= (BitStream_buffer_output[10])? 5'd3:5'd6;
|
516 |
|
|
2'b01:TotalCoeff <= (BitStream_buffer_output[10])? 5'd1:5'd3;
|
517 |
|
|
2'b10:TotalCoeff <= 5'd5;
|
518 |
|
|
2'b11:TotalCoeff <= 5'd2;
|
519 |
|
|
endcase
|
520 |
|
|
else
|
521 |
|
|
case (BitStream_buffer_output[11:10])
|
522 |
|
|
2'b00 :TotalCoeff <= 5'd7;
|
523 |
|
|
2'b11 :TotalCoeff <= 5'd2;
|
524 |
|
|
default:TotalCoeff <= 5'd4;
|
525 |
|
|
endcase
|
526 |
|
|
end
|
527 |
|
|
else if (nC_2to4_t2)
|
528 |
|
|
begin
|
529 |
|
|
if (heading_one_pos == 4'd4)
|
530 |
|
|
case (BitStream_buffer_output[10:9])
|
531 |
|
|
2'b00 :TotalCoeff <= 5'd8;
|
532 |
|
|
2'b11 :TotalCoeff <= 5'd3;
|
533 |
|
|
default:TotalCoeff <= 5'd5;
|
534 |
|
|
endcase
|
535 |
|
|
else if (heading_one_pos == 4'd5)
|
536 |
|
|
case (BitStream_buffer_output[9:8])
|
537 |
|
|
2'b00 :TotalCoeff <= 5'd5;
|
538 |
|
|
2'b11 :TotalCoeff <= 5'd4;
|
539 |
|
|
default:TotalCoeff <= 5'd6;
|
540 |
|
|
endcase
|
541 |
|
|
else
|
542 |
|
|
case (BitStream_buffer_output[8:7])
|
543 |
|
|
2'b00 :TotalCoeff <= 5'd9;
|
544 |
|
|
2'b11 :TotalCoeff <= 5'd6;
|
545 |
|
|
default:TotalCoeff <= 5'd7;
|
546 |
|
|
endcase
|
547 |
|
|
end
|
548 |
|
|
else if (nC_2to4_t3)
|
549 |
|
|
begin
|
550 |
|
|
if (heading_one_pos == 4'd7)
|
551 |
|
|
case (BitStream_buffer_output[7:5])
|
552 |
|
|
3'b000 :TotalCoeff <= 5'd11;
|
553 |
|
|
3'b001,3'b010:TotalCoeff <= 5'd9;
|
554 |
|
|
3'b100 :TotalCoeff <= 5'd10;
|
555 |
|
|
3'b111 :TotalCoeff <= 5'd7;
|
556 |
|
|
default :TotalCoeff <= 5'd8;
|
557 |
|
|
endcase
|
558 |
|
|
else
|
559 |
|
|
case (BitStream_buffer_output[6:4])
|
560 |
|
|
3'b000,3'b001,3'b010:TotalCoeff <= 5'd11;
|
561 |
|
|
3'b100 :TotalCoeff <= 5'd12;
|
562 |
|
|
3'b111 :TotalCoeff <= 5'd9;
|
563 |
|
|
default :TotalCoeff <= 5'd10;
|
564 |
|
|
endcase
|
565 |
|
|
end
|
566 |
|
|
else
|
567 |
|
|
begin
|
568 |
|
|
if (heading_one_pos == 4'd9)
|
569 |
|
|
case (BitStream_buffer_output[5:3])
|
570 |
|
|
3'b000 :TotalCoeff <= 5'd14;
|
571 |
|
|
3'b101,3'b110,3'b111:TotalCoeff <= 5'd12;
|
572 |
|
|
default :TotalCoeff <= 5'd13;
|
573 |
|
|
endcase
|
574 |
|
|
else if (heading_one_pos == 4'd10)
|
575 |
|
|
TotalCoeff <= (BitStream_buffer_output[4:2] == 3'b0 || BitStream_buffer_output[4:2] == 3'b001 || BitStream_buffer_output[4:2] == 3'b010)? 5'd15:5'd14;
|
576 |
|
|
else if (heading_one_pos == 4'd11)
|
577 |
|
|
TotalCoeff <= 5'd16;
|
578 |
|
|
else
|
579 |
|
|
TotalCoeff <= 5'd15;
|
580 |
|
|
end
|
581 |
|
|
end
|
582 |
|
|
else if (nC_n1)
|
583 |
|
|
begin
|
584 |
|
|
if (nC_n1_t0)
|
585 |
|
|
begin
|
586 |
|
|
if (BitStream_buffer_output[15]) TotalCoeff <= 5'd1;
|
587 |
|
|
else if (BitStream_buffer_output[14]) TotalCoeff <= 5'd0;
|
588 |
|
|
else TotalCoeff <= 5'd2;
|
589 |
|
|
end
|
590 |
|
|
else
|
591 |
|
|
begin
|
592 |
|
|
if (heading_one_pos == 4'd3)
|
593 |
|
|
case (BitStream_buffer_output[11:10])
|
594 |
|
|
2'b01 :TotalCoeff <= 5'd3;
|
595 |
|
|
2'b11 :TotalCoeff <= 5'd1;
|
596 |
|
|
default:TotalCoeff <= 5'd2;
|
597 |
|
|
endcase
|
598 |
|
|
else if (heading_one_pos == 4'd4)
|
599 |
|
|
TotalCoeff <= (BitStream_buffer_output[10])? 5'd3:5'd4;
|
600 |
|
|
else if (heading_one_pos == 4'd5)
|
601 |
|
|
TotalCoeff <= 5'd3;
|
602 |
|
|
else
|
603 |
|
|
TotalCoeff <= 5'd4;
|
604 |
|
|
end
|
605 |
|
|
end
|
606 |
|
|
else if (nC_4to8)
|
607 |
|
|
begin
|
608 |
|
|
if (nC_4to8_t0)
|
609 |
|
|
TotalCoeff <= {2'b0,~BitStream_buffer_output[14:12]};
|
610 |
|
|
else if (nC_4to8_t1)
|
611 |
|
|
begin
|
612 |
|
|
if (heading_one_pos == 4'd1)
|
613 |
|
|
case (BitStream_buffer_output[13:11])
|
614 |
|
|
3'b000,3'b001:TotalCoeff <= 5'd5;
|
615 |
|
|
3'b010,3'b011:TotalCoeff <= 5'd4;
|
616 |
|
|
3'b101 :TotalCoeff <= 5'd8;
|
617 |
|
|
3'b111 :TotalCoeff <= 5'd2;
|
618 |
|
|
default :TotalCoeff <= 5'd3;
|
619 |
|
|
endcase
|
620 |
|
|
else if (heading_one_pos == 4'd2)
|
621 |
|
|
case (BitStream_buffer_output[12:10])
|
622 |
|
|
3'b000 :TotalCoeff <= 5'd3;
|
623 |
|
|
3'b001,3'b010:TotalCoeff <= 5'd7;
|
624 |
|
|
3'b011 :TotalCoeff <= 5'd2;
|
625 |
|
|
3'b100 :TotalCoeff <= 5'd9;
|
626 |
|
|
3'b111 :TotalCoeff <= 5'd1;
|
627 |
|
|
default :TotalCoeff <= 5'd6;
|
628 |
|
|
endcase
|
629 |
|
|
else if (heading_one_pos == 4'd3)
|
630 |
|
|
case (BitStream_buffer_output[11:9])
|
631 |
|
|
3'b000 :TotalCoeff <= 5'd7;
|
632 |
|
|
3'b001 :TotalCoeff <= 5'd6;
|
633 |
|
|
3'b010 :TotalCoeff <= 5'd9;
|
634 |
|
|
3'b011 :TotalCoeff <= 5'd5;
|
635 |
|
|
3'b100 :TotalCoeff <= 5'd10;
|
636 |
|
|
3'b111 :TotalCoeff <= 5'd4;
|
637 |
|
|
default:TotalCoeff <= 5'd8;
|
638 |
|
|
endcase
|
639 |
|
|
else
|
640 |
|
|
case (BitStream_buffer_output[10:8])
|
641 |
|
|
3'b000 :TotalCoeff <= 5'd12;
|
642 |
|
|
3'b001,3'b100:TotalCoeff <= 5'd11;
|
643 |
|
|
3'b010,3'b101:TotalCoeff <= 5'd10;
|
644 |
|
|
3'b111 :TotalCoeff <= 5'd8;
|
645 |
|
|
default :TotalCoeff <= 5'd9;
|
646 |
|
|
endcase
|
647 |
|
|
end
|
648 |
|
|
else
|
649 |
|
|
begin
|
650 |
|
|
if (heading_one_pos == 4'd5)
|
651 |
|
|
case (BitStream_buffer_output[9:7])
|
652 |
|
|
3'b001,3'b100 :TotalCoeff <= 5'd13;
|
653 |
|
|
3'b011,3'b110 :TotalCoeff <= 5'd11;
|
654 |
|
|
3'b111 :TotalCoeff <= 5'd10;
|
655 |
|
|
default :TotalCoeff <= 5'd12;
|
656 |
|
|
endcase
|
657 |
|
|
else if (heading_one_pos == 4'd6)
|
658 |
|
|
case (BitStream_buffer_output[8:6])
|
659 |
|
|
3'b000 :TotalCoeff <= 5'd15;
|
660 |
|
|
3'b101,3'b110,3'b111:TotalCoeff <= 5'd13;
|
661 |
|
|
default :TotalCoeff <= 5'd14;
|
662 |
|
|
endcase
|
663 |
|
|
else if (heading_one_pos == 4'd7)
|
664 |
|
|
TotalCoeff <= (BitStream_buffer_output[7:6] == 2'b00)? 5'd16:5'd15;
|
665 |
|
|
else
|
666 |
|
|
TotalCoeff <= 5'd16;
|
667 |
|
|
end
|
668 |
|
|
end
|
669 |
|
|
else if (nC_GE8)
|
670 |
|
|
begin
|
671 |
|
|
if (heading_one_pos == 4'd4)
|
672 |
|
|
TotalCoeff <= 5'd0;
|
673 |
|
|
else
|
674 |
|
|
TotalCoeff <= BitStream_buffer_output[15:12] + 1;
|
675 |
|
|
end
|
676 |
|
|
else
|
677 |
|
|
TotalCoeff <= TotalCoeff_reg;
|
678 |
|
|
endmodule
|