OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [CAVLC.bsv] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 jamey.hick
//**********************************************************************
2
// CAVLC codes
3
//----------------------------------------------------------------------
4
//
5
//
6
//
7
 
8
package CAVLC;
9
 
10
import H264Types::*;
11
 
12
 
13
   //-----------------------------------------------------------
14
   // Helper functions
15
 
16
 
17
   (* noinline *)
18
   function Tuple3#(Bit#(2),Bit#(5),Bufcount) cavlc_coeff_token( Buffer inbuffer, Bit#(6) nC );
19
      if(nC[5] == 1)
20
         begin
21
            Bit#(8) buffertemp = inbuffer[buffersize-1:buffersize-8];
22
            if(buffertemp[7:6]  ==  2'b01) return tuple3(0,0,2);
23
            else if(buffertemp[7:2]  ==  6'b000111) return tuple3(0,1,6);
24
            else if(buffertemp[7:7]  ==  1'b1) return tuple3(1,1,1);
25
            else if(buffertemp[7:2]  ==  6'b000100) return tuple3(0,2,6);
26
            else if(buffertemp[7:2]  ==  6'b000110) return tuple3(1,2,6);
27
            else if(buffertemp[7:5]  ==  3'b001) return tuple3(2,2,3);
28
            else if(buffertemp[7:2]  ==  6'b000011) return tuple3(0,3,6);
29
            else if(buffertemp[7:1]  ==  7'b0000011) return tuple3(1,3,7);
30
            else if(buffertemp[7:1]  ==  7'b0000010) return tuple3(2,3,7);
31
            else if(buffertemp[7:2]  ==  6'b000101) return tuple3(3,3,6);
32
            else if(buffertemp[7:2]  ==  6'b000010) return tuple3(0,4,6);
33
            else if(buffertemp[7:0]  ==  8'b00000011) return tuple3(1,4,8);
34
            else if(buffertemp[7:0]  ==  8'b00000010) return tuple3(2,4,8);
35
            else if(buffertemp[7:1]  ==  7'b0000000) return tuple3(3,4,7);
36
            else return tuple3(0,0,100);
37
         end
38
      else if(nC[4] == 1 || nC[3] == 1)
39
         begin
40
            Bit#(6) buffertemp = inbuffer[buffersize-1:buffersize-6];
41
            if(buffertemp[5:0]  ==  6'b000011) return tuple3(0,0,6);
42
            else if(buffertemp[5:0]  ==  6'b000000) return tuple3(0,1,6);
43
            else if(buffertemp[5:0]  ==  6'b000001) return tuple3(1,1,6);
44
            else if(buffertemp[5:0]  ==  6'b000100) return tuple3(0,2,6);
45
            else if(buffertemp[5:0]  ==  6'b000101) return tuple3(1,2,6);
46
            else if(buffertemp[5:0]  ==  6'b000110) return tuple3(2,2,6);
47
            else if(buffertemp[5:0]  ==  6'b001000) return tuple3(0,3,6);
48
            else if(buffertemp[5:0]  ==  6'b001001) return tuple3(1,3,6);
49
            else if(buffertemp[5:0]  ==  6'b001010) return tuple3(2,3,6);
50
            else if(buffertemp[5:0]  ==  6'b001011) return tuple3(3,3,6);
51
            else if(buffertemp[5:0]  ==  6'b001100) return tuple3(0,4,6);
52
            else if(buffertemp[5:0]  ==  6'b001101) return tuple3(1,4,6);
53
            else if(buffertemp[5:0]  ==  6'b001110) return tuple3(2,4,6);
54
            else if(buffertemp[5:0]  ==  6'b001111) return tuple3(3,4,6);
55
            else if(buffertemp[5:0]  ==  6'b010000) return tuple3(0,5,6);
56
            else if(buffertemp[5:0]  ==  6'b010001) return tuple3(1,5,6);
57
            else if(buffertemp[5:0]  ==  6'b010010) return tuple3(2,5,6);
58
            else if(buffertemp[5:0]  ==  6'b010011) return tuple3(3,5,6);
59
            else if(buffertemp[5:0]  ==  6'b010100) return tuple3(0,6,6);
60
            else if(buffertemp[5:0]  ==  6'b010101) return tuple3(1,6,6);
61
            else if(buffertemp[5:0]  ==  6'b010110) return tuple3(2,6,6);
62
            else if(buffertemp[5:0]  ==  6'b010111) return tuple3(3,6,6);
63
            else if(buffertemp[5:0]  ==  6'b011000) return tuple3(0,7,6);
64
            else if(buffertemp[5:0]  ==  6'b011001) return tuple3(1,7,6);
65
            else if(buffertemp[5:0]  ==  6'b011010) return tuple3(2,7,6);
66
            else if(buffertemp[5:0]  ==  6'b011011) return tuple3(3,7,6);
67
            else if(buffertemp[5:0]  ==  6'b011100) return tuple3(0,8,6);
68
            else if(buffertemp[5:0]  ==  6'b011101) return tuple3(1,8,6);
69
            else if(buffertemp[5:0]  ==  6'b011110) return tuple3(2,8,6);
70
            else if(buffertemp[5:0]  ==  6'b011111) return tuple3(3,8,6);
71
            else if(buffertemp[5:0]  ==  6'b100000) return tuple3(0,9,6);
72
            else if(buffertemp[5:0]  ==  6'b100001) return tuple3(1,9,6);
73
            else if(buffertemp[5:0]  ==  6'b100010) return tuple3(2,9,6);
74
            else if(buffertemp[5:0]  ==  6'b100011) return tuple3(3,9,6);
75
            else if(buffertemp[5:0]  ==  6'b100100) return tuple3(0,10,6);
76
            else if(buffertemp[5:0]  ==  6'b100101) return tuple3(1,10,6);
77
            else if(buffertemp[5:0]  ==  6'b100110) return tuple3(2,10,6);
78
            else if(buffertemp[5:0]  ==  6'b100111) return tuple3(3,10,6);
79
            else if(buffertemp[5:0]  ==  6'b101000) return tuple3(0,11,6);
80
            else if(buffertemp[5:0]  ==  6'b101001) return tuple3(1,11,6);
81
            else if(buffertemp[5:0]  ==  6'b101010) return tuple3(2,11,6);
82
            else if(buffertemp[5:0]  ==  6'b101011) return tuple3(3,11,6);
83
            else if(buffertemp[5:0]  ==  6'b101100) return tuple3(0,12,6);
84
            else if(buffertemp[5:0]  ==  6'b101101) return tuple3(1,12,6);
85
            else if(buffertemp[5:0]  ==  6'b101110) return tuple3(2,12,6);
86
            else if(buffertemp[5:0]  ==  6'b101111) return tuple3(3,12,6);
87
            else if(buffertemp[5:0]  ==  6'b110000) return tuple3(0,13,6);
88
            else if(buffertemp[5:0]  ==  6'b110001) return tuple3(1,13,6);
89
            else if(buffertemp[5:0]  ==  6'b110010) return tuple3(2,13,6);
90
            else if(buffertemp[5:0]  ==  6'b110011) return tuple3(3,13,6);
91
            else if(buffertemp[5:0]  ==  6'b110100) return tuple3(0,14,6);
92
            else if(buffertemp[5:0]  ==  6'b110101) return tuple3(1,14,6);
93
            else if(buffertemp[5:0]  ==  6'b110110) return tuple3(2,14,6);
94
            else if(buffertemp[5:0]  ==  6'b110111) return tuple3(3,14,6);
95
            else if(buffertemp[5:0]  ==  6'b111000) return tuple3(0,15,6);
96
            else if(buffertemp[5:0]  ==  6'b111001) return tuple3(1,15,6);
97
            else if(buffertemp[5:0]  ==  6'b111010) return tuple3(2,15,6);
98
            else if(buffertemp[5:0]  ==  6'b111011) return tuple3(3,15,6);
99
            else if(buffertemp[5:0]  ==  6'b111100) return tuple3(0,16,6);
100
            else if(buffertemp[5:0]  ==  6'b111101) return tuple3(1,16,6);
101
            else if(buffertemp[5:0]  ==  6'b111110) return tuple3(2,16,6);
102
            else if(buffertemp[5:0]  ==  6'b111111) return tuple3(3,16,6);
103
            else return tuple3(0,0,100);
104
         end
105
      else if(nC[2] == 1)
106
         begin
107
            Bit#(10) buffertemp = inbuffer[buffersize-1:buffersize-10];
108
            if(buffertemp[9:6]  ==  4'b1111) return tuple3(0,0,4);
109
            else if(buffertemp[9:4]  ==  6'b001111) return tuple3(0,1,6);
110
            else if(buffertemp[9:6]  ==  4'b1110) return tuple3(1,1,4);
111
            else if(buffertemp[9:4]  ==  6'b001011) return tuple3(0,2,6);
112
            else if(buffertemp[9:5]  ==  5'b01111) return tuple3(1,2,5);
113
            else if(buffertemp[9:6]  ==  4'b1101) return tuple3(2,2,4);
114
            else if(buffertemp[9:4]  ==  6'b001000) return tuple3(0,3,6);
115
            else if(buffertemp[9:5]  ==  5'b01100) return tuple3(1,3,5);
116
            else if(buffertemp[9:5]  ==  5'b01110) return tuple3(2,3,5);
117
            else if(buffertemp[9:6]  ==  4'b1100) return tuple3(3,3,4);
118
            else if(buffertemp[9:3]  ==  7'b0001111) return tuple3(0,4,7);
119
            else if(buffertemp[9:5]  ==  5'b01010) return tuple3(1,4,5);
120
            else if(buffertemp[9:5]  ==  5'b01011) return tuple3(2,4,5);
121
            else if(buffertemp[9:6]  ==  4'b1011) return tuple3(3,4,4);
122
            else if(buffertemp[9:3]  ==  7'b0001011) return tuple3(0,5,7);
123
            else if(buffertemp[9:5]  ==  5'b01000) return tuple3(1,5,5);
124
            else if(buffertemp[9:5]  ==  5'b01001) return tuple3(2,5,5);
125
            else if(buffertemp[9:6]  ==  4'b1010) return tuple3(3,5,4);
126
            else if(buffertemp[9:3]  ==  7'b0001001) return tuple3(0,6,7);
127
            else if(buffertemp[9:4]  ==  6'b001110) return tuple3(1,6,6);
128
            else if(buffertemp[9:4]  ==  6'b001101) return tuple3(2,6,6);
129
            else if(buffertemp[9:6]  ==  4'b1001) return tuple3(3,6,4);
130
            else if(buffertemp[9:3]  ==  7'b0001000) return tuple3(0,7,7);
131
            else if(buffertemp[9:4]  ==  6'b001010) return tuple3(1,7,6);
132
            else if(buffertemp[9:4]  ==  6'b001001) return tuple3(2,7,6);
133
            else if(buffertemp[9:6]  ==  4'b1000) return tuple3(3,7,4);
134
            else if(buffertemp[9:2]  ==  8'b00001111) return tuple3(0,8,8);
135
            else if(buffertemp[9:3]  ==  7'b0001110) return tuple3(1,8,7);
136
            else if(buffertemp[9:3]  ==  7'b0001101) return tuple3(2,8,7);
137
            else if(buffertemp[9:5]  ==  5'b01101) return tuple3(3,8,5);
138
            else if(buffertemp[9:2]  ==  8'b00001011) return tuple3(0,9,8);
139
            else if(buffertemp[9:2]  ==  8'b00001110) return tuple3(1,9,8);
140
            else if(buffertemp[9:3]  ==  7'b0001010) return tuple3(2,9,7);
141
            else if(buffertemp[9:4]  ==  6'b001100) return tuple3(3,9,6);
142
            else if(buffertemp[9:1]  ==  9'b000001111) return tuple3(0,10,9);
143
            else if(buffertemp[9:2]  ==  8'b00001010) return tuple3(1,10,8);
144
            else if(buffertemp[9:2]  ==  8'b00001101) return tuple3(2,10,8);
145
            else if(buffertemp[9:3]  ==  7'b0001100) return tuple3(3,10,7);
146
            else if(buffertemp[9:1]  ==  9'b000001011) return tuple3(0,11,9);
147
            else if(buffertemp[9:1]  ==  9'b000001110) return tuple3(1,11,9);
148
            else if(buffertemp[9:2]  ==  8'b00001001) return tuple3(2,11,8);
149
            else if(buffertemp[9:2]  ==  8'b00001100) return tuple3(3,11,8);
150
            else if(buffertemp[9:1]  ==  9'b000001000) return tuple3(0,12,9);
151
            else if(buffertemp[9:1]  ==  9'b000001010) return tuple3(1,12,9);
152
            else if(buffertemp[9:1]  ==  9'b000001101) return tuple3(2,12,9);
153
            else if(buffertemp[9:2]  ==  8'b00001000) return tuple3(3,12,8);
154
            else if(buffertemp[9:0]  == 10'b0000001101) return tuple3(0,13,10);
155
            else if(buffertemp[9:1]  ==  9'b000000111) return tuple3(1,13,9);
156
            else if(buffertemp[9:1]  ==  9'b000001001) return tuple3(2,13,9);
157
            else if(buffertemp[9:1]  ==  9'b000001100) return tuple3(3,13,9);
158
            else if(buffertemp[9:0]  == 10'b0000001001) return tuple3(0,14,10);
159
            else if(buffertemp[9:0]  == 10'b0000001100) return tuple3(1,14,10);
160
            else if(buffertemp[9:0]  == 10'b0000001011) return tuple3(2,14,10);
161
            else if(buffertemp[9:0]  == 10'b0000001010) return tuple3(3,14,10);
162
            else if(buffertemp[9:0]  == 10'b0000000101) return tuple3(0,15,10);
163
            else if(buffertemp[9:0]  == 10'b0000001000) return tuple3(1,15,10);
164
            else if(buffertemp[9:0]  == 10'b0000000111) return tuple3(2,15,10);
165
            else if(buffertemp[9:0]  == 10'b0000000110) return tuple3(3,15,10);
166
            else if(buffertemp[9:0]  == 10'b0000000001) return tuple3(0,16,10);
167
            else if(buffertemp[9:0]  == 10'b0000000100) return tuple3(1,16,10);
168
            else if(buffertemp[9:0]  == 10'b0000000011) return tuple3(2,16,10);
169
            else if(buffertemp[9:0]  == 10'b0000000010) return tuple3(3,16,10);
170
            else return tuple3(0,0,100);
171
         end
172
      else if(nC[1] == 1)
173
         begin
174
            Bit#(14) buffertemp = inbuffer[buffersize-1:buffersize-14];
175
            if(buffertemp[13:12] ==  2'b11) return tuple3(0,0,2);
176
            else if(buffertemp[13:8]  ==  6'b001011) return tuple3(0,1,6);
177
            else if(buffertemp[13:12] ==  2'b10) return tuple3(1,1,2);
178
            else if(buffertemp[13:8]  ==  6'b000111) return tuple3(0,2,6);
179
            else if(buffertemp[13:9]  ==  5'b00111) return tuple3(1,2,5);
180
            else if(buffertemp[13:11] ==  3'b011) return tuple3(2,2,3);
181
            else if(buffertemp[13:7]  ==  7'b0000111) return tuple3(0,3,7);
182
            else if(buffertemp[13:8]  ==  6'b001010) return tuple3(1,3,6);
183
            else if(buffertemp[13:8]  ==  6'b001001) return tuple3(2,3,6);
184
            else if(buffertemp[13:10] ==  4'b0101) return tuple3(3,3,4);
185
            else if(buffertemp[13:6]  ==  8'b00000111) return tuple3(0,4,8);
186
            else if(buffertemp[13:8]  ==  6'b000110) return tuple3(1,4,6);
187
            else if(buffertemp[13:8]  ==  6'b000101) return tuple3(2,4,6);
188
            else if(buffertemp[13:10] ==  4'b0100) return tuple3(3,4,4);
189
            else if(buffertemp[13:6]  ==  8'b00000100) return tuple3(0,5,8);
190
            else if(buffertemp[13:7]  ==  7'b0000110) return tuple3(1,5,7);
191
            else if(buffertemp[13:7]  ==  7'b0000101) return tuple3(2,5,7);
192
            else if(buffertemp[13:9]  ==  5'b00110) return tuple3(3,5,5);
193
            else if(buffertemp[13:5]  ==  9'b000000111) return tuple3(0,6,9);
194
            else if(buffertemp[13:6]  ==  8'b00000110) return tuple3(1,6,8);
195
            else if(buffertemp[13:6]  ==  8'b00000101) return tuple3(2,6,8);
196
            else if(buffertemp[13:8]  ==  6'b001000) return tuple3(3,6,6);
197
            else if(buffertemp[13:3]  == 11'b00000001111) return tuple3(0,7,11);
198
            else if(buffertemp[13:5]  ==  9'b000000110) return tuple3(1,7,9);
199
            else if(buffertemp[13:5]  ==  9'b000000101) return tuple3(2,7,9);
200
            else if(buffertemp[13:8]  ==  6'b000100) return tuple3(3,7,6);
201
            else if(buffertemp[13:3]  == 11'b00000001011) return tuple3(0,8,11);
202
            else if(buffertemp[13:3]  == 11'b00000001110) return tuple3(1,8,11);
203
            else if(buffertemp[13:3]  == 11'b00000001101) return tuple3(2,8,11);
204
            else if(buffertemp[13:7]  ==  7'b0000100) return tuple3(3,8,7);
205
            else if(buffertemp[13:2]  == 12'b000000001111) return tuple3(0,9,12);
206
            else if(buffertemp[13:3]  == 11'b00000001010) return tuple3(1,9,11);
207
            else if(buffertemp[13:3]  == 11'b00000001001) return tuple3(2,9,11);
208
            else if(buffertemp[13:5]  ==  9'b000000100) return tuple3(3,9,9);
209
            else if(buffertemp[13:2]  == 12'b000000001011) return tuple3(0,10,12);
210
            else if(buffertemp[13:2]  == 12'b000000001110) return tuple3(1,10,12);
211
            else if(buffertemp[13:2]  == 12'b000000001101) return tuple3(2,10,12);
212
            else if(buffertemp[13:3]  == 11'b00000001100) return tuple3(3,10,11);
213
            else if(buffertemp[13:2]  == 12'b000000001000) return tuple3(0,11,12);
214
            else if(buffertemp[13:2]  == 12'b000000001010) return tuple3(1,11,12);
215
            else if(buffertemp[13:2]  == 12'b000000001001) return tuple3(2,11,12);
216
            else if(buffertemp[13:3]  == 11'b00000001000) return tuple3(3,11,11);
217
            else if(buffertemp[13:1]  == 13'b0000000001111) return tuple3(0,12,13);
218
            else if(buffertemp[13:1]  == 13'b0000000001110) return tuple3(1,12,13);
219
            else if(buffertemp[13:1]  == 13'b0000000001101) return tuple3(2,12,13);
220
            else if(buffertemp[13:2]  == 12'b000000001100) return tuple3(3,12,12);
221
            else if(buffertemp[13:1]  == 13'b0000000001011) return tuple3(0,13,13);
222
            else if(buffertemp[13:1]  == 13'b0000000001010) return tuple3(1,13,13);
223
            else if(buffertemp[13:1]  == 13'b0000000001001) return tuple3(2,13,13);
224
            else if(buffertemp[13:1]  == 13'b0000000001100) return tuple3(3,13,13);
225
            else if(buffertemp[13:1]  == 13'b0000000000111) return tuple3(0,14,13);
226
            else if(buffertemp[13:0]  == 14'b00000000001011) return tuple3(1,14,14);
227
            else if(buffertemp[13:1]  == 13'b0000000000110) return tuple3(2,14,13);
228
            else if(buffertemp[13:1]  == 13'b0000000001000) return tuple3(3,14,13);
229
            else if(buffertemp[13:0]  == 14'b00000000001001) return tuple3(0,15,14);
230
            else if(buffertemp[13:0]  == 14'b00000000001000) return tuple3(1,15,14);
231
            else if(buffertemp[13:0]  == 14'b00000000001010) return tuple3(2,15,14);
232
            else if(buffertemp[13:1]  == 13'b0000000000001) return tuple3(3,15,13);
233
            else if(buffertemp[13:0]  == 14'b00000000000111) return tuple3(0,16,14);
234
            else if(buffertemp[13:0]  == 14'b00000000000110) return tuple3(1,16,14);
235
            else if(buffertemp[13:0]  == 14'b00000000000101) return tuple3(2,16,14);
236
            else if(buffertemp[13:0]  == 14'b00000000000100) return tuple3(3,16,14);
237
            else return tuple3(0,0,100);
238
         end
239
      else
240
         begin
241
            Bit#(16) buffertemp = inbuffer[buffersize-1:buffersize-16];
242
            if(buffertemp[15:15] ==  1'b1) return tuple3(0,0,1);
243
            else if(buffertemp[15:10] ==  6'b000101) return tuple3(0,1,6);
244
            else if(buffertemp[15:14] ==  2'b01) return tuple3(1,1,2);
245
            else if(buffertemp[15:8]  ==  8'b00000111) return tuple3(0,2,8);
246
            else if(buffertemp[15:10] ==  6'b000100) return tuple3(1,2,6);
247
            else if(buffertemp[15:13] ==  3'b001) return tuple3(2,2,3);
248
            else if(buffertemp[15:7]  ==  9'b000000111) return tuple3(0,3,9);
249
            else if(buffertemp[15:8]  ==  8'b00000110) return tuple3(1,3,8);
250
            else if(buffertemp[15:9]  ==  7'b0000101) return tuple3(2,3,7);
251
            else if(buffertemp[15:11] ==  5'b00011) return tuple3(3,3,5);
252
            else if(buffertemp[15:6]  == 10'b0000000111) return tuple3(0,4,10);
253
            else if(buffertemp[15:7]  ==  9'b000000110) return tuple3(1,4,9);
254
            else if(buffertemp[15:8]  ==  8'b00000101) return tuple3(2,4,8);
255
            else if(buffertemp[15:10] ==  6'b000011) return tuple3(3,4,6);
256
            else if(buffertemp[15:5]  == 11'b00000000111) return tuple3(0,5,11);
257
            else if(buffertemp[15:6]  == 10'b0000000110) return tuple3(1,5,10);
258
            else if(buffertemp[15:7]  ==  9'b000000101) return tuple3(2,5,9);
259
            else if(buffertemp[15:9]  ==  7'b0000100) return tuple3(3,5,7);
260
            else if(buffertemp[15:3]  == 13'b0000000001111) return tuple3(0,6,13);
261
            else if(buffertemp[15:5]  == 11'b00000000110) return tuple3(1,6,11);
262
            else if(buffertemp[15:6]  == 10'b0000000101) return tuple3(2,6,10);
263
            else if(buffertemp[15:8]  ==  8'b00000100) return tuple3(3,6,8);
264
            else if(buffertemp[15:3]  == 13'b0000000001011) return tuple3(0,7,13);
265
            else if(buffertemp[15:3]  == 13'b0000000001110) return tuple3(1,7,13);
266
            else if(buffertemp[15:5]  == 11'b00000000101) return tuple3(2,7,11);
267
            else if(buffertemp[15:7]  ==  9'b000000100) return tuple3(3,7,9);
268
            else if(buffertemp[15:3]  == 13'b0000000001000) return tuple3(0,8,13);
269
            else if(buffertemp[15:3]  == 13'b0000000001010) return tuple3(1,8,13);
270
            else if(buffertemp[15:3]  == 13'b0000000001101) return tuple3(2,8,13);
271
            else if(buffertemp[15:6]  == 10'b0000000100) return tuple3(3,8,10);
272
            else if(buffertemp[15:2]  == 14'b00000000001111) return tuple3(0,9,14);
273
            else if(buffertemp[15:2]  == 14'b00000000001110) return tuple3(1,9,14);
274
            else if(buffertemp[15:3]  == 13'b0000000001001) return tuple3(2,9,13);
275
            else if(buffertemp[15:5]  == 11'b00000000100) return tuple3(3,9,11);
276
            else if(buffertemp[15:2]  == 14'b00000000001011) return tuple3(0,10,14);
277
            else if(buffertemp[15:2]  == 14'b00000000001010) return tuple3(1,10,14);
278
            else if(buffertemp[15:2]  == 14'b00000000001101) return tuple3(2,10,14);
279
            else if(buffertemp[15:3]  == 13'b0000000001100) return tuple3(3,10,13);
280
            else if(buffertemp[15:1]  == 15'b000000000001111) return tuple3(0,11,15);
281
            else if(buffertemp[15:1]  == 15'b000000000001110) return tuple3(1,11,15);
282
            else if(buffertemp[15:2]  == 14'b00000000001001) return tuple3(2,11,14);
283
            else if(buffertemp[15:2]  == 14'b00000000001100) return tuple3(3,11,14);
284
            else if(buffertemp[15:1]  == 15'b000000000001011) return tuple3(0,12,15);
285
            else if(buffertemp[15:1]  == 15'b000000000001010) return tuple3(1,12,15);
286
            else if(buffertemp[15:1]  == 15'b000000000001101) return tuple3(2,12,15);
287
            else if(buffertemp[15:2]  == 14'b00000000001000) return tuple3(3,12,14);
288
            else if(buffertemp[15:0]  == 16'b0000000000001111) return tuple3(0,13,16);
289
            else if(buffertemp[15:1]  == 15'b000000000000001) return tuple3(1,13,15);
290
            else if(buffertemp[15:1]  == 15'b000000000001001) return tuple3(2,13,15);
291
            else if(buffertemp[15:1]  == 15'b000000000001100) return tuple3(3,13,15);
292
            else if(buffertemp[15:0]  == 16'b0000000000001011) return tuple3(0,14,16);
293
            else if(buffertemp[15:0]  == 16'b0000000000001110) return tuple3(1,14,16);
294
            else if(buffertemp[15:0]  == 16'b0000000000001101) return tuple3(2,14,16);
295
            else if(buffertemp[15:1]  == 15'b000000000001000) return tuple3(3,14,15);
296
            else if(buffertemp[15:0]  == 16'b0000000000000111) return tuple3(0,15,16);
297
            else if(buffertemp[15:0]  == 16'b0000000000001010) return tuple3(1,15,16);
298
            else if(buffertemp[15:0]  == 16'b0000000000001001) return tuple3(2,15,16);
299
            else if(buffertemp[15:0]  == 16'b0000000000001100) return tuple3(3,15,16);
300
            else if(buffertemp[15:0]  == 16'b0000000000000100) return tuple3(0,16,16);
301
            else if(buffertemp[15:0]  == 16'b0000000000000110) return tuple3(1,16,16);
302
            else if(buffertemp[15:0]  == 16'b0000000000000101) return tuple3(2,16,16);
303
            else if(buffertemp[15:0]  == 16'b0000000000001000) return tuple3(3,16,16);
304
            else return tuple3(0,0,100);
305
         end
306
   endfunction
307
 
308
   (* noinline *)
309
   function Bit#(4) cavlc_level_prefix( Buffer inbuffer );
310
      Bit#(4) tempout = 15;
311
      for(Integer ii=15; ii>0; ii=ii-1)
312
         begin
313
            if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
314
               tempout = fromInteger(ii)-1;
315
         end
316
      return tempout;
317
   endfunction
318
 
319
   (* noinline *)
320
   function Tuple2#(Bit#(4),Bufcount) cavlc_total_zeros( Buffer inbuffer, Bit#(4) inTotalCoeff, Bit#(5) inMaxNumCoeff);
321
      if(inMaxNumCoeff==4)
322
         begin
323
            Bit#(3) buffertemp3 = inbuffer[buffersize-1:buffersize-3];
324
            Bit#(2) buffertemp2 = inbuffer[buffersize-1:buffersize-2];
325
            case ( inTotalCoeff )
326
               1:
327
               begin
328
                  if(inbuffer[buffersize-1] == 1)
329
                     return tuple2(0,1);
330
                  else if(buffertemp2 == 2'b01)
331
                     return tuple2(1,2);
332
                  else if(buffertemp3 == 3'b001)
333
                     return tuple2(2,3);
334
                  else
335
                     return tuple2(3,3);
336
               end
337
               2:
338
               begin
339
                  if(inbuffer[buffersize-1] == 1)
340
                     return tuple2(0,1);
341
                  else if(buffertemp2 == 2'b01)
342
                     return tuple2(1,2);
343
                  else
344
                     return tuple2(2,2);
345
               end
346
               3:
347
               begin
348
                  if(inbuffer[buffersize-1] == 1)
349
                     return tuple2(0,1);
350
                  else
351
                     return tuple2(1,1);
352
               end
353
               default: return tuple2(0,100);
354
            endcase
355
         end
356
      else
357
         begin
358
            Bit#(6) buffertemp = inbuffer[buffersize-1:buffersize-6];
359
            case ( inTotalCoeff )
360
               1:
361
               begin
362
                  Bit#(10) buffertemp2 = inbuffer[buffersize-1:buffersize-10];
363
                  if(buffertemp2[9:9]  ==  1'b1) return tuple2(0,1);
364
                  else if(buffertemp2[9:7]  ==  3'b011) return tuple2(1,3);
365
                  else if(buffertemp2[9:7]  ==  3'b010) return tuple2(2,3);
366
                  else if(buffertemp2[9:6]  ==  4'b0011) return tuple2(3,4);
367
                  else if(buffertemp2[9:6]  ==  4'b0010) return tuple2(4,4);
368
                  else if(buffertemp2[9:5]  ==  5'b00011) return tuple2(5,5);
369
                  else if(buffertemp2[9:5]  ==  5'b00010) return tuple2(6,5);
370
                  else if(buffertemp2[9:4]  ==  6'b000011) return tuple2(7,6);
371
                  else if(buffertemp2[9:4]  ==  6'b000010) return tuple2(8,6);
372
                  else if(buffertemp2[9:3]  ==  7'b0000011) return tuple2(9,7);
373
                  else if(buffertemp2[9:3]  ==  7'b0000010) return tuple2(10,7);
374
                  else if(buffertemp2[9:2]  ==  8'b00000011) return tuple2(11,8);
375
                  else if(buffertemp2[9:2]  ==  8'b00000010) return tuple2(12,8);
376
                  else if(buffertemp2[9:1]  ==  9'b000000011) return tuple2(13,9);
377
                  else if(buffertemp2[9:1]  ==  9'b000000010) return tuple2(14,9);
378
                  else return tuple2(15,9);
379
               end
380
               2:
381
               begin
382
                  if(buffertemp[5:3]  ==  3'b111) return tuple2(0,3);
383
                  else if(buffertemp[5:3]  ==  3'b110) return tuple2(1,3);
384
                  else if(buffertemp[5:3]  ==  3'b101) return tuple2(2,3);
385
                  else if(buffertemp[5:3]  ==  3'b100) return tuple2(3,3);
386
                  else if(buffertemp[5:3]  ==  3'b011) return tuple2(4,3);
387
                  else if(buffertemp[5:2]  ==  4'b0101) return tuple2(5,4);
388
                  else if(buffertemp[5:2]  ==  4'b0100) return tuple2(6,4);
389
                  else if(buffertemp[5:2]  ==  4'b0011) return tuple2(7,4);
390
                  else if(buffertemp[5:2]  ==  4'b0010) return tuple2(8,4);
391
                  else if(buffertemp[5:1]  ==  5'b00011) return tuple2(9,5);
392
                  else if(buffertemp[5:1]  ==  5'b00010) return tuple2(10,5);
393
                  else if(buffertemp[5:0]  ==  6'b000011) return tuple2(11,6);
394
                  else if(buffertemp[5:0]  ==  6'b000010) return tuple2(12,6);
395
                  else if(buffertemp[5:0]  ==  6'b000001) return tuple2(13,6);
396
                  else return tuple2(14,6);
397
               end
398
               3:
399
               begin
400
                  if(buffertemp[5:2]  ==  4'b0101) return tuple2(0,4);
401
                  else if(buffertemp[5:3]  ==  3'b111) return tuple2(1,3);
402
                  else if(buffertemp[5:3]  ==  3'b110) return tuple2(2,3);
403
                  else if(buffertemp[5:3]  ==  3'b101) return tuple2(3,3);
404
                  else if(buffertemp[5:2]  ==  4'b0100) return tuple2(4,4);
405
                  else if(buffertemp[5:2]  ==  4'b0011) return tuple2(5,4);
406
                  else if(buffertemp[5:3]  ==  3'b100) return tuple2(6,3);
407
                  else if(buffertemp[5:3]  ==  3'b011) return tuple2(7,3);
408
                  else if(buffertemp[5:2]  ==  4'b0010) return tuple2(8,4);
409
                  else if(buffertemp[5:1]  ==  5'b00011) return tuple2(9,5);
410
                  else if(buffertemp[5:1]  ==  5'b00010) return tuple2(10,5);
411
                  else if(buffertemp[5:0]  ==  6'b000001) return tuple2(11,6);
412
                  else if(buffertemp[5:1]  ==  5'b00001) return tuple2(12,5);
413
                  else return tuple2(13,6);
414
               end
415
               4:
416
               begin
417
                  if(buffertemp[5:1]  ==  5'b00011) return tuple2(0,5);
418
                  else if(buffertemp[5:3]  ==  3'b111) return tuple2(1,3);
419
                  else if(buffertemp[5:2]  ==  4'b0101) return tuple2(2,4);
420
                  else if(buffertemp[5:2]  ==  4'b0100) return tuple2(3,4);
421
                  else if(buffertemp[5:3]  ==  3'b110) return tuple2(4,3);
422
                  else if(buffertemp[5:3]  ==  3'b101) return tuple2(5,3);
423
                  else if(buffertemp[5:3]  ==  3'b100) return tuple2(6,3);
424
                  else if(buffertemp[5:2]  ==  4'b0011) return tuple2(7,4);
425
                  else if(buffertemp[5:3]  ==  3'b011) return tuple2(8,3);
426
                  else if(buffertemp[5:2]  ==  4'b0010) return tuple2(9,4);
427
                  else if(buffertemp[5:1]  ==  5'b00010) return tuple2(10,5);
428
                  else if(buffertemp[5:1]  ==  5'b00001) return tuple2(11,5);
429
                  else return tuple2(12,5);
430
               end
431
               5:
432
               begin
433
                  if(buffertemp[5:2]  ==  4'b0101) return tuple2(0,4);
434
                  else if(buffertemp[5:2]  ==  4'b0100) return tuple2(1,4);
435
                  else if(buffertemp[5:2]  ==  4'b0011) return tuple2(2,4);
436
                  else if(buffertemp[5:3]  ==  3'b111) return tuple2(3,3);
437
                  else if(buffertemp[5:3]  ==  3'b110) return tuple2(4,3);
438
                  else if(buffertemp[5:3]  ==  3'b101) return tuple2(5,3);
439
                  else if(buffertemp[5:3]  ==  3'b100) return tuple2(6,3);
440
                  else if(buffertemp[5:3]  ==  3'b011) return tuple2(7,3);
441
                  else if(buffertemp[5:2]  ==  4'b0010) return tuple2(8,4);
442
                  else if(buffertemp[5:1]  ==  5'b00001) return tuple2(9,5);
443
                  else if(buffertemp[5:2]  ==  4'b0001) return tuple2(10,4);
444
                  else return tuple2(11,5);
445
               end
446
               6:
447
               begin
448
                  if(buffertemp[5:0]  ==  6'b000001) return tuple2(0,6);
449
                  else if(buffertemp[5:1]  ==  5'b00001) return tuple2(1,5);
450
                  else if(buffertemp[5:3]  ==  3'b111) return tuple2(2,3);
451
                  else if(buffertemp[5:3]  ==  3'b110) return tuple2(3,3);
452
                  else if(buffertemp[5:3]  ==  3'b101) return tuple2(4,3);
453
                  else if(buffertemp[5:3]  ==  3'b100) return tuple2(5,3);
454
                  else if(buffertemp[5:3]  ==  3'b011) return tuple2(6,3);
455
                  else if(buffertemp[5:3]  ==  3'b010) return tuple2(7,3);
456
                  else if(buffertemp[5:2]  ==  4'b0001) return tuple2(8,4);
457
                  else if(buffertemp[5:3]  ==  3'b001) return tuple2(9,3);
458
                  else return tuple2(10,6);
459
               end
460
               7:
461
               begin
462
                  if(buffertemp[5:0]  ==  6'b000001) return tuple2(0,6);
463
                  else if(buffertemp[5:1]  ==  5'b00001) return tuple2(1,5);
464
                  else if(buffertemp[5:3]  ==  3'b101) return tuple2(2,3);
465
                  else if(buffertemp[5:3]  ==  3'b100) return tuple2(3,3);
466
                  else if(buffertemp[5:3]  ==  3'b011) return tuple2(4,3);
467
                  else if(buffertemp[5:4]  ==  2'b11) return tuple2(5,2);
468
                  else if(buffertemp[5:3]  ==  3'b010) return tuple2(6,3);
469
                  else if(buffertemp[5:2]  ==  4'b0001) return tuple2(7,4);
470
                  else if(buffertemp[5:3]  ==  3'b001) return tuple2(8,3);
471
                  else return tuple2(9,6);
472
               end
473
               8:
474
               begin
475
                  if(buffertemp[5:0]  ==  6'b000001) return tuple2(0,6);
476
                  else if(buffertemp[5:2]  ==  4'b0001) return tuple2(1,4);
477
                  else if(buffertemp[5:1]  ==  5'b00001) return tuple2(2,5);
478
                  else if(buffertemp[5:3]  ==  3'b011) return tuple2(3,3);
479
                  else if(buffertemp[5:4]  ==  2'b11) return tuple2(4,2);
480
                  else if(buffertemp[5:4]  ==  2'b10) return tuple2(5,2);
481
                  else if(buffertemp[5:3]  ==  3'b010) return tuple2(6,3);
482
                  else if(buffertemp[5:3]  ==  3'b001) return tuple2(7,3);
483
                  else return tuple2(8,6);
484
               end
485
               9:
486
               begin
487
                  if(buffertemp[5:0]  ==  6'b000001) return tuple2(0,6);
488
                  else if(buffertemp[5:0]  ==  6'b000000) return tuple2(1,6);
489
                  else if(buffertemp[5:2]  ==  4'b0001) return tuple2(2,4);
490
                  else if(buffertemp[5:4]  ==  2'b11) return tuple2(3,2);
491
                  else if(buffertemp[5:4]  ==  2'b10) return tuple2(4,2);
492
                  else if(buffertemp[5:3]  ==  3'b001) return tuple2(5,3);
493
                  else if(buffertemp[5:4]  ==  2'b01) return tuple2(6,2);
494
                  else return tuple2(7,5);
495
               end
496
               10:
497
               begin
498
                  if(buffertemp[5:1]  ==  5'b00001) return tuple2(0,5);
499
                  else if(buffertemp[5:1]  ==  5'b00000) return tuple2(1,5);
500
                  else if(buffertemp[5:3]  ==  3'b001) return tuple2(2,3);
501
                  else if(buffertemp[5:4]  ==  2'b11) return tuple2(3,2);
502
                  else if(buffertemp[5:4]  ==  2'b10) return tuple2(4,2);
503
                  else if(buffertemp[5:4]  ==  2'b01) return tuple2(5,2);
504
                  else return tuple2(6,4);
505
               end
506
               11:
507
               begin
508
                  if(buffertemp[5:2]  ==  4'b0000) return tuple2(0,4);
509
                  else if(buffertemp[5:2]  ==  4'b0001) return tuple2(1,4);
510
                  else if(buffertemp[5:3]  ==  3'b001) return tuple2(2,3);
511
                  else if(buffertemp[5:3]  ==  3'b010) return tuple2(3,3);
512
                  else if(buffertemp[5:5]  ==  1'b1) return tuple2(4,1);
513
                  else return tuple2(5,3);
514
               end
515
               12:
516
               begin
517
                  if(buffertemp[5:2]  ==  4'b0000) return tuple2(0,4);
518
                  else if(buffertemp[5:2]  ==  4'b0001) return tuple2(1,4);
519
                  else if(buffertemp[5:4]  ==  2'b01) return tuple2(2,2);
520
                  else if(buffertemp[5:5]  ==  1'b1) return tuple2(3,1);
521
                  else return tuple2(4,3);
522
               end
523
               13:
524
               begin
525
                  if(buffertemp[5:3]  ==  3'b000) return tuple2(0,3);
526
                  else if(buffertemp[5:3]  ==  3'b001) return tuple2(1,3);
527
                  else if(buffertemp[5:5]  ==  1'b1) return tuple2(2,1);
528
                  else return tuple2(3,2);
529
               end
530
               14:
531
               begin
532
                  if(buffertemp[5:4]  ==  2'b00) return tuple2(0,2);
533
                  else if(buffertemp[5:4]  ==  2'b01) return tuple2(1,2);
534
                  else return tuple2(2,1);
535
               end
536
               15:
537
               begin
538
                  if(buffertemp[5:5]  ==  1'b0) return tuple2(0,1);
539
                  else return tuple2(1,1);
540
               end
541
               default: return tuple2(0,100);
542
            endcase
543
         end
544
   endfunction
545
 
546
   (* noinline *)
547
   function Tuple2#(Bit#(4),Bufcount) cavlc_run_before( Buffer inbuffer, Bit#(4) inZerosLeft);
548
      Bit#(3) buffertemp3 = inbuffer[buffersize-1:buffersize-3];
549
      Bit#(2) buffertemp2 = inbuffer[buffersize-1:buffersize-2];
550
      case ( inZerosLeft )
551
         0: return tuple2(0,100);
552
         1:
553
         begin
554
            if(inbuffer[buffersize-1] == 1)
555
               return tuple2(0,1);
556
            else
557
               return tuple2(1,1);
558
         end
559
         2:
560
         begin
561
            if(inbuffer[buffersize-1] == 1)
562
               return tuple2(0,1);
563
            else if(buffertemp2 == 2'b01)
564
               return tuple2(1,2);
565
            else
566
               return tuple2(2,2);
567
         end
568
         3:
569
         begin
570
            if(buffertemp2 == 2'b11)
571
               return tuple2(0,2);
572
            else if(buffertemp2 == 2'b10)
573
               return tuple2(1,2);
574
            else if(buffertemp2 == 2'b01)
575
               return tuple2(2,2);
576
            else
577
               return tuple2(3,2);
578
         end
579
         4:
580
         begin
581
            if(buffertemp2 == 2'b11)
582
               return tuple2(0,2);
583
            else if(buffertemp2 == 2'b10)
584
               return tuple2(1,2);
585
            else if(buffertemp2 == 2'b01)
586
               return tuple2(2,2);
587
            else if(buffertemp3 == 3'b001)
588
               return tuple2(3,3);
589
            else
590
               return tuple2(4,3);
591
         end
592
         5:
593
         begin
594
            if(buffertemp2 == 2'b11)
595
               return tuple2(0,2);
596
            else if(buffertemp2 == 2'b10)
597
               return tuple2(1,2);
598
            else if(buffertemp3 == 3'b011)
599
               return tuple2(2,3);
600
            else if(buffertemp3 == 3'b010)
601
               return tuple2(3,3);
602
            else if(buffertemp3 == 3'b001)
603
               return tuple2(4,3);
604
            else
605
               return tuple2(5,3);
606
         end
607
         6:
608
         begin
609
            if(buffertemp2 == 2'b11)
610
               return tuple2(0,2);
611
            else if(buffertemp3 == 3'b000)
612
               return tuple2(1,3);
613
            else if(buffertemp3 == 3'b001)
614
               return tuple2(2,3);
615
            else if(buffertemp3 == 3'b011)
616
               return tuple2(3,3);
617
            else if(buffertemp3 == 3'b010)
618
               return tuple2(4,3);
619
            else if(buffertemp3 == 3'b101)
620
               return tuple2(5,3);
621
            else
622
               return tuple2(6,3);
623
         end
624
         default:
625
         begin
626
            if(buffertemp3 != 3'b000)
627
               begin
628
                  Bit#(4) outputtemp = zeroExtend(3'b111 - buffertemp3);
629
                  return tuple2(outputtemp,3);
630
               end
631
            else
632
               begin
633
                  Bit#(4) returnVal1 = 14;
634
                  Bufcount returnVal2 = 11;
635
                  for(Integer ii=10; ii>=4; ii=ii-1)
636
                     begin
637
                        if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
638
                           begin
639
                              returnVal1 = fromInteger(ii)+3;
640
                              returnVal2 = fromInteger(ii);
641
                           end
642
                     end
643
                  return tuple2(returnVal1,returnVal2);
644
               end
645
         end
646
      endcase
647
   endfunction
648
 
649
 
650
 
651
endpackage

powered by: WebSVN 2.1.0

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