[comp.lang.c] Floating mul vs div

bright@Data-IO.COM (Walter Bright) (10/15/88)

In article <711@wsccs.UUCP> dharvey@wsccs.UUCP (David Harvey) writes:
<In article <10332@s.ms.uky.edu<, aash@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.