diff options
author | Owen Anderson <resistor@mac.com> | 2008-06-27 21:48:21 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2008-06-27 21:48:21 +0000 |
commit | 0215fced396e0e7f8861d9f4448cc504d9091f78 (patch) | |
tree | 16deb5d4118fb620a406e0c75cf1952f1de9437b /include/llvm/Support/MathExtras.h | |
parent | a6d2a3ceb31a7b68db2806946ebdb2ba3a783901 (diff) | |
download | external_llvm-0215fced396e0e7f8861d9f4448cc504d9091f78.zip external_llvm-0215fced396e0e7f8861d9f4448cc504d9091f78.tar.gz external_llvm-0215fced396e0e7f8861d9f4448cc504d9091f78.tar.bz2 |
Add a NextPowerOf2 function to calculate the next power of two greater than a given integer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52839 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/MathExtras.h')
-rw-r--r-- | include/llvm/Support/MathExtras.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index f57beed..8a89d85 100644 --- a/include/llvm/Support/MathExtras.h +++ b/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 |