RFR: 8240615: is_power_of_2() has Undefined Behaviour and is inconsistent
Stuart Monteith
stuart.monteith at arm.com
Wed Mar 11 14:26:35 UTC 2020
Oh for goodness sake... Sorry, that's just me not paying attention...
On 11/03/2020 14:22, Andrew Haley wrote:
> On 3/11/20 1:53 PM, Stuart Monteith wrote:
>> Look good, tests ok on aarch64. However, the case for "0" isn't passed
>> in the test, or handled by the function. Is "count_leading_zeros"
>> sufficiently well defined that we can expect it to produce "64" or "32"
>> in this case, or should there be an assertion in exact_log2* to trip
>> when 0 is passed?
>
> Hmm. Am I missing something?
>
> There is, surely, everything you need to reject 0 here:
>
> bool is_power_of_2(T x) {
> return (x > T(0)) && ((x & (x - 1)) == T(0));
> }
>
> inline int exact_log2(intptr_t x) {
> assert(is_power_of_2((uintptr_t)x), "x must be a power of 2: " INTPTR_FORMAT, x);
>
More information about the hotspot-runtime-dev
mailing list