定点数学函数 - 2021.2 Chinese

Vitis 高层次综合用户指南 (UG1399)

Document ID
UG1399
Release Date
2021-12-15
Version
2021.2 Chinese

针对以下数学函数还提供了定点实现。

所有定点匹配函数都支持 ap_[u]fixed 类型和 ap_[u]int 数据类型,并采用以下位宽规格。

  1. ap_fixed<W,I>(当 I<=33 且 W-I<=32 时)
  2. ap_ufixed<W,I>(当 I<=32 且 W-I<=32 时)
  3. ap_int<I>(当 I<=33 时)
  4. 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

对数函数

log log10 ilogb log1p

幂函数

pow sqrt rsqrt cbrt hypot

误差函数

erf erfc

舍入函数

ceil floor trunc round rint nearbyint

浮点

nextafter nexttoward

差分函数

erf erfc fdim fmax fmin maxmag minmag

其它函数

fabs recip abs fract divide

分类函数

signbit

比较函数

isgreater isgreaterequal isless islessequal islessgreater

关系函数

isequal isnotequal any all bitselect

定点类型提供的函数值版本准确性略低,但 RTL 实现更小且更快。

使用定点数据类型实现数学函数的方法是:

  1. 判定是否支持定点实现。
  2. 将数学函数更新为使用 ap_fixed 类型。
  3. 执行 C 语言仿真来确认设计按所需精度是否仍可正常操作。执行 C 语言仿真时所使用的位精度类型与 RTL 实现相同。
  4. 对设计执行综合。

例如,使用含如下数学函数的定点类型来指定函数 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);

使用定点数学函数时,结果类型的宽度和整数位数必须与输入相同。