Fixed-Point Math Functions - 2024.2 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2024-11-13
Version
2024.2 English

Fixed-point implementations are also provided for the following math functions.

All fixed-point math functions support ap_[u]fixed and ap_[u]int data types with the following bit-width specification,

  1. ap_fixed<W,I> where I<=33 and W-I<=32
  2. ap_ufixed<W,I> where I<=32 and W-I<=32
  3. ap_int<I> where I<=33
  4. ap_uint<I> where I<=32
Important: Fixed-point math functions from the hls_math library do not support the ap_[u]fixed template parameters Q,O, and N, for quantization mode, overflow mode, and the number of saturation bits, respectively. The quantization and overflow modes are only effective when an ap_[u]fixed variable is on the left hand of assignment or being initialized, but not during the calculation.

Trigonometric Functions

cos sin tan acos asin atan atan2 sincos
cospi sinpi            

Hyperbolic Functions

cosh sinh tanh acosh asinh atanh

Exponential Functions

exp frexp modf exp2 expm1

Logarithmic Functions

log log10 ilogb log1p

Power Functions

pow sqrt rsqrt cbrt hypot

Error Functions

erf erfc

Rounding Functions

ceil floor trunc round rint nearbyint

Floating Point

nextafter nexttoward

Difference Functions

erf erfc fdim fmax fmin maxmag minmag

Other Functions

fabs recip abs fract divide

Classification Functions

signbit

Comparison Functions

isgreater isgreaterequal isless islessequal islessgreater

Relational Functions

isequal isnotequal any all bitselect

The fixed-point type provides a slightly-less accurate version of the function value, but a smaller and faster RTL implementation.

The methodology for implementing a math function with a fixed-point data types is:

  1. Determine if a fixed-point implementation is supported.
  2. Update the math functions to use ap_fixed types.
  3. Perform C simulation to validate the design still operates with the required precision. The C simulation is performed using the same bit-accurate types as the RTL implementation.
  4. Synthesize the design.

For example, a fixed-point implementation of the function sin is specified by using fixed-point types with the math function as follows:

#include "hls_math.h"
#include "ap_fixed.h"

ap_fixed<26,6> my_input, my_output;

my_input = 24.675;
my_output = sin(my_input);