[FFmpeg-devel] [RFC] abs vs FFABS
Sat Jan 17 17:37:11 CET 2009
On Sat, 2009-01-17 at 16:52 +0100, Stefan Gehrer wrote:
> Ronald S. Bultje wrote:
> >  1billion abs/FFABS cycles + some checks, m = macro (FFABS()), b =
> > built-in (abs()), see attached code
> > i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build
> > 5367), compiled with -O3
> If I compile with -O3 (gcc 4.3.2), execution takes no measurable time.
> It seems the loop gets optimized away.
> If I compile without optimization, both macro and builtin run for
> the same time of about two seconds and then print a
> "math op failed", which is surprising.
Strictly speaking the whole thing is undefined behavior because of
multiple signed overflows. So optimized code is basically free to do
whatever it wants.
What causes the "math op failed" in this case is probably *lack* of
optimization: with literal 32-bit hardware operations
536870912 * 0x1234fedc = -0x80000000, and
-(-0x80000000) = -0x80000000.
More information about the ffmpeg-devel