From: Jason Garrett-Glaser Date: Sat, 13 Feb 2010 05:15:12 +0000 (-0800) Subject: Backport various speed tweak ideas from ffmpeg X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=41db4e8355e2390c430071c6f5ed9a2c8851e0a6;p=x264.git Backport various speed tweak ideas from ffmpeg Add mv0 early termination to spatial direct calculation Up to twice as fast direct mv calculation on near-motionless video. Branchless CAVLC level code adjustment based on trailing ones. A few clocks faster. Check tc value before clipping in C version of deblock functions. Much faster, but nobody uses those anyways. Thanks to Michael Niedermayer for the ideas. --- diff --git a/common/frame.c b/common/frame.c index 40cc78f7..d89f5abf 100644 --- a/common/frame.c +++ b/common/frame.c @@ -472,12 +472,14 @@ static inline void deblock_luma_c( uint8_t *pix, int xstride, int ystride, int a int delta; if( abs( p2 - p0 ) < beta ) { - pix[-2*xstride] = p1 + x264_clip3( (( p2 + ((p0 + q0 + 1) >> 1)) >> 1) - p1, -tc0[i], tc0[i] ); + if( tc0[i] ) + pix[-2*xstride] = p1 + x264_clip3( (( p2 + ((p0 + q0 + 1) >> 1)) >> 1) - p1, -tc0[i], tc0[i] ); tc++; } if( abs( q2 - q0 ) < beta ) { - pix[ 1*xstride] = q1 + x264_clip3( (( q2 + ((p0 + q0 + 1) >> 1)) >> 1) - q1, -tc0[i], tc0[i] ); + if( tc0[i] ) + pix[ 1*xstride] = q1 + x264_clip3( (( q2 + ((p0 + q0 + 1) >> 1)) >> 1) - q1, -tc0[i], tc0[i] ); tc++; } diff --git a/common/macroblock.c b/common/macroblock.c index cc9a3fd3..278659c3 100644 --- a/common/macroblock.c +++ b/common/macroblock.c @@ -272,6 +272,9 @@ static int x264_mb_predict_mv_direct16x16_spatial( x264_t *h ) x264_macroblock_cache_mv_ptr( h, 0, 0, 4, 4, 0, mv[0] ); x264_macroblock_cache_mv_ptr( h, 0, 0, 4, 4, 1, mv[1] ); + if( !M64( mv ) ) + return 1; + if( h->param.i_threads > 1 && ( mv[0][1] > h->mb.mv_max_spel[1] || mv[1][1] > h->mb.mv_max_spel[1] ) ) diff --git a/encoder/cavlc.c b/encoder/cavlc.c index c65c9bd2..85d2dde3 100644 --- a/encoder/cavlc.c +++ b/encoder/cavlc.c @@ -147,10 +147,9 @@ static int block_residual_write_cavlc( x264_t *h, int i_ctxBlockCat, int16_t *l, if( i_trailing < i_total ) { - int16_t val = runlevel.level[i_trailing]; - int16_t val_original = runlevel.level[i_trailing]+LEVEL_TABLE_SIZE/2; - if( i_trailing < 3 ) - val -= (val>>15)|1; /* as runlevel.level[i] can't be 1 for the first one if i_trailing < 3 */ + int val = runlevel.level[i_trailing]; + int val_original = runlevel.level[i_trailing]+LEVEL_TABLE_SIZE/2; + val -= ((val>>31)|1) & -(i_trailing < 3); /* as runlevel.level[i] can't be 1 for the first one if i_trailing < 3 */ val += LEVEL_TABLE_SIZE/2; if( (unsigned)val_original < LEVEL_TABLE_SIZE )