定点数学函数 - 2023.2 简体中文

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

Document ID
UG1399
Release Date
2023-12-18
Version
2023.2 简体中文

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

所有定点数学函数都支持 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)
重要: 来自 hls_math 库的定点数学函数不支持 ap_[u]fixed 模板参数 Q、O 和 N,这三个参数依次分别对应于量化模式、上溢模式和饱和位数。仅当 ap_[u]fixed 变量位于赋值左侧时或者在初始化期间,量化模式和上溢模式才有效,但在变量计算期间无效。

三角函数

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<26,6> my_input, my_output;

my_input = 24.675;
my_output = sin(my_input);