舍入到正无穷 | AP_RND |
舍入到 0 | AP_RND_ZERO |
舍入到负无穷 | AP_RND_MIN_INF |
舍入到无穷 | AP_RND_INF |
收敛舍入 | AP_RND_CONV |
截位 | AP_TRN |
截位到 0 | AP_TRN_ZERO |
AP_RND
- 将值舍入到特定
ap_[u]fixed
类型最接近的可表示值。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
AP_RND_ZERO
- 将值舍入到最接近的可表示值。
- 向 0 舍入。
- 对于正值,删除冗余位。
- 对于负值,添加最低有效位以获取最接近的可表示值。
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
AP_RND_MIN_INF
- 将值舍入到最接近的可表示值。
- 向负无穷舍入。
- 对于正值,删除冗余位。
- 对于负值,添加最低有效位。
ap_fixed<3, 2, AP_RND_MIN_INF, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.0 ap_fixed<3, 2, AP_RND_MIN_INF, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.5
AP_RND_INF
- 将值舍入到最接近的可表示值。
- 舍入方式取决于最低有效位。
- 对于正值,如果已设置最低有效位,则向正无穷舍入。否则,向负无穷舍入。
- 对于负值,如果已设置最低有效位,则向负无穷舍入。否则,向正无穷舍入。
ap_fixed<3, 2, AP_RND_INF, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.5 ap_fixed<3, 2, AP_RND_INF, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.5
AP_RND_CONV
- 舍入到最近的可表示值,并将舍入“绑定”到偶数,即舍入后的最低有效位强制为零 (0)。
- “绑定”是两个可表示值的中点,当紧随舍入后的最低有效位之后的位为 1 并且其下方所有位全部为 0 时,即发生“绑定”。
// For the following examples, bit3 of the 8-bit value becomes the // LSB of the final 5-bit value (after rounding). // Notes: // * bit7 of the 8-bit value is the MSB (sign bit) // * the 3 LSBs of the 8-bit value (bit2, bit1, bit0) are treated as // guard, round and sticky bits. // * See http://pages.cs.wisc.edu/~david/courses/cs552/S12/handouts/guardbits.pdf ap_fixed<8,3> p1 = 1.59375; // p1 = 001.10011 ap_fixed<5,3,AP_RND_CONV> rconv1 = p1; // rconv1 = 1.5 (001.10) ap_fixed<8,3> p2 = 1.625; // p2 = 001.10100 => tie with bit3 (LSB-to-be) = 0 ap_fixed<5,3,AP_RND_CONV> rconv2 = p2; // rconv2 = 1.5 (001.10) => lsb is already zero, just truncate ap_fixed<8,3> p3 = 1.375; // p3 = 001.01100 => tie with bit3 (LSB-to-be) = 1 ap_fixed<5,3,AP_RND_CONV> rconv3 = p3; // rconv3 = 1.5 (001.10) => lsb is made zero by rounding up ap_fixed<8,3> p3 = 1.65625; // p3 = 001.10101 ap_fixed<5,3,AP_RND_CONV> rconv3 = p3; // rconv3 = 1.75 (001.11) => round up
AP_TRN
- 始终将值向负无穷舍入。
ap_fixed<3, 2, AP_TRN, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.0 ap_fixed<3, 2, AP_TRN, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.5
AP_TRN_ZERO
将值舍入为:
- 对于正值,舍入方式与
AP_TRN
模式相同。 - 对于负值,向 0 舍入。
ap_fixed<3, 2, AP_TRN_ZERO, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.0 ap_fixed<3, 2, AP_TRN_ZERO, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.0