[FFmpeg-devel] [PATCH] Yet more ALAC cleanup (#define removal)
Vitor Sessak
vitor1001
Thu Aug 30 12:42:33 CEST 2007
Hi, and sorry for taking so long to reply.
Michael Niedermayer wrote:
> Hi
>> On 8/18/07, Michael Niedermayer <michaelni at gmx.at> wrote:
>>
>> [...]
>>
>>> -#define SIGN_EXTENDED32(val, bits) ((val << (32 - bits)) >> (32 - bits))
>>>> +static inline int32_t sign_extended32(int32_t val, int bits)
>>>> +{
>>>> + return (val << (32 - bits)) >> (32 - bits);
>>>> +}
>>> maybe
>>>
>>> X= (-1)<<(bits-1)
>>> return (val+X)^X
>>>
>>> is faster?
>>> X can be precalcualted if bits is const
>>>
>>
>> I'm not really good in logical math, but it looks like this code do not give
>> the same values. What looks to me to give the same values (with only one op
>> if bits is const) is:
>>
>> int32_t x = 0;
>> x = (~x) >> bits;
>> return val & x;
>>
>> Am I missing something?
>
> yes, val is signed
> and the function / macro is called sign extend not mask out the evil bits that
> i fear :)
Well, actually your code would work in something like
sign_extended32(get_bits(gb, bits), bits);
But sign_extended32 is called with negative values as parameters (!) so
you'll need something like:
int32_t x = 0;
x = (~x) >> bits;
val = val & x;
w= (-1)<<(bits-1)
return (val+w)^w
but it is slower... I also propose to rename sign_extended32 to
extend_sign32.
-Vitor
More information about the ffmpeg-devel
mailing list