如何设置和恢复FPU CTRL寄存器? [英] How can I set and restore FPU CTRL registers?

查看:570
本文介绍了如何设置和恢复FPU CTRL寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过以下方式重置FPU的CTRL寄存器:



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



但是如何保存当前的寄存器,然后再恢复? p>

来自.net代码..



我在做什么,是从Delphi调用.net dll一个COM模块。检查delphi中的 Ctrl 寄存器产生一个值,检查.net代码中的controlfp是否提供另一个值。
我需要的是,必须做到这一点:

  _controlfp(_CW_DEFAULT,0xfffff); 

所以我的.net代码中的浮点计算不会崩溃,但是我想恢复 Ctrl 返回时注册。



也许我没有? Delphi可能需要时重置它们?
我发表了关于这个问题的文章 here

 使用
SysUtils;

var
SavedCW:Word;
begin
SavedCW:= Get8087CW;
try
Set8087CW($ 027f);
//调用.NET代码
finally
Set8087CW(SavedCW);
结束
结束


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;

这篇关于如何设置和恢复FPU CTRL寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