Newsgroups: | comp.parallel,comp.arch,comp.compilers |
From: | luigi@paris.CS.Berkeley.EDU (Luigi Semenzato) |
Status: | RO |
Originator: | rmuise@dragon.acadiau.ca |
Organization: | University of California, Berkeley |
References: | <3aqv5k$e27@monalisa.usc.edu> |
Date: | Wed, 23 Nov 1994 22:14:14 GMT |
In article <3aqv5k$e27@monalisa.usc.edu>,
Zhiwei Xu <zxu@monalisa.usc.edu> wrote:
>Can any one explain why a C program using single precision (float) is slower
>that the same code using double precision (double)?
> 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 ) ;
> }
It would have been better if you reported the results,
particularly the system time. A possible explanation is that
when you use floats this code spends a lot of time in the
denormalized exception handler. Denormalized numbers are
a feature of IEEE floating point that insure graceful underflow
for numbers close to zero. They are too expensive to
implement in hardware, so the floating point unit traps and
lets system software handle them. On some systems you can
request to turn this feature off and simply underflow.
In general, though, I would not expect single precision code
to be any faster than double precision. Most floating point
units are optimized for double precision and if you use single
precision at best you will spend extra time in converting between
the two formats. Single precision is used for compactness, not
for speed. ---Luigi
Return to the
comp.compilers page.
Search the
comp.compilers archives again.