This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

Dale Johannesen <> 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 <> <>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]