Developer Guide

Intel oneAPI FPGA Handbook

ID 785441
Date 2/07/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Declare the ac_int Data Type

Perform the following steps to declare the ac_int data type:

  1. Include the ac_int.hpp header file as follows:
    #include <sycl/ext/intel/ac_types/ac_int.hpp>
  2. Declare your ac_int variables in one of the following ways:
    • Template-based declaration:
      ac_int<N, true> var_name; //Signed N-bit integer
      ac_int<N, false> var_name; //Unsigned N-bit integer
    • Predefined types up to 63 bits:
      ac_intN::intN var_name; //Signed N-bit integer
      ac_intN::uintN var_name; //Unsigned N-bit integer

    Where, N is the total length of the integer in bits.

    The ac_int data type has several API calls. For more information about the Algorithmic C data types, refer to https://cdrdv2.intel.com/v1/dl/getContent/728986.

RESTRICTION:

If you want to initialize an ac_int variable to a value larger than 64 bits, you must use the bit_fill or bit_fill_hex utility function. For details, refer to the section Methods to Fill Bits in the documentation provided in https://cdrdv2.intel.com/v1/dl/getContent/728986.

The following code example shows the use of the bit_fill or bit_fill_hex utility functions:

typedef ac_int<80,false> i80_t;
i80_t x;
x.bit_fill_hex("a9876543210fedcba987"); // member funtion
x = ac::bit_fill_hex<i80_t>("a9876543210fedcba987"); // global function
int vec[] = { 0xa987, 0x6543210f, 0xedcba987 };
x.bit_fill(vec); // member function
x = bit_fill<i80_t>(vec); // global function
// inlining the constant array
x.bit_fill( (int [3]) { 0xa987,0x6543210f,0xedcba987 } ); // member function
x = bit_fill<i80_t>( (int [3]) { 0xa987,0x6543210f,0xedcba987 } ); // global function

Debugging the ac_int Data Type Use

The ac_int.hpp header file provides tools to help you check ac_int data type operations and assignments for overflow.

RESTRICTION:

Currently, you can debug ac_int data type operations and assignments for overflow only in the emulation flow and only for non-kernel code.

NOTE:
  • When you use DEBUG_AC_INT_WARNING and DEBUG_AC_INT_ERROR macros, you cannot declare constexpr ac_int variables or constexpr ac_int arrays.
    Macro Description
    DEBUG_AC_INT_WARNING Emits a warning for each detected overflow.
    DEBUG_AC_INT_ERROR Emits a message for the first overflow that is detected and then exits the code with an error.
  • Within your code, you must declare the macros before you include the ac_int.hpp header file.

Explicit Conversion Functions

The following table lists the functions to convert to C signed and unsigned integer types int, long and Slong for the ac_int data type:

Function Return Type
to_int() int
to_uint() unsigned int
to_long() long
to_ulong() unsigned long
to_int64() Slong
to_uint64() Ulong
to_double() double
NOTE:

For additional information, refer to the FPGA tutorial sample "Algorithmic C Integer Data Type ac_int" listed in the Intel® oneAPI Samples Browser on Linux* or Windows*, or access the code sample on GitHub.