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

Subversion Repositories cavlc

[/] [cavlc/] [trunk/] [rtl/] [cavlc_read_total_coeffs.v] - Blame information for rev 8

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

Line No. Rev Author Line
1 7 qiubin
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  cavlc_read_total_coeffs                                     ////
4
////                                                              ////
5
////  Description                                                 ////
6
////      decode total_coeffs and trailing ones                   ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - bin qiu, qiubin@opencores.org                         ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2011 Authors and OPENCORES.ORG                 ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37 6 qiubin
 
38 7 qiubin
//2011-8-7  initial creation
39
//2011-8-9  optimize output mux
40 6 qiubin
 
41 7 qiubin
 
42 6 qiubin
`include "defines.v"
43
 
44 7 qiubin
module cavlc_read_total_coeffs
45
(
46
    clk,
47
    rst_n,
48
    ena,
49
    start,
50
    sel,
51
    rbsp, nC,
52
    TrailingOnes,
53
    TotalCoeff,
54
    TrailingOnes_comb,
55
    TotalCoeff_comb,
56
    len_comb
57 6 qiubin
);
58
//------------------------
59
//ports
60
//------------------------
61 7 qiubin
input   clk;
62
input   rst_n;
63
input   ena;
64
input   start;
65
input   sel;
66 6 qiubin
 
67 7 qiubin
input   [0:15]   rbsp;
68
input   signed   [5:0]   nC;
69 6 qiubin
 
70 7 qiubin
output  [4:0]  TotalCoeff;        //range from 0 to 16
71
output  [1:0]  TrailingOnes;      //range from 0 to 3   
72
output  [4:0]  TotalCoeff_comb;   //unsaved result of TotalCoeff_comb
73
output  [1:0]  TrailingOnes_comb; //unsaved result of TrailingOnes_comb
74
output  [4:0]  len_comb;          //indicate how many rbsp bit consumed, range from 0 to 16
75 6 qiubin
 
76
 
77
//------------------------
78
//regs
79
//------------------------
80 7 qiubin
reg     [4:0]   TotalCoeff_comb;
81
reg     [1:0]   TrailingOnes_comb;
82
reg     [4:0]   len_comb;
83 6 qiubin
 
84
//for nC >= 0 && nC < 2
85 7 qiubin
reg     [4:0]   TotalCoeff_1;
86
reg     [1:0]   TrailingOnes_1;
87
reg     [4:0]   len_1;
88 6 qiubin
 
89
//for nC >= 2 && nC < 4
90 7 qiubin
reg     [4:0]   TotalCoeff_2;
91
reg     [1:0]   TrailingOnes_2;
92
reg     [4:0]   len_2;
93 6 qiubin
 
94
//for nC >= 4 && nC < 8
95 7 qiubin
reg     [4:0]   TotalCoeff_3;
96
reg     [1:0]   TrailingOnes_3;
97
reg     [4:0]   len_3;
98 6 qiubin
 
99
//for nC >= 8
100 7 qiubin
reg     [4:0]   TotalCoeff_4;
101
reg     [1:0]   TrailingOnes_4;
102
reg     [4:0]   len_4;
103 6 qiubin
 
104
//for nC == -1
105 7 qiubin
reg     [4:0]   TotalCoeff_5;
106
reg     [1:0]   TrailingOnes_5;
107
reg     [4:0]   len_5;
108 6 qiubin
 
109
 
110
//------------------------
111
//FFs
112
//------------------------
113
//len is not necessary to be saved
114
//TotalCoeff & TrailingOnes should be valid when cavlc_state == `cavlc_read_total_coeffs_s
115
//to do that,combinational result "TotalCoeff_comb & TrailingOnes_comb" are outputed
116 7 qiubin
reg     [0:15]  rbsp_1;
117
reg     [0:13]  rbsp_2;
118
reg     [0:9]   rbsp_3;
119
reg     [0:5]   rbsp_4;
120
reg     [0:7]   rbsp_5;
121 6 qiubin
 
122 7 qiubin
reg     [4:0]   TotalCoeff;
123
reg     [1:0]   TrailingOnes;
124 6 qiubin
 
125
//------------------------
126
//input mux
127
//------------------------
128
always @(posedge clk or negedge rst_n)
129
if (!rst_n)
130
begin
131 7 qiubin
        rbsp_1 <=  0;
132
        rbsp_2 <=  0;
133
        rbsp_3 <=  0;
134
        rbsp_4 <=  0;
135
        rbsp_5 <=  0;
136 6 qiubin
 
137
end
138 7 qiubin
else if (ena && start)
139 6 qiubin
begin
140 7 qiubin
    if (nC[5])
141
        rbsp_5 <=  rbsp[0:7];
142
    else if ( nC[4] || nC[3])
143
        rbsp_4 <= rbsp[0:5];
144
    else if (nC[2])
145
        rbsp_3 <= rbsp[0:9];
146
    else if (nC[1])
147
        rbsp_2 <= rbsp[0:13];
148
    else
149
        rbsp_1 <= rbsp;
