Overflow Modes - 2023.2 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2023-12-18
Version
2023.2 English
Saturation AP_SAT
Saturation to zero AP_SAT_ZERO
Symmetrical saturation AP_SAT_SYM
Wrap-around AP_WRAP
Sign magnitude wrap-around AP_WRAP_SM

AP_SAT

Saturate the value.

  • To the maximum value in case of overflow.
  • To the negative maximum value in case of negative overflow.
    ap_fixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 7.0
    ap_fixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: -8.0
    ap_ufixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 15.0
    ap_ufixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: 0.0

AP_SAT_ZERO

Force the value to zero in case of overflow, or negative overflow.

ap_fixed<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_ufixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = -19.0; // Yields: 0.0

AP_SAT_SYM

Saturate the value:

  • To the maximum value in case of overflow.
  • To the minimum value in case of negative overflow.
    • Negative maximum for signed ap_fixed types
    • Zero for unsigned ap_ufixed types
    ap_fixed<4, 4, AP_RND, AP_SAT_SYM> UAPFixed4 = 19.0; // Yields: 7.0
    ap_fixed<4, 4, AP_RND, AP_SAT_SYM> UAPFixed4 = -19.0; // Yields: -7.0
    ap_ufixed<4, 4, AP_RND, AP_SAT_SYM> UAPFixed4 = 19.0; // Yields: 15.0
    ap_ufixed<4, 4, AP_RND, AP_SAT_SYM> UAPFixed4 = -19.0; // Yields: 0.0

AP_WRAP

Wrap the value around in case of overflow.

ap_fixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = 31.0; // Yields: -1.0
ap_fixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = -19.0; // Yields: -3.0
ap_ufixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = 19.0; // Yields: 3.0
ap_ufixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = -19.0; // Yields: 13.0

If the value of N is set to zero (the default overflow mode):

  • All MSB bits outside the range are deleted.
  • For unsigned numbers. After the maximum it wraps around to zero.
  • For signed numbers. After the maximum, it wraps to the minimum values.

If N>0:

  • When N > 0, N MSB bits are saturated or set to 1.
  • The sign bit is retained, so positive numbers remain positive and negative numbers remain negative.
  • The bits that are not saturated are copied starting from the LSB side.

AP_WRAP_SM

The value should be sign-magnitude wrapped around.

ap_fixed<4, 4, AP_RND, AP_WRAP_SM> UAPFixed4 = 19.0; // Yields: -4.0
ap_fixed<4, 4, AP_RND, AP_WRAP_SM> UAPFixed4 = -19.0; // Yields: 2.0

If the value of N is set to zero (the default overflow mode):

  • This mode uses sign magnitude wrapping.
  • Sign bit set to the value of the least significant deleted bit.
  • If the most significant remaining bit is different from the original MSB, all the remaining bits are inverted.
  • If MSBs are same, the other bits are copied over.
    1. Delete redundant MSBs.
    2. The new sign bit is the least significant bit of the deleted bits. 0 in this case.
    3. Compare the new sign bit with the sign of the new value.
  • If different, invert all the numbers. They are different in this case.

If N>0:

  • Uses sign magnitude saturation
  • N MSBs are saturated to 1.
  • Behaves similar to a case in which N = 0, except that positive numbers stay positive and negative numbers stay negative.