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) |
Re: Why is using single-precision slower than using double-precision davidm@Rational.COM (1994-11-23) |
[10 later articles] |
Newsgroups: | comp.parallel,comp.arch,comp.compilers |
From: | meissner@osf.org (Michael Meissner) |
In-Reply-To: | zxu@monalisa.usc.edu's message of Wed, 23 Nov 1994 00:38:40 GMT |
Status: | R |
Originator: | rmuise@dragon.acadiau.ca |
Organization: | Open Software Foundation |
References: | <3aqv5k$e27@monalisa.usc.edu> |
Date: | Wed, 23 Nov 1994 21:47:24 GMT |
In article <3aqv5k$e27@monalisa.usc.edu> zxu@monalisa.usc.edu (Zhiwei Xu) writes:
| Can any one explain why a C program using single precision (float) is slower
| that the same code using double precision (double)? Please try the following
| code for computing pi. I have tried it on IBM RS6000/250, IBM SP2, Sun4, and
| Sun SS20, and got the same strange timing.
You use constants in your calculations:
local = ( ((double) i) - 0.5 ) * w ;
pi = pi + 4.0 / ( 1.0 + local * local ) ;
The ISO C standard says that without the proper suffix, constants are
automatically assumed to be double precision. This means that on systems where
you evaluate floating point in the precision specified, you have to add
conversions from single precision to double precision and then back to single
precision.
On the 486 I use at work on the other hand, I see no appreciable difference in
speed. The reason is that the x86 family calculates everything in extended
double precision, and the instructions automatically convert from single and
double precisions into extended double when the value is moved from memory to
the register stack.
If you change your code to:
local = ( ((double) i) - (double)0.5 ) * w ;
pi = pi + (double)4.0 / ( (double)1.0 + local * local ) ;
Any reasonable compiler will not need the extra conversions. If a compiler
can't be bothered to fold a cast of a floating point constant at compile time,
you surely have move serious things to worry about.
--
Michael Meissner email: meissner@osf.org phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
Old hackers never die, their bugs just increase.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.