如何规格化在C#中处理的花车? [英] How are denormalized floats handled in C#?

查看:163
本文介绍了如何规格化在C#中处理的花车?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚看完这篇有关20X-200X速度变慢,你可以在Intel的CPU与非规范化的花车获得引人入胜的文章(浮点数字非常接近0)。

Just read this fascinating article about the 20x-200x slowdowns you can get on Intel CPUs with denormalized floats (floating point numbers very close to 0).

有一个与上证所一个选项,这轮关闭至0,恢复性能都遇到过这样的浮点值时。

There is an option with SSE to round these off to 0, restoring performance when such floating point values are encountered.

如何C#应用程序处理呢?是否有一个选项来启用/禁用 _MM_FLUSH_ZERO

How do C# apps handle this? Is there an option to enable/disable _MM_FLUSH_ZERO?

推荐答案

有没有这样的选择。

在C#应用程序的FPU控制字是由CLR启动时初始化的。改变它不是由框架提供一个选项。即使你试图通过pinvoking改变它 _control87_2()那么它是不会长久;任何异常将导致控制字再次由CLR内部的异常处理执行复位。这是写处理FPU控制字的另一个方面,它允许揭露浮点异常。这也将不利于任何其他托管code表示不会对全局状态进行这样的改变。

The FPU control word in a C# app is initialized by the CLR at startup. Changing it is not an option provided by the framework. Even if you try to change it by pinvoking _control87_2() then it is not going to last long; any exception will cause the control word to be reset again by the exception handling implementation inside the CLR. Which was written to deal with another aspect of the FPU control word, it allows unmasking floating point exceptions. It will also be detrimental to any other managed code that will not expect global state to be changed like that.

由于没有直接控制硬件是一个隐含的限制,当您运行code在虚拟机中。不,这是在所有容易做到的本土code两种,图书馆往往胡作非为时,他们也希望FPU有默认的初始化。特别是除屏蔽标志的问题,用Borland工具创建的DLL有一个诀窍开启例外的,让其他code失败,未写入处理这样的例外。一个极其丑陋的问题要解决,FPU控制字是你能想象的最糟糕的全局变量。

Having no direct control over the hardware is an implied restriction when you run code in a virtual machine. Not that this is at all easy to do in native code either, libraries tend to misbehave when they too expect the FPU to have the default initialization. Particularly a problem with the exception masking flags, DLLs created with Borland tools have a knack for turning exceptions on, making other code fail that isn't written to deal with such an exception. An extremely ugly problem to solve, the FPU control word is the worst possible global variable you can imagine.

这不把你的负担,不要让你的浮点计算就会失控这样的。与非正规数计算几乎总是产生废话结果,如果不从根本上对较小的值,然后从快捷损失显著位数最少。截断值小于2.2E-308到0是由你。是的,不是很实用。也许这是正常的一个程序传送废话结果比正常慢了一点:)

This does put the burden on you to not let your floating point calculations go haywire like this. Calculating with denormals almost always produces nonsense results, if not from the radically small values, then at least from the quick loss of significant digits. Truncating values less than 2.2E-308 to 0 is up to you. Yes, not very practical. Perhaps it is okay for a program to deliver nonsense results a bit slower than normal :)

这篇关于如何规格化在C#中处理的花车?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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