6. Example application using VFP

A simple application is provided as part of the associated code suite, as main.c. This carries out three floating-point operations, the first two of which are executed by the VFP hardware, the third uses a denormalized number and therefore bounces to the VFP Support Code for handling (except if RunFast mode is enabled). This provides a simple test that the VFP support code has been successfully integrated into a system.

#include <stdio.h>

double VFPtest(double x, double y)
{
    return x + y;
}

int main(void)
{
    double val1 = 1.0;
    double val2 = 2.0;
    double val3 = 2.22524e-308; //Small, just normalized number
    double val4 = 3.1234e-322; // denormalized number
    double res1;
    double res2;
    double res3;
    printf("VFP Support Code Test\n");
    printf("=====================\n\n");
    printf("Non-bouncing calculation of %f + %f\n",val1,val2);
    printf("The result should be : 3.000000\n");
    res1=VFPtest(val1,val2);
    printf("The result is        : %f\n\n", res1);
    printf("Non-bouncing calculation of %e + %e\n",val3,val3);
    printf("The result should be : 4.45048e-308\n");
    res2=VFPtest(val3,val3);
    printf("The result is        : %e\n\n", res2);
    printf("Bouncing calculation of %e + %e\n", val4, val4);
    printf("The result should be : 6.225227e-322\n");
    res3=VFPtest(val4,val4);
    printf("The result is        : %e\n\n", res3);
    return 0;
}

Details of how to build and run this code can be found in the readme.txt of the associated example code.

Note

In fact, the code above should bounce to the support code four times, twice for the printf which displays val4, once for the denormalized addition itself in VFPtest(), and once for the printf that displays the result of the denormalized addition.

Note

The result 6.225227e-322 is correct, even though the mathematical error is large. Calculations using small denormalized numbers are significantly less accurate than those using normalized arithmetic.

Copyright © 2005. All rights reserved.DAI0133B