[llvm] Use Log2_64_Ceil to compute PowerOf2Ceil (PR #67580)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 23:10:31 PDT 2023
MaskRay wrote:
> The current implemention of `NextPowerOf2` seems to be the most portable way to achieve the power of 2, which is equivalent to `int(pow(2, ceil(log2(x))))`. Only noticeable difference to me is that in the PR implementation, if `x > (UINT32_MAX + 1)`, the current `NextPowerOf2` and PR changes of that function will yield different results.
Thanks for catching this.
Minor correction, when the argument is larger than 2**63, `NextPowerOf2(A - 1)` returns 0 (reasonable) while `UINT64_C(1) << 64-std::countl_zero(A-1)` is undefined (the right operand is 0)
https://github.com/llvm/llvm-project/pull/67580
More information about the llvm-commits
mailing list