[PATCH] D47017: [Fixed Point Arithmetic] Validation Test for Saturated Shift Left, Saturated Unsigned _Fract Types, and Fix for Saturated Unsigned Addition

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 17 08:24:01 PDT 2018


leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr, jakehehrlich.
leonardchan added a project: clang.

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.

This is a child of https://reviews.llvm.org/D47016


Repository:
  rC Clang

https://reviews.llvm.org/D47017

Files:
  include/clang/AST/Type.h
  lib/CodeGen/CGExprScalar.cpp
  test/Frontend/fixed_point_all_builtin_operations.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47017.147324.patch
Type: text/x-patch
Size: 10860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180517/bb1610c5/attachment-0001.bin>


More information about the cfe-commits mailing list