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

Subversion Repositories bluespec-h264

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 85 jamey.hick
// The MIT License
2
 
3
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
4
 
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
 
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
14
 
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
// THE SOFTWARE.
22 84 jamey.hick
//**********************************************************************
23
// Exp-Golomb codes
24
//----------------------------------------------------------------------
25
//
26
//
27
//
28
 
29
package ExpGolomb;
30
 
31
import H264Types::*;
32
 
33
 
34
 
35
   //-----------------------------------------------------------
36
   // Helper functions
37
   (* noinline *)
38
   function Bufcount expgolomb_numbits32( Buffer inbuffer );//number of bits consumed by exp-golomb code
39
      Bufcount tempout = 100;
40
      for(Integer ii=33; ii>0; ii=ii-1)
41
         begin
42
            if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
43
               tempout = fromInteger(ii);
44
         end
45
      return tempout;
46
   endfunction
47
 
48
   (* noinline *)
49
   function Bit#(33) expgolomb_codenum32( Buffer inbuffer, Bufcount egnumbits );//exp-golomb codenum calculation
50
      Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33];
51
      Bufcount shiftamount = 33-egnumbits;
52
      return (tempbuffer >> zeroExtend(shiftamount))-1;
53
   endfunction
54
 
55
   (* noinline *)
56
   function Bit#(32) expgolomb_unsigned32( Buffer inbuffer, Bufcount egnumbits );//unsigned exp-golomb code calculation
57
      Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
58
      return truncate(codenum);
59
   endfunction
60
 
61
   (* noinline *)
62
   function Bit#(32) expgolomb_signed32( Buffer inbuffer, Bufcount egnumbits );//signed exp-golomb code calculation
63
      Bit#(33) codenum = expgolomb_codenum32( inbuffer, egnumbits );
64
      Bit#(33) tempout = (codenum+1) >> 1;
65
      Bit#(33) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
66
      return truncate(tempout2);
67
   endfunction
68
 
69
 
70
 
71
   (* noinline *)
72
   function Bufcount expgolomb_numbits( Buffer inbuffer );//number of bits consumed by exp-golomb code
73
      Bufcount tempout = 100;
74
      for(Integer ii=17; ii>0; ii=ii-1)
75
         begin
76
            if(inbuffer[buffersize-fromInteger(ii)]==1'b1)
77
               tempout = (fromInteger(ii)*2)-1;
78
         end
79
      return tempout;
80
   endfunction
81
 
82
   (* noinline *)
83
   function Bit#(17) expgolomb_codenum( Buffer inbuffer );//exp-golomb codenum calculation
84
      Bufcount egnumbits = expgolomb_numbits( inbuffer ) >> 1;
85
      Bit#(33) tempbuffer = inbuffer[buffersize-1:buffersize-33] << zeroExtend(egnumbits);
86
      Bit#(17) tempout = tempbuffer[32:16];
87
      Bufcount shiftamount = 17-egnumbits-1;
88
      return (tempout >> zeroExtend(shiftamount))-1;
89
   endfunction
90
 
91
   (* noinline *)
92
   function Bit#(16) expgolomb_unsigned( Buffer inbuffer );//unsigned exp-golomb code calculation
93
      Bit#(17) codenum = expgolomb_codenum( inbuffer );
94
      return truncate(codenum);
95
   endfunction
96
 
97
   (* noinline *)
98
   function Bit#(16) expgolomb_signed( Buffer inbuffer );//signed exp-golomb code calculation
99
      Bit#(17) codenum = expgolomb_codenum( inbuffer );
100
      Bit#(17) tempout = (codenum+1) >> 1;
101
      Bit#(17) tempout2 = (codenum[0]==1 ? tempout : (~tempout)+1 );
102
      return truncate(tempout2);
103
   endfunction
104
 
105
   (* noinline *)
106
   function Bit#(6) expgolomb_coded_block_pattern( Buffer inbuffer, MbType mbtype );//unsigned exp-golomb code calculation
107
      Bit#(6) codenum = truncate(expgolomb_codenum( inbuffer ));
108
      if(mbPartPredMode(mbtype,0) == Intra_4x4)
109
         begin
110
            case(codenum)
111
               0: return 47;
112
               1: return 31;
113
               2: return 15;
114
               3: return 0;
115
               4: return 23;
116
               5: return 27;
117
               6: return 29;
118
               7: return 30;
119
               8: return 7;
120
               9: return 11;
121
               10: return 13;
122
               11: return 14;
123
               12: return 39;
124
               13: return 43;
125
               14: return 45;
126
               15: return 46;
127
               16: return 16;
128
               17: return 3;
129
               18: return 5;
130
               19: return 10;
131
               20: return 12;
132
               21: return 19;
133
               22: return 21;
134
               23: return 26;
135
               24: return 28;
136
               25: return 35;
137
               26: return 37;
138
               27: return 42;
139
               28: return 44;
140
               29: return 1;
141
               30: return 2;
142
               31: return 4;
143
               32: return 8;
144
               33: return 17;
145
               34: return 18;
146
               35: return 20;
147
               36: return 24;
148
               37: return 6;
149
               38: return 9;
150
               39: return 22;
151
               40: return 25;
152
               41: return 32;
153
               42: return 33;
154
               43: return 34;
155
               44: return 36;
156
               45: return 40;
157
               46: return 38;
158
               47: return 41;
159
            endcase
160
         end
161
      else
162
         begin
163
            case(codenum)
164
               0: return 0;
165
               1: return 16;
166
               2: return 1;
167
               3: return 2;
168
               4: return 4;
169
               5: return 8;
170
               6: return 32;
171
               7: return 3;
172
               8: return 5;
173
               9: return 10;
174
               10: return 12;
175
               11: return 15;
176
               12: return 47;
177
               13: return 7;
178
               14: return 11;
179
               15: return 13;
180
               16: return 14;
181
               17: return 6;
182
               18: return 9;
183
               19: return 31;
184
               20: return 35;
185
               21: return 37;
186
               22: return 42;
187
               23: return 44;
188
               24: return 33;
189
               25: return 34;
190
               26: return 36;
191
               27: return 40;
192
               28: return 39;
193
               29: return 43;
194
               30: return 45;
195
               31: return 46;
196
               32: return 17;
197
               33: return 18;
198
               34: return 20;
199
               35: return 24;
200
               36: return 19;
201
               37: return 21;
202
               38: return 26;
203
               39: return 28;
204
               40: return 23;
205
               41: return 27;
206
               42: return 29;
207
               43: return 30;
208
               44: return 22;
209
               45: return 25;
210
               46: return 38;
211
               47: return 41;
212
            endcase
213
         end
214
   endfunction
215
 
216
 
217
 
218
endpackage

powered by: WebSVN 2.1.0

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