This is the mail archive of the
`gcc-patches@gcc.gnu.org`
mailing list for the GCC project.

# Re: IEEE 754 and fused-madd (was: Re: patch: rs6000 specific)

*From*: Geoff Keating <geoffk at geoffk dot org>
*To*: Dale Johannesen <dalej at apple dot com>
*Cc*: gcc-patches at gcc dot gnu dot org
*Date*: 07 Dec 2001 14:49:55 -0800
*Subject*: Re: IEEE 754 and fused-madd (was: Re: patch: rs6000 specific)
*References*: <74BD58BB-EB52-11D5-8923-003065C86F94@apple.com>
*Reply-to*: Geoff Keating <geoffk at redhat dot com>

Dale Johannesen <dalej@apple.com> writes:
> All right, so I need to generate additional FMA patterns by modifying
> combine.
> Our FP expert says all the required transformations are IEEE-compliant.
> Before I get too far into it, does anybody want to dispute this? Here are
> the patterns. The claim is that each of them can be transformed safely
> into the first one in its group.
Under IEEE arithmetic, A - B is equivalent to A + (-B). So those
changes are safe.
Also, ((-A) * B) is equivalent to -(A * B). The sign bits for the
result of a multiplication is the XOR of the sign bits of the inputs,
and a negation performs a logical NOT of the sign bit, so all
expressions involving MINUS and MUL can be simplified to (A * B) or
-(A * B).
In IEEE arithmetic, A + B can never generate -0; it's always +0. A
consequence of this is that -(A + B) can never generate +0. This
means that the transformation (A - B) to -(B - A) is not valid;
likewise -((-A) - B) to A+B is not valid either.
> fmadd:
> A*C + B
> B + A*C
These are safe. Addition and multiplication are both commutative
under IEEE arithmetic.
> fnmsub:
> -(A*C - B)
> ((-A)*C) + B
This change is not safe. ((-A)*C)+B) is equivalent to (B - A*C),
but as discussed above, that's not the same as -(A*C - B).
> -((-B) + A*C)
This change is safe.
> B - A*C
This change is not safe.
> fmsub:
> A*C -B
> -B + A*C
This is OK...
> -(B - A*C)
> -((-A)*C + B)
... these are not.
> fnmadd:
> -(A*C + B)
> ((-A)*C) -B
This is not OK.
> (-B) - A*C
Neither is this...
> -(B + A*C)
... but this is OK.
--
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>