Selecting floating-point options
ARM Compiler supports floating-point arithmetic and floating-point data types in your source code or application. ARM Compiler supports floating-point arithmetic either by using libraries that implement floating-point arithmetic in software, or by using the hardware floating-point registers and instructions that are available on most ARM architecture-based processors.
You can use various options that determine how ARM Compiler generates code for floating-point arithmetic. Depending on your target, you might need to specify one or more of these options to generate floating-point code that correctly uses floating-point hardware or software libraries.
Table 2-5 Options for floating-point selection
||Specify the floating point architecture to the compiler.|
||Specify the floating-point linkage to the compiler.|
||Specify the target architecture to the compiler. This automatically selects the default floating-point architecture.|
||Specify the target processor to the compiler. This automatically selects the default floating-point architecture.|
||Specify the floating-point architecture to the linker.|
Benefits of using floating-point hardware versus software floating-point libraries
Code that uses floating-point hardware is more compact and faster than code that uses software libraries for floating-point arithmetic. But code that uses the floating-point hardware can only be run on processors that have the floating-point hardware. Code that uses software floating-point libraries can also run on ARM processors that do not have floating-point hardware, for example Cortex-M0, and this makes the code more portable. You might also disable floating-point hardware to reduce power consumption.
Enabling and disabling the use of floating-point hardware
By default, ARM Compiler uses the available floating-point hardware that is
based on the target you specify for
-march. However, you can force ARM Compiler to
disable the floating-point hardware. This forces ARM Compiler to use software
floating-point libraries, if available, to perform the floating-point arithmetic in
your source code.
When compiling for AArch64:
- By default, ARM Compiler uses floating-point hardware that is available on the target.
To disable the use of floating-point arithmetic, use the
+nofpextension on the
armclang --target=aarch64-arm-none-eabi -march=armv8-a+nofp
- Software floating-point library for AArch64 is not currently available. Therefore, ARM Compiler does not support floating-point arithmetic in your source code, if you disable floating-point hardware when compiling for AArch64 targets.
Disabling floating-point arithmetic does not disable all the floating-point hardware because the floating-point hardware is also used for Advanced SIMD arithmetic. To disable all Advanced SIMD and floating-point hardware, use the
+nofp+nosimdextension on the
armclang --target=aarch64-arm-none-eabi -march=armv8-a+nofp+nosimd
See the armclang Reference Guide for more information on the -march option.
When compiling for AArch32:
- By default, ARM Compiler uses floating-point hardware that is available on the target, with the exception for ARMv6-M, which does not have any floating-point hardware.
To disable the use of floating-point hardware instructions, use the
armclang --target=arm-arm-none-eabi -march=armv8-a -mfpu=none
On AArch32 targets, using
-mfpu=nonedisables the hardware for both Advanced SIMD and floating-point arithmetic. You can use
-mfputo selectively enable certain hardware features. For example, if you want to use the hardware for Advanced SIMD operations on an ARMv7 architecture-based processor, but not for floating-point arithmetic, then use
armclang --target=arm-arm-none-eabi -march=armv7-a -mfpu=neon
See the armclang Reference Guide for more information on the -mfpu option.
Floating-point linkage refers to how the floating-point arguments are passed to and returned from function calls.
For AArch64, ARM Compiler always uses hardware floating-point registers to pass and return floating-point values. This is called hardware linkage.
For AArch32, ARM Compiler can use hardware linkage or software linkage. When
using software linkage, floating-point values are passed and returned using the
general purpose registers. By default, ARM Compiler uses software linkage. You can
-mfloat-abi option to force hardware linkage or software
Table 2-6 Floating-point linkage for AArch32
|-mfloat-abi value||Linkage||Floating-point operations|
||Hardware linkage. Use floating-point registers. But if
||Use hardware floating-point instructions. But if
||Software linkage. Use general-purpose registers.||Use software libraries without floating-point hardware.|
||Software linkage. Use general-purpose registers.||Use hardware floating-point instructions. But if
Code with hardware linkage can be faster than the same code with software linkage. However, code with software linkage can be more portable because it does not require the hardware floating-point registers. Hardware floating-point is not available on some architectures such as ARMv6-M, or on processors where the floating-point hardware might be powered down for energy efficiency reasons.
See the armclang Reference Guide for more information on the -mfloat-abi option.
NoteAll objects to be linked together must have the same type of linkage. If you link object files that have hardware linkage with object files that have software linkage, then the image might have unpredictable behavior. When linking objects, specify the
namespecifies the correct linkage type and floating-point hardware. This enables the linker to provide diagnostic information if it detects different linkage types.
See the armlink User Guide for more information on how the --fpu option specifies the linkage type and floating-point hardware.