This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C++: How to use Fused Multiply Add (VFMA)

Hi,
I am writing a PID control loop for STM32F407 (Cortex M4).

Here I use such calculations as:

fPid += fKI * fIntegral;

C++ compiler produces quite nice code, using the VMLA instruction automatically.

Just I would prefer to use the fused version VFMA, to minimize rounding errors.

Is there a way to use VFMA in C++? (I tried the math.h function fma and fmaf, but these functions are recognized only, if I use the define __USE_C99_MATH, and then they are implemented as very cumbersome function invocations including push/pop and much more - NOT using VFMA - which is only 1 assembler command).

PS: According to help file, it seems to be quite straight forward to include inline assembly code also into C++ (although I did not find some destription how to address class variables - but I did not try it yet - perhaps just in the standard C++ writing). Has anyone some hints whether it is easy to mix inline assembly code into C++, using e. g. the standard inline assembly with __asm, or should I better restrict such things as inline assembly to C modules?

  • One further point concerning VFMA (compared to VMLA):

    Googling quite a bit in Internet, I nowhere found some number example, where anybody showed the advantage of the FUSED multiply add.

    Can anybody demonstrate the advantage of VFMA against VMLA with some practical number example? This would be very helpful for me. Otherwise perhaps better, to keep with VMLA (as there are some warnings in Internet, that with VFMA a*a-a*a might create a negative result, crashing on a successive sqrt ...).