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

Rich Felker dalias
Fri Mar 23 02:58:12 CET 2007


On Fri, Mar 23, 2007 at 02:50:50AM +0200, Uoti Urpala wrote:
> On Fri, 2007-03-23 at 01:14 +0100, Michael Niedermayer wrote:
> > On Fri, Mar 23, 2007 at 01:59:22AM +0200, Uoti Urpala wrote:
> > > 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
> 
> Right shift of positive signed numbers is defined by the standard. Right
> shift of negative numbers is implementation-defined and gcc defines it
> to work by sign extension in
> http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Integers-implementation.html
> 
> Overflow of signed number operations appears to be undefined rather than
> implementation-defined. At least I didn't notice anything which would
> cover it more specifically than this text from 6.5:
> "If an exceptional condition occurs during the evaluation of an
> expression (that is, if the result is not mathematically defined or not
> in the range of representable values for its type), the behavior is
> undefined."

While you are correct, nothing about "undefined" precludes the
implementation giving a definition. It just means that, unlike
something specified to be "implementation defined", the implementation
is not required to give a definition.

I agree quite strongly with Michael here that anything other than twos
complement behavior with reduction modulo UINT_MAX (identical to the
behavior for unsigned integers) is counterintuitive and idiotic,
regardless of what the standard specifies. gcc has always historically
behaved this way and I wonder why they changed it...

Rich




More information about the ffmpeg-cvslog mailing list