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

Subversion Repositories cavlc

[/] [cavlc/] [trunk/] [rtl/] [cavlc_read_levels.v] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 qiubin
//2011-8-6      initiial revision
2
//2011-8-19     reverse the order of level
3
 
4
//  include TrailingOnes
5
 
6
`include "defines.v"
7
 
8
module cavlc_read_levels (
9
        clk,
10
        rst_n,
11
        ena,
12
        t1s_sel,
13
        prefix_sel,
14
        suffix_sel,
15
        calc_sel,
16
        TrailingOnes,
17
        TotalCoeff,
18
        rbsp,
19
        i,
20
        level_0, level_1, level_2, level_3, level_4, level_5, level_6, level_7,
21
        level_8, level_9, level_10, level_11, level_12, level_13, level_14, level_15,
22
        len_comb
23
);
24
//------------------------
25
// ports
26
//------------------------
27
input   clk;
28
input   rst_n;
29
 
30
input   ena;
31
input   t1s_sel;
32
input   prefix_sel;
33
input   suffix_sel;
34
input   calc_sel;
35
 
36
input   [1:0]    TrailingOnes;
37
input   [4:0]    TotalCoeff;
38
input   [0:15]   rbsp;
39
input   [3:0]    i;
40
 
41
output  [8:0]    level_0, level_1, level_2, level_3, level_4, level_5, level_6, level_7;
42
output  [8:0]    level_8, level_9, level_10, level_11, level_12, level_13, level_14, level_15;
43
output  [4:0]    len_comb;
44
 
45
//------------------------
46
//  regs
47
//------------------------
48
reg             [0:15]   rbsp_prefix;            //for level_prefix_comb
49
reg             [3:0]    level_prefix_comb;
50
reg             [8:0]    level_suffix;
51
reg             [4:0]    len_comb;
52
 
53
//------------------------
54
// FFs
55
//------------------------
56
reg     [3:0]    level_prefix;
57
reg             [2:0]    suffixLength;   // range from 0 to 6
58
reg             [8:0]    level;
59
reg             [8:0]    level_abs;
60
reg             [8:0]    level_code_tmp;
61
reg             [8:0]    level_0, level_1, level_2, level_3, level_4, level_5, level_6, level_7;
62
reg             [8:0]    level_8, level_9, level_10, level_11, level_12, level_13, level_14, level_15;
63
 
64
//------------------------
65
// level_prefix_comb
66
//------------------------
67
wire    level_prefix_refresh;
68
assign level_prefix_refresh = (prefix_sel && ena);
69
 
70
always @(level_prefix_refresh or rbsp)
71
if (level_prefix_refresh)
72
        rbsp_prefix <= rbsp;
73
else
74
        rbsp_prefix <= 'hffff;
75
 
76
always @(*)
77
if (rbsp_prefix[0])              level_prefix_comb <= 0;
78
else if (rbsp_prefix[1])        level_prefix_comb <= 1;
79
else if (rbsp_prefix[2])        level_prefix_comb <= 2;
80
else if (rbsp_prefix[3])        level_prefix_comb <= 3;
81
else if (rbsp_prefix[4])        level_prefix_comb <= 4;
82
else if (rbsp_prefix[5])        level_prefix_comb <= 5;
83
else if (rbsp_prefix[6])        level_prefix_comb <= 6;
84
else if (rbsp_prefix[7])        level_prefix_comb <= 7;
85
else if (rbsp_prefix[8])        level_prefix_comb <= 8;
86
else if (rbsp_prefix[9])        level_prefix_comb <= 9;
87
else if (rbsp_prefix[10])       level_prefix_comb <= 10;
88
else if (rbsp_prefix[11])       level_prefix_comb <= 11;
89
else if (rbsp_prefix[12])       level_prefix_comb <= 12;
90
else if (rbsp_prefix[13])       level_prefix_comb <= 13;
91
else if (rbsp_prefix[14])       level_prefix_comb <= 14;
92
else if (rbsp_prefix[15])       level_prefix_comb <= 15;
93
else                                            level_prefix_comb <= 'bx;
94
 
95
 
96
//------------------------
97
// level_prefix
98
//------------------------
99
always @(posedge clk or negedge rst_n)
100
if (~rst_n)
101
        level_prefix <= 0;
102
else if (level_prefix_refresh) begin
103
        level_prefix <= level_prefix_comb;
104
end
105
 
106
//------------------------
107
// suffixLength
108
//------------------------
109
wire first_level;
110
assign first_level = (i == TotalCoeff - TrailingOnes - 1);
111
 
112
wire suffixLength_refresh;
113
assign suffixLength_refresh = prefix_sel && ena;
114
 
115
always @(posedge clk or negedge rst_n)
116
if (~rst_n) begin
117
        suffixLength <= 0;
118
end
119
else if (suffixLength_refresh) begin
120
        if (TotalCoeff > 10 && TrailingOnes < 3 && first_level )        //initialize suffixLength before proceeding first level_suffix
121
                suffixLength <= 1;
122
        else if (first_level)
123
                suffixLength <= 0;
124
        else if (suffixLength == 0 && level_abs > 2'd3)
125
                suffixLength <= 2;
126
        else if (suffixLength == 0)
127
                suffixLength <= 1;
128
        else if (  level_abs > (2'd3 << (suffixLength - 1'b1) ) && suffixLength < 6)
129
                suffixLength <= suffixLength + 1'b1;
130
end
131
 
132
 
133
//------------------------
134
// level_suffix
135
//------------------------
136
wire level_suffix_refresh;
137
assign level_suffix_refresh = suffix_sel && ena;
138
 
139
always @(*)
140
if (level_suffix_refresh) begin
141
        if (suffixLength > 0 && level_prefix <= 14) begin
142
                level_suffix <= {3'b0, rbsp[0:5] >> (3'd6 - suffixLength)};
143
        end
144
        else if (level_prefix == 14) begin      //level_prefix == 14 && suffixLength == 0
145
                level_suffix <= {3'b0, rbsp[0:3] };
146
        end
147
        else if (level_prefix == 15) begin
148
                level_suffix <= rbsp[3:11];
149
        end
150
        else begin
151
                level_suffix <= 0;
152
        end
153
end
154
else begin
155
        level_suffix <= 0;
156
end
157
 
158
//------------------------
159
// level_code_tmp
160
//------------------------
161
always @(posedge clk or negedge rst_n)
162
if (~rst_n) begin
163
        level_code_tmp <=  0;
164
end
165
else if (level_suffix_refresh) begin
166
        level_code_tmp <= (level_prefix << suffixLength) + level_suffix +
167
        ((suffixLength == 0 && level_prefix == 15) ? 4'd15 : 0);
168
end
169
 
170
 
171
//------------------------
172
// level
173
//------------------------
174
wire    [2:0]    tmp1;
175
 
176
assign tmp1 = (first_level && TrailingOnes < 3)? 2'd2 : 2'd0;
177
 
178
always @(*)
179
begin
180
        if (level_code_tmp % 2 == 0) begin
181
                level <= ( level_code_tmp + tmp1 + 2 ) >> 1;
182
        end
183
        else begin
184
                level <= (-level_code_tmp - tmp1 - 1 ) >> 1;
185
        end
186
end
187
 
188
//------------------------
189
// level_abs
190
//------------------------
191
wire level_abs_refresh;
192
assign level_abs_refresh = calc_sel && ena;
193
 
194
always @(posedge clk or negedge rst_n)
195
if (~rst_n) begin
196
        level_abs <= 0;
197
end
198
else if (level_abs_refresh) begin
199
        level_abs <= level[8] ? -level : level;
200
end
201
 
202
//------------------------
203
// level regfile
204
//------------------------
205
always @ (posedge clk or negedge rst_n)
206
if (!rst_n) begin
207
        level_0 <= 0;    level_1 <= 0;    level_2 <= 0;    level_3 <= 0;
208
        level_4 <= 0;    level_5 <= 0;    level_6 <= 0;    level_7 <= 0;
209
        level_8 <= 0;    level_9 <= 0;    level_10<= 0;    level_11<= 0;
210
        level_12<= 0;    level_13<= 0;    level_14<= 0;    level_15<= 0;
211
end
212
else if (t1s_sel && ena)
213
        case (i)
214
 
215
        1 : begin
216
                        level_1 <= rbsp[0]? -1 : 1;
217
                        if (TrailingOnes[1])
218
                                level_0 <= rbsp[1]? -1 : 1;
219
                end
220
        2 : begin
221
                        level_2 <= rbsp[0]? -1 : 1;
222
                        if (TrailingOnes[1])
223
                                level_1 <= rbsp[1]? -1 : 1;
224
                        if (TrailingOnes == 3)
225
                                level_0 <= rbsp[2]? -1 : 1;
226
                end
227
        3 : begin
228
                        level_3 <= rbsp[0]? -1 : 1;
229
                        if (TrailingOnes[1])
230
                                level_2 <= rbsp[1]? -1 : 1;
231
                        if (TrailingOnes == 3)
232
                                level_1 <= rbsp[2]? -1 : 1;
233
                end
234
        4 : begin
235
                        level_4 <= rbsp[0]? -1 : 1;
236
                        if (TrailingOnes[1])
237
                                level_3 <= rbsp[1]? -1 : 1;
238
                        if (TrailingOnes == 3)
239
                                level_2 <= rbsp[2]? -1 : 1;
240
                end
241
        5 : begin
242
                        level_5 <= rbsp[0]? -1 : 1;
243
                        if (TrailingOnes[1])
244
                                level_4 <= rbsp[1]? -1 : 1;
245
                        if (TrailingOnes == 3)
246
                                level_3 <= rbsp[2]? -1 : 1;
247
                end
248
        6 : begin
249
                        level_6 <= rbsp[0]? -1 : 1;
250
                        if (TrailingOnes[1])
251
                                level_5 <= rbsp[1]? -1 : 1;
252
                        if (TrailingOnes == 3)
253
                                level_4 <= rbsp[2]? -1 : 1;
254
                end
255
        7 : begin
256
                        level_7 <= rbsp[0]? -1 : 1;
257
                        if (TrailingOnes[1])
258
                                level_6 <= rbsp[1]? -1 : 1;
259
                        if (TrailingOnes == 3)
260
                                level_5 <= rbsp[2]? -1 : 1;
261
                end
262
        8 : begin
263
                        level_8 <= rbsp[0]? -1 : 1;
264
                        if (TrailingOnes[1])
265
                                level_7 <= rbsp[1]? -1 : 1;
266
                        if (TrailingOnes == 3)
267
                                level_6 <= rbsp[2]? -1 : 1;
268
                end
269
        9 : begin
270
                        level_9 <= rbsp[0]? -1 : 1;
271
                        if (TrailingOnes[1])
272
                                level_8 <= rbsp[1]? -1 : 1;
273
                        if (TrailingOnes == 3)
274
                                level_7 <= rbsp[2]? -1 : 1;
275
                end
276
        10: begin
277
                        level_10 <= rbsp[0]? -1 : 1;
278
                        if (TrailingOnes[1])
279
                                level_9 <= rbsp[1]? -1 : 1;
280
                        if (TrailingOnes == 3)
281
                                level_8 <= rbsp[2]? -1 : 1;
282
                end
283
        11: begin
284
                        level_11 <= rbsp[0]? -1 : 1;
285
                        if (TrailingOnes[1])
286
                                level_10 <= rbsp[1]? -1 : 1;
287
                        if (TrailingOnes == 3)
288
                                level_9 <= rbsp[2]? -1 : 1;
289
                end
290
        12: begin
291
                        level_12 <= rbsp[0]? -1 : 1;
292
                        if (TrailingOnes[1])
293
                                level_11 <= rbsp[1]? -1 : 1;
294
                        if (TrailingOnes == 3)
295
                                level_10 <= rbsp[2]? -1 : 1;
296
                end
297
        13: begin
298
                        level_13 <= rbsp[0]? -1 : 1;
299
                        if (TrailingOnes[1])
300
                                level_12 <= rbsp[1]? -1 : 1;
301
                        if (TrailingOnes == 3)
302
                                level_11 <= rbsp[2]? -1 : 1;
303
                end
304
        14: begin
305
                        level_14 <= rbsp[0]? -1 : 1;
306
                        if (TrailingOnes[1])
307
                                level_13 <= rbsp[1]? -1 : 1;
308
                        if (TrailingOnes == 3)
309
                                level_12 <= rbsp[2]? -1 : 1;
310
                end
311
        15: begin
312
                        level_15 <= rbsp[0]? -1 : 1;
313
                        if (TrailingOnes[1])
314
                                level_14 <= rbsp[1]? -1 : 1;
315
                        if (TrailingOnes == 3)
316
                                level_13 <= rbsp[2]? -1 : 1;
317
                end
318
endcase
319
else if (calc_sel && ena)
320
case (i)
321
 
322
        1 :level_1 <= level;
323
        2 :level_2 <= level;
324
        3 :level_3 <= level;
325
        4 :level_4 <= level;
326
        5 :level_5 <= level;
327
        6 :level_6 <= level;
328
        7 :level_7 <= level;
329
        8 :level_8 <= level;
330
        9 :level_9 <= level;
331
        10:level_10<= level;
332
        11:level_11<= level;
333
        12:level_12<= level;
334
        13:level_13<= level;
335
        14:level_14<= level;
336
        15:level_15<= level;
337
endcase
338
 
339
always @(*)
340
if(t1s_sel)
341
        len_comb <= TrailingOnes;
342
else if(prefix_sel)
343
        len_comb <= level_prefix_comb + 1;
344
else if(suffix_sel && suffixLength > 0 && level_prefix <= 14)
345
        len_comb <= suffixLength;
346
else if(suffix_sel && level_prefix == 14)
347
        len_comb <= 4;
348
else if(suffix_sel && level_prefix == 15)
349
        len_comb <= 12;
350
else
351
        len_comb <= 0;
352
 
353
endmodule

powered by: WebSVN 2.1.0

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