Saturday, September 1, 2018

Floating point on ARM

What's that "funny clicking noise"?  Floating point denormalization seems to be the culprit.
The RPi3B has hardware floating point which is enabled with the GCC incantation:
    CFLAGS=-mcpu=cortex-a53 -mfpu=crypto-neon-fp-armv8 -mfloat-abi=hard -funsafe-math-optimizations

All the above is a bit misleading.  /proc/cpuinfo thinks the CPU is ARMv7 but the feature flags show ARMv8 neon float support.  Hardware float support certainly improves performance, but noise is most unwelcome.  I think it's due to the "unsafe-math-optimizations" which were needed for older versions of the RPi.  The Cortex-A53 does not need this and GCC will use the FPU hardware if told correctly.

    processor       : 0
    model name      : ARMv7 Processor rev 4 (v7l)
    BogoMIPS        : 38.40
    Features        : half thumb fastmult vfp edsp neon vfpv3 tls                          vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
    CPU implementer : 0x41
    CPU architecture: 7
    CPU variant     : 0x0
    CPU part        : 0xd03
    CPU revision    : 4

The "unsafe-math-optimizations" is the interesting part.  This was necessary for older ARM processors.  Now it is no longer needed, and causes issues.  According to the ARM Cortex-A Series Programmer's Guide (PDF), "Support is provided in AArch64 NEON for double-precision floating-point and full IEEE754 operation including rounding modes, denormalized numbers, and NaN handling."   This means that the unsafe optimizations are not needed.  Time to recompile Ardour without that flag and listen to see if the clicking noise is gone.  GCC 6.4 only needs the -mcpu=cortex-a53 -mfpu=crypto-neon-fp-armv8 -mfloat-abi=hard flags.  I am happy to report that ardour is not adding the clicking/popping noise with this setting.

I also recompiled the Calf studio plugins with the same flags.  With the unsafe-math-optimizations, the snapping and popping was noticeable.   Now they are blissfully silent.