4.42 Example of hardware and software support differences for floating-point arithmetic

This example shows how the compiler deals with floating-point arithmetic for different processors supporting either hardware or software floating-point arithmetic.

The following example shows a function implementing floating-point arithmetic in C code.
float foo(float num1, float num2)
{
    float temp, temp2;
    temp = num1 + num2;
    temp2 = num2 * num2;
    return temp2 - temp;
}
When the example C code is compiled with the command-line options --cpu 5TE and --fpu softvfp, the compiler produces machine code with the disassembly shown below. In this case, floating-point arithmetic is performed in software through calls to library routines such as __aeabi_fmul.
||foo|| PROC
    PUSH     {r4-r6, lr}
    MOV      r4, r1
    BL       __aeabi_fadd
    MOV      r5, r0
    MOV      r1, r4
    MOV      r0, r4
    BL       __aeabi_fmul
    MOV      r1, r5
    POP      {r4-r6, lr}
    B        __aeabi_fsub
    ENDP
However, when the example C code is compiled with the command-line option --fpu vfp, the compiler produces machine code with the disassembly shown below. In this case, floating-point arithmetic is performed in hardware through floating-point arithmetic instructions such as VMUL.F32.
||foo|| PROC
    VADD.F32 s2, s0, s1
    VMUL.F32 s0, s1, s1
    VSUB.F32 s0, s0, s2
    BX       lr
    ENDP
Related concepts
4.40 Compiler support for floating-point arithmetic
4.41 Default selection of hardware or software floating-point support
4.43 Vector Floating-Point (VFP) architectures
4.44 Limitations on hardware handling of floating-point arithmetic
4.45 Implementation of Vector Floating-Point (VFP) support code
4.46 Compiler and library support for half-precision floating-point numbers
4.47 Half-precision floating-point number format
4.48 Compiler support for floating-point computations and linkage
4.49 Types of floating-point linkage
4.50 Compiler options for floating-point linkage and computations
Related reference
4.51 Floating-point linkage and computational requirements of compiler options
4.52 Processors and their implicit Floating-Point Units (FPUs)
7.27 --cpu=name compiler option
7.26 --cpu=list
7.66 --fpu=list
7.67 --fpu=name compiler option
Related information
Application Binary Interface (ABI) for the ARM Architecture
Non-ConfidentialPDF file icon PDF versionARM DUI0375E
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.