Mercurial > libavcodec.hg
annotate cabac.h @ 3963:075b3e6bdc05 libavcodec
Fixes:
rv10.c:494: warning: implicit declaration of function ¡Æff_mpeg4_init_direct_mv¡Ç
Approved by Michael.
author | rathann |
---|---|
date | Sun, 08 Oct 2006 21:26:19 +0000 |
parents | 2acfc35c3075 |
children | 162bea01a5d4 |
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 | |
269 static void refill2(CABACContext *c){ | |
270 int i, x; | |
271 | |
272 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
|
273 i= 9 - ff_h264_norm_shift[x>>(CABAC_BITS+1)]; |
2323 | 274 |
275 x= -CABAC_MASK; | |
2967 | 276 |
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
|
277 if(c->bytestream <= c->bytestream_end) |
2323 | 278 #if CABAC_BITS == 16 |
279 x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); | |
280 #else | |
281 x+= c->bytestream[0]<<1; | |
282 #endif | |
2967 | 283 |
2323 | 284 c->low += x<<i; |
285 c->bytestream+= CABAC_BITS/8; | |
286 } | |
287 | |
1287 | 288 static inline void renorm_cabac_decoder(CABACContext *c){ |
2323 | 289 while(c->range < (0x200 << CABAC_BITS)){ |
1287 | 290 c->range+= c->range; |
291 c->low+= c->low; | |
2323 | 292 if(!(c->low & CABAC_MASK)) |
293 refill(c); | |
1287 | 294 } |
295 } | |
296 | |
2323 | 297 static inline void renorm_cabac_decoder_once(CABACContext *c){ |
3951 | 298 #ifdef ARCH_X86_DISABLED |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
299 int temp; |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
300 #if 0 |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
301 //P3:683 athlon:475 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
302 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
303 "lea -0x2000000(%0), %2 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
304 "shr $31, %2 \n\t" //FIXME 31->63 for x86-64 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
305 "shl %%cl, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
306 "shl %%cl, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
307 : "+r"(c->range), "+r"(c->low), "+c"(temp) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
308 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
309 #elif 0 |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
310 //P3:680 athlon:474 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
311 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
312 "cmp $0x2000000, %0 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
313 "setb %%cl \n\t" //FIXME 31->63 for x86-64 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
314 "shl %%cl, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
315 "shl %%cl, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
316 : "+r"(c->range), "+r"(c->low), "+c"(temp) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
317 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
318 #elif 1 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
319 int temp2; |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
320 //P3:665 athlon:517 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
321 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
322 "lea -0x2000000(%0), %%eax \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
323 "cdq \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
324 "mov %0, %%eax \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
325 "and %%edx, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
326 "and %1, %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
327 "add %%eax, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
328 "add %%edx, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
329 : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
330 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
331 #elif 0 |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
332 int temp2; |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
333 //P3:673 athlon:509 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
334 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
335 "cmp $0x2000000, %0 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
336 "sbb %%edx, %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
337 "mov %0, %%eax \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
338 "and %%edx, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
339 "and %1, %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
340 "add %%eax, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
341 "add %%edx, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
342 : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
343 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
344 #else |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
345 int temp2; |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
346 //P3:677 athlon:511 |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
347 asm( |
3948
3edbf131ee44
refill cabac variables in 16bit steps, 3% faster get_cabac()
michael
parents:
3947
diff
changeset
|
348 "cmp $0x2000000, %0 \n\t" |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
349 "lea (%0, %0), %%eax \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
350 "lea (%1, %1), %%edx \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
351 "cmovb %%eax, %0 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
352 "cmovb %%edx, %1 \n\t" |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
353 : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
354 ); |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
355 #endif |
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
356 #else |
3950
900d21b85dd6
renorm_cabac_decoder_once START/STOP_TIMER scores for athlon
michael
parents:
3948
diff
changeset
|
357 //P3:675 athlon:476 |
3642 | 358 int shift= (uint32_t)(c->range - (0x200 << CABAC_BITS))>>31; |
359 c->range<<= shift; | |
360 c->low <<= shift; | |
3943
811a9b0d9f32
several x86 renorm_cabac_decoder_once optimizations
michael
parents:
3928
diff
changeset
|
361 #endif |
2323 | 362 if(!(c->low & CABAC_MASK)) |
363 refill(c); | |
364 } | |
365 | |
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
|
366 static int get_cabac(CABACContext *c, uint8_t * const state){ |
3642 | 367 //FIXME gcc generates duplicate load/stores for c->low and c->range |
3951 | 368 //START_TIMER |
3642 | 369 int s = *state; |
370 int RangeLPS= c->lps_range[s][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1); | |
2522
e25782262d7d
kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents:
2323
diff
changeset
|
371 int bit, lps_mask attribute_unused; |
2967 | 372 |
1287 | 373 c->range -= RangeLPS; |
2323 | 374 #if 1 |
1287 | 375 if(c->low < c->range){ |
3642 | 376 bit= s&1; |
3955 | 377 #ifdef ARCH_X86 |
378 //P3:627 | |
379 asm( | |
380 "addb $2, %b0 \n\t" | |
381 " js 1f \n\t" | |
382 "movb %b0, %1 \n\t" | |
383 "1: \n\t" | |
384 : "+q"(s), "=m"(*state) | |
385 ); | |
386 #else | |
387 *state= c->mps_state[s]; //P3:655 | |
388 /* if(s<126) //P3:657 | |
389 *state= s+2;*/ | |
390 s+=2; //P3:631 | |
391 if(s<128) | |
392 *state= s; | |
393 #endif | |
2323 | 394 renorm_cabac_decoder_once(c); |
1287 | 395 }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
|
396 bit= ff_h264_norm_shift[RangeLPS>>17]; |
1287 | 397 c->low -= c->range; |
3642 | 398 *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
|
399 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
|
400 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
|
401 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
|
402 |
2323 | 403 if(!(c->low & 0xFFFF)){ |
404 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
|
405 } |
1287 | 406 } |
2323 | 407 #else |
408 lps_mask= (c->range - c->low)>>31; | |
2967 | 409 |
2323 | 410 c->low -= c->range & lps_mask; |
411 c->range += (RangeLPS - c->range) & lps_mask; | |
2967 | 412 |
3642 | 413 bit= (s^lps_mask)&1; |
414 *state= c->mps_state[s - (128&lps_mask)]; | |
2967 | 415 |
2323 | 416 lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+2)]; |
417 c->range<<= lps_mask; | |
418 c->low <<= lps_mask; | |
419 if(!(c->low & CABAC_MASK)) | |
420 refill2(c); | |
421 #endif | |
3951 | 422 //STOP_TIMER("get_cabac") |
2967 | 423 return bit; |
1287 | 424 } |
425 | |
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
|
426 static int get_cabac_bypass(CABACContext *c){ |
1287 | 427 c->low += c->low; |
428 | |
2323 | 429 if(!(c->low & CABAC_MASK)) |
430 refill(c); | |
2967 | 431 |
1287 | 432 if(c->low < c->range){ |
433 return 0; | |
434 }else{ | |
435 c->low -= c->range; | |
436 return 1; | |
437 } | |
438 } | |
439 | |
1300
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
440 /** |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
441 * |
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
442 * @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
|
443 */ |
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
|
444 static int get_cabac_terminate(CABACContext *c){ |
2323 | 445 c->range -= 4<<CABAC_BITS; |
1287 | 446 if(c->low < c->range){ |
2323 | 447 renorm_cabac_decoder_once(c); |
1287 | 448 return 0; |
449 }else{ | |
1300
e18667d1e94d
FFV1 codec (our very simple lossless intra only codec, compresses much better then huffyuv)
michaelni
parents:
1298
diff
changeset
|
450 return c->bytestream - c->bytestream_start; |
2967 | 451 } |
1287 | 452 } |
453 | |
1290 | 454 /** |
455 * get (truncated) unnary binarization. | |
456 */ | |
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
|
457 static int get_cabac_u(CABACContext *c, uint8_t * state, int max, int max_index, int truncated){ |
1290 | 458 int i; |
2967 | 459 |
460 for(i=0; i<max; i++){ | |
1290 | 461 if(get_cabac(c, state)==0) |
462 return i; | |
2967 | 463 |
1290 | 464 if(i< max_index) state++; |
465 } | |
466 | |
467 return truncated ? max : -1; | |
468 } | |
469 | |
470 /** | |
471 * get unary exp golomb k-th order binarization. | |
472 */ | |
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
|
473 static int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signed, int k, int max_index){ |
1290 | 474 int i, v; |
475 int m= 1<<k; | |
2967 | 476 |
477 if(get_cabac(c, state)==0) | |
1290 | 478 return 0; |
2967 | 479 |
1290 | 480 if(0 < max_index) state++; |
2967 | 481 |
482 for(i=1; i<max; i++){ | |
1290 | 483 if(get_cabac(c, state)==0){ |
484 if(is_signed && get_cabac_bypass(c)){ | |
485 return -i; | |
486 }else | |
487 return i; | |
488 } | |
489 | |
490 if(i < max_index) state++; | |
491 } | |
2967 | 492 |
1290 | 493 while(get_cabac_bypass(c)){ |
494 i+= m; | |
495 m+= m; | |
496 } | |
2967 | 497 |
1290 | 498 v=0; |
499 while(m>>=1){ | |
500 v+= v + get_cabac_bypass(c); | |
501 } | |
502 i += v; | |
503 | |
504 if(is_signed && get_cabac_bypass(c)){ | |
505 return -i; | |
506 }else | |
507 return i; | |
508 } |