Re: C performance

From: Jack Klein (jackklein_at_spamcop.net)
Date: 05/18/04


Date: Tue, 18 May 2004 00:36:53 -0500

On Tue, 18 May 2004 05:10:46 GMT, "Tim Prince" <tprince@computer.org>
wrote in comp.lang.c:

>
> "Stephen Sprunk" <stephen@sprunk.org> wrote in message
> news:160cd1ac7038464cae4be2010b9ab537@news.teranews.com...
> > "Chris Torek" <nospam@torek.net> wrote in message
> > news:c8ar0u12ddv@news3.newsguy.com...
> > > It its probably worth noting that the hardware architecture with
> > > which most people are familiar -- the Intel IA32 -- is one of
> > > these. All of its calculations use "long double" internally
> > > (assuming, of course, that your C compiler maps "long double"
> > > onto this 80-bit internal format!).
> > >
> > > The IA32 does have a "precision" field in its FPU control word,
> > > but this does not work in quite the same way as actually converting
> > > the final result down to the 32 or 64 bit "memory format" for float
> > > and double. In particular, setting the precision to "float" causes
> > > mantissa rounding, but leaves the exponent range +/- 16383 instead
> > > of +/- 127. In other words, the internal format is as if you had
> > > 39 bits to work with, instead of the "expected" 32. This means
> > > that infinities and NaNs do not occur when one might expect them.
> >
> > These "problems" go away when switching to SSE[12] for FP, right?
> >
> > My understanding is that the SSE unit only has 32-bit floats and 64-bit
> > doubles, and the x87 unit is still used for long doubles (but nothing
> else).
> > This is why I was curious about promotion of floats to doubles and back to
> > floats -- that seems like it would seriously mess up the SSE registers.
> >
> In SSE/SSE2 code, there's no implicit promotion of float to double.
> "Vector" parallel code requires going through memory to cast between float
> and double. In Windows, there's no support for long double wider than
> double. The Windows-64 ABI doesn't even support use of the x87
> instructions, although the influence of Kahan may live on in the linux ABI.

It is quite inaccurate to say that there is no support in Windows for
long double wider than double. Microsoft made a marketing decision to
deprive programmers using their compiler of the full potential of the
x86 coprocessor/FPU. This has the effect of seriously reducing the
accuracy of many types of scientific and engineering programs
developed with their compiler.

On the other hand, GCC, lcc-win32, Borland, and probably others,
support 80 bit long doubles very will in Windows.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html


Relevant Pages

  • Re: When to use float (in teaching)
    ... the Turing Award in 1989 for his work on floating-point computations, ... initially floats or doubles. ... transferred to said hardware. ...
    (comp.lang.java.programmer)
  • Re: Now everyone has had a good old laugh...
    ... Nice airplane too bad the floats aren't registered ... promotion I am surprised that they would want that kind of promotion. ... tricycle gear so the retrofit floats manufacturer is not identified, ...
    (rec.photo.equipment.35mm)
  • Re: Rounding by prayer?
    ... John Harrison wrote: ... > You should normally use doubles. ... So the only reason to use floats is to save space, ...
    (comp.lang.cpp)
  • Re: float, double and decimal
    ... floats and doubles - like a wrapper around floats and doubles. ... Double is an approximated format; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: why float
    ... Modern CPUs are geared up for 64-bit floating point operations, so other operations involve converting at the start and the end, I believe. ... With that in mind it would be quite surprising if there would be any huge difference in performance between floats and doubles. ... A single calculation would be faster when using double, ...
    (microsoft.public.dotnet.languages.csharp)