Page MenuHomePhabricator

[Fixed Point Arithmetic] Validation Test for Saturated Shift Left, Saturated Unsigned _Fract Types, and Fix for Saturated Unsigned Addition
Needs ReviewPublic

Authored by leonardchan on May 17 2018, 8:23 AM.

Details

Summary

This patch includes changes for the shift left operator involving saturated fixed point types.

For unsigned shifting, overflow occurs if the number of bits we shift exceeds the number of leading zeros in the number. This number is found using the intrinsic llvm function ctlz.

For signed shifting, if the number is positive, we cap at the max value for that type if the number of bits we shift exceeds the number of leading zeros. If the number is negative, we cap at the min value for that type if the number of bits we shift exceeds the number of leading ones. ctlz can be used in this case after flipping the bits in the number.

  • Saturation tests were also added for saturated unsigned _Fract types.
  • Added a fix to unsigned addition for saturated fixed point types where we would not be able to get the overflow if the number of data bits was equal to the underlying integer width. In this case, we need to use the intrinsic function uadd.with.overflow to detect overflow on this carry bit.

Diff Detail

Repository
rC Clang