Fixed-Point Math Functions - 2021.2 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
ft:locale
English (United States)
Release Date
2021-12-15
Version
2021.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 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

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<32,2> my_input, my_output;

my_input = 24.675;
my_output = sin(my_input);

When using fixed-point math functions, the result type must have the same width and integer bits as the input.