comparison cabac.h @ 3642:0efda682253c libavcodec

tweak cabac. 0.5% faster h264.
author lorenm
date Sun, 27 Aug 2006 09:19:02 +0000
parents a224d9752912
children 987fffdf6ae7
comparison
equal deleted inserted replaced
3641:b325c92e7bed 3642:0efda682253c
293 refill(c); 293 refill(c);
294 } 294 }
295 } 295 }
296 296
297 static inline void renorm_cabac_decoder_once(CABACContext *c){ 297 static inline void renorm_cabac_decoder_once(CABACContext *c){
298 int mask= (c->range - (0x200 << CABAC_BITS))>>31; 298 int shift= (uint32_t)(c->range - (0x200 << CABAC_BITS))>>31;
299 c->range+= c->range&mask; 299 c->range<<= shift;
300 c->low += c->low &mask; 300 c->low <<= shift;
301 if(!(c->low & CABAC_MASK)) 301 if(!(c->low & CABAC_MASK))
302 refill(c); 302 refill(c);
303 } 303 }
304 304
305 static inline int get_cabac(CABACContext *c, uint8_t * const state){ 305 static inline int get_cabac(CABACContext *c, uint8_t * const state){
306 int RangeLPS= c->lps_range[*state][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1); 306 //FIXME gcc generates duplicate load/stores for c->low and c->range
307 int s = *state;
308 int RangeLPS= c->lps_range[s][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1);
307 int bit, lps_mask attribute_unused; 309 int bit, lps_mask attribute_unused;
308 310
309 c->range -= RangeLPS; 311 c->range -= RangeLPS;
310 #if 1 312 #if 1
311 if(c->low < c->range){ 313 if(c->low < c->range){
312 bit= (*state)&1; 314 bit= s&1;
313 *state= c->mps_state[*state]; 315 *state= c->mps_state[s];
314 renorm_cabac_decoder_once(c); 316 renorm_cabac_decoder_once(c);
315 }else{ 317 }else{
316 // int shift= ff_h264_norm_shift[RangeLPS>>17]; 318 // int shift= ff_h264_norm_shift[RangeLPS>>17];
317 bit= ((*state)&1)^1; 319 bit= (s&1)^1;
318 c->low -= c->range; 320 c->low -= c->range;
319 *state= c->lps_state[*state]; 321 *state= c->lps_state[s];
320 c->range = RangeLPS; 322 c->range = RangeLPS;
321 renorm_cabac_decoder(c); 323 renorm_cabac_decoder(c);
322 /* c->range = RangeLPS<<shift; 324 /* c->range = RangeLPS<<shift;
323 c->low <<= shift; 325 c->low <<= shift;
324 if(!(c->low & 0xFFFF)){ 326 if(!(c->low & 0xFFFF)){
329 lps_mask= (c->range - c->low)>>31; 331 lps_mask= (c->range - c->low)>>31;
330 332
331 c->low -= c->range & lps_mask; 333 c->low -= c->range & lps_mask;
332 c->range += (RangeLPS - c->range) & lps_mask; 334 c->range += (RangeLPS - c->range) & lps_mask;
333 335
334 bit= ((*state)^lps_mask)&1; 336 bit= (s^lps_mask)&1;
335 *state= c->mps_state[(*state) - (128&lps_mask)]; 337 *state= c->mps_state[s - (128&lps_mask)];
336 338
337 lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+2)]; 339 lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+2)];
338 c->range<<= lps_mask; 340 c->range<<= lps_mask;
339 c->low <<= lps_mask; 341 c->low <<= lps_mask;
340 if(!(c->low & CABAC_MASK)) 342 if(!(c->low & CABAC_MASK))