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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src/] [ExpGolomb.bsv] - Blame information for rev 100

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
// Exp-Golomb codes
26
//----------------------------------------------------------------------
27 27 jamey.hick
//
28 2 jamey.hick
//
29
//
30
 
31
package ExpGolomb;
32
 
33
import H264Types::*;
34
 
35
 
36
 
37
   //-----------------------------------------------------------
38
   // Helper functions
39
   (* noinline *)
40
   function Bufcount expgolomb_numbits32( Buffer inbuffer );//number of bits consumed by exp-golomb code
41
      Bufcount tempout = 100;
42
      for(Integer ii=33; ii>0; ii=ii-1)
43
         begin
44
            if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
45
               tempout = fromInteger(ii);
46
         end
47
      return tempout;
48
   endfunction
49
 
50
   (* noinline *)
51
   function Bit#(33) expgolomb_codenum32( Buffer inbuffer, Bufcount egnumbits );//exp-golomb codenum calculation
52
      Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33];
53
      Bufcount shiftamount = 33-egnumbits;
54
      return (tempbuffer >> zeroExtend(shiftamount))-1;
55
   endfunction
56
 
57
   (* noinline *)
58
   function Bit#(32) expgolomb_unsigned32( Buffer inbuffer, Bufcount egnumbits );//unsigned exp-golomb code calculation
59
      Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
60
      return truncate(codenum);
61
   endfunction
62
 
63
   (* noinline *)
64
   function Bit#(32) expgolomb_signed32( Buffer inbuffer, Bufcount egnumbits );//signed exp-golomb code calculation
65
      Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
66
      Bit#(33) tempout = (codenum+1) >> 1;
67
      Bit#(33) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
68
      return truncate(tempout2);
69
   endfunction
70
 
71
 
72
 
73
   (* noinline *)
74
   function Bufcount expgolomb_numbits( Buffer inbuffer );//number of bits consumed by exp-golomb code
75
      Bufcount tempout = 100;
76
      for(Integer ii=17; ii>0; ii=ii-1)
77
         begin
78
            if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
79
               tempout = (fromInteger(ii)*2)-1;
80
         end
81
      return tempout;
82
   endfunction
83
 
84
   (* noinline *)
85
   function Bit#(17) expgolomb_codenum( Buffer inbuffer );//exp-golomb codenum calculation
86
      Bufcount egnumbits = expgolomb_numbits( inbuffer ) >> 1;
87
      Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33] << zeroExtend(egnumbits);
88
      Bit#(17) tempout = tempbuffer[32:16];
89
      Bufcount shiftamount = 17-egnumbits-1;
90
      return (tempout >> zeroExtend(shiftamount))-1;
91
   endfunction
92
 
93
   (* noinline *)
94
   function Bit#(16) expgolomb_unsigned( Buffer inbuffer );//unsigned exp-golomb code calculation
95
      Bit#(17) codenum = expgolomb_codenum( inbuffer );
96
      return truncate(codenum);
97
   endfunction
98
 
99
   (* noinline *)
100
   function Bit#(16) expgolomb_signed( Buffer inbuffer );//signed exp-golomb code calculation
101
      Bit#(17) codenum = expgolomb_codenum( inbuffer );
102
      Bit#(17) tempout = (codenum+1) >> 1;
103
      Bit#(17) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
104
      return truncate(tempout2);
105
   endfunction
106
 
107
   (* noinline *)
108
   function Bit#(6) expgolomb_coded_block_pattern( Buffer inbuffer, MbType mbtype );//unsigned exp-golomb code calculation
109
      Bit#(6) codenum = truncate(expgolomb_codenum( inbuffer ));
110
      if(mbPartPredMode(mbtype,0) == Intra_4x4)
111
         begin
112
            case(codenum)
113
               0: return 47;
114
               1: return 31;
115
               2: return 15;
116
               3: return 0;
117
               4: return 23;
118
               5: return 27;
119
               6: return 29;
120
               7: return 30;
121
               8: return 7;
122
               9: return 11;
123
               10: return 13;
124
               11: return 14;
125
               12: return 39;
126
               13: return 43;
127
               14: return 45;
128
               15: return 46;
129
               16: return 16;
130
               17: return 3;
131
               18: return 5;
132
               19: return 10;
133
               20: return 12;
134
               21: return 19;
135
               22: return 21;
136
               23: return 26;
137
               24: return 28;
138
               25: return 35;
139
               26: return 37;
140
               27: return 42;
141
               28: return 44;
142
               29: return 1;
143
               30: return 2;
144
               31: return 4;
145
               32: return 8;
146
               33: return 17;
147
               34: return 18;
148
               35: return 20;
149
               36: return 24;
150
               37: return 6;
151
               38: return 9;
152
               39: return 22;
153
               40: return 25;
154
               41: return 32;
155
               42: return 33;
156
               43: return 34;
157
               44: return 36;
158
               45: return 40;
159
               46: return 38;
160
               47: return 41;
161
            endcase
162
         end
163
      else
164
         begin
165
            case(codenum)
166
               0: return 0;
167
               1: return 16;
168
               2: return 1;
169
               3: return 2;
170
               4: return 4;
171
               5: return 8;
172
               6: return 32;
173
               7: return 3;
174
               8: return 5;
175
               9: return 10;
176
               10: return 12;
177
               11: return 15;
178
               12: return 47;
179
               13: return 7;
180
               14: return 11;
181
               15: return 13;
182
               16: return 14;
183
               17: return 6;
184
               18: return 9;
185
               19: return 31;
186
               20: return 35;
187
               21: return 37;
188
               22: return 42;
189
               23: return 44;
190
               24: return 33;
191
               25: return 34;
192
               26: return 36;
193
               27: return 40;
194
               28: return 39;
195
               29: return 43;
196
               30: return 45;
197
               31: return 46;
198
               32: return 17;
199
               33: return 18;
200
               34: return 20;
201
               35: return 24;
202
               36: return 19;
203
               37: return 21;
204
               38: return 26;
205
               39: return 28;
206
               40: return 23;
207
               41: return 27;
208
               42: return 29;
209
               43: return 30;
210
               44: return 22;
211
               45: return 25;
212
               46: return 38;
213
               47: return 41;
214
            endcase
215
         end
216
   endfunction
217
 
218
 
219
 
220
endpackage

powered by: WebSVN 2.1.0

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