MatchLib
Classes | Macros | Functions

Integer library with built-in support for sc_int and ac_int datatypes. More...

Classes

struct  nvhls::nbits< X >
 Compute number of bits to represent a constant. More...
 
struct  nvhls::log2_floor< X >
 Compute Floor of log2 of a constant. More...
 
struct  nvhls::log2_floor< 0 >
 log2 of 0 is not defined: generate compiler error More...
 
struct  nvhls::log2_ceil< X >
 Compute Celing of log2 of a constant. More...
 
struct  nvhls::log2_ceil< 0 >
 log2 of 0 is not defined: generate compiler error More...
 
struct  nvhls::next_pow2< n_val >
 Compute power of 2 value greater than a given value. More...
 
struct  nvhls::index_width< X >
 Compute index width of a constant. More...
 
struct  nvhls::nvhls_t< N, B >
 Definition of vendor agnostic integer data types. More...
 

Macros

#define NVUINTW(width)   typename nvhls::nvhls_t<width>::nvuint_t
 
#define NVINTW(width)   typename nvhls::nvhls_t<width>::nvint_t
 
#define NVINTC(width)   nvhls::nvhls_t<width>::nvint_t
 
#define NVUINTC(width)   nvhls::nvhls_t<width>::nvuint_t
 

Functions

template<typename type1 , typename type2 >
type1 nvhls::set_slc (type1 X, type2 Y, const unsigned int i)
 Function that replaces slice of bits. More...
 
template<unsigned int W, typename type >
nvhls_t< W >::nvuint_t nvhls::get_slc (type X, const unsigned int i)
 Function that returns slice of bits. More...
 
template<typename type >
type nvhls::get_slc (type X, const unsigned int i, const unsigned int j)
 Function that returns slice of bits with dynamic range. More...
 
template<unsigned int W1, typename type1 , typename type2 >
type2 nvhls::leading_ones (type1 X)
 LeadingOne Detector. More...
 
template<typename type1 >
unsigned int nvhls::lzd (type1 X)
 Leading zero detector. More...
 
template<typename type >
type nvhls::get_min_val ()
 Minimum Value of a type. More...
 
template<typename type >
type nvhls::left_shift (type X, int shift)
 Function that performs left shift while preserving sign. More...
 
template<typename type >
type nvhls::right_shift (type X, int shift)
 Function that performs right shift while preserving sign. More...
 
template<typename type1 , typename type2 >
bool nvhls::normalize (type1 &X, type2 &Y)
 Normalize function. More...
 

Detailed Description

Integer library with built-in support for sc_int and ac_int datatypes.

Macro Definition Documentation

◆ NVUINTW

#define NVUINTW (   width)    typename nvhls::nvhls_t<width>::nvuint_t

Macro to declare nvuint type with template parameter width

A Simple Example
#include <nvhls_types.h>
template <unsigned NumInputLanes, unsigned NumOutputLanes>
void func(NVUINTW(NumInputLanes), NVUINTW(NumOutputLanes));
NVUINTW(Wrapped< T >::width) TypeToNVUINT(T in)
Convert Type to NVUINT.
Definition: TypeToBits.h:115

Definition at line 35 of file nvhls_types.h.

◆ NVINTW

#define NVINTW (   width)    typename nvhls::nvhls_t<width>::nvint_t

Macro to declare nvint type with template parameter width

A Simple Example
#include <nvhls_types.h>
template <unsigned NumInputLanes, unsigned NumOutputLanes>
void func(NVINTW(NumInputLanes), NVINTW(NumOutputLanes));
#define NVINTW(width)
Definition: nvhls_types.h:51

Definition at line 51 of file nvhls_types.h.

◆ NVINTC

#define NVINTC (   width)    nvhls::nvhls_t<width>::nvint_t

Macro to declare nvuint type with constant width

A Simple Example
#include <nvhls_types.h>
static const int NumInputs = 4;
NVUINTC(NumInputs) input;
#define NVUINTC(width)

Definition at line 79 of file nvhls_types.h.

◆ NVUINTC

#define NVUINTC (   width)    nvhls::nvhls_t<width>::nvuint_t

Macro to declare nvint type with constant width

A Simple Example
#include <nvhls_types.h>
static const int NumInputs = 4;
NVINTC(NumInputs) input;
#define NVINTC(width)
Definition: nvhls_types.h:79

Function Documentation

◆ set_slc()

template<typename type1 , typename type2 >
type1 nvhls::set_slc ( type1  X,
type2  Y,
const unsigned int  i 
)

Function that replaces slice of bits.

Template Parameters
type1Datatype of X
type2Datatype of Y
Parameters
[in]XVariable whose bits are to be replaced
[in]YVariable that stores new bits for the bit slice
[in]iStarting LSB position in variable X
[out]ReturnTypevariable of type1 with slice of bits replaced.
Overview
  • Function that replaces slice of bits [i,i+W2-1] in X with Y.
  • type1 and type2 can be: nvint or nvuint type.
  • W2 is width of Y.
A Simple Example
#include <nvhls_int.h>
#include <nvhls_types.h>
...
NVUINT8 X = 5;
NVUINT2 Y = 3;
int pos = 3;
X = nvhls::set_slc(X, Y, pos);
...
type1 set_slc(type1 X, type2 Y, const unsigned int i)
Function that replaces slice of bits.
Definition: nvhls_int.h:387

Definition at line 387 of file nvhls_int.h.

◆ get_slc() [1/2]

template<unsigned int W, typename type >
nvhls_t<W>::nvuint_t nvhls::get_slc ( type  X,
const unsigned int  i 
)

Function that returns slice of bits.

