如何设置和恢复FPU CTRL寄存器?寄存器、如何设置、FPU、CTRL

由网友(阶下囚)分享简介:我可以重新设置FPU的CTRL登记本:http://support.microsoft.com/kb/326219 但我怎么能保存当前的寄存器,并在以后恢复他们?这是一个从.NET code .. 我在做什么,是从德尔福调用一个.NET的DLL作为一个COM模块。检查控制在Delphi中产生一个值,与controlf...

我可以重新设置FPU的CTRL登记本:

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

但我怎么能保存当前的寄存器,并在以后恢复他们?

这是一个从.NET code ..

我在做什么,是从德尔福调用一个.NET的DLL作为一个COM模块。检查控制在Delphi中产生一个值,与controlfp在.NET code检查提供了另一个值寄存器。 我需要的,是重要的是要做到这一点:

  _controlfp(_CW_DEFAULT,的0xFFFFF);
 

所以,我的浮点计算在.NET code不会崩溃,但我想恢复控制寄存器返回时。

也许我不?在需要的时候也许德尔福重置呢? 我的博客上讲述这个问题这里。

解决方案

 用途
   SysUtils单元;

变种
   SavedCW:字;
开始
   SavedCW:= Get8087CW;
   尝试
     Set8087CW($ 027f);
     //调用.NET code在这里
   最后
     Set8087CW(SavedCW);
   结束;
结束;
 
sai按ctrl t后怎么还原

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.

解决方案

uses
   SysUtils;

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

阅读全文

相关推荐

最新文章