[LAD] Is -ffast-math safe for audio?

Hermann Meyer brummer- at web.de
Thu Nov 22 21:27:58 CET 2018

Am 22.11.18 um 21:07 schrieb Fons Adriaensen:
> On Thu, Nov 22, 2018 at 06:57:15PM +0100, Hermann Meyer wrote:
>> Am 22.11.18 um 18:30 schrieb Will Godfrey:
>>> While testing some mixed floating point and integer calculations I found a
>>> quite surprising difference when this compiler option was set (gcc 6.x). It was
>>> clearly different at only 100 iterations and got dramatically worse with
>>> larger counts.
>>> ...
>> In the guitarix project we've disabled  -ffast-math several years ago, when
>> I remember right it was at gcc3, as it could lead to different
>> un-reproduciable calculations. Last option I've disabled on gcc8 now, is
>> -ffinite-math-only, this one leads to nan's and inf's in several cases,
>> which been as well not reproducible.
> -ffast-math should be perfectly OK for any normal audio DSP code.
> The only use case where I'd consider not using it is for precision
> measurement applications.
> If using it leads to unexpected results that means that the algorithm
> used is itself numerically unstable. A classic example of this is the
> 'biquad' and similar structures when used for filters that operate
> mainly on low frequencies. Unfortunately, that sort of code is
> everywhere, cut and pasted from one bad example to the next.
> Strange that this turns up right now. Earlier today I was implementing
> an IIR filter originally designed in MatLab which uses doubles for
> everything. When the coefficients were truncated to 32-bit floats,
> the filter became unstable. This doesn't mean that such a filter
> needs double precision. It just indicates bad design.
> Ciao,

In guitarix nearly all DSP is generated by FAUST.

However, problems with NAN's and INF's when use -ffinite-math-only 
occurs only when we save preset values to file, and only sometimes then. 
Without  -ffinite-math-only never ever.

More information about the Linux-audio-dev mailing list