Soffloat vs hardfloat

From Tuxamito
Jump to: navigation, search

Many modern ARM v6 CPUs are build with a FPU (floating-pint unit) but GNU/Linux distributors often only prepared soft-float versions (for ARM v7 usually they are build with hard-float support). For this reasons when building applications for the ARM v6 CPUs (such as the s3c6410 in mini6410 or RaspberryPi) we have to consider the base system and the compiler we are using.

According to the GCC Manual (for 4.7) we can set the floating point ABI for the ARM binary code with the flat '-mfloat' which can take the values 'soft', 'softfp' and 'hard':

  • soft: Specifying soft causes GCC to generate output containing library calls for floating-point operations. This means that the fpu operations will be emulated by the integer unit and data stored in the integer registers.
  • softfp: Allows the generation of code using hardware floating-point instructions, but still uses the soft-float calling conventions. In this case the hardware floating point will be used but using the soft ABI, so FP argument calls will use the integer registers, that later have to be copied to the FP registers (this creates a pipeline stall that increases the function overhead). In exchange soft and softfp code can be intermixed.
  • hard: allows generation of floating-point instructions and uses FPU-specific calling conventions. The implication is that FP data arguments are passed directly in the FPU registers. It could be emulated by the kernel in a FPU-less system by capturing the illegal instruction codes.

Note that the hard-float and soft-float ABIs are not link-compatible; you must compile your entire program with the same ABI, and link with a compatible set of libraries.