On Oct 27, 2005, at 17:25, Steve Ellcey wrote:
It would be easy enough to add an option that turned off the use of
the
fused multiply and add in GCC but I would hate to see its use
turned off
by default.
Code that cares should be able to express barriers across which no
contraction is possible. Especially with templates or inlining
across compilation units, global flags become too limited.
Many useful primitives can only be implemented with exact knowledge
of where rounding happens. With arbitrary contractions, numerical
analysis becomes infeasible and some essential algorithms break
down completely.
For example, you may have code that evaluates some polynomials and
other straightforward computations involving approximated inputs.
This code may benefit from contractions due to fused multiply-add
both with regards to speed and accuracy. However, then you might
want to round computed values to integer, rounding halfway
values away from zero. If the machine has no primitive, this may
be implemented with truncation and addition of a special constant.
But, when such addition gets combined with other operations,
eliminating the rounding operation, the final result can be incorrect,
causing numbers to be rounded the wrong way.
There are two ways around this: for code targeted to a specific
processor, use inline assembly for the code relying on precise
rounding. The other is: compile all code with conservative
optimizations. For GCC, we are interested in writing and compiling
code that works across a wide range of targets. The two workarounds
mentioned above either needlessly limit the performance (by using
conservative optimization everywhere), or portability (by relying
on inline assembly).
-Geert