This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication
On Thu, Oct 07, 2004 at 02:58:53PM -0700, Dale Johannesen wrote:
> >It is possible that (X op C1) would overflow or lose precision
> >when the second form would not, even if (C1 op C2) is exactly
> >representable; consider X and C1 very large, C2==1/C1.
>
> Offhand it seems that the combination might be safe if C1 op C2 is
> representable, and C1 and C2 both "move the result in the same
> direction", i.e. both absolute values >1 or both <1 for multiplication,
> both positive or both negative for addition and subtraction.
Ho hum.
0x3f000001 * 3 = 0x3fc00002
0x3fc00002 * 3 = 0x40900002
0x3f000001 * 9 = 0x40900001
So it looks like the only thing we can fold for multiply is
C2 a power of B, the base of the floating point format.
I've exhaustively tested 2 * 3 -> 6 for single precision, so I'm
certain I havn't made a mistake in intuition for that particular
case. I can't see anything about how fp multiplication works
that would contradict this -- the fraction doesn't change, so the
resultant fraction shouldn't change. Only the exponent changes,
and if we verify "moves in the same direction" then we shouldn't
hit silly things with edge conditions.
r~