Factor code out of APInt to form a isUIntN helper function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118133 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2010-11-03 00:38:40 +00:00
parent 9372fd3c92
commit 5005e27f97
2 changed files with 7 additions and 1 deletions

View File

@@ -348,7 +348,7 @@ public:
return true; return true;
if (isSingleWord()) if (isSingleWord())
return VAL == (VAL & (~0ULL >> (64 - N))); return isUIntN(N, VAL);
APInt Tmp(N, getNumWords(), pVal); APInt Tmp(N, getNumWords(), pVal);
Tmp.zext(getBitWidth()); Tmp.zext(getBitWidth());
return Tmp == (*this); return Tmp == (*this);

View File

@@ -71,6 +71,12 @@ inline bool isUInt<32>(uint64_t x) {
return static_cast<uint32_t>(x) == x; return static_cast<uint32_t>(x) == x;
} }
/// isUIntN - Checks if an unsigned integer fits into the given (dynamic)
/// bit width.
inline bool isUIntN(unsigned N, uint64_t x) {
return x == (x & (~0ULL >> (64 - N)));
}
/// isMask_32 - This function returns true if the argument is a sequence of ones /// isMask_32 - This function returns true if the argument is a sequence of ones
/// starting at the least significant bit with the remainder zero (32 bit /// starting at the least significant bit with the remainder zero (32 bit
/// version). Ex. isMask_32(0x0000FFFFU) == true. /// version). Ex. isMask_32(0x0000FFFFU) == true.