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

Hermann Meyer brummer- at web.de
Thu Nov 22 18:57:15 CET 2018


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.
>
> My test routine was this:
>
> int a = 0;
> float b = 0;
> float c = 0;
> float inc = 0.1f;
> float dec = 0.05f;
> int it = 100;
> for (int i = 0; i < it; ++ i)
> {
>      a = (int)truncf(b);
>      c = b - floorf(b);
>      b += inc;
>      a = (int)truncf(b);
>      c = b - floorf(b);
>      b -= dec;
> }
>
> cout << "int " << a << "  rem " << c << endl;
>
> My suspicion is that the difference is due to accumulated rounding errors.
>
> Curiously without the decrements the behavior with and without -ffast-math
> seems to be identical well into the millions.
>

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.linuxaudio.org/archives/linux-audio-dev/attachments/20181122/0219bacd/attachment.html>


More information about the Linux-audio-dev mailing list