Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!pasteur!agate!ig!uwmcsd1!bbn!rochester!ur-tut!sunybcs!rutgers!umn-d-ub!umn-cs!hall!pmk From: pmk@hall.cray.com (Peter Klausler) Newsgroups: comp.lang.c Subject: FP math used for int operations Message-ID: <3337@hall.cray.com> Date: 22 Jan 88 18:29:52 GMT References: <2335@haddock.ISC.COM> Organization: Cray Research, Inc., Mendota Heights, MN Lines: 26 Summary: Supercomputer trivia In article <2335@haddock.ISC.COM>, karl@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)