[FFmpeg-devel] [PATCH] Avoid a branch in MP2 decoder

Vitor Sessak vitor1001
Sun Jun 27 00:14:13 CEST 2010


On 06/26/2010 08:11 PM, M?ns Rullg?rd wrote:
> Vitor Sessak<vitor1001 at gmail.com>  writes:
>
>> $subj.
>>
>> -Vitor
>>
>> Index: libavcodec/mpegaudiodec.c
>> ===================================================================
>> --- libavcodec/mpegaudiodec.c	(revision 23792)
>> +++ libavcodec/mpegaudiodec.c	(working copy)
>> @@ -202,9 +202,7 @@
>>
>>       val = (mant - (steps>>  1)) * scale_factor_mult2[steps>>  2][mod];
>>       /* NOTE: at this point, 0<= shift<= 21 */
>> -    if (shift>  0)
>> -        val = (val + (1<<  (shift - 1)))>>  shift;
>> -    return val;
>> +    return ((val<<  1) + (1<<  shift))>>  (shift+1);
>>   }
>
> This assumes the MSB of val is zero.  Is this always the case?

Good point, but it is.

mant is always < 9

scale_factor_mult2[a][b] < 2*FRAC_ONE <= 2*(1 << 23)

-Vitor



More information about the ffmpeg-devel mailing list