comparison h264_cabac.c @ 11190:afc60af2d008 libavcodec

2x faster ff_h264_init_cabac_states(), 4k cpu cycles less. Sadly this is just per slice so the speedup with normal files should be negligible.
author michael
date Tue, 16 Feb 2010 23:43:08 +0000
parents 90de754f70d6
children 5e583a785508
comparison
equal deleted inserted replaced
11189:638415aafbda 11190:afc60af2d008
686 }; 686 };
687 687
688 void ff_h264_init_cabac_states(H264Context *h) { 688 void ff_h264_init_cabac_states(H264Context *h) {
689 MpegEncContext * const s = &h->s; 689 MpegEncContext * const s = &h->s;
690 int i; 690 int i;
691 const int8_t (*tab)[2];
692
693 if( h->slice_type_nos == FF_I_TYPE ) tab = cabac_context_init_I;
694 else tab = cabac_context_init_PB[h->cabac_init_idc];
691 695
692 /* calculate pre-state */ 696 /* calculate pre-state */
693 for( i= 0; i < 460; i++ ) { 697 for( i= 0; i < 460; i++ ) {
694 int pre; 698 int pre = 2*(((tab[i][0] * s->qscale) >>4 ) + tab[i][1]) - 127;
695 if( h->slice_type_nos == FF_I_TYPE ) 699
696 pre = av_clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 ); 700 pre^= pre>>31;
697 else 701 if(pre > 124)
698 pre = av_clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 ); 702 pre= 124 + (pre&1);
699 703
700 if( pre <= 63 ) 704 h->cabac_state[i] = pre;
701 h->cabac_state[i] = 2 * ( 63 - pre ) + 0;
702 else
703 h->cabac_state[i] = 2 * ( pre - 64 ) + 1;
704 } 705 }
705 } 706 }
706 707
707 static int decode_cabac_field_decoding_flag(H264Context *h) { 708 static int decode_cabac_field_decoding_flag(H264Context *h) {
708 MpegEncContext * const s = &h->s; 709 MpegEncContext * const s = &h->s;