Vitis HLS provides integer and fixed-point arbitrary precision data types for C++.
Language | Integer Data Type | Required Header |
---|---|---|
C++ | ap_[u]int<W> (1024 bits) Can be extended to 4K bits wide as described below. |
#include “ap_int.h” |
C++ | ap_[u]fixed<W,I,Q,O,N> | #include “ap_fixed.h” |
The header files which define the arbitrary precision types are also provided with Vitis HLS as a standalone package with the rights to use them in your own source code. The package, xilinx_hls_lib_<release_number>.tgz is provided in the include directory in the Vitis HLS installation area. The package does not include the C arbitrary precision types defined in ap_cint.h. These types cannot be used with standard C compilers.
For the C++ language ap_[u]int
data
types the header file ap_int.h defines the
arbitrary precision integer data type. To use arbitrary precision integer data types in
a C++ function:
- Add header file ap_int.h to the source code.
- Change the bit types to
ap_int<N>
orap_uint<N>
, where N is a bit-size from 1 to 1024.
The following example shows how the header file is added and two variables implemented to use 9-bit integer and 10-bit unsigned integer types:
#include "ap_int.h"
void foo_top (…) {
ap_int<9> var1; // 9-bit
ap_uint<10> var2; // 10-bit unsigned
The default maximum width allowed for ap_[u]int
data types is 1024 bits. This default may be overridden by
defining the macro AP_INT_MAX_W
with a positive integer
value less than or equal to 4096 before inclusion of the ap_int.h header file.
AP_INT_MAX_W
too high can cause slow software
compile and runtimes.The following is an example of overriding AP_INT_MAX_W
:
#define AP_INT_MAX_W 4096 // Must be defined before next line
#include "ap_int.h"
ap_int<4096> very_wide_var;