• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: long double data type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: long double data type


  • Subject: Re: long double data type
  • From: "Paul Sanders" <email@hidden>
  • Date: Tue, 15 Jun 2010 23:50:28 +0100

I did a few simple tests from the command line.  I also took a glance at the object code generated (on Intel) and measured a few things.  This is what I found, using gcc 4.2 and no special command-line switches:
 
  - sizeof (long double) = 16 = 128 bits, as already reported by Luigi
 
  - arithmetic on doubles uses (scalar) SSE instructions for a simple add-and-store, but uses the 'traditional' 8087  instructions for a
    more complex _expression_, presumably to preserve 80 bits of precision in the intermediate results (which I like)
 
  - arithmetic on long doubles also uses traditional 8087 instructions and stores 80 bit / 10 byte values to memory (left-aligned in 16 bytes) rather than 64 bits
 
  - no software emulation is used for long doubles (which is no loss IMO - it would be too slow for DSP anyway)
 
According to my ancient 486 programmer's reference manual:
    Single (32 bit): 24 bit mantissa, 8 bit exponent
    Double (64 bit): 53 bit mantissa, 11 bit exponent
    Extended (80 bit): 64 bit mantissa, 15 bit exponent
 
So the extra precision offered by long doubles on Intel is significant.
 
According to my (very simple) timings, arithmetic on long doubles is no slower than arithmetic on doubles (which is what you would expect, given that the code generated is very similar) but it does double the size of all your arrays, which in turn hits the CPU cache.  My own experience of this (using floats vs doubles in an 8192 byte FFT) is that it makes a noticeable but not startling difference.  But as they say, memory is the new I/O.  Perhaps store any temporaries as long doubles but keep your arrays as doubles.  In any case, it pays to experiment.  Performance gains (or losses) can come from unexpected places.  Failure to 8-byte align your doubles is a famous one on x86, but I think gcc handles this in most cases.
 
I noticed that oddity in the AIFF spec too.  It is a little strange.  Tricky to handle if you're not on Intel.
 
Regards,
 
Paul Sanders.
 
----- Original Message -----
From: Richard Dobson
To: email@hidden
Sent: Tuesday, June 15, 2010 11:05 PM
Subject: Re: long double data type

there is a 128bit IEEE standard, summarised here:
http://en.wikipedia.org/wiki/Quadruple_precision_floating-point_format

Note that long double = 128bits  is not universally supported yet, so
use of it is not as portable as you might wish. Also note it tends to
depend on software emulation, so if you ~can~ arrange your dsp to manage
with native 64bit types, it will clearly be advantageous to do so. There
will remain some curiosity on this list as to what you are doing for
which 64bits are insufficient.

The only explicit use of 80 bit floats I am aware of is, curiously
enough, in the AIFF spec where it is used, more than a little
extravagantly, for the sample rate.

Richard Dobson
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: long double data type
      • From: Dominik Peklo <email@hidden>
References: 
 >Re: long double data type (From: Luigi Castelli <email@hidden>)
 >Re: long double data type (From: Richard Dobson <email@hidden>)

  • Prev by Date: Re: long double data type
  • Next by Date: Re: long double data type
  • Previous by thread: Re: long double data type
  • Next by thread: Re: long double data type
  • Index(es):
    • Date
    • Thread