This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Supporting 'MAC' instruction on gcc v4.1.1
On May 11, 2007, at 08:26, Rahul wrote:
But for the following example
int a = 1;
int b = 2;
int c = 3;
c = c + a * b;
the MAC pattern is not getting recognized, instead it is still using
PLUS and MULT patterns.
In general, this transformation is not valid, as it has
different rounding behavior from the expression with the
+ and * operations. While fused multiply-add is a very
powerful instruction that can be helpful for both speed
and accuracy (especially accuracy exceeding native precision),
good algorithms may become unstable if fused multiply-add
is used when a*b+c is expected or vice versa.
So, implementing a builtin (conforming to C99's fma)
would seem the best approach. The -ffast-math option, or
preferably #pragma STDC CONTRACT ON, could be used to
enable the transformation.
-Geert