5

I can reset FPU's CTRL registers with this:

http://support.microsoft.com/kb/326219

But how can I save current registers, and restore them later?

It's from .net code..

What I'm doing, is from Delphi calling an .net dll as an COM module. Checking the Ctrl registers in delphi yield one value, checking with controlfp in the .net code gives another value. What I need, is in essential is to do this:

_controlfp(_CW_DEFAULT, 0xfffff); 

So my floatingpoint calculations in the .net code does not crash, but I want to restore the Ctrl registers when returning.

Maybe I don't? Maybe Delphi is resetting them when needed? I blogged about this problem here.

2 Answers 2

7
uses
   SysUtils;

var
   SavedCW: Word;
begin
   SavedCW := Get8087CW;
   try
     Set8087CW($027f);
     // Call .NET code here
   finally
     Set8087CW(SavedCW);
   end;
end;
0
5

Same function you use to change them: _controlfp(). If you pass in a mask of 0, the current value won't be altered, but it will be returned - save it, and use a second call to _controlfp() to restore it later.

2
  • good idea, the problem is that I did not understand what to put in the mask etc, but the delphi method Set8087CW abowe was very nice.
    – neslekkiM
    Oct 14, 2008 at 14:43
  • Yeah... You hadn't mentioned you were using Delphi, so i assumed C/C++.
    – Shog9
    Oct 14, 2008 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.