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 27

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

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

powered by: WebSVN 2.1.0

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