Search code examples
stm32stm32cubeide

GNU support for extended inline assembler for cortex m7 double precision FPU


The GCC suite of programs provides an extended inline assembler constraint for single precision FPU code for Cortex M4 & M7 MPUs, so it is straightforward to code a check of FPU performance.

However this facility is not available for double precision FPUs (as available with Cortex M7) and extra coding is required. Is anyone aware of whether GNU is working on the provision of such a facility?


Solution

  • My main problem was being able to output a double return from my inline assembler. In the absence of the compiler recognising a double constraint (which GNU documents clearly as not being available on Thumb instructions) there was no apparent way of achieving this. However by inspecting the emitted assembler for double returning functions, I noticed that the compiler ALWAYS moves the D7 register to the D0 register (as one of its last instructions) and D0 is of course a function's output register by convention. So I modified my code to use the D7 register to store my returned double and, it works!

    Subsequent to the above, Nate Eldridge drew my attention to an undocumented GCC modifier (%P) in association with the (documented but not supposed to work with THUMB instructions) "w" constraint. The double precision code now works. Interestingly, when using the %P modifier the compiler emits D7 as its choice of register for the DP arithmetic; the subsequent move of D7 to D0 remains, but this time to good effect.