Template Parameters
typeDatatype
Wwidth of slice
Parameters
[in]XVariable whose bit slice is requested
[in]iStarting LSB position in variable X
[out]ReturnTypeSlice of bits
Overview
  • Function that returns slice of bits [i+W-1,i] in X.
  • W should be a constant.
  • type can be: nvint or nvuint type.
  • Stratus does not work with typename nvhls_t<W>::nvuint_t as return type. Modifying it to scuint<W>. This will be a problem if W>64.
A Simple Example
#include <nvhls_int.h>
#include <nvhls_types.h>
...
NVUINT8 X = 5;
int pos = 3;
NVUINT2 Y = nvhls::get_slc<2>(X, pos)
...

Definition at line 437 of file nvhls_int.h.

◆ get_slc() [2/2]

template<typename type >
type nvhls::get_slc ( type  X,
const unsigned int  i,
const unsigned int  j 
)

Function that returns slice of bits with dynamic range.

Template Parameters
typeDatatype
Parameters
[in]XVariable whose bit slice is requested
[in]iLSB position for bit-slice in variable X
[in]jMSB position for bit-slice in variable X
[out]ReturnTypeSlice of bits
Overview
  • Function that returns slice of bits [i, j] in X.
  • i >= j.
  • type can be: nvint or nvuint type.
  • SystemC supports this with range function. ac_int does not have equivalent functionality.
A Simple Example
#include <nvhls_int.h>
#include <nvhls_types.h>
...
NVUINT8 X = 5;
const int pos1 = 5;
const int pos2 = 3;
NVUINT2 Y = nvhls::get_slc(X, pos1, pos2)
...
nvhls_t< W >::nvuint_t get_slc(type X, const unsigned int i)
Function that returns slice of bits.
Definition: nvhls_int.h:437

Definition at line 487 of file nvhls_int.h.

◆ leading_ones()

template<unsigned int W1, typename type1 , typename type2 >
type2 nvhls::leading_ones ( type1  X)
inline

LeadingOne Detector.

Template Parameters
type1InputDatatype
type2ReturnType
W1Width of type1
Parameters
[in]XVariable whose leading one pos is requested
[out]ReturnTypePosition of leading one
Overview
  • Function that returns position of leading one.
  • type can be: nvint or nvuint type.
A Simple Example
#include <nvhls_int.h>
#include <nvhls_types.h>
...
NVUINT8 X = 5;
NVUINT3 pos =
nvhls::leading_ones<8, NVUINT8,
NVUINT3>(X);
...
type2 leading_ones(type1 X)
LeadingOne Detector.
Definition: nvhls_int.h:561

Definition at line 561 of file nvhls_int.h.

◆ lzd()

template<typename type1 >
unsigned int nvhls::lzd ( type1  X)

Leading zero detector.

Template Parameters
type1InputDatatype
Parameters
[in]XVariable whose leading zero position is requested
[out]ReturnTypePosition of leading one
Overview
  • Function that returns position of leading zero.
A Simple Example
#include <nvhls_int.h>
#include <nvhls_types.h>
...
NVUINT8 X = 5;
NVUINT3 pos =
nvhls::lzd<NVUINT8>(X);
...

Definition at line 627 of file nvhls_int.h.

◆ get_min_val()

template<typename type >
type nvhls::get_min_val ( )

Minimum Value of a type.

Template Parameters
typeDatatype
Parameters
[out]ReturnValMinimum value of the type
Overview
  • Returns minumum value of nvint and nvuint depending on their bitwidth
A Simple Example
#include <nvhls_int.h>
#include <nvhls_types.h>
...
NVINT3 min_val =
nvhls::get_min_val<NVINT3>();
...

Definition at line 682 of file nvhls_int.h.

◆ left_shift()

template<typename type >
type nvhls::left_shift ( type  X,
int  shift 
)

Function that performs left shift while preserving sign.

Template Parameters
typeDatatype
Parameters
[in]XInput variable
[in]shiftNumber of bits to be shifted
[out]ReturnValX shifted left while preserving sign
Overview
  • Function that performs left shift while preserving sign
A Simple Example
#include <nvhls_int.h>
...
NVINT8 X = -5;
NVINT8 ShiftedX =
nvhls::left_shift<NVINT8>(X, 2);
...

Definition at line 722 of file nvhls_int.h.

◆ right_shift()

template<typename type >
type nvhls::right_shift ( type  X,
int  shift 
)

Function that performs right shift while preserving sign.

Template Parameters
typeDatatype
Parameters
[in]XInput variable
[in]shiftNumber of bits to be shifted
[out]ReturnValX shifted right while preserving sign
Overview
  • Function that performs right shift while preserving sign
A Simple Example
#include <nvhls_int.h>
...
NVINT8 X = -5;
NVINT8 ShiftedX =
nvhls::right_shift<NVINT8>(X, 2);
...

Definition at line 782 of file nvhls_int.h.

◆ normalize()

template<typename type1 , typename type2 >
bool nvhls::normalize ( type1 &  X,
type2 &  Y 
)

Normalize function.

Template Parameters
type1MantissaType
type2ExponentType
Parameters
[in,out]Xmantissa
[in,out]Yexponent
[out]ReturnValsuccess?
Overview
  • Function that takes exponent and mantissa as input and returns normalized mantissa and exponent
  • Return value indicates success or failure
A Simple Example
#include <nvhls_int.h>
...
NVINT8 X = -5;
NVINT8 Y = 2;
bool is_normalized =
nvhls::normalize<NVINT8, NVINT8>(X, Y);
...

Definition at line 848 of file nvhls_int.h.