150 6 qiubin
end
151
//------------------------
152 7 qiubin
//nC >= 0 && nC < 2                 
153 6 qiubin
//------------------------
154
always @(rbsp_1)
155 7 qiubin
case (1'b1)
156 6 qiubin
rbsp_1[0] : begin
157 7 qiubin
    TrailingOnes_1  <= 0;
158
    TotalCoeff_1    <= 0;
159
    len_1           <= 1;
160 6 qiubin
end
161
rbsp_1[1] : begin
162 7 qiubin
    TrailingOnes_1  <= 1;
163
    TotalCoeff_1    <= 1;
164
    len_1           <= 2;
165 6 qiubin
end
166
rbsp_1[2] : begin
167 7 qiubin
    TrailingOnes_1  <= 2;
168
    TotalCoeff_1    <= 2;
169
    len_1           <= 3;
170 6 qiubin
end
171
rbsp_1[3] : begin
172 7 qiubin
    if (rbsp_1[4] == 'b1) begin
173
        TrailingOnes_1  <= 3;
174
        TotalCoeff_1    <= 3;
175
        len_1           <= 5;
176
    end
177
    else if (rbsp_1[5] == 'b1) begin
178
        TrailingOnes_1  <= 0;
179
        TotalCoeff_1    <= 1;
180
        len_1           <= 6;
181
    end
182
    else begin
183
        TrailingOnes_1  <= 1;
184
        TotalCoeff_1    <= 2;
185
        len_1           <= 6;
186
    end
187 6 qiubin
end
188
rbsp_1[4] : begin
189 7 qiubin
    if (rbsp_1[5] == 'b1) begin
190
        TrailingOnes_1  <= 3;
191
        TotalCoeff_1    <= 4;
192
        len_1           <= 6;
193
    end
194
    else if (rbsp_1[6] == 'b1) begin
195
        TrailingOnes_1  <= 2;
196
        TotalCoeff_1    <= 3;
197
        len_1           <= 7;
198
    end
199
    else begin
200
        TrailingOnes_1  <= 3;
201
        TotalCoeff_1    <= 5;
202
        len_1           <= 7;
203
    end
204 6 qiubin
end
205
rbsp_1[5] : begin
206 7 qiubin
    len_1           <= 8;
207
    if (rbsp_1[6:7] == 'b11) begin
208
        TrailingOnes_1  <= 0;
209
        TotalCoeff_1    <= 2;
210
    end
211
    else if (rbsp_1[6:7] == 'b10) begin
212
        TrailingOnes_1  <= 1;
213
        TotalCoeff_1    <= 3;
214
    end
215
    else if (rbsp_1[6:7] == 'b01) begin
216
        TrailingOnes_1  <= 2;
217
        TotalCoeff_1    <= 4;
218
    end
219
    else begin
220
        TrailingOnes_1  <= 3;
221
        TotalCoeff_1    <= 6;
222
    end
223 6 qiubin
end
224
rbsp_1[6] : begin
225 7 qiubin
    len_1           <= 9;
226
    if (rbsp_1[7:8] == 2'b11) begin
227
        TrailingOnes_1  <= 0;
228
        TotalCoeff_1    <= 3;
229
    end
230
    else if (rbsp_1[7:8] == 2'b10) begin
231
        TrailingOnes_1  <= 1;
232
        TotalCoeff_1    <= 4;
233
    end
234
    else if (rbsp_1[7:8] == 2'b01) begin
235
        TrailingOnes_1  <= 2;
236
        TotalCoeff_1    <= 5;
237
    end
238
    else  begin
239
        TrailingOnes_1  <= 3;
240
        TotalCoeff_1    <= 7;
241
    end
242 6 qiubin
end
243
rbsp_1[7] : begin
244 7 qiubin
    len_1           <= 10;
245
    if (rbsp_1[8:9] == 2'b11) begin
246
        TrailingOnes_1  <= 0;
247
        TotalCoeff_1    <= 4;
248
    end
249
    else if (rbsp_1[8:9] == 2'b10) begin
250
        TrailingOnes_1  <= 1;
251
        TotalCoeff_1    <= 5;
252
    end
253
    else if (rbsp_1[8:9] == 2'b01) begin
254
        TrailingOnes_1  <= 2;
255
        TotalCoeff_1    <= 6;
256
    end
257
    else begin
258
        TrailingOnes_1  <= 3;
259
        TotalCoeff_1    <= 8;
260
    end
261 6 qiubin
end
262
rbsp_1[8] : begin
263 7 qiubin
    len_1           <= 11;
264
    if (rbsp_1[9:10] == 2'b11) begin
265
        TrailingOnes_1  <= 0;
266
        TotalCoeff_1    <= 5;
267
    end
268
    else if (rbsp_1[9:10] == 2'b10) begin
269
        TrailingOnes_1  <= 1;
270
        TotalCoeff_1    <= 6;
271
    end
272
    else if (rbsp_1[9:10] == 2'b01) begin
273
        TrailingOnes_1  <= 2;
274
        TotalCoeff_1    <= 7;
275
    end
276
    else begin
277
        TrailingOnes_1  <= 3;
278
        TotalCoeff_1    <= 9;
279
    end
280 6 qiubin
end
281
rbsp_1[9] : begin
282 7 qiubin
    len_1           <= 13;
283
    if (rbsp_1[10:12] == 3'b111) begin
284
        TrailingOnes_1  <= 0;
285
        TotalCoeff_1    <= 6;
286
    end
287
    else if (rbsp_1[10:12] == 3'b011) begin
288
        TrailingOnes_1  <= 0;
289
        TotalCoeff_1    <= 7;
290
    end
291
    else if (rbsp_1[10:12] == 3'b110) begin
292
        TrailingOnes_1  <= 1;
293
        TotalCoeff_1    <= 7;
294
    end
295
    else if (rbsp_1[10:12] == 3'b000) begin
296
        TrailingOnes_1  <= 0;
297
        TotalCoeff_1    <= 8;
298
    end
299
    else if (rbsp_1[10:12] == 3'b010) begin
300
        TrailingOnes_1  <= 1;
301
        TotalCoeff_1    <= 8;
302
    end
303
    else if (rbsp_1[10:12] == 3'b101) begin
304
        TrailingOnes_1  <= 2;
305
        TotalCoeff_1    <= 8;
306
    end
307
    else if (rbsp_1[10:12] == 3'b001) begin
308
        TrailingOnes_1  <= 2;
309
        TotalCoeff_1    <= 9;
310
    end
311
    else begin
312
        TrailingOnes_1  <= 3;
313
        TotalCoeff_1    <= 10;
314
    end
315 6 qiubin
end
316
rbsp_1[10] : begin
317 7 qiubin
    len_1           <= 14;
318
    if (rbsp_1[11:13] == 3'b111) begin
319
        TrailingOnes_1  <= 0;
320
        TotalCoeff_1    <= 9;
321
    end
322
    else if (rbsp_1[11:13] == 3'b110) begin
323
        TrailingOnes_1  <= 1;
324
        TotalCoeff_1    <= 9;
325
    end
326
    else if (rbsp_1[11:13] == 3'b011) begin
327
        TrailingOnes_1  <= 0;
328
        TotalCoeff_1    <= 10;
329
    end
330
    else if (rbsp_1[11:13] == 3'b010) begin
331
        TrailingOnes_1  <= 1;
332
        TotalCoeff_1    <= 10;
333
    end
334
    else if (rbsp_1[11:13] == 3'b101) begin
335
        TrailingOnes_1  <= 2;
336
        TotalCoeff_1    <= 10;
337
    end
338
    else if (rbsp_1[11:13] == 3'b001) begin
339
        TrailingOnes_1  <= 2;
340
        TotalCoeff_1    <= 11;
341
    end
342
    else if (rbsp_1[11:13] == 3'b100) begin
343
        TrailingOnes_1  <= 3;
344
        TotalCoeff_1    <= 11;
345
    end
346
    else begin
347
        TrailingOnes_1  <= 3;
348
        TotalCoeff_1    <= 12;
349
    end
350 6 qiubin
end
351
rbsp_1[11] : begin
352 7 qiubin
    len_1           <= 15;
353
    if (rbsp_1[12:14] == 3'b111) begin
354
        TrailingOnes_1  <= 0;
355
        TotalCoeff_1    <= 11;
356
    end
357
    else if (rbsp_1[12:14] == 3'b110) begin
358
        TrailingOnes_1  <= 1;
359
        TotalCoeff_1    <= 11;
360
    end
361
    else if (rbsp_1[12:14] == 3'b011) begin
362
        TrailingOnes_1  <= 0;
363
        TotalCoeff_1    <= 12;
364
    end
365
    else if (rbsp_1[12:14] == 3'b010) begin
366
        TrailingOnes_1  <= 1;
367
        TotalCoeff_1    <= 12;
368
    end
369
    else if (rbsp_1[12:14] == 3'b101) begin
370
        TrailingOnes_1  <= 2;
371
        TotalCoeff_1    <= 12;
372
    end
373
    else if (rbsp_1[12:14] == 3'b001) begin
374
        TrailingOnes_1  <= 2;
375
        TotalCoeff_1    <= 13;
376
    end
377
    else if (rbsp_1[12:14] == 3'b100) begin
378
        TrailingOnes_1  <= 3;
379
        TotalCoeff_1    <= 13;
380
    end
381
    else begin
382
        TrailingOnes_1  <= 3;
383
        TotalCoeff_1    <= 14;
384
    end
385 6 qiubin
end
386
rbsp_1[12] : begin
387 7 qiubin
    len_1           <= 16;
388
    if (rbsp_1[13:15] == 3'b111) begin
389
        TrailingOnes_1  <= 0;
390
        TotalCoeff_1    <= 13;
391
    end
392
    else if (rbsp_1[13:15] == 3'b011) begin
393
        TrailingOnes_1  <= 0;
394
        TotalCoeff_1    <= 14;
395
    end
396
    else if (rbsp_1[13:15] == 3'b110) begin
397
        TrailingOnes_1  <= 1;
398
        TotalCoeff_1    <= 14;
399
    end
400
    else if (rbsp_1[13:15] == 3'b101) begin
401
        TrailingOnes_1  <= 2;
402
        TotalCoeff_1    <= 14;
403
    end
404
    else if (rbsp_1[13:15] == 3'b010) begin
405
        TrailingOnes_1  <= 1;
406
        TotalCoeff_1    <= 15;
407
    end
408
    else if (rbsp_1[13:15] == 3'b001) begin
409
        TrailingOnes_1  <= 2;
410
        TotalCoeff_1    <= 15;
411
    end
412
    else if (rbsp_1[13:15] == 3'b100) begin
413
        TrailingOnes_1  <= 3;
414
        TotalCoeff_1    <= 15;
415
    end
416
    else begin
417
        TrailingOnes_1  <= 3;
418
        TotalCoeff_1    <= 16;
419
    end
420 6 qiubin
end
421
rbsp_1[13] : begin
422 7 qiubin
    len_1           <= 16;
423
    if (rbsp_1[14:15] == 2'b11) begin
424
        TrailingOnes_1  <= 0;
425
        TotalCoeff_1    <= 15;
426
    end
427
    else if (rbsp_1[14:15] == 2'b00) begin
428
        TrailingOnes_1  <= 0;
429
        TotalCoeff_1    <= 16;
430
    end
431
    else if (rbsp_1[14:15] == 2'b10) begin
432
        TrailingOnes_1  <= 1;
433
        TotalCoeff_1    <= 16;
434
    end
435
    else begin
436
        TrailingOnes_1  <= 2;
437
        TotalCoeff_1    <= 16;
438
    end
439 6 qiubin
end
440
default : begin
441 7 qiubin
    len_1           <= 15;
442
    TrailingOnes_1  <= 1;
443
    TotalCoeff_1    <= 13;
444 6 qiubin
end
445
endcase
446
 
447
//------------------------
448
//nC >= 2 && nC < 4
449
//------------------------
450
always @(rbsp_2)
451 7 qiubin
case (1'b1)
452 6 qiubin
rbsp_2[0] : begin
453 7 qiubin
    len_2           <= 2;
454
    if (rbsp_2[1] == 'b1) begin
455
        TrailingOnes_2  <= 0;
456
        TotalCoeff_2    <= 0;
457
    end
458
    else begin
459
        TrailingOnes_2  <= 1;
460
        TotalCoeff_2    <= 1;
461
    end
462 6 qiubin
end
463
rbsp_2[1] : begin
464 7 qiubin
    if (rbsp_2[2] == 'b1) begin
465
        TrailingOnes_2  <= 2;
466
        TotalCoeff_2    <= 2;
467
        len_2           <= 3;
468
    end
469
    else if (rbsp_2[3] == 'b1) begin
470
        TrailingOnes_2  <= 3;
471
        TotalCoeff_2    <= 3;
472
        len_2           <= 4;
473
    end
474
    else begin
475
        TrailingOnes_2  <= 3;
476
        TotalCoeff_2    <= 4;
477
        len_2           <= 4;
478
    end
479 6 qiubin
end
480
rbsp_2[2] : begin
481 7 qiubin
    if (rbsp_2[3:4] == 'b11) begin
482
        TrailingOnes_2  <= 1;
483
        TotalCoeff_2    <= 2;
484
        len_2           <= 5;
485
    end
486
    else if (rbsp_2[3:4] == 'b10) begin
487
        TrailingOnes_2  <= 3;
488
        TotalCoeff_2    <= 5;
489
        len_2           <= 5;
490
    end
491
    else if (rbsp_2[4:5] == 'b11) begin
492
        TrailingOnes_2  <= 0;
493
        TotalCoeff_2    <= 1;
494
        len_2           <= 6;
495
    end
496
    else if (rbsp_2[4:5] == 'b10) begin
497
        TrailingOnes_2  <= 1;
498
        TotalCoeff_2    <= 3;
499
        len_2           <= 6;
500
    end
501
    else if (rbsp_2[4:5] == 'b01) begin
502
        TrailingOnes_2  <= 2;
503
        TotalCoeff_2    <= 3;
504
        len_2           <= 6;
505
    end
506
    else begin
507
        TrailingOnes_2  <= 3;
508
        TotalCoeff_2    <= 6;
509
        len_2           <= 6;
510
    end
511 6 qiubin
end
512
rbsp_2[3] : begin
513 7 qiubin
    len_2           <= 6;
514
    if (rbsp_2[4:5] == 'b11) begin
515
        TrailingOnes_2  <= 0;
516
        TotalCoeff_2    <= 2;
517
    end
518
    else if (rbsp_2[4:5] == 'b10) begin
519
        TrailingOnes_2  <= 1;
520
        TotalCoeff_2    <= 4;
521
    end
522
    else if (rbsp_2[4:5] == 'b01) begin
523
        TrailingOnes_2  <= 2;
524
        TotalCoeff_2    <= 4;
525
    end
526
    else begin
527
        TrailingOnes_2  <= 3;
528
        TotalCoeff_2    <= 7;
529
    end
530 6 qiubin
end
531
rbsp_2[4] : begin
532 7 qiubin
    len_2           <= 7;
533
    if (rbsp_2[5:6] == 'b11) begin
534
        TrailingOnes_2  <= 0;
535
        TotalCoeff_2    <= 3;
536
    end
537
    else if (rbsp_2[5:6] == 'b10) begin
538
        TrailingOnes_2  <= 1;
539
        TotalCoeff_2    <= 5;
540
    end
541
    else if (rbsp_2[5:6] == 'b01) begin
542
        TrailingOnes_2  <= 2;
543
        TotalCoeff_2    <= 5;
544
    end
545
    else begin
546
        TrailingOnes_2  <= 3;
547
        TotalCoeff_2    <= 8;
548
    end
549 6 qiubin
end
550
rbsp_2[5] : begin
551 7 qiubin
    len_2           <= 8;
552
    if (rbsp_2[6:7] == 'b11) begin
553
        TrailingOnes_2  <= 0;
554
        TotalCoeff_2    <= 4;
555
    end
556
    else if (rbsp_2[6:7] == 'b00) begin
557
        TrailingOnes_2  <= 0;
558
        TotalCoeff_2    <= 5;
559
    end
560
    else if (rbsp_2[6:7] == 'b10) begin
561
        TrailingOnes_2  <= 1;
562
        TotalCoeff_2    <= 6;
563
    end
564
    else begin
565
        TrailingOnes_2  <= 2;
566
        TotalCoeff_2    <= 6;
567
    end
568 6 qiubin
end
569
rbsp_2[6] : begin
570 7 qiubin
    len_2           <= 9;
571
    if (rbsp_2[7:8] == 'b11) begin
572
        TrailingOnes_2  <= 0;
573
        TotalCoeff_2    <= 6;
574
    end
575
    else if (rbsp_2[7:8] == 'b10) begin
576
        TrailingOnes_2  <= 1;
577
        TotalCoeff_2    <= 7;
578
    end
579
    else if (rbsp_2[7:8] == 'b01) begin
580
        TrailingOnes_2  <= 2;
581
        TotalCoeff_2    <= 7;
582
    end
583
    else begin
584
        TrailingOnes_2  <= 3;
585
        TotalCoeff_2    <= 9;
586
    end
587 6 qiubin
end
588
rbsp_2[7] : begin
589 7 qiubin
    len_2           <= 11;
590
    if (rbsp_2[8:10] == 'b111) begin
591
        TrailingOnes_2  <= 0;
592
        TotalCoeff_2    <= 7;
593
    end
594
    else if (rbsp_2[8:10] == 'b011) begin
595
        TrailingOnes_2  <= 0;
596
        TotalCoeff_2    <= 8;
597
    end
598
    else if (rbsp_2[8:10] == 'b110) begin
599
        TrailingOnes_2  <= 1;
600
        TotalCoeff_2    <= 8;
601
    end
602
    else if (rbsp_2[8:10] == 'b101) begin
603
        TrailingOnes_2  <= 2;
604
        TotalCoeff_2    <= 8;
605
    end
606
    else if (rbsp_2[8:10] == 'b010) begin
607
        TrailingOnes_2  <= 1;
608
        TotalCoeff_2    <= 9;
609
    end
610
    else if (rbsp_2[8:10] == 'b001) begin
611
        TrailingOnes_2  <= 2;
612
        TotalCoeff_2    <= 9;
613
    end
614
    else if (rbsp_2[8:10] == 'b100) begin
615
        TrailingOnes_2  <= 3;
616
        TotalCoeff_2    <= 10;
617
    end
618
    else begin
619
        TrailingOnes_2  <= 3;
620
        TotalCoeff_2    <= 11;
621
    end
622 6 qiubin
end
623
rbsp_2[8] : begin
624 7 qiubin
    len_2           <= 12;
625
    if (rbsp_2[9:11] == 'b111) begin
626
        TrailingOnes_2  <= 0;
627
        TotalCoeff_2    <= 9;
628
    end
629
    else if (rbsp_2[9:11] == 'b011) begin
630
        TrailingOnes_2  <= 0;
631
        TotalCoeff_2    <= 10;
632
    end
633
    else if (rbsp_2[9:11] == 'b110) begin
634
        TrailingOnes_2  <= 1;
635
        TotalCoeff_2    <= 10;
636
    end
637
    else if (rbsp_2[9:11] == 'b101) begin
638
        TrailingOnes_2  <= 2;
639
        TotalCoeff_2    <= 10;
640
    end
641
    else if (rbsp_2[9:11] == 'b000) begin
642
        TrailingOnes_2  <= 0;
643
        TotalCoeff_2    <= 11;
644
    end
645
    else if (rbsp_2[9:11] == 'b010) begin
646
        TrailingOnes_2  <= 1;
647
        TotalCoeff_2    <= 11;
648
    end
649
    else if (rbsp_2[9:11] == 'b001) begin
650
        TrailingOnes_2  <= 2;
651
        TotalCoeff_2    <= 11;
652
    end
653
    else  begin
654
        TrailingOnes_2  <= 3;
655
        TotalCoeff_2    <= 12;
656
    end
657 6 qiubin
end
658
rbsp_2[9] : begin
659 7 qiubin
    len_2           <= 13;
660
    if (rbsp_2[10:12] == 'b111) begin
661
        TrailingOnes_2  <= 0;
662
        TotalCoeff_2    <= 12;
663
    end
664
    else if (rbsp_2[10:12] == 'b110) begin
665
        TrailingOnes_2  <= 1;
666
        TotalCoeff_2    <= 12;
667
    end
668
    else if (rbsp_2[10:12] == 'b101) begin
669
        TrailingOnes_2  <= 2;
670
        TotalCoeff_2    <= 12;
671
    end
672
    else if (rbsp_2[10:12] == 'b011) begin
673
        TrailingOnes_2  <= 0;
674
        TotalCoeff_2    <= 13;
675
    end
676
    else if (rbsp_2[10:12] == 'b010) begin
677
        TrailingOnes_2  <= 1;
678
        TotalCoeff_2    <= 13;
679
    end
680
    else if (rbsp_2[10:12] == 'b001) begin
681
        TrailingOnes_2  <= 2;
682
        TotalCoeff_2    <= 13;
683
    end
684
    else if (rbsp_2[10:12] == 'b100) begin
685
        TrailingOnes_2  <= 3;
686
        TotalCoeff_2    <= 13;
687
    end
688
    else begin
689
        TrailingOnes_2  <= 3;
690
        TotalCoeff_2    <= 14;
691
    end
692 6 qiubin
end
693
rbsp_2[10] : begin
694 7 qiubin
    if (rbsp_2[11:12] == 'b11) begin
695
        TrailingOnes_2  <= 0;
696
        TotalCoeff_2    <= 14;
697
        len_2           <= 13;
698
    end
699
    else if (rbsp_2[11:12] == 'b10) begin
700
        TrailingOnes_2  <= 2;
701
        TotalCoeff_2    <= 14;
702
        len_2           <= 13;
703
    end
704
    else if (rbsp_2[12:13] == 'b11) begin
705
        TrailingOnes_2  <= 1;
706
        TotalCoeff_2    <= 14;
707
        len_2           <= 14;
708
    end
709
    else if (rbsp_2[12:13] == 'b01) begin
710
        TrailingOnes_2  <= 0;
711
        TotalCoeff_2    <= 15;
712
        len_2           <= 14;
713
    end
714
    else if (rbsp_2[12:13] == 'b00) begin
715
        TrailingOnes_2  <= 1;
716
        TotalCoeff_2    <= 15;
717
        len_2           <= 14;
718
    end
719
    else begin
720
        TrailingOnes_2  <= 2;
721
        TotalCoeff_2    <= 15;
722
        len_2           <= 14;
723
    end
724 6 qiubin
end
725
rbsp_2[11] : begin
726 7 qiubin
    len_2           <= 14;
727
    if (rbsp_2[12:13] == 'b11) begin
728
        TrailingOnes_2  <= 0;
729
        TotalCoeff_2    <= 16;
730
    end
731
    else if (rbsp_2[12:13] == 'b10) begin
732
        TrailingOnes_2  <= 1;
733
        TotalCoeff_2    <= 16;
734
    end
735
    else if (rbsp_2[12:13] == 'b01) begin
736
        TrailingOnes_2  <= 2;
737
        TotalCoeff_2    <= 16;
738
    end
739
    else begin
740
        TrailingOnes_2  <= 3;
741
        TotalCoeff_2    <= 16;
742
    end
743 6 qiubin
end
744
default : begin
745 7 qiubin
    TrailingOnes_2  <= 3;
746
    TotalCoeff_2    <= 15;
747
    len_2           <= 13;
748 6 qiubin
end
749
endcase
750
 
751
//------------------------
752
// nC >= 4 && nC < 8
753
//------------------------
754
always @(rbsp_3)
755 7 qiubin
case (1'b1)
756 6 qiubin
rbsp_3[0] : begin
757 7 qiubin
    len_3           <= 4;
758
    case (rbsp_3[1:3])
759
        'b111 : begin
760
            TrailingOnes_3  <= 0;
761
            TotalCoeff_3    <= 0;
762
        end
763
        'b110 : begin
764
            TrailingOnes_3  <= 1;
765
            TotalCoeff_3    <= 1;
766
        end
767
        'b101 : begin
768
            TrailingOnes_3  <= 2;
769
            TotalCoeff_3    <= 2;
770
        end
771
        'b100 : begin
772
            TrailingOnes_3  <= 3;
773
            TotalCoeff_3    <= 3;
774
        end
775
        'b011 : begin
776
            TrailingOnes_3  <= 3;
777
            TotalCoeff_3    <= 4;
778
        end
779
        'b010 : begin
780
            TrailingOnes_3  <= 3;
781
            TotalCoeff_3    <= 5;
782
        end
783
        'b001 : begin
784
            TrailingOnes_3  <= 3;
785
            TotalCoeff_3    <= 6;
786
        end
787
        'b000 : begin
788
            TrailingOnes_3  <= 3;
789
            TotalCoeff_3    <= 7;
790
        end
791
    endcase
792 6 qiubin
end
793
rbsp_3[1] : begin
794 7 qiubin
    len_3           <= 5;
795
    case (rbsp_3[2:4])
796
        'b111 : begin
797
            TrailingOnes_3  <= 1;
798
            TotalCoeff_3    <= 2;
799
        end
800
        'b100 : begin
801
            TrailingOnes_3  <= 1;
802
            TotalCoeff_3    <= 3;
803
        end
804
        'b110 : begin
805
            TrailingOnes_3  <= 2;
806
            TotalCoeff_3    <= 3;
807
        end
808
        'b010 : begin
809
            TrailingOnes_3  <= 1;
810
            TotalCoeff_3    <= 4;
811
        end
812
        'b011 : begin
813
            TrailingOnes_3  <= 2;
814
            TotalCoeff_3    <= 4;
815
        end
816
        'b000 : begin
817
            TrailingOnes_3  <= 1;
818
            TotalCoeff_3    <= 5;
819
        end
820
        'b001 : begin
821
            TrailingOnes_3  <= 2;
822
            TotalCoeff_3    <= 5;
823
        end
824
        'b101 : begin
825
            TrailingOnes_3  <= 3;
826
            TotalCoeff_3    <= 8;
827
        end
828
    endcase
829 6 qiubin
end
830
rbsp_3[2] : begin
831 7 qiubin
    len_3           <= 6;
832
    case (rbsp_3[3:5])
833
        3'b111 : begin
834
            TrailingOnes_3  <= 0;
835
            TotalCoeff_3    <= 1;
836
        end
837
        3'b011 : begin
838
            TrailingOnes_3  <= 0;
839
            TotalCoeff_3    <= 2;
840
        end
841
        3'b000 : begin
842
            TrailingOnes_3  <= 0;
843
            TotalCoeff_3    <= 3;
844
        end
845
        3'b110 : begin
846
            TrailingOnes_3  <= 1;
847
            TotalCoeff_3    <= 6;
848
        end
849
        3'b101 : begin
850
            TrailingOnes_3  <= 2;
851
            TotalCoeff_3    <= 6;
852
        end
853
        3'b010 : begin
854
            TrailingOnes_3  <= 1;
855
            TotalCoeff_3    <= 7;
856
        end
857
        3'b001 : begin
858
            TrailingOnes_3  <= 2;
859
            TotalCoeff_3    <= 7;
860
        end
861
        3'b100 : begin
862
            TrailingOnes_3  <= 3;
863
            TotalCoeff_3    <= 9;
864
        end
865
    endcase
866 6 qiubin
end
867
rbsp_3[3] : begin
868 7 qiubin
    len_3           <= 7;
869
    case (rbsp_3[4:6])
870
        'b111 : begin
871
            TrailingOnes_3  <= 0;
872
            TotalCoeff_3    <= 4;
873
        end
874
        'b011 : begin
875
            TrailingOnes_3  <= 0;
876
            TotalCoeff_3    <= 5;
877
        end
878
        'b001 : begin
879
            TrailingOnes_3  <= 0;
880
            TotalCoeff_3    <= 6;
881
        end
882
        'b000 : begin
883
            TrailingOnes_3  <= 0;
884
            TotalCoeff_3    <= 7;
885
        end
886
        'b110 : begin
887
            TrailingOnes_3  <= 1;
888
            TotalCoeff_3    <= 8;
889
        end
890
        'b101 : begin
891
            TrailingOnes_3  <= 2;
892
            TotalCoeff_3    <= 8;
893
        end
894 6 qiubin
 
895 7 qiubin
        'b010 : begin
896
            TrailingOnes_3  <= 2;
897
            TotalCoeff_3    <= 9;
898
        end
899
        'b100 : begin
900
            TrailingOnes_3  <= 3;
901
            TotalCoeff_3    <= 10;
902
        end
903
    endcase
904 6 qiubin
end
905
rbsp_3[4] : begin
906 7 qiubin
    len_3           <= 8;
907
    case (rbsp_3[5:7])
908
        'b111 : begin
909
            TrailingOnes_3  <= 0;
910
            TotalCoeff_3    <= 8;
911
        end
912
        'b011 : begin
913
            TrailingOnes_3  <= 0;
914
            TotalCoeff_3    <= 9;
915
        end
916
        'b110 : begin
917
            TrailingOnes_3  <= 1;
918
            TotalCoeff_3    <= 9;
919
        end
920
        'b010 : begin
921
            TrailingOnes_3  <= 1;
922
            TotalCoeff_3    <= 10;
923
        end
924
        'b101 : begin
925
            TrailingOnes_3  <= 2;
926
            TotalCoeff_3    <= 10;
927
        end
928
        'b001 : begin
929
            TrailingOnes_3  <= 2;
930
            TotalCoeff_3    <= 11;
931
        end
932
        'b100 : begin
933
            TrailingOnes_3  <= 3;
934
            TotalCoeff_3    <= 11;
935
        end
936
        'b000 : begin
937
            TrailingOnes_3  <= 3;
938
            TotalCoeff_3    <= 12;
939
        end
940
    endcase
941 6 qiubin
end
942
rbsp_3[5] : begin
943 7 qiubin
    len_3           <= 9;
944
    case (rbsp_3[6:8])
945
        'b111 : begin
946
            TrailingOnes_3  <= 0;
947
            TotalCoeff_3    <= 10;
948
        end
949
        'b011 : begin
950
            TrailingOnes_3  <= 0;
951
            TotalCoeff_3    <= 11;
952
        end
953
        'b110 : begin
954
            TrailingOnes_3  <= 1;
955
            TotalCoeff_3    <= 11;
956
        end
957
        'b000 : begin
958
            TrailingOnes_3  <= 0;
959
            TotalCoeff_3    <= 12;
960
        end
961
        'b010 : begin
962
            TrailingOnes_3  <= 1;
963
            TotalCoeff_3    <= 12;
964
        end
965
        'b101 : begin
966
            TrailingOnes_3  <= 2;
967
            TotalCoeff_3    <= 12;
968
        end
969
        'b001 : begin
970
            TrailingOnes_3  <= 2;
971
            TotalCoeff_3    <= 13;
972
        end
973
        'b100 : begin
974
            TrailingOnes_3  <= 3;
975
            TotalCoeff_3    <= 13;
976
        end
977
    endcase
978 6 qiubin
end
979
rbsp_3[6] : begin
980 7 qiubin
    if (rbsp_3[7:8] == 'b11)begin
981
        TrailingOnes_3  <= 1;
982
        TotalCoeff_3    <= 13;
983
        len_3           <= 9;
984
    end
985
    else if (rbsp_3[7:9] == 'b101)begin
986
        TrailingOnes_3  <= 0;
987
        TotalCoeff_3    <= 13;
988
        len_3           <= 10;
989
    end
990
    else if (rbsp_3[7:9] == 'b001)begin
991
        TrailingOnes_3  <= 0;
992
        TotalCoeff_3    <= 14;
993
        len_3           <= 10;
994
    end
995
    else if (rbsp_3[7:9] == 'b100)begin
996
        TrailingOnes_3  <= 1;
997
        TotalCoeff_3    <= 14;
998
        len_3           <= 10;
999
    end
1000
    else if (rbsp_3[7:9] == 'b011)begin
1001
        TrailingOnes_3  <= 2;
1002
        TotalCoeff_3    <= 14;
1003
        len_3           <= 10;
1004
    end
1005
    else if (rbsp_3[7:9] == 'b010)begin
1006
        TrailingOnes_3  <= 3;
1007
        TotalCoeff_3    <= 14;
1008
        len_3           <= 10;
1009
    end
1010
    else begin
1011
        TrailingOnes_3  <= 1;
1012
        TotalCoeff_3    <= 15;
1013
        len_3           <= 10;
1014
    end
1015 6 qiubin
end
1016
rbsp_3[7] : begin
1017 7 qiubin
    len_3           <= 10;
1018
    case (rbsp_3[8:9])
1019
        'b01 : begin
1020
            TrailingOnes_3  <= 0;
1021
            TotalCoeff_3    <= 15;
1022
        end
1023
        'b11 : begin
1024
            TrailingOnes_3  <= 2;
1025
            TotalCoeff_3    <= 15;
1026
        end
1027
        'b10 : begin
1028
            TrailingOnes_3  <= 3;
1029
            TotalCoeff_3    <= 15;
1030
        end
1031
        'b00 : begin
1032
            TrailingOnes_3  <= 1;
1033
            TotalCoeff_3    <= 16;
1034
        end
1035
    endcase
1036 6 qiubin
end
1037
rbsp_3[8] : begin
1038 7 qiubin
    len_3           <= 10;
1039
    if (rbsp_3[9] == 'b1)begin
1040
        TrailingOnes_3  <= 2;
1041
        TotalCoeff_3    <= 16;
1042
    end
1043
    else begin
1044
        TrailingOnes_3  <= 3;
1045
        TotalCoeff_3    <= 16;
1046
    end
1047 6 qiubin
end
1048
default : begin
1049 7 qiubin
    len_3           <= 10;
1050
    TrailingOnes_3  <= 0;
1051
    TotalCoeff_3    <= 16;
1052 6 qiubin
end
1053
endcase
1054
 
1055 7 qiubin
//------------------------
1056
// nC > 8
1057
//------------------------
1058 6 qiubin
always @(rbsp_4)
1059
begin
1060 7 qiubin
    len_4 <= 6;
1061
    if (rbsp_4[0:4] == 5'b00001) begin
1062
        TrailingOnes_4  <= 0;
1063
        TotalCoeff_4    <= 0;
1064
    end
1065
    else begin
1066
        TrailingOnes_4  <= rbsp_4[4:5];
1067
        TotalCoeff_4    <= rbsp_4[0:3] + 1'b1;
1068
    end
1069 6 qiubin
end
1070
 
1071
//------------------------
1072
// nC == -1
1073
//------------------------
1074
always @(rbsp_5)
1075
case (1'b1)
1076
rbsp_5[0] : begin
1077 7 qiubin
    TrailingOnes_5  <= 1;
1078
    TotalCoeff_5    <= 1;
1079
    len_5           <= 1;
1080 6 qiubin
end
1081
rbsp_5[1] : begin
1082 7 qiubin
    TrailingOnes_5  <= 0;
1083
    TotalCoeff_5    <= 0;
1084
    len_5           <= 2;
1085 6 qiubin
end
1086
rbsp_5[2] : begin
1087 7 qiubin
    TrailingOnes_5  <= 2;
1088
    TotalCoeff_5    <= 2;
1089
    len_5           <= 3;
1090 6 qiubin
end
1091
rbsp_5[3] : begin
1092 7 qiubin
    len_5           <= 6;
1093
    if (rbsp_5[4:5] == 'b11) begin
1094
        TrailingOnes_5  <= 0;
1095
        TotalCoeff_5    <= 1;
1096
    end
1097
    else if (rbsp_5[4:5] == 'b00) begin
1098
        TrailingOnes_5  <= 0;
1099
        TotalCoeff_5    <= 2;
1100
    end
1101
    else if (rbsp_5[4:5] == 'b10) begin
1102
        TrailingOnes_5  <= 1;
1103
        TotalCoeff_5    <= 2;
1104
    end
1105
    else begin
1106
        TrailingOnes_5  <= 3;
1107
        TotalCoeff_5    <= 3;
1108
    end
1109 6 qiubin
end
1110
rbsp_5[4] : begin
1111 7 qiubin
    len_5           <= 6;
1112
    if (rbsp_5[5] == 'b1) begin
1113
        TrailingOnes_5  <= 0;
1114
        TotalCoeff_5    <= 3;
1115
    end
1116
    else begin
1117
        TrailingOnes_5  <= 0;
1118
        TotalCoeff_5    <= 4;
1119
    end
1120 6 qiubin
end
1121
rbsp_5[5] : begin
1122 7 qiubin
    len_5           <= 7;
1123
    if (rbsp_5[6] == 'b1) begin
1124
        TrailingOnes_5  <= 1;
1125
        TotalCoeff_5    <= 3;
1126
    end
1127
    else begin
1128
        TrailingOnes_5  <= 2;
1129
        TotalCoeff_5    <= 3;
1130
    end
1131 6 qiubin
end
1132
rbsp_5[6] : begin
1133 7 qiubin
    len_5           <= 8;
1134
    if (rbsp_5[7] == 'b1) begin
1135
        TrailingOnes_5  <= 1;
1136
        TotalCoeff_5    <= 4;
1137
    end
1138
    else begin
1139
        TrailingOnes_5  <= 2;
1140
        TotalCoeff_5    <= 4;
1141
    end
1142 6 qiubin
end
1143
default : begin
1144 7 qiubin
    len_5           <= 7;
1145
    TrailingOnes_5  <= 3;
1146
    TotalCoeff_5    <= 4;
1147 6 qiubin
end
1148
endcase
1149
 
1150
//------------------------
1151
//output mux
1152
//------------------------
1153
//startect a colum according to nC
1154
always @(*)
1155
begin
1156 7 qiubin
    if (nC == -1) begin
1157
        TrailingOnes_comb   <= TrailingOnes_5;
1158
        TotalCoeff_comb     <= TotalCoeff_5;
1159
        len_comb            <= len_5;
1160
    end
1161
    else if (nC[4] | nC[3]) begin
1162
        TrailingOnes_comb   <= TrailingOnes_4;
1163
        TotalCoeff_comb     <= TotalCoeff_4;
1164
        len_comb            <= len_4;
1165
    end
1166
    else if (nC[2]) begin
1167
        TrailingOnes_comb   <= TrailingOnes_3;
1168
        TotalCoeff_comb     <= TotalCoeff_3;
1169
        len_comb            <= len_3;
1170
    end
1171
    else if (nC[1]) begin
1172
        TrailingOnes_comb   <= TrailingOnes_2;
1173
        TotalCoeff_comb     <= TotalCoeff_2;
1174
        len_comb            <= len_2;
1175
    end
1176
    else begin
1177
        TrailingOnes_comb   <= TrailingOnes_1;
1178
        TotalCoeff_comb     <= TotalCoeff_1;
1179
        len_comb            <= len_1;
1180
    end
1181 6 qiubin
end
1182 7 qiubin
 
1183 6 qiubin
//------------------------
1184
//TrailingOnes & TotalCoeff
1185
//------------------------
1186
always @(posedge clk or negedge rst_n)
1187 7 qiubin
if (!rst_n) begin
1188
    TrailingOnes    <= 0;
1189
    TotalCoeff      <= 0;
1190 6 qiubin
end
1191 7 qiubin
else if (ena && sel) begin
1192
    TrailingOnes    <= TrailingOnes_comb;
1193
    TotalCoeff      <= TotalCoeff_comb;
1194 6 qiubin
end
1195
 
1196
endmodule
1197
 

powered by: WebSVN 2.1.0

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