MicroBlaze Processor Reference Guide
81
UG081 (v14.7)
Floating Point Unit (FPU)
Software Support
The EDK compiler system, based on GCC, provides support for the Floating Point Unit compliant
with the MicroBlaze API. Compiler flags are automatically added to the GCC command line based
on the type of FPU present in the system, when using XPS or SDK.
All double-precision operations are emulated in software. Be aware that the xil_printf() function
does not support floating-point output. The standard C library printf() and related functions do
support floating-point output, but will increase the program code size.
Libraries and Binary Compatibility
The EDK compiler system only includes software floating point C runtime libraries. To take
advantage of the hardware FPU, the libraries must be recompiled with the appropriate compiler
switches.
For all cases where separate compilation is used, it is very important that you ensure the consistency
of FPU compiler flags throughout the build.
Operator Latencies
The latencies of the various operations supported by the FPU are listed in
Instruction Set Architecture.”
The FPU instructions are not pipelined, so only one operation can be
ongoing at any time.
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. When 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! */
Note that 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-
constants.
Avoid unnecessary casting
While conversions between floating-point and integer formats are supported in hardware by the
FPU, when
C_USE_FPU
is set to 2 (Extended), it is still best to avoid them when possible.
The following “bad” example calculates the sum of squares of the integers from 1 to 10 using
floating-point representation: