English
Language : 

DS693 Datasheet, PDF (9/13 Pages) Xilinx, Inc – Integrated into Xilinx Embedded Development Kit
LogiCORE IP Virtex-5 APU Floating-Point Unit (v1.01a)
separate compilation is used, it is very important that you ensure the consistency of FPU compiler flags throughout
the build.
C Language Programming
To gain maximum benefit from the FPU without low-level assembly-language programming, it is important to
consider how the C compiler will interpret your source code. Very often the same algorithm can be expressed in
many different ways, and some are more efficient than others.
Immediate Constants
Floating-point constants in C are double-precision by default. If you are using a single-precision FPU, careless
coding may result in double-precision software emulation routines being used instead of the native single-precision
instructions. To avoid this, explicitly specify (by cast or suffix) that immediate constants in your arithmetic
expressions are single-precision values.
For example:
float x=0.0;
…
x += (float)1.0; /* float addition */
x += 1.0F;
/* alternative to above */
x += 1.0;
/* warning - uses double addition! */
The GNU C compiler can be instructed to treat all floating-point constants as single-precision (contrary to the ANSI
C standard) by supplying the compiler flag -fsingle-precision-constant.
Avoid Unnecessary Casting
While conversions between floating-point and integer formats are supported in hardware by the FPU, it is still best
to avoid them when possible. Such casts require transfers between the floating-point and the integer register files,
which in the PowerPC processor architecture always go via memory. These transfers are a bottleneck and can cause
performance degradation. This applies to both single- and double-precision FPU variants.
The following “bad” example calculates the sum of squares of the integers from 1 to 10 using floating-point
representation:
float sum, t;
int i;
sum = 0.0f;
for (i = 1; i <= 10; i++) {
t = (float)i;
sum += t * t;
}
The above code requires a cast from an integer to a float on each loop iteration. This can be rewritten as:
float sum, t;
int i;
t = sum = 0.0f;
for(i = 1; i <= 10; i++) {
t += 1.0f;
sum += t * t;
}
DS693 March 1, 2011
www.xilinx.com
9
Product Specification