Re: Q: division vs multiplication

brandis@inf.ethz.ch (Marc Brandis)
Tue, 4 Apr 1995 13:21:35 GMT

          From comp.compilers

Related articles
Q: division vs multiplication t.hulek@imperial.ac.uk (1995-03-24)
Re: Q: division vs multiplication kptben@aol.com (1995-04-02)
Re: Q: division vs multiplication Terje.Mathisen@hda.hydro.com (1995-04-02)
Re: Q: division vs multiplication mikeq@primenet.com (1995-04-02)
Re: Q: division vs multiplication hbaker@netcom.com (1995-04-03)
Re: Q: division vs multiplication davidm@Rational.COM (1995-04-03)
Re: Q: division vs multiplication brandis@inf.ethz.ch (1995-04-04)
Re: Q: division vs multiplication Terje.Mathisen@hda.hydro.com (1995-04-06)
Re: Q: division vs multiplication meissner@cygnus.com (Mike Meissner) (1995-04-16)
Re: Q: division vs multiplication martens@cis.ohio-state.edu (1995-04-16)
Re: Q: division vs multiplication jmccarty@spdmail.spd.dsccc.com (1995-04-18)
Re: Q: division vs multiplication leichter@zodiac.rutgers.edu (1995-04-11)
Re: Q: division vs multiplication kptben@aol.com (1995-04-17)
[6 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: brandis@inf.ethz.ch (Marc Brandis)
Keywords: arithmetic, optimize
Organization: Dept. Informatik, Swiss Federal Institute of Technology
References: 95-04-003
Date: Tue, 4 Apr 1995 13:21:35 GMT

In article 95-04-003,
Mr Tomas Hulek <t.hulek@imperial.ac.uk> wrote:
>It is presumably well known that on many hardware platform floating point
>division is slower than floating point multiplication.


[example deleted]


>My question is: does this also apply to division by constants that are powers
>of 2? For real-world compilers (C,C++ let's say) and machines, is there any
>benefit in using
>
>r = 0.5*(a+b);
>
>rather than
>
>r = (a+b)/2.0;
>
>???


An obvious way to simplify the operation would be to decrement the exponent
of the floating-point value (a+b) by one. No compiler I know does so, as it
would not work in all cases. First of all, it would be wrong for the value
0.0. Furthermore, it would be wrong for denormalized numbers in the IEEE
standard. One could check for these cases, but it is questionable whether the
resulting code pattern would be faster than the division.


In general, compilers tend to not rewrite floating-point operations too much,
as slight changes in ordering or other modifications could change rounding
errors or the exception behavior of the code.




Marc-Michael Brandis
Institute for Computer Systems
ETH-Zentrum (Swiss Federal Institute of Technology)
CH-8092 Zurich, Switzerland
email: brandis@inf.ethz.ch
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.