The SmartHLS math library provides HLS C++ library functions for algorithm prototyping of fixed point math applications.
By open sourcing the math library, we hope to deliver new features and fixes under a faster release cycle, and share the source code to serve as examples for developers to implement other HLS designs. We welcome all developers to contribute by reporting issues, feedback, and feature requests (by raising "Issues"); and even better, contribute back new algorithms and fixes into this open-source repository.
Below is the directory structure of the math library and each sub-directory's respective content. Please see the readme files in sub-directories for more details.
- docs: Documentation for the HLS C++ Library. See documentation notes.
- include: The HLS C++ library.
- examples: Examples showcasing the usage of the HLS C++ library. See examples notes.
- utils: Utilities to make using the library easier.
Function | Description |
---|---|
sin_lut | Lookup Table implementation of sin. |
sin_cordic | CORDIC implementation of sin. |
sin_taylor | Taylor Series implementation of sin. |
tan_lut | Lookup Table implementation of tan. |
tan_cordic | CORDIC implementation of tan. |
tan_taylor | Taylor Series implementation of tan. |
cos_lut | Lookup Table implementation of cos. |
cos_cordic | CORDIC implementation of cos. |
cos_taylor | Taylor Series implementation of cos. |
sqrt | Iterative implementation of sqrt. |
atan_cordic | CORDIC implementation of atan. |
atan_rational | Rational function approximation of atan. |
exp_taylor | Taylor Series implementation of exp. |
exp_cordic | CORDIC implementation of exp. |
ln | Lookup Table based implementation of ln. |
log | Lookup Table based implementation of log. |
pow | Implementation of pow based on ln and exp. |
ceil | Rounds the input upwards. |
floor | Rounds the input downwards. |
round | Rounds the input to the closest integer. |
trunc | Rounds the input towards zero. |
abs | Returns the absolute value of the input. |
asin_cordic | CORDIC implementation of asin. |
acos_cordic | CORDIC implementation of acos. |
sincos | CORDIC implementation of sincos. |
log2_lut | Lookup Table implementation of log2. |
log2_cordic | CORDIC implementation of log2. |
cordic | CORDIC algorithm. |
The SmartHLS Fixed Point Math Library also includes a gdb pretty-printer that simplifies the debugging of applications that use ap_[u]fixpt datatypes. The pretty-printer will display the real value, the hexadecimal representation, the word width (W) and the width of the integer part (IW) of ap_[u]fixpt types:
(gdb) print x
$2 = 0.49999999906867743 [0xfffffff8] <W:34,IW:1>
For more information on SHLS ap_fixpt, see the User Guide.
Fixed point math functions internal calculations use the default Quantization (Q_M) and Overflow (O_M) modes (i.e. AP_TRN and AP_WRAP respectively.)
Documentation for each function in the HLS Math Library can be found in docs/md. The resource usage displayed in the documentation was generated using a specific set of parameters, which are listed at the top of the resource report table and in the title of the graph. W is the width of the input/output in bits, IW is how far the most significant bit is above the decimal, W_M is the Quantization (rounding) mode used when a result has precision below the least significant bit, and O_M is the Overflow mode used when a result exceeds the maximum or minimum representable value. Your resource usage may change depending on your parameters.
Note that FMax in the resource reports is an estimation made during synthesis. Your FMax may be different depending on your design.
The wrappers for the HLS Math Library functions in the examples include "XS", "S", "M", "L", "XL" in their names. These represent fixed point configurations used to test different datapoints. These are by no means the only configurations the HLS Math Library can support, but were arbitrarly chosen to represent a good range of precisions one might use. See examples/simple/configs.hpp.
The HLS Math Library also includes RISC-V SoC examples for the Icicle Kit (MPFS250T) running Linux, and the PolarFire Video Kit (MPF300) for the Soft-MiV processor running baremetal.