针对以下数学函数还提供了定点实现。
所有定点匹配函数都支持 ap_[u]fixed 类型和 ap_[u]int 数据类型,并采用以下位宽规格。
-
ap_fixed<W,I>
(当 I<=33 且 W-I<=32 时)
-
ap_ufixed<W,I>
(当 I<=32 且 W-I<=32 时)
-
ap_int<I>
(当 I<=33 时)
-
ap_uint<I>
(当 I<=32 时)
三角函数
cos |
sin |
tan |
acos |
asin |
atan |
atan2 |
sincos |
cospi |
sinpi |
|
|
|
|
|
|
双曲函数
cosh |
sinh |
tanh |
acosh |
asinh |
atanh |
指数函数
exp |
frexp |
modf |
exp2 |
expm1 |
幂函数
pow |
sqrt |
rsqrt |
cbrt |
hypot |
舍入函数
ceil |
floor |
trunc |
round |
rint |
nearbyint |
差分函数
erf |
erfc |
fdim |
fmax |
fmin |
maxmag |
minmag |
其它函数
fabs |
recip |
abs |
fract |
divide |
比较函数
isgreater |
isgreaterequal |
isless |
islessequal |
islessgreater |
关系函数
isequal |
isnotequal |
any |
all |
bitselect |
定点类型提供的函数值版本准确性略低,但 RTL 实现更小且更快。
使用定点数据类型实现数学函数的方法是:
- 判定是否支持定点实现。
- 将数学函数更新为使用
ap_fixed
类型。
- 执行 C 语言仿真来确认设计按所需精度是否仍可正常操作。执行 C 语言仿真时所使用的位精度类型与 RTL 实现相同。
- 对设计执行综合。
例如,使用含如下数学函数的定点类型来指定函数 sin
的定点实现:
#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);
使用定点数学函数时,结果类型的宽度和整数位数必须与输入相同。