How are denormalized floats handled in C #?

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

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

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

+45
performance c # sse intel
Apr 07 '14 at
source share
1 answer

There is no such option.

The FPU control word in a C # application is initialized by the CLR at startup. Changing this parameter is not an option provided by the infrastructure. Even if you try to change it by creating _control87_2 () , it will not last long; any exception will cause the control word to be reset again by handling the exception handling inside the CLR. What was written to address another aspect of the FPU control word is that it exposes floating point exceptions. This will also be detrimental to any other managed code that will not expect a global state change.

Without direct control of the equipment, it implies a restriction when running code on a virtual machine. Not that it was easy to do this in native code either, libraries are generally mistaken when they also expect FPUs to get initialized by default. In particular, a problem with exception masking flags, a DLL created using Borland tools has the ability to turn exceptions, which leads to the failure of other code that is not written to handle such an exception. An extremely ugly problem to solve, the FPU control word is the worst possible global variable you can imagine.

This puts a burden on you to prevent your floating point calculations from going the way it is. Computing with denormals almost always leads to meaningless results, if not for radically small values, then at least from the rapid loss of significant numbers. Truncating values ​​less than 2.2E-308 to 0 is up to you. Yes, not very practical. Perhaps this is normal for the program to deliver meaningless results a little slower than usual :)

+43
Apr 07 '14 at 2:56
source share



All Articles