Related articles |
---|
[4 earlier articles] |
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) |
Re: Q: division vs multiplication pcg@aber.ac.uk (1995-04-17) |
Re: Q: division vs multiplication gsc@magna.com.au (1995-04-18) |
Re: Q: division vs multiplication jbuck@Synopsys.COM (1995-04-28) |
Re: Q: division vs multiplication davidm@flora.Rational.com (1995-04-28) |
[2 later articles] |
Newsgroups: | comp.compilers |
From: | jmccarty@spdmail.spd.dsccc.com (Mike McCarty) |
Keywords: | arithmetic, optimize, comment |
Organization: | DSC Communications Corporation, Plano, Texas USA |
References: | 95-04-003 |
Date: | Tue, 18 Apr 1995 16:46:26 GMT |
Mr Tomas Hulek <t.hulek@imperial.ac.uk> wrote:
)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;
)
)???
)
)I would imagine that division by 2.0 could be done very efficiently, just like
)division by 10 in our decimal system. But is it really so?
Depends on the floating point base. If the base is 2, then all one has
to do is extract the exponent, subtract one, put it back, and then
normalize the result. This is indeed much faster than dividing by 2. But
I know of no compilers which make use of this fact.
Mike
[As noted elsewhere, there are FPUs that have a floating scale operation that
does this in one instruction, but it's not always faster than a multiplication
or division. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.