summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2008-06-27 21:48:21 +0000
committerOwen Anderson <resistor@mac.com>2008-06-27 21:48:21 +0000
commit05546f67cbcb85228ab17b7e52f4a960ce680466 (patch)
treec8b72c16ec013a1ce1e86190f2a87f4c37d3d5cf /llvm
parent36b4e8f2fe421e42b11708524c76e3297938fcc5 (diff)
downloadbcm5719-llvm-05546f67cbcb85228ab17b7e52f4a960ce680466.tar.gz
bcm5719-llvm-05546f67cbcb85228ab17b7e52f4a960ce680466.zip
Add a NextPowerOf2 function to calculate the next power of two greater than a given integer.
llvm-svn: 52839
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Support/MathExtras.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index f57beed0939..8a89d85cd58 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -396,6 +396,18 @@ static inline uint64_t MinAlign(uint64_t A, uint64_t B) {
// 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
OpenPOWER on IntegriCloud