On Fri, Aug 20, 2010 at 9:26 PM, Dr. David Kirkby
<david.kir...@onetel.net> wrote:
> Unless OS X rounds by default to 64-bits, I can't understand how this would
> have ever worked. Why was it not necessary to change the rounding behavior
> of an Intel based OS X system?

Modern x86 family chips actually have two totally separate
floating-point units (at least logically, I don't know if they share
hardware).  The older uses the "x87" instructions, dating back to the
8087; this rounds to 80 bits by default.  SYMPOW's fpu.c changes the
x87 instructions to round to 64 bits.  The newer is the SSE/SSE2
floating-point unit (SSE only had single-precision floating point,
SSE2 extended this to double precision); this rounds to 64 bits (or 32
bits for single-precision instructions).

In general, SSE2 is faster than x87 (partly because SSE2 has a real
register-based instruction set, instead of x87's mostly stack-based
instruction set); so people prefer to generate SSE2 code whenever the
option is available.

Debian's gcc for 32-bit x86 defaults to generating x87 code, because
Debian supports 80486 and up and SSE2 code wouldn't work on such old
chips.  Debian's gcc for 64-bit x86 defaults to SSE/SSE2, because all
64-bit x86 processors have SSE2, so there are no
backward-compatibility issues to worry about.

I don't know what defaults gcc has if you compile it from upstream
source, but I suspect the behavior may match the default Debian
behavior I described in the previous paragraph.

So on Debian (and any similarly configured systems), fpu.c would be
necessary for 32-bit x86 but not 64-bit x86.

I checked on bsd.math, and there gcc uses SSE2 by default (mulsd is an
SSE2 instruction):

bsd:tmp cwitty$ cat testfpu.c
double prod(double a, double b) {
  return a*b;
}
bsd:tmp cwitty$ gcc -O2 -S testfpu.c
bsd:tmp cwitty$ grep mulsd testfpu.s
        mulsd   %xmm1, %xmm0

as opposed to my Debian 32-bit x86 system that uses x87 by default
(fmull is an x87 instruction):

cwi...@magnetar:/tmp$ grep fmull testfpu.s
        fmull   8(%ebp)

My guess is that OSX does not target pre-SSE2 processors, so they were
able to safely change their gcc default.

(technical nit: "round to 64 bits" isn't quite correct; better would
be "rounds to the precision of the standard 64-bit IEEE754 floating
point type", which actually has a 53-bit mantissa.)

Carl

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to