Setting the FTZ and DAZ Flags

In Intel® processors, the flush-to-zero (FTZ) and denormals-are-zero (DAZ) flags in the MXCSR register are used to control floating-point calculations. When the FTZ and DAZ flags are enabled, the single instructions and multiple data (SIMD) floating-point computation can be accelerated, thus improving the performance of the application.

You can use the -ftz (Linux* and Mac OS*) or /Qftz (Windows*) option to flush denormal results to zero when the application is in the gradual underflow mode. This option may improve performance if the denormal values are not critical to your application's behavior.

The -ftz or /Qftz option sets or resets the FTZ and the DAZ hardware flags. The following table describes how the compiler process denormal values based on the status of the FTZ and DAZ flags:

Flag

When set to ON, the compiler...

When set to OFF, the compiler...

Supported Architectures

FTZ

Sets denormal results from floating-point calculations to zero.

Does not change the denormal results.

IA-64

Intel® 64

DAZ

Treats denormal values used as input to floating-point instructions as zero.

Does not change the denormal instruction inputs.

Intel® 64

Options -ftz and /Qftz are performance options. Setting these options does not guarantee that all denormals in a program are flushed to zero. They only cause denormals generated at run time to be flushed to zero.

When -ftz or /Qftz is used in combination with an SSE-enabling option on systems based on the IA-32 architecture (for example, xW or QxW), the compiler will insert code in the main routine to set FTZ and DAZ. When -ftz or /Qftz is used without such an option, the compiler will insert code to conditionally set FTZ/DAZ based on a run-time processor check. -no-ftz (Linux and Mac OS) or /Qftz- (Windows) will prevent the compiler from inserting any code that might set FTZ or DAZ.

The -ftz or /Qftz option only has an effect when the main program is being compiled. It sets the FTZ/DAZ mode for the process. The initial thread and any threads subsequently created by that process will operate in the FTZ/DAZ mode.

On systems based on the IA-64 architecture, optimization option O3 sets -ftz and /Qftz; optimization option O2 sets -no-ftz (Linux) and /Qftz- (Windows). On systems based on the IA-32 and Intel® 64 architectures, every optimization option O level, except O0, sets -ftz and /Qftz.

If this option produces undesirable results of the numerical behavior of your program, you can turn the FTZ/DAZ mode off by using -no-ftz or /Qftz- in the command line while still benefiting from the O3 optimizations.

For some non-Intel processors, you can set the flags manually with the following macros:

Feature

Examples

Enable FTZ

_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON)

Enable DAZ

_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON)

The prototypes for these macros are in xmmintrin.h (FTZ) and pmmintrin.h (DAZ).

See Also