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.