[FFmpeg-cvslog] r21069 - trunk/libavcodec/alsdec.c

Måns Rullgård mans
Sat Jan 9 13:42:53 CET 2010


Thilo Borgmann <thilo.borgmann at googlemail.com> writes:

> Am 09.01.10 12:12, schrieb M?ns Rullg?rd:
>> Thilo Borgmann <thilo.borgmann at googlemail.com> writes:
>> 
>>> Am 08.01.10 12:58, schrieb Thilo Borgmann:
>>>> Am 08.01.10 10:35, schrieb Michael Kostylev:
>>>>>
>>>>> On Thu Jan  7 23:23:28 2010
>>>>> thilo.borgmann wrote:
>>>>>
>>>>>> Optimize short-term prediction by reducing index arithmetic.
>>>>>
>>>>> Now the lossless-als test returns a different crc on gcc-4.1.x configurations.
>>>>> http://fate.multimedia.cx/index.php?build_record=156471
>>>>> http://fate.multimedia.cx/index.php?build_record=156456
>>>>> http://fate.multimedia.cx/index.php?build_record=156464
>>>>> etc.
>>>>
>>>> Thanks for letting me know!
>>>>
>>>> Seems like I have to install gcc-4.1.x to see myself.
>>>
>>> I could reproduce this using gcc-4.1.3 in a virtual box. Seems like
>>> another unsigned/signed issue exclusively for 4.1.x versions.
>> 
>> Did you figure out exactly what was happening?  I'm curious...
>
> I think so:
>
>>        for (sb = -opt_order; sb < 0; sb++)
>>            y += MUL64(lpc_cof[sb], raw_samples[sb]);
>
> does not work in gcc 4.1.x if opt_order is an unsigned int.
> Debug output showed that the loop is not executed even once then (so I
> think sb got a big positive number assigned). A quick test worked with:
>
>>        for (sb = -(int)(opt_order); ...)
>
> so the local opt_order variable has been changed to int now.
> Thus, using "-a" is not a good idea if a is unsigned. At least for gcc
> 4.1.x.

OK, here's what's happening.

When opt_order is unsigned, the expression -opt_order has a (large)
positive value obtained by wrapping the mathematical negation of
opt_order into the proper number of bits (32 here).  The type of the
expression is still unsigned.  When an out of range value is assigned
to a signed type, the result is undefined.  Most compilers seem to
simply copy the bits, which has the intended effect.  GCC 4.1
apparently pretends that 'sb' can represent the value, and proceeds to
optimise the entire loop out since the condition sb<0 will then never
be true.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-cvslog mailing list