Mercurial > libavcodec.hg
annotate cabac.h @ 3960:d075bbfca527 libavcodec
Fixes:
parser.c:555: warning: implicit declaration of function ff_cavs_find_frame_end
Approved by Michael.
author | rathann |
---|---|
date | Sun, 08 Oct 2006 21:23:57 +0000 |
parents | 0910f2844f9a |
children | 2acfc35c3075 |
rev | line source |
---|---|
1287 | 1 /* |
2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder | |
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
4 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3946
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3946
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3946
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
1287 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3946
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
1287 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3946
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
1287 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3946
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1287 | 20 * |
21 */ | |
2967 | 22 |
1287 | 23 /** |
24 * @file cabac.h | |
25 * Context Adaptive Binary Arithmetic Coder. | |
26 */ | |
27 | |
28 | |
3284
a224d9752912
don't force asserts in release builds. 2% faster h264.
lorenm
parents:
3036
diff
changeset
|
29 //#undef NDEBUG |
1287 | 30 #include <assert.h> |
31 | |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
32 #define CABAC_BITS 16 |
2323 | 33 #define CABAC_MASK ((1<<CABAC_BITS)-1) |
34 | |
1287 | 35 typedef struct CABACContext{ |
36 int low; | |
37 int range; | |
38 int outstanding_count; | |
39 #ifdef STRICT_LIMITS | |
40 int symCount; | |
41 #endif | |
3955 | 42 uint8_t lps_range[2*66][4]; ///< rangeTabLPS |
43 uint8_t lps_state[2*65]; ///< transIdxLPS | |
44 uint8_t mps_state[2*65]; ///< transIdxMPS | |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
1787
diff
changeset
|
45 const uint8_t *bytestream_start; |
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
1787
diff
changeset
|
46 const uint8_t *bytestream; |
2116 | 47 const uint8_t *bytestream_end; |
1287 | 48 PutBitContext pb; |
49 }CABACContext; | |
50 | |
1301 | 51 extern const uint8_t ff_h264_lps_range[64][4]; |
52 extern const uint8_t ff_h264_mps_state[64]; | |
53 extern const uint8_t ff_h264_lps_state[64]; | |
2323 | 54 extern const uint8_t ff_h264_norm_shift[256]; |
55 | |
1287 | 56 |
57 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size); | |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
1787
diff
changeset
|
58 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); |
2967 | 59 void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4], |
1287 | 60 uint8_t const *mps_state, uint8_t const *lps_state, int state_count); |
61 | |
62 | |
63 static inline void put_cabac_bit(CABACContext *c, int b){ | |
2967 | 64 put_bits(&c->pb, 1, b); |
65 for(;c->outstanding_count; c->outstanding_count--){ | |
1287 | 66 put_bits(&c->pb, 1, 1-b); |
67 } | |
68 } | |
69 | |
70 static inline void renorm_cabac_encoder(CABACContext *c){ | |
71 while(c->range < 0x100){ | |
72 //FIXME optimize | |
73 if(c->low<0x100){ | |
74 put_cabac_bit(c, 0); | |
75 }else if(c->low<0x200){ | |
76 c->outstanding_count++; | |
77 c->low -= 0x100; | |
78 }else{ | |
79 put_cabac_bit(c, 1); | |
80 c->low -= 0x200; | |
81 } | |
2967 | 82 |
1287 | 83 c->range+= c->range; |
84 c->low += c->low; | |
85 } | |
86 } | |
87 | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
88 static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ |
2323 | 89 int RangeLPS= c->lps_range[*state][c->range>>6]; |
2967 | 90 |
1287 | 91 if(bit == ((*state)&1)){ |
92 c->range -= RangeLPS; | |
93 *state= c->mps_state[*state]; | |
94 }else{ | |
95 c->low += c->range - RangeLPS; | |
96 c->range = RangeLPS; | |
97 *state= c->lps_state[*state]; | |
98 } | |
2967 | 99 |
1287 | 100 renorm_cabac_encoder(c); |
101 | |
102 #ifdef STRICT_LIMITS | |
103 c->symCount++; | |
104 #endif | |
105 } | |
106 | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
107 static void put_cabac_static(CABACContext *c, int RangeLPS, int bit){ |
1287 | 108 assert(c->range > RangeLPS); |
109 | |
110 if(!bit){ | |
111 c->range -= RangeLPS; | |
112 }else{ | |
113 c->low += c->range - RangeLPS; | |
114 c->range = RangeLPS; | |
115 } | |
116 | |
117 renorm_cabac_encoder(c); | |
118 | |
119 #ifdef STRICT_LIMITS | |
120 c->symCount++; | |
121 #endif | |
122 } | |
123 | |
1290 | 124 /** |
125 * @param bit 0 -> write zero bit, !=0 write one bit | |
126 */ | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
127 static void put_cabac_bypass(CABACContext *c, int bit){ |
1287 | 128 c->low += c->low; |
129 | |
130 if(bit){ | |
131 c->low += c->range; | |
132 } | |
133 //FIXME optimize | |
134 if(c->low<0x200){ | |
135 put_cabac_bit(c, 0); | |
136 }else if(c->low<0x400){ | |
137 c->outstanding_count++; | |
138 c->low -= 0x200; | |
139 }else{ | |
140 put_cabac_bit(c, 1); | |
141 c->low -= 0x400; | |
142 } | |
2967 | 143 |
1287 | 144 #ifdef STRICT_LIMITS |
145 c->symCount++; | |
146 #endif | |
147 } | |
148 | |
1300
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
149 /** |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
150 * |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
151 * @return the number of bytes written |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
152 */ |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
153 static int put_cabac_terminate(CABACContext *c, int bit){ |
1287 | 154 c->range -= 2; |
155 | |
156 if(!bit){ | |
157 renorm_cabac_encoder(c); | |
158 }else{ | |
159 c->low += c->range; | |
160 c->range= 2; | |
2967 | 161 |
1287 | 162 renorm_cabac_encoder(c); |
163 | |
164 assert(c->low <= 0x1FF); | |
165 put_cabac_bit(c, c->low>>9); | |
166 put_bits(&c->pb, 2, ((c->low>>7)&3)|1); | |
2967 | 167 |
1287 | 168 flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong |
169 } | |
2967 | 170 |
1287 | 171 #ifdef STRICT_LIMITS |
172 c->symCount++; | |
173 #endif | |
1300
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
174 |
1787 | 175 return (put_bits_count(&c->pb)+7)>>3; |
1287 | 176 } |
177 | |
1290 | 178 /** |
179 * put (truncated) unary binarization. | |
180 */ | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
181 static void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){ |
1290 | 182 int i; |
2967 | 183 |
1290 | 184 assert(v <= max); |
2967 | 185 |
1290 | 186 #if 1 |
187 for(i=0; i<v; i++){ | |
188 put_cabac(c, state, 1); | |
189 if(i < max_index) state++; | |
190 } | |
191 if(truncated==0 || v<max) | |
192 put_cabac(c, state, 0); | |
193 #else | |
194 if(v <= max_index){ | |
195 for(i=0; i<v; i++){ | |
196 put_cabac(c, state+i, 1); | |
197 } | |
198 if(truncated==0 || v<max) | |
199 put_cabac(c, state+i, 0); | |
200 }else{ | |
201 for(i=0; i<=max_index; i++){ | |
202 put_cabac(c, state+i, 1); | |
203 } | |
204 for(; i<v; i++){ | |
205 put_cabac(c, state+max_index, 1); | |
206 } | |
207 if(truncated==0 || v<max) | |
208 put_cabac(c, state+max_index, 0); | |
209 } | |
210 #endif | |
211 } | |
212 | |
213 /** | |
214 * put unary exp golomb k-th order binarization. | |
215 */ | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
216 static void put_cabac_ueg(CABACContext *c, uint8_t * state, int v, int max, int is_signed, int k, int max_index){ |
1290 | 217 int i; |
2967 | 218 |
1290 | 219 if(v==0) |
220 put_cabac(c, state, 0); | |
221 else{ | |
1298 | 222 const int sign= v < 0; |
2967 | 223 |
1298 | 224 if(is_signed) v= ABS(v); |
2967 | 225 |
1290 | 226 if(v<max){ |
227 for(i=0; i<v; i++){ | |
228 put_cabac(c, state, 1); | |
229 if(i < max_index) state++; | |
230 } | |
231 | |
232 put_cabac(c, state, 0); | |
233 }else{ | |
234 int m= 1<<k; | |
235 | |
236 for(i=0; i<max; i++){ | |
237 put_cabac(c, state, 1); | |
238 if(i < max_index) state++; | |
239 } | |
240 | |
241 v -= max; | |
242 while(v >= m){ //FIXME optimize | |
243 put_cabac_bypass(c, 1); | |
244 v-= m; | |
245 m+= m; | |
246 } | |
247 put_cabac_bypass(c, 0); | |
248 while(m>>=1){ | |
249 put_cabac_bypass(c, v&m); | |
250 } | |
251 } | |
252 | |
253 if(is_signed) | |
254 put_cabac_bypass(c, sign); | |
255 } | |
256 } | |
257 | |
2323 | 258 static void refill(CABACContext *c){ |
2736 | 259 if(c->bytestream <= c->bytestream_end) |
2323 | 260 #if CABAC_BITS == 16 |
3946 | 261 c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); |
2323 | 262 #else |
263 c->low+= c->bytestream[0]<<1; | |
264 #endif | |
265 c->low -= CABAC_MASK; | |
266 c->bytestream+= CABAC_BITS/8; | |
267 } | |
268 | |
3956
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
269 #if 1 /* all use commented */ |
2323 | 270 static void refill2(CABACContext *c){ |
271 int i, x; | |
272 | |
273 x= c->low ^ (c->low-1); | |
3956
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
274 i= 9 - ff_h264_norm_shift[x>>(CABAC_BITS+1)]; |
2323 | 275 |
276 x= -CABAC_MASK; | |
2967 | 277 |
3956
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
278 if(c->bytestream <= c->bytestream_end) |
2323 | 279 #if CABAC_BITS == 16 |
280 x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); | |
281 #else | |
282 x+= c->bytestream[0]<<1; | |
283 #endif | |
2967 | 284 |
2323 | 285 c->low += x<<i; |
286 c->bytestream+= CABAC_BITS/8; | |
287 } | |
2522
e25782262d7d
kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents:
2323
diff
changeset
|
288 #endif |
2323 | 289 |
1287 | 290 static inline void renorm_cabac_decoder(CABACContext *c){ |
2323 | 291 while(c->range < (0x200 << CABAC_BITS)){ |
1287 | 292 c->range+= c->range; |
293 c->low+= c->low; | |
2323 | 294 if(!(c->low & CABAC_MASK)) |
295 refill(c); | |
1287 | 296 } |
297 } | |
298 | |
2323 | 299 static inline void renorm_cabac_decoder_once(CABACContext *c){ |
3951 | 300 #ifdef ARCH_X86_DISABLED |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
301 int temp; |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
302 #if 0 |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
303 //P3:683 athlon:475 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
304 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
305 "lea -0x2000000(%0), %2 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
306 "shr $31, %2 \n\t" //FIXME 31->63 for x86-64 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
307 "shl %%cl, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
308 "shl %%cl, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
309 : "+r"(c->range), "+r"(c->low), "+c"(temp) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
310 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
311 #elif 0 |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
312 //P3:680 athlon:474 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
313 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
314 "cmp $0x2000000, %0 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
315 "setb %%cl \n\t" //FIXME 31->63 for x86-64 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
316 "shl %%cl, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
317 "shl %%cl, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
318 : "+r"(c->range), "+r"(c->low), "+c"(temp) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
319 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
320 #elif 1 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
321 int temp2; |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
322 //P3:665 athlon:517 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
323 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
324 "lea -0x2000000(%0), %%eax \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
325 "cdq \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
326 "mov %0, %%eax \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
327 "and %%edx, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
328 "and %1, %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
329 "add %%eax, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
330 "add %%edx, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
331 : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
332 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
333 #elif 0 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
334 int temp2; |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
335 //P3:673 athlon:509 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
336 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
337 "cmp $0x2000000, %0 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
338 "sbb %%edx, %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
339 "mov %0, %%eax \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
340 "and %%edx, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
341 "and %1, %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
342 "add %%eax, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
343 "add %%edx, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
344 : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
345 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
346 #else |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
347 int temp2; |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
348 //P3:677 athlon:511 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
349 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
350 "cmp $0x2000000, %0 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
351 "lea (%0, %0), %%eax \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
352 "lea (%1, %1), %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
353 "cmovb %%eax, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
354 "cmovb %%edx, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
355 : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
356 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
357 #endif |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
358 #else |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
359 //P3:675 athlon:476 |
3642 | 360 int shift= (uint32_t)(c->range - (0x200 << CABAC_BITS))>>31; |
361 c->range<<= shift; | |
362 c->low <<= shift; | |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
363 #endif |
2323 | 364 if(!(c->low & CABAC_MASK)) |
365 refill(c); | |
366 } | |
367 | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
368 static int get_cabac(CABACContext *c, uint8_t * const state){ |
3642 | 369 //FIXME gcc generates duplicate load/stores for c->low and c->range |
3951 | 370 //START_TIMER |
3642 | 371 int s = *state; |
372 int RangeLPS= c->lps_range[s][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1); | |
2522
e25782262d7d
kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents:
2323
diff
changeset
|
373 int bit, lps_mask attribute_unused; |
2967 | 374 |
1287 | 375 c->range -= RangeLPS; |
2323 | 376 #if 1 |
1287 | 377 if(c->low < c->range){ |
3642 | 378 bit= s&1; |
3955 | 379 #ifdef ARCH_X86 |
380 //P3:627 | |
381 asm( | |
382 "addb $2, %b0 \n\t" | |
383 " js 1f \n\t" | |
384 "movb %b0, %1 \n\t" | |
385 "1: \n\t" | |
386 : "+q"(s), "=m"(*state) | |
387 ); | |
388 #else | |
389 *state= c->mps_state[s]; //P3:655 | |
390 /* if(s<126) //P3:657 | |
391 *state= s+2;*/ | |
392 s+=2; //P3:631 | |
393 if(s<128) | |
394 *state= s; | |
395 #endif | |
2323 | 396 renorm_cabac_decoder_once(c); |
1287 | 397 }else{ |
3956
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
398 bit= ff_h264_norm_shift[RangeLPS>>17]; |
1287 | 399 c->low -= c->range; |
3642 | 400 *state= c->lps_state[s]; |
3956
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
401 // c->range = RangeLPS; |
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
402 // renorm_cabac_decoder(c); |
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
403 c->range = RangeLPS<<bit; |
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
404 c->low <<= bit; |
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
405 bit= (s&1)^1; |
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
406 |
2323 | 407 if(!(c->low & 0xFFFF)){ |
408 refill2(c); | |
3956
0910f2844f9a
branchless renormalization (1% faster get_cabac) old branchless renormalization wasnt faster because gcc was scared of the shift variable (missusing bit variable now)
michael
parents:
3955
diff
changeset
|
409 } |
1287 | 410 } |
2323 | 411 #else |
412 lps_mask= (c->range - c->low)>>31; | |
2967 | 413 |
2323 | 414 c->low -= c->range & lps_mask; |
415 c->range += (RangeLPS - c->range) & lps_mask; | |
2967 | 416 |
3642 | 417 bit= (s^lps_mask)&1; |
418 *state= c->mps_state[s - (128&lps_mask)]; | |
2967 | 419 |
2323 | 420 lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+2)]; |
421 c->range<<= lps_mask; | |
422 c->low <<= lps_mask; | |
423 if(!(c->low & CABAC_MASK)) | |
424 refill2(c); | |
425 #endif | |
3951 | 426 //STOP_TIMER("get_cabac") |
2967 | 427 return bit; |
1287 | 428 } |
429 | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
430 static int get_cabac_bypass(CABACContext *c){ |
1287 | 431 c->low += c->low; |
432 | |
2323 | 433 if(!(c->low & CABAC_MASK)) |
434 refill(c); | |
2967 | 435 |
1287 | 436 if(c->low < c->range){ |
437 return 0; | |
438 }else{ | |
439 c->low -= c->range; | |
440 return 1; | |
441 } | |
442 } | |
443 | |
1300
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
444 /** |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
445 * |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
446 * @return the number of bytes read or 0 if no end |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
447 */ |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
448 static int get_cabac_terminate(CABACContext *c){ |
2323 | 449 c->range -= 4<<CABAC_BITS; |
1287 | 450 if(c->low < c->range){ |
2323 | 451 renorm_cabac_decoder_once(c); |
1287 | 452 return 0; |
453 }else{ | |
1300
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
454 return c->bytestream - c->bytestream_start; |
2967 | 455 } |
1287 | 456 } |
457 | |
1290 | 458 /** |
459 * get (truncated) unnary binarization. | |
460 */ | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
461 static int get_cabac_u(CABACContext *c, uint8_t * state, int max, int max_index, int truncated){ |
1290 | 462 int i; |
2967 | 463 |
464 for(i=0; i<max; i++){ | |
1290 | 465 if(get_cabac(c, state)==0) |
466 return i; | |
2967 | 467 |
1290 | 468 if(i< max_index) state++; |
469 } | |
470 | |
471 return truncated ? max : -1; | |
472 } | |
473 | |
474 /** | |
475 * get unary exp golomb k-th order binarization. | |
476 */ | |
3928
987fffdf6ae7
don't try to inline cabac functions. gcc ignored the hint anyway, and forcing it would make h264 slower.
lorenm
parents:
3642
diff
changeset
|
477 static int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signed, int k, int max_index){ |
1290 | 478 int i, v; |
479 int m= 1<<k; | |
2967 | 480 |
481 if(get_cabac(c, state)==0) | |
1290 | 482 return 0; |
2967 | 483 |
1290 | 484 if(0 < max_index) state++; |
2967 | 485 |
486 for(i=1; i<max; i++){ | |
1290 | 487 if(get_cabac(c, state)==0){ |
488 if(is_signed && get_cabac_bypass(c)){ | |
489 return -i; | |
490 }else | |
491 return i; | |
492 } | |
493 | |
494 if(i < max_index) state++; | |
495 } | |
2967 | 496 |
1290 | 497 while(get_cabac_bypass(c)){ |
498 i+= m; | |
499 m+= m; | |
500 } | |
2967 | 501 |
1290 | 502 v=0; |
503 while(m>>=1){ | |
504 v+= v + get_cabac_bypass(c); | |
505 } | |
506 i += v; | |
507 | |
508 if(is_signed && get_cabac_bypass(c)){ | |
509 return -i; | |
510 }else | |
511 return i; | |
512 } |