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

From: Martin Homuth-Rosemann <linuxaudio@email-addr-hidden>
Date: Thu Aug 02 2012 - 15:39:51 EEST

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.
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Thu Aug 2 16:15:03 2012

This archive was generated by hypermail 2.1.8 : Thu Aug 02 2012 - 16:15:03 EEST