gnucap-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnucap-devel] floating point optimization


From: al davis
Subject: Re: [Gnucap-devel] floating point optimization
Date: Thu, 7 Dec 2006 18:00:21 -0500
User-agent: KMail/1.9.5

In case anyone wants to try it, here is the source for the 
plug-in that forces 64 bit math on an Intel processor:
============================
// "ieee-math.cc"
/*
  This puts the X86 FPU in 64-bit precision mode.  The default
  under Linux is to use 80-bit mode, which produces subtle
  differences from FreeBSD and other systems, eg,
  (int)(1000*atof("0.3")) is 300 in 64-bit mode, 299 in 80-bit
  mode.
*/

#include <fpu_control.h>

class IEEE_MATH {
  fpu_control_t old_cw;
public:
  IEEE_MATH() {
    fpu_control_t cw;
    _FPU_GETCW(cw);
    old_cw = cw;
    cw &= ~_FPU_EXTENDED;
    cw |= _FPU_DOUBLE;
    _FPU_SETCW(cw);
  }
  ~IEEE_MATH() {
    _FPU_SETCW(old_cw);
  }    
};

static IEEE_MATH x;
============================

To use it: 
Compile with "-fPIC -shared" options:
"g++ -PIC -shared ieee-math.cc -o ieee-math.so"

Run gnucap, when inside load it:
gnucap> attach ./ieee-math.so

Note that the file name must have a slash in it.  It can be a 
local or full path name.  Without a slash it will use 
LD_LIBRARY_PATH to find it.

If you want it to always load, make a file ".gnucaprc" in your 
home directory, and put the attach command (with a dot) there.

You can revert to full 80 bit precision by detaching it:
gnucap> detach  ./ieee-math.so

Question for all:
On an intel processor, what should be the default:
( ) 64 bit IEEE compliant math
( ) mixed 64 and 80 bit math







reply via email to

[Prev in Thread] Current Thread [Next in Thread]