The following are common use errors when synthesizing math functions. These are often (but not exclusively) caused by converting C functions to C++ to take advantage of synthesis for math functions.
If the C++
cmath.h header file is used, the floating point functions (for
cosf) can be used.
These result in 32-bit operations in hardware. The
cmath.h header file also
overloads the standard functions (for example,
cos) so they can be used for float and double types.
If the C
math.h library is used, the single-precision functions (for
cosf) are required
to synthesize 32-bit floating point operations. All standard function calls (for
cos) result in
doubles and 64-bit double-precision operations being synthesized.
When converting C functions to C++ to take advantage of
math.h support, be
sure that the new C++ code compiles correctly before synthesizing with Vitis HLS.
For example, if
sqrtf() is used in the code with
math.h, it requires the following code extern added to the C++ code to
#include <math.h> extern “C” float sqrtf(float);
To avoid unnecessary hardware caused by type conversion, follow the warnings on mixing double and float types discussed in Floats and Doubles.