Vivado HLS ap_fixed数据类型

任意精度定点数定点数

C++ Arbitrary Precision Fixed Point Types的缩写就是ap_fixed

定义如下

ap_[u]fixed int I,
ap_q_mode Q,
ap_o_mode O,
ap_sat_bits N>;

W:宽度,数据占用的位宽,

I:整数部分的位数,那么(W-I)就是小数部分fraction占用的宽度了

Q:量化模式

有这么几种:

Rounding to plus infinity AP_RNDAP_RND 指示该值应舍入到最接近ap_ [u]定点类型的可表示值。

ap_fixed<3, 2, AP_RND, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.5
ap_fixed<3, 2, AP_RND, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.0

Rounding to zero AP_RND_ZERO 向零取整

ap_fixed<3, 2, AP_RND_ZERO, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.0
ap_fixed<3, 2, AP_RND_ZERO, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.0


Rounding to minus infinity AP_RND_MIN_INF 向负无穷取整


Rounding to infinity AP_RND_INF 向正无穷取整
Convergent rounding AP_RND_CONV
Truncation AP_TRN
Truncation to zero AP_TRN_ZERO

O:溢出模式

Saturation AP_SAT 取到剩余位数能表示的最大的值

p_ufixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 15.0 4位无符号最大能取到15
ap_fixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 7.0 4位有符号数最大能取到7
ap_ufixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: 0.0   4位无符号最大能取到0
ap_fixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: -8.0 4位有符号极限能取到-8


Saturation to zero AP_SAT_ZERO

ap_ufixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = 19.0; // Yields: 0.0
ap_fixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = 19.0; // Yields: 0.0
ap_ufixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = -19.0; // Yields: 0.0
ap_fixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = -19.0; // Yields: 0.0


Symmetrical saturation AP_SAT_SYM 根 AP_SAT差不多,以后具体情况再分析区别吧跑一下程序验证一下,我先偷个懒O(∩_∩)O~~

Wrap-around AP_WRAP

ap_ufixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = 19.0; // Yields: 3.0 10011取低4位就是3
ap_fixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = 31.0; // Yields: -1.0 
ap_ufixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = -19.0; // Yields: 13.0
ap_fixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = -19.0; // Yields: -3.0


Sign magnitude wrap-around AP_WRAP_SM


编译这个类型,要加上头文件:

#include

g++编译要有
-I//include选项

最佳性能

g++ -O3 








你可能感兴趣的:(HLS)