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

weaver@weitek.COM (Michael Gordon Weaver)
Wed, 23 Nov 1994 19:18:03 GMT

          From comp.compilers

Related articles
Why is using single-precision slower than using double-precision zxu@monalisa.usc.edu (1994-11-23)
Re: Why is using single-precision slower than using double-precision weaver@weitek.COM (1994-11-23)
Re: Why is using single-precision slower than using double-precision meissner@osf.org (1994-11-23)
Re: Why is using single-precision slower than using double-precision scott@cs.arizona.edu (1994-11-23)
Re: Why is using single-precision slower than using double-precision joelw@convex.convex.com (1994-11-23)
Re: Why is using single-precision slower than using double-precision koppel@omega.ee.lsu.edu (1994-11-23)
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)
[11 later articles]
| List of all articles for this month |

Newsgroups: comp.arch,comp.compilers
From: weaver@weitek.COM (Michael Gordon Weaver)
Followup-To: comp.compilers
Keywords: C, optimize
Organization: WEITEK Corporation, Sunnyvale CA
References: <3aqv5k$e27@monalisa.usc.edu>
Date: Wed, 23 Nov 1994 19:18:03 GMT

zxu@monalisa.usc.edu (Zhiwei Xu) writes:
[why does this run slower with floats than with doubles?]
[ 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 ) ;
> }
>


I believe that on the machines you mention, double operations should be about
the same speed as float.


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.


It seems that the floating point constants are being treated the same way
double variables would be, regardless of the -fsingle option. 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.


Michael.
--


Post a followup to this message

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