Keil™, An ARM® Company

RealView Compiler User's Guide

Support for floating-point operations

4.6.1. Support for floating-point operations

The ARM processor core does not contain floating-point hardware. Floating-point arithmetic must be supported separately, either:

  • In software, through the floating-point library fplib. This library provides functions that can be called to implement floating-point operations using no additional hardware. See The software floating‑point library, fplib in the Libraries Guide for more information.

  • In hardware, using a hardware VFP coprocessor attached to the ARM processor core to provide the required floating-point operations. VFP is a coprocessor architecture that implements IEEE floating-point and supports single and double precision, but not extended precision.

    Note

    In practice, floating-point arithmetic in the VFP is actually implemented using a combination of hardware, which executes the common cases, and software, which deals with the uncommon cases, and cases causing exceptions. See VFP support for more information.

The differences between software and hardware support for floating-point arithmetic are illustrated with Example 4.1, which shows a function implementing floating-point arithmetic operations in C.

Example 4.1.  Floating-point operations

float foo(float num1, float num2)
{
    float temp, temp2;

    temp = num1 + num2;
    temp2 = num2 * num2;
    return temp2-temp;
}

When the C code of Example 4.1 is compiled with the command-line option --softvfp, the compiler produces machine code with the disassembly of Example 4.2. In this example, floating-point arithmetic is performed in software through calls to library routines such as __aeabi_fmul.

Example 4.2.  Support for floating-point operations in software

||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

When the C code of Example 4.1 is compiled with the command-line option --vfp, the compiler produces machine code with the disassembly of Example 4.3. In this example, floating-point arithmetic is performed in hardware through floating-point arithmetic instructions such as VMUL.F32.

Example 4.3. Support for floating-point operations in hardware

||foo|| PROC
    VADD.F32 s2, s0, s1
    VMUL.F32 s0, s1, s1
    VSUB.F32 s0, s0, s2
    BX       lr
    ENDP

In practice, code that makes use of hardware support for floating-point arithmetic is more compact and offers better performance than code that performs floating-point arithmetic in software. However, hardware support for floating-point arithmetic requires a VFP coprocessor.

The default option is to support floating-point arithmetic using the software floating-point library fplib. fplib is available as part of the standard distribution of the RealView Development Suite C libraries.

Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0375A