Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting denormal flush to zero (FTZ) in XCode

I'm using XCode to develop in C++ on OS X Mountain Lion, to run on the local machine. I'm having performance issues relating to denormal numbers and I wish to set the FTZ flag so that they will be flushed to zero. (I have checked that denormals are indeed the problem, and flushing them to zero will not cause accuracy issues in my case.) However, I can't find any information about how I should actually achieve this in XCode. Is it an option I can change in the build settings? Or some code I should type somewhere? Any help would be much appreciated.

like image 892
N. Virgo Avatar asked May 25 '13 07:05

N. Virgo


1 Answers

If I understand the comments in "/usr/include/fenv.h" correctly,

#include <fenv.h>
fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV);

should do what you want.

    FE_DFL_DISABLE_SSE_DENORMS_ENV

    A pointer to a fenv_t object with the default floating-point state modifed
    to set the DAZ and FZ bits in the SSE status/control register.  When using
    this environment, denormals encountered by SSE based calculation (which
    normally should be all single and double precision scalar floating point
    calculations, and all SSE/SSE2/SSE3 computation) will be treated as zero.
    Calculation results that are denormals will also be truncated to zero.

Setting this option reduced the running time of the program in Why does changing 0.1f to 0 slow down performance by 10x? (link given by @Mysticial in his comment) from 27 seconds to 0.3 seconds (MacBook Pro, 2.5 GHz Intel Core 2 Duo).

like image 81
Martin R Avatar answered Oct 24 '22 06:10

Martin R