5.43 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
5.41 Compiler support for floating-point arithmetic
5.42 Default selection of hardware or software floating-point support
5.44 Vector Floating-Point (VFP) architectures
5.45 Limitations on hardware handling of floating-point arithmetic
5.46 Implementation of Vector Floating-Point (VFP) support code
5.47 Compiler and library support for half-precision floating-point numbers
5.48 Half-precision floating-point number format
5.49 Compiler support for floating-point computations and linkage
5.50 Types of floating-point linkage
5.51 Compiler options for floating-point linkage and computations
Related reference
5.52 Floating-point linkage and computational requirements of compiler options
5.53 Processors and their implicit Floating-Point Units (FPUs)
8.39 --cpu=name compiler option
8.38 --cpu=list
8.86 --fpu=list
8.87 --fpu=name compiler option
Related information
Application Binary Interface (ABI) for the ARM Architecture
Non-ConfidentialPDF file icon PDF versionARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.