5

So there is an Intel page about what to do about denorms. (BTW, I know exactly what denormals are and am quite familiar with IEEE-754 floating point standard.)

I have two questions:

  1. What are the names of the system calls (in Visual Studio) to turn on these FTZ and DAZ bits so that denorms don't cause exceptions?

  2. What is the difference between the FTZ (Flush to zero) and DAZ (Denorms are zero) bits? is the DAZ bit only one of interpretation?

Are denorms considered so rare that no real estate on the silicon is deemed necessary to deal with them numerically properly? Why is there even an exception for these? (I guess that's a 3rd question.)

1 Answer 1

8

On Windows you can do the following:

#include <mmintrin.h>
#define DISABLE_DENORMALS   \
        int oldMXCSR = _mm_getcsr();        /*read the old MXCSR setting  */    \
        int newMXCSR = oldMXCSR |= 0x8040;  /* set DAZ and FZ bits        */    \
        _mm_setcsr( newMXCSR );             /* write the new MXCSR setting to the MXCSR */

    #define RESTORE_DENORMALS   \
        _mm_setcsr( oldMXCSR );

On Mac (or any Posix system) you can do

#include <fenv.h>
#define DISABLE_DENORMALS   \
    fenv_t fenv;                \
        fegetenv(&fenv);        \
        fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV);

#define RESTORE_DENORMALS   \
        fesetenv(&fenv);

and you can use either one as

processing_function(...)
{
DISABLE_DENORMALS

// signal processing code

RESTORE_DENORMALS
}

Denorms are pretty rare for calculations that don't have feedback; they are pretty degenerate. And you have to remember that they correspond extremely small values. For any calculation that you would actually care about those values not being flushed to zero, you also probably don't care about how efficient the processing is.

Denormals being flushed to zero is the right thing to do for audio; they also do appear more often than one would expect because of the decaying feedback structures that we tend to have in audio algorithms.

FTZ makes it so that the result of your calculation is set to Zero if the result is denormal; it ensures you don't generate denormals.

DAZ makes it so that inputs to your calculation are treated as Zero if they are denormal; it ensures that your calculations don't slow down if the input passed to you contains denormals.

2
  • @robert - I know you care about the efficiency; but generically if you were doing some high-precision calc like a physics simulation, you might rather sacrifice speed for precision. As far as the the meanings of FZ and DAZ -- see my edit.
    – B.J.
    Dec 1, 2016 at 2:37
  • thanx, B.J. ... Dec 1, 2016 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.