mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 23:32:27 +00:00
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
This commit is contained in:
parent
97388469b1
commit
d98a45d29a
@ -397,6 +397,18 @@ static inline uint64_t MinAlign(uint64_t A, uint64_t 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
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user