[comp.sys.sgi] float vs double

ckchee@dgp.toronto.edu (Chuan Chee) (04/29/89)

I have been using "double" almost extensively on a Personal Iris 4D/20.
I am curious about the advantages/performance of using "float".  Yes I
realize that "float" has less precision but let's assume that I only
need float precision.

The assumptions I have about float are:
(1) The floating point accelerator computes float expressions faster
    than double expressions.
(2) float takes half the amount of storage.

I am posting this to confirm my assumptions and maybe get some statistics.
Are there other advantages/performance considerations?

How fast/slow is converting between float and double?

One other thing - I am compiling with:
    cc -g -signed -Zg

...Chuan Chee
   CDNNET: ckchee@dgp.utoronto.ca
   CSNET:  ckchee@dgp.toronto.edu
   BITNET: ckchee@dgp.utoronto.bitnet
   ARPA:   ckchee%dgp.toronto.edu@relay.cs.net
   UUCP:   ckchee@dgp.uucp

bron@bronze.SGI.COM (Bron Campbell Nelson) (04/29/89)

In article <8904281948.AA28223@cartier.dgp.toronto.edu>, ckchee@dgp.toronto.edu (Chuan Chee) writes:
> The assumptions I have about float are:
> (1) The floating point accelerator computes float expressions faster
>     than double expressions.
> (2) float takes half the amount of storage.
> 
These are both true.

If memory serves me, a "float" add take 2 clocks, a "float" multiply
takes 4 clocks, while "double" takes 3 and 6 respectively.  The
single to double conversion is (I believe) 1 clock.  This is from
memory; these times could easily be off by a clock or two.

These are extremely fast if you ask me, and the second order effects
caused by (2) start to be significant. i.e. the path to memory is only
32 bits wide, so loading/storing a double takes an extra clock; when
you miss the cache, you fetch twice as many floats as doubles, so you
do fewer fetches, etc.

I have seen about a 50% difference in float vs double for a floating
point intensive job (i.e. if the float version takes 2 seconds, the
double version takes 3 seconds).  This is just one data point; your
mileage will vary.

--
Bron Campbell Nelson
bron@sgi.com  or possibly  ..!ames!sgi!bron
These statements are my own, not those of Silicon Graphics.

tarolli@dragon.SGI.COM (Gary Tarolli) (05/01/89)

One thing to remember - even if you declare variables to be float, they are
still passed as doubles and expressions are usually evaulated in double
precision.  To prevent expressions from being done in double prec. except
where necessary, compile with -float.  To pass arguments as floats, use
ANSI templates (see gl.h for examples).  Beware with templates - both
the caller and callee have to be properly compiled with the template for
things to work.

I agree with the previous comment, that the time to do double prec. vs. 
single prec. is probably insignificant compared to the time it takes to
do the memory accesses and conversions.