[llvm-dev] Reasoning about known bits of the absolute value of a signed integer

Carlos Liam via llvm-dev llvm-dev at lists.llvm.org
Tue May 3 09:31:44 PDT 2016


I'm trying to reason about how to find certain bit positions of the absolute value of a given integer value. Specifically, I want to know the highest possibly set bit and lowest possibly set bit of the absolute value, in order to find the range between the two.

Note that I'm specifically trying to be as conservative as possible.

This is what I have so far:

If the sign bit of the original integer is a known 0 (known positive) - the highest possibly set bit is the highest bit not known to be zero, and the lowest possibly set bit is the lowest bit not known to be zero.

If the sign bit of the original integer is a known 1 (known negative) - the highest possibly set bit is the one *to the left of* the *lowest* bit not known to be one (unless that would be the sign bit, in which case it is replaced with the bit to the right of the sign bit), and the lowest possibly set bit is the lowest bit not known to be zero, UNLESS *every* bit other than the sign bit is not known to be one, in which case the highest possibly set bit is the sign bit.

If the sign bit of the original integer is unknown - same as if known negative, except the highest possibly set bit is initially the higher of the two rules for highest possibly set bit.

Is this correct? Can it be less conservative in certain situations? Are there any times where we know that only one of the highest and lowest possibly set bits can actually be set?

I apologize for any headaches this causes.

 - CL

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160503/e9550cc2/attachment.html>


More information about the llvm-dev mailing list