On 3 Dec 2010 at 7:39, John Foust wrote:
I had a hard time imagining a C that used floating
point ops to
handle integer divides. On the other hand, if someone wasn't
watching the type of their variables, they might not realize
that a right-hand operation would be calculated as floats,
even if it was being stored back into an int.
Not at all. On the CDC 6000, the usual way to do an integer divide
by a non-constant was:
* Divide integer X1 by X2 leaving result in X3.
PX4 X1,B0
PX5 X2,B0
NX4 X4
NX5 X5
FX3 X4/X5
UX3 X3,B3
LX3 X3,B3
Hope I've got the syntax right--it's been 30-odd years since I've
written any COMPASS. The point is that on some systems, the only
divide is a floating-point one and is by far faster than any bit-by-
bit software integer divide.
I can't recall, but I think the i860 also falls in this category; the
Cray-1 certainly does, not even having a floating-point divide, but
rather a reciprocal approximation.
On the 6000, system code that needed to calculate a low-precision
(say, 18 bits) result often substituted a divide by a constant with
an unnormalized double-precision multiply of the shifted reciprocal
of the divisor.
--Chuck