Developer Guide

FPGA Optimization Guide for Intel® oneAPI Toolkits

ID 767853
Date 12/16/2022
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 <span class='codeph'>ac_fixed</span> Data Type

Perform the following steps to declare the ac_fixed data type:

  1. Include the ac_fixed.hpp header file as follows:
    #include <sycl/ext/intel/ac_types/ac_fixed.hpp>
  2. Declare your ac_fixed variables as follows:

    ac_fixed<N, I, true, Q, O> var_name; //Signed fixed-point number
    ac_fixed<N, I, false, Q, O> var_name; //Unsigned fixed-point number

    The following table describes the template parameters:

    Template Parameter Description
    N The total length of the fixed-point number in bits.
    I

    The number of bits used to represent the integer value of the fixed-point number. The difference of N−I determines how many bits represent the fractional part of the fixed-point number.

    Q

    The quantization mode that determines how to handle values where the generated precision (number of decimal places) exceeds the number of bits available in the variable to represent the fractional part of the number.

    For a list of quantization modes and their descriptions, refer to the Quantization and Overflow section in https://github.com/hlslibs/ac_types/blob/v3.7/pdfdocs/ac_datatypes_ref.pdf.

    O

    The overflow mode that determines how to handle values where the generated value has more bits than the number of bits available in the variable. For a list of overflow modes and their descriptions, refer to the Quantization and Overflow section in https://github.com/hlslibs/ac_types/blob/v3.7/pdfdocs/ac_datatypes_ref.pdf.

For a list of supported operators and their return types, refer to the Arbitrary-Length Bit-Accurate Integer and Fixed-Point Datatypes chapter in https://github.com/hlslibs/ac_types/blob/v3.7/pdfdocs/ac_datatypes_ref.pdf.

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_fixed 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
to_float() float
to_ac_int() ac_int<max(I,1), S>, where I represents the integer width and S is a bool parameter representing the signedness of the ac_int data type.

Math Functions Provided by the ac_fixed_math.hpp Header File

Include the header file as follows:

#include <sycl/ext/intel/ac_types/ac_fixed_math.hpp>

The ac_fixed_math.hpp header file provides support for the following arbitrary precision fixed-point (ac_fixed) data type functions:

  • sqrt_fixed
  • reciprocal_fixed
  • reciprocal_sqrt_fixed
  • sin_fixed
  • cos_fixed
  • sincos_fixed
  • sinpi_fixed
  • cospi_fixed
  • sincospi_fixed
  • log_fixed
  • exp_fixed

For details about input type restrictions, input value limits, and output type propagation rules, review the comments in the ac_fixed_math.hpp header file.

IMPORTANT:

Due to the differences in the internal math implementations, the results from the ac_fixed data type operations might differ between simulation and emulation. The maximum difference is within a few units in the last place (ULPs).