Floating mul vs div

Walter Bright bright at Data-IO.COM
Sat Oct 15 04:37:54 AEST 1988


In article <711 at wsccs.UUCP> dharvey at wsccs.UUCP (David Harvey) writes:
<In article <10332 at s.ms.uky.edu<, aash at ms.uky.edu ( Aashi Deacon ) writes:
<< <    o	Try very hard to replace divides with other operations, as in:
<< <		x / 10
<< <	with:
<< <		x * .1
<Also, if the operation is done in emulation mode (no
<floating point in MPU or if math coprocessor it is not in machine) the
<advantage will be nonexistent.  In other words, a sequence of left
<shifts and adds is no better than a sequence of right shifts, et al.
<Even with the coprocessor (math ops) a MUL takes approximately the same
<amount of clock cycles a DIV does.

In emulation mode, floating multiply is usually significantly faster than
divide because the hardware integer multiply can be used. In emulating
the floating divide, the hardware integer divide usually can't be used,
meaning you're reduced to using shifts and divides.
Even if you found a way to use the integer divide, on machines I've looked
at the MUL is faster than the DIV.

Looking at the spec sheet for the 8087, FMUL is nearly twice as fast as FDIV.



More information about the Comp.lang.c mailing list