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

Robin Gareus robin at gareus.org
Thu Aug 2 12:19:51 UTC 2012


On 08/02/2012 02:06 PM, Harry van Haaren wrote:
> Hi all,
> 
> I've working on a LV2 instrument plugin, and it consumes about 1-2% CPU on
> idle. When I leave it for about 20 seconds, the CPU usage jumps to 38 / 40
> % of a core, and JACK xruns. The code contains IIR's for a reverb effect,
> so I'm going to blame this CPU burning on denormal values.
> 
> I'm using waf as the build system, and appending "-O3" and "-ffast-math" to
> the CFLAGS and CXXFLAGS. Building with ./waf -v shows the runner thread to
> have the "-O3" and "-ffast-math" in the command.
> Yet when I run it it still hogs CPU after about 10-20 seconds.
> 
> Reading on gcc's pages (http://www.acsu.buffalo.edu/~charngda/cc.html) tells
> me that if DenomalsAreZero and FlushToZero are set, it should be linked
> with crtfastmath.o. I don't know how to check if this is happening?
>

Hi Harry,

IIRC those CPU/Compiler FlushToZero workarounds only work with SSE. try
adding `-msse -mfpmath=sse` to the CFLAGS.

> I'm not sure where to look next to fix the problem. Help appreciated!
> -Harry

Simply add a small value to the every input sample (before it enters the
IR or filter stage).  -- Small being around (1e-20).

Alternatively you could use some "if" clauses

#define DENORMALTOZERO(x) \
   if (((*(unsigned int *) &(x)) & 0x7f800000) == 0) x = 0;
#define SMALLVALUETOZERO(x) \
   if (x < 1e-30) x = 0;

More info is at http://carlh.net/plugins/denormals.php

HTH,
robin



More information about the Linux-audio-dev mailing list