Standard Types - 2021.1 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2021-06-16
Version
2021.1 English

The following code example shows some basic arithmetic operations being performed.


#include "types_standard.h"

void types_standard(din_A  inA, din_B  inB, din_C  inC, din_D  inD,
 dout_1 *out1, dout_2 *out2, dout_3 *out3, dout_4 *out4
) {

 // Basic arithmetic operations
 *out1 = inA * inB;
 *out2 = inB + inA;
 *out3 = inC / inA;
 *out4 = inD % inA;

} 

The data types in the example above are defined in the header file types_standard.h shown in the following code example. They show how the following types can be used:

  • Standard signed types
  • Unsigned types
  • Exact-width integer types (with the inclusion of header file stdint.h)
    
    #include <stdio.h>
    #include <stdint.h>
    
    #define N 9
    
    typedef char din_A;
    typedef short din_B;
    typedef int din_C;
    typedef long long din_D;
    
    typedef int dout_1;
    typedef unsigned char dout_2;
    typedef int32_t dout_3;
    typedef int64_t dout_4;
    
    void types_standard(din_A inA,din_B inB,din_C inC,din_D inD,dout_1 
    
    *out1,dout_2 *out2,dout_3 *out3,dout_4 *out4);
    

These different types result in the following operator and port sizes after synthesis:

  • The multiplier used to calculate result out1 is a 24-bit multiplier. An 8-bit char type multiplied by a 16-bit short type requires a 24-bit multiplier. The result is sign-extended to 32-bit to match the output port width.
  • The adder used for out2 is 8-bit. Because the output is an 8-bit unsigned char type, only the bottom 8-bits of inB (a 16-bit short) are added to 8-bit char type inA.
  • For output out3 (32-bit exact width type), 8-bit char type inA is sign-extended to 32-bit value and a 32-bit division operation is performed with the 32-bit (int type) inC input.
  • A 64-bit modulus operation is performed using the 64-bit long long type inD and 8-bit char type inA sign-extended to 64-bit, to create a 64-bit output result out4.

As the result of out1 indicates, Vitis HLS uses the smallest operator it can and extends the result to match the required output bit-width. For result out2, even though one of the inputs is 16-bit, an 8-bit adder can be used because only an 8-bit output is required. As the results for out3 and out4 show, if all bits are required, a full sized operator is synthesized.