Cortex-M4 Floating Point Support
Most ARM-based systems have historically not implemented any form of floating point in hardware. This means that any floating point operations contained in your code will be converted into calls to library functions that then implement the required operations in software.
However many Cortex-M4 based MCUs incorporate a single precision floating point hardware unit. Note that not all Cortex-M4 based MCU implement floating point in hardware, so please check the documentation provided by the MCU vendor to confirm if the MCU you are using does.
Also be aware that the optional Cortex-M4 floating point unit implements single precision operations (C/C++ float) only. Thus if your code makes use of double precision floating point (C/C++ double), then any such floating point operations contained in your code will still be converted into calls to library functions that then implement the required operations in software.
Floating Point variants
When a hardware floating point unit is implemented, ARM define that it may be used in one of two modes.
- Single precision floating point operations are implemented in hardware and hence provide a large performance increase over code that uses traditional floating point library calls, but when calls are made between functions any floating point parameters are passed in ARM (integer) registers or on the stack.
- SoftABI is the 'most compatible' as it allows code that is not built with hardware floating point usage enabled to be linked with code that is built using software floating point library calls.
- Single precision floating point operations are implemented in hardware, and floating point registers are used when passing floating point parameters to functions.
HardABI will provide the highest absolute floating point performance, but is the 'least compatible' as it means that all of the code base for a project (including all library code) must be built for HardABI.
Currently Code Red's only provides support for SoftABI usage, and only supplies libraries that use SoftABI. Libraries that support HardABI are planned for implementation in a future release.
When you use a project wizard for a Cortex-M4 where a hardware floating point unit may be implemented, there will be an option to enable the use of the hardware within the wizard's options. Selecting this will make the appropriate changes to the compiler, assembler and linker settings to cause SoftABI code to be generated. It will also enable code within the startup code generated by the wizard that will turn the floating point unit on.
Note though that in some MCU families, some MCUs may not provide hardware floating point, even though most of the members of the family do. Thus it is a good idea to double check the documentation, even if the project wizard in Code Red's IDE for the family that you are targeting suggests that hardware floating point is available.
Please note that even though the project wizard will create Cortex-M4 projects configured to use the SoftABI mode of hardware floating point, it is possible to manually modify the compiler/assembler/linker settings in Project Properties to cause a switch to the use of HardABI mode. This will result in link time errors, as appropriate HardABI library variants are not currently provided by Code Red.