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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src/] [CAVLC.bsv] - Blame information for rev 101

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

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

powered by: WebSVN 2.1.0

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