[FFmpeg-devel] [PATCH] Yet more ALAC cleanup (#define removal)

Michael Niedermayer michaelni
Thu Aug 30 15:19:29 CEST 2007


Hi

On Thu, Aug 30, 2007 at 12:42:33PM +0200, Vitor Sessak wrote:
> 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 

ok, i see the problem, the needed operation is not really extending the
sign but rather truncating the msbs and then extending the remaining bit
so your original code is ok


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070830/6c6544ae/attachment.pgp>



More information about the ffmpeg-devel mailing list