Re: Why is using single-precision slower than using double-precision

dik@cwi.nl (Dik T. Winter)
Thu, 24 Nov 1994 03:05:54 GMT

          From comp.compilers

Related articles
[6 earlier articles]
Re: Why is using single-precision slower than using double-precision bevan@cs.man.ac.uk (1994-11-23)
Re: Why is using single-precision slower than using double-precision luigi@paris.CS.Berkeley.EDU (1994-11-23)
Re: Why is using single-precision slower than using double-precision davidm@Rational.COM (1994-11-23)
Re: Why is using single-precision slower than using double-precision dsmentek@hpfcla.fc.hp.com (1994-11-23)
Re: Why is using single-precision slower than using double-precision trobey@taos.arc.unm.edu (1994-11-23)
Re: Why is using single-precision slower than using double-precision kenneta@hubcap.clemson.edu (1994-11-23)
Re: Why is using single-precision slower than using double-precision dik@cwi.nl (1994-11-24)
Re: Why is using single-precision slower than using double-precision davidc@panix.com (David B. Chorlian) (1994-11-24)
Re: Why is using single-precision slower than using double-precision roedy@BIX.com (1994-11-30)
Re: Why is using single-precision slower than using double-precision tgl@netcom.com (1994-11-30)
Re: Why is using single-precision slower than using double-precision hebert@prism.uvsq.fr (1994-11-24)
Re: Why is using single-precision slower than using double-precision dekker@dutiag.twi.tudelft.nl (Rene Dekker) (1994-11-30)
Re: Why is using single-precision slower than using double-precision meissner@osf.org (1994-11-24)
| List of all articles for this month |
Newsgroups: comp.compilers
From: dik@cwi.nl (Dik T. Winter)
Keywords: C, optimize
Organization: CWI, Amsterdam
References: <3aqv5k$e27@monalisa.usc.edu> 94-11-147
Date: Thu, 24 Nov 1994 03:05:54 GMT

  zxu@monalisa.usc.edu (Zhiwei Xu) writes:
  [ deleted ... except for inner loop: ]
  > w = 1.0 / (double) N ;
  > for(i=1;i<=N;i=i+1) {
  > local = ( ((double) i) - 0.5 ) * w ;
  > pi = pi + 4.0 / ( 1.0 + local * local ) ;
  > }
  >


weaver@weitek.COM (Michael Gordon Weaver) writes:
> I believe that on the machines you mention, double operations should be about
> the same speed as float.


No, on the RS6000 (and so also the SP2) single is in general slower than
double. On the Sparc they are about the same time.
  >
  > I investigated this on my workstation (Sun4), by looking at the assembly
  > and found that:
  > 1. the constants (0.5, 4.0, 1.0) were stored as double
  > 2. in the expressions, the float variables were converted
  > to double, rather than the constants being converted
  > to single.


And this is the key for Sparc. C mandates that in expressions conversions
are performed to some common type before calculation. So, when you write
        local = ( ((double) i) - 0.5) * w;
i is converted to double (that is what the program says), 0.5 is a double
constant (according to the standard), the result is a double, so one
operand of * is double and the other has to be converted to double (again
according to the standard), finally the result of the multiplication is
transformed to single.


  > I was able
  > the 'correct' code by replacing the constants (0.5,4.0,1.0) with
  > (0.5f,4.0f,1.0f), respectively. Then the program ran about the same speed
  > as the original, all double version.
  >
Did you also change "(double) i" to "(float) i"?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
home: bovenover 215, 1025 jn amsterdam, nederland; e-mail: dik@cwi.nl
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.