The HLS math functions are implemented as synthesizable bit-approximate functions from the
hls_math.h library. Bit-approximate HLS math library functions do not provide the same accuracy as the standard C function. To achieve the desired result, the bit-approximate implementation might use a different underlying algorithm than the standard C math library version. The accuracy of the function is specified in terms of ULP (Unit of Least Precision). This difference in accuracy has implications for both C simulation and C/RTL co-simulation.
The ULP difference is typically in the range of 1-4 ULP.
- If the standard C math library is used in the C source code, there may be a difference between the C simulation and the C/RTL co-simulation due to the fact that some functions exhibit a ULP difference from the standard C math library.
- If the HLS math library is used in the C source code, there will be no difference between the C simulation and the C/RTL co-simulation. A C simulation using the HLS math library, may however differ from a C simulation using the standard C math library.
In addition, the following seven functions might show some differences, depending on the C standard used to compile and run the C simulation:
copysign are usually provided by the system header files, and they
operate on doubles. In particular,
always returns a double result. This might result in unexpected results after
synthesis if it must be returned to a float, because a double-to-float conversion
block is introduced into the hardware.
C99 mode (-std=c99)
All seven functions are usually provided under the expectation that
the system header files will redirect them to
__isnan(float). The usual GCC header files do not redirect
isnormal, but implement it in terms of
C++ Using math.h
All seven are provided by the system header files, and they operate on doubles.
copysign always returns a
double result. This might cause unexpected results after synthesis if it must be
returned to a float, because a double-to-float conversion block is introduced into
C++ Using cmath
Similar to C99
- The system header files are usually different.
- The functions are properly overloaded for:
copysignf are handled as built-ins even when using
C++ Using cmath and namespace std
No issues. AMD recommends using the following for best results:
-fno-builtinfor C and C++
-std=c99, use the Tcl command
-cflagsoption. Alternatively, use the Edit CFLAGs button in the Project Settings dialog box.