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

Michael Niedermayer michaelni
Sat Aug 18 01:35:33 CEST 2007


Hi

On Wed, Aug 15, 2007 at 08:50:05PM +0200, Vitor Sessak wrote:
> Hi
>
> Reimar D?ffinger wrote:
>> Hello,
>> On Wed, Aug 15, 2007 at 08:22:59PM +0200, Vitor Sessak wrote:
>>> -#define SIGN_ONLY(v) \
>>> -                     ((v < 0) ? (-1) : \
>>> -                                ((v > 0) ? (1) : \
>>> -                                           (0)))
>>> +static inline int sign_only(int v)
>>> +{
>>> +    if (v < 0)
>>> +        return -1;
>>> +    else if (v > 0)
>>> +        return 1;
>>> +    else
>>> +        return 0;
>>> +}
>> Since you change it anyway, I'd suggest
>> if (v == 0) return 0;
>> return FFSIGN(v);
>> Though benchmarking it might be a good idea unless it is really
>> uncritical.
>> Greetings,
>> Reimar D?ffinger
>
> Nice suggestion, but I don't think it is worth benchmarking. Unless the 
> compiler is very stupid, all this should generate the same asm. New patch 
> attached.
>
> -Vitor

> Index: libavcodec/alac.c
> ===================================================================
> --- libavcodec/alac.c	(revision 10119)
> +++ libavcodec/alac.c	(working copy)
> @@ -269,12 +269,15 @@
>      }
>  }
>  
> -#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


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

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- 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/20070818/cba6cef3/attachment.pgp>



More information about the ffmpeg-devel mailing list