You copied the Doc URL to your clipboard.

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 by using one of the following:

  • Libraries that implement floating-point arithmetic in software.
  • Hardware floating-point registers and instructions that are available on most Arm-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-13 Options for floating-point selection

Option Description
armclang -mfpu Specify the floating-point architecture to the compiler.
armclang -mfloat-abi Specify the floating-point linkage to the compiler.
armclang -march Specify the target architecture to the compiler. This option automatically selects the default floating-point architecture.
armclang -mcpu Specify the target processor to the compiler. This option automatically selects the default floating-point architecture.
armlink --fpu Specify the floating-point architecture to the linker.

To improve performance, the compiler can use floating-point registers instead of the stack. You can disable this feature with the [COMMUNITY] option -mno-implicit-float.

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 run on Arm-based processors that do not have floating-point hardware, for example the Cortex®‑M0 processor. Therefore, using software floating-point libraries 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 -mcpu or -march. However, you can force Arm Compiler to disable the floating-point hardware. Disabling floating-point hardware 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 +nofp extension on the -mcpu or -march options.

    armclang --target=aarch64-arm-none-eabi -march=armv8-a+nofp
  • Software floating-point library for AArch64 is not currently available. Therefore, if you disable floating-point hardware when compiling for AArch64 targets, Arm Compiler does not support floating-point arithmetic in your source code.
  • 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+nosimd extension on the -mcpu or -march options:

    armclang --target=aarch64-arm-none-eabi -march=armv8-a+nofp+nosimd

See the Arm Compiler 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, except for Armv6‑M, which does not have any floating-point hardware.
  • To disable the use of floating-point hardware instructions, use the -mfpu=none option.

    armclang --target=arm-arm-none-eabi -march=armv8-a -mfpu=none
  • On AArch32 targets, using -mfpu=none disables the hardware for both Advanced SIMD and floating-point arithmetic. You can use -mfpu to 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 -mfpu=neon.

    armclang --target=arm-arm-none-eabi -march=armv7-a -mfpu=neon

See the Arm Compiler Reference Guide for more information on the -mfpu option.

Floating-point linkage

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 linkage. When using hardware linkage, Arm Compiler passes and returns floating-point values in hardware floating-point registers.

For AArch32, Arm Compiler can use hardware linkage or software linkage. When using software linkage, Arm Compiler passes and returns floating-point values in general-purpose registers. By default, Arm Compiler uses software linkage. You can use the -mfloat-abi option to force hardware linkage or software linkage.

Table 2-14 Floating-point linkage for AArch32

-mfloat-abi value Linkage Floating-point operations
hard Hardware linkage. Use floating-point registers. But if -mfpu=none is specified for AArch32, then use general-purpose registers. Use hardware floating-point instructions. But if -mfpu=none is specified for AArch32, then use software libraries.
soft Software linkage. Use general-purpose registers. Use software libraries without floating-point hardware.
softfp (This value is the default) Software linkage. Use general-purpose registers. Use hardware floating-point instructions. But if -mfpu=none is specified for AArch32, then use software libraries.

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.

Note

In AArch32 state, if you specify -mfloat-abi=soft, then specifying the -mfpu option does not have an effect.

See the Arm Compiler Reference Guide for more information on the -mfloat-abi option.

Note

All 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 armlink option --fpu=name where name specifies the correct linkage type and floating-point hardware. This option enables the linker to provide diagnostic information if it detects different linkage types.

See the Arm Compiler Reference Guide for more information on how the --fpu option specifies the linkage type and floating-point hardware.

Was this page helpful? Yes No