[LAD] Floating point Denormals: C++ and Waf

Martin Homuth-Rosemann linuxaudio at cryptomys.de
Thu Aug 2 12:39:51 UTC 2012


Hi,

that's my solution regardless of CPU type:

//
// DENORMALS ARE EVIL
//
// 32 bit float
// SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM
// E = 0, M != 0 -> denormal
// processing denormals uses lot of cpu.
// problem: an IIR feeds back 0.7*y.
// a value > 0 will decay until the smallest float is reached:
// 00000000000000000000000000000001
// multiplying with 0.7 and rounding (to nearest, default) gives again:
// 00000000000000000000000000000001
// this value circulates forever and consumes lot of cpu cycles :(
// even with "round to zero" - set in main() -
// it takes about 5 seconds until the denorm fades to zero...
//
// solution:
// "it's better to burn out than to fade away"
//
// denormals are zero
static inline float daz( float f )
{
  // define an aliasing type to perform a "reinterpret cast"
  typedef __u32 __attribute__ (( __may_alias__ )) u32bit;
  if ( *( (u32bit*)&f ) & 0x7F000000 ) // E > 1 : normal.
    return f;
  else // E <= 1 : zero or _almost_ denormal 
       // (may become denormal with next operation)
    return 0.0;
} 

Ciao, Martin
-- 
View this message in context: http://old.nabble.com/Floating-point-Denormals%3A-C%2B%2B-and-Waf-tp34245224p34245359.html
Sent from the linux-audio-dev mailing list archive at Nabble.com.




More information about the Linux-audio-dev mailing list