[llvm-branch-commits] [llvm-branch] r118525 - in /llvm/branches/Apple/whitney/include/llvm: ADT/APInt.h Support/MathExtras.h

Daniel Dunbar daniel at zuster.org
Tue Nov 9 09:28:10 PST 2010


Author: ddunbar
Date: Tue Nov  9 11:28:09 2010
New Revision: 118525

URL: http://llvm.org/viewvc/llvm-project?rev=118525&view=rev
Log:
Merge r118133:
--
Author: Dan Gohman <gohman at apple.com>
Date:   Wed Nov 3 00:38:40 2010 +0000

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

Modified:
    llvm/branches/Apple/whitney/include/llvm/ADT/APInt.h
    llvm/branches/Apple/whitney/include/llvm/Support/MathExtras.h

Modified: llvm/branches/Apple/whitney/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/include/llvm/ADT/APInt.h?rev=118525&r1=118524&r2=118525&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/include/llvm/ADT/APInt.h (original)
+++ llvm/branches/Apple/whitney/include/llvm/ADT/APInt.h Tue Nov  9 11:28:09 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/branches/Apple/whitney/include/llvm/Support/MathExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/include/llvm/Support/MathExtras.h?rev=118525&r1=118524&r2=118525&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/include/llvm/Support/MathExtras.h (original)
+++ llvm/branches/Apple/whitney/include/llvm/Support/MathExtras.h Tue Nov  9 11:28:09 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-branch-commits mailing list