[llvm-commits] [llvm] r118133 - in /llvm/trunk/include/llvm: ADT/APInt.h Support/MathExtras.h

Dan Gohman gohman at apple.com
Tue Nov 2 17:38:41 PDT 2010


Author: djg
Date: Tue Nov  2 19:38:40 2010
New Revision: 118133

URL: http://llvm.org/viewvc/llvm-project?rev=118133&view=rev
Log:
Factor code out of APInt to form a isUIntN helper function.

Modified:
    llvm/trunk/include/llvm/ADT/APInt.h
    llvm/trunk/include/llvm/Support/MathExtras.h

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=118133&r1=118132&r2=118133&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Tue Nov  2 19:38:40 2010
@@ -348,7 +348,7 @@
       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);

Modified: llvm/trunk/include/llvm/Support/MathExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=118133&r1=118132&r2=118133&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h (original)
+++ llvm/trunk/include/llvm/Support/MathExtras.h Tue Nov  2 19:38:40 2010
@@ -71,6 +71,12 @@
   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.





More information about the llvm-commits mailing list