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,
-
ap_fixed<W,I>
where
I<=33 and W-I<=32
-
ap_ufixed<W,I>
where
I<=32 and W-I<=32
-
ap_int<I>
where
I<=33
-
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 |
Power Functions
pow |
sqrt |
rsqrt |
cbrt |
hypot |
Rounding Functions
ceil |
floor |
trunc |
round |
rint |
nearbyint |
Difference Functions
erf |
erfc |
fdim |
fmax |
fmin |
maxmag |
minmag |
Other Functions
fabs |
recip |
abs |
fract |
divide |
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:
- Determine if a fixed-point implementation is supported.
- Update the math functions to use
ap_fixed
types.
- 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.
- 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);