FP math used for int operations
Peter Klausler
pmk at hall.cray.com
Sat Jan 23 04:29:52 AEST 1988
In article <2335 at haddock.ISC.COM>, karl at haddock.ISC.COM (Karl Heuer) writes:
> ... Just as the "/" symbol invokes the integer-divide operator when both
> operands are integers (it most certainly does *not* invoke floating-point
> divide and then truncate the result), ...
Our architectures do not possess integer division instructions, so we're
forced to do generic integer division (i=j/k) via something like:
i = (int) ((float) j / (float) k)
In fact, it's even more complicated, since there's no actual floating
division instruction either, but rather a "reciprocal approximation"
instruction, which generates a half-precision reciprocal that must then
be refined with the Newton-Raphson method iteration instruction.
It gets worse on Cray-1's and X-MP's, which don't have instructions
for coercing full ints into floats or vice versa. All of these
complications conspire to require 15 instructions for i=j/k.
(There's no integer multiplication instruction for full-word integers,
either, so similar tricks are also necessary for things like i=j*k.)
Moral: Try to use floats when programming a scientific machine.
Your generated code will use them anyway.
- Peter Klausler @ Cray Research compiler development (ihnp4!cray!hall!pmk)
More information about the Comp.lang.c
mailing list