Factor code out of APInt to form a isUIntN helper function.
authorDan Gohman <gohman@apple.com>
Wed, 3 Nov 2010 00:38:40 +0000 (00:38 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 3 Nov 2010 00:38:40 +0000 (00:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118133 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
include/llvm/Support/MathExtras.h

index e03f63bebfc229caaa4c1de1cdac889ed2537e7d..d398f8e3f6fc43f6627540a532abe5d83e61b3b8 100644 (file)
@@ -348,7 +348,7 @@ public:
       return true;
 
     if (isSingleWord())
       return true;
 
     if (isSingleWord())
-      return VAL == (VAL & (~0ULL >> (64 - N)));
+      return isUIntN(N, VAL);
     APInt Tmp(N, getNumWords(), pVal);
     Tmp.zext(getBitWidth());
     return Tmp == (*this);
     APInt Tmp(N, getNumWords(), pVal);
     Tmp.zext(getBitWidth());
     return Tmp == (*this);
index 3b907808ddc83995f570fb48981e403a44f949e0..dafb479a99938bbae4e5a6c349415fbf89858d7d 100644 (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
 /// starting at the least significant bit with the remainder zero (32 bit
 /// version).   Ex. isMask_32(0x0000FFFFU) == true.
 /// 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
 /// version).   Ex. isMask_32(0x0000FFFFU) == true.