[llvm-commits] [llvm] r52839 - /llvm/trunk/include/llvm/Support/MathExtras.h
Owen Anderson
resistor at mac.com
Fri Jun 27 14:48:21 PDT 2008
Author: resistor
Date: Fri Jun 27 16:48:21 2008
New Revision: 52839
URL: http://llvm.org/viewvc/llvm-project?rev=52839&view=rev
Log:
Add a NextPowerOf2 function to calculate the next power of two greater than a given integer.
Modified:
llvm/trunk/include/llvm/Support/MathExtras.h
Modified: llvm/trunk/include/llvm/Support/MathExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=52839&r1=52838&r2=52839&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h (original)
+++ llvm/trunk/include/llvm/Support/MathExtras.h Fri Jun 27 16:48:21 2008
@@ -396,6 +396,18 @@
// The largest power of 2 that divides both A and B.
return (A | B) & -(A | B);
}
+
+/// NextPowerOf2 - Returns the next power of two (in 64-bits)
+/// that is strictly greater than A. Returns zero on overflow.
+static inline uint64_t NextPowerOf2(uint64_t A) {
+ A |= (A >> 1);
+ A |= (A >> 2);
+ A |= (A >> 4);
+ A |= (A >> 8);
+ A |= (A >> 16);
+ A |= (A >> 32);
+ return A + 1;
+}
} // End llvm namespace
More information about the llvm-commits
mailing list