How can I set and restore FPU CTRL registers?

别说谁变了你拦得住时间么 提交于 2019-12-22 07:07:21

问题


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.


回答1:


uses
   SysUtils;

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



回答2:


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.



来源:https://stackoverflow.com/questions/191368/how-can-i-set-and-restore-fpu-ctrl-registers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!