[Ffmpeg-cvslog] r8474 - trunk/libavcodec/resample2.c

Michael Niedermayer michaelni
Fri Mar 23 01:14:40 CET 2007


Hi

On Fri, Mar 23, 2007 at 01:59:22AM +0200, Uoti Urpala wrote:
> On Thu, 2007-03-22 at 23:39 +0100, Michael Niedermayer wrote:
> > just tried:
> > -----
> > int test(int a){
> >     a*=3;
> >     a+=1;
> >     a*=-1431655765;
> >     a-=-1431655765;
> >     return a;
> > }
> > 
> > main(){
> >     int i;
> > 
> >     for(i=0; i<100000000; i++){
> >         if(test(i) != i)
> >             printf("OPSI %d %d\n", i, test(i));
> >     }
> > }
> > -----
> > 
> > gcc 4.1.2 missompiles the code causing the printf() to be executed
> > 
> > every time i test gcc iam more disappointed after the test than before...
> 
> I'm not sure whether that's really a miscompilation. At least you're
> using implementation-defined behavior; whether it's a bug depends on
> whether gcc defines it to work otherwise (I'm not sure whether it does).
> 
> The issue is that you're using doing overflowing multiplies with signed
> integers. The standard certainly doesn't guarantee anything about such
> calculations. If you use unsigned types then the result is guaranteed to
> be reduced modulo maximum value of type plus one, and if you change that
> to "unsigned int a" then gcc doesn't trigger the printf.

multiplication of signed numbers behaves the same on every 
twos complement architecture which is identical to unsigned multiplication

its highly unintuitive if it breaks, though iam not arguing against that
it may be undefined strictly speaking, shift right of signed numbers is
too and i too would say gcc is broken if (-1)>>1 != -1 on a twos complement
architecture because it is from a practical POV

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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-cvslog/attachments/20070323/0b635e2c/attachment.pgp>



More information about the ffmpeg-cvslog mailing list