[llvm-commits] [llvm] r107199 - /llvm/trunk/include/llvm/ADT/SmallPtrSet.h
Jakob Stoklund Olesen
stoklund at 2pi.dk
Wed Jun 30 08:02:24 PDT 2010
On Jun 30, 2010, at 7:49 AM, Duncan Sands wrote:
> Hi Jakob,
>
>>> NextPowerOfTwo was already used to ensure that SmallSizePowTwo is a power
>>> of two, no need to do it a second time (NextPowerOfTwo is idempotent).
>>
>> No it isn't.
>>
>> Ignoring overflow, NextPowerOfTwo(x) is always strictly greater than x.
>
> are you sure? C++ templates make my head hurt, but as far as I can see it
> works as follows.
Oh wait, there's a template?
I was talking about the function in MathExtras.h:
/// 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;
}
You are right, the template is idempotent.
Clearly the meaning of the word 'next' is up for debate.
/jakob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100630/c78269b8/attachment.bin>
More information about the llvm-commits
mailing list