May 13, 2016

[c][c++] Denormal_number

why-does-changing-0-1f-to-0-slow-down-performance-by-10x

reference:
Denormal_number

How-to: Flushing denormalised numbers to zero


//warning these macros has to be used in the same scope
#define MXCSR_SET_DAZ_AND_FTZ \
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 MXCSR_RESET_DAZ_AND_FTZ \
/*restore old MXCSR settings to turn denormals back on if they were on*/ \
_mm_setcsr( oldMXCSR__ ); 

To flush denormals locally:
const Float32 k_DENORMAL_DC = 1e-25f;
inline void FlushDenormalToZero(Float32& ioFloat) 
{ 
    ioFloat += k_DENORMAL_DC;
    ioFloat -= k_DENORMAL_DC;    
} 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.