RFR: 8257815: Replace global log2 functions with efficient implementations

Kim Barrett kim.barrett at oracle.com
Tue Dec 8 01:43:12 UTC 2020


> On Dec 7, 2020, at 8:18 PM, Kim Barrett <kbarrett at openjdk.java.net> wrote:
> 
> On Mon, 7 Dec 2020 12:00:48 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> 
>> Naming is hard, but I think the following scheme is reasonable:
>> 
>>    * log2i: any integral type. 0-hostile
> 
> Not yet a review, but the "usual" name is "ilog2".  Do a web search for that and you'll find lots of relevant hits.  I like the short name having the non-zero precondition.  Whether the longer version that tests for zero carry's it's weight is a question.

I think the approach to dealing with negative values should be reconsidered. 

------------------------------------------------------------------------------
src/hotspot/share/utilities/powerOfTwo.hpp 
 49 // Log2 of any integral value, i.e., largest i such that 2^i <= x
 50 // Precondition: x != 0
 51 // For negative values this will return 63 for 64-bit types, 31 for
 52 // 32-bit types, and so on.
 
I think the behavior for negative values here is wrong. The precondition
should be x > 0.  That flows through into the implementation.  This also
affects the design around the proposed _allow_zero function.

------------------------------------------------------------------------------
src/hotspot/share/utilities/powerOfTwo.hpp 
 80 inline int exact_log2(intptr_t value) {
 81   return exact_log2i(value);
 82 }

This is widening the domain to include negative values, which were
previously excluded since it had is_power_of_2 as a precondition, and that
function is false for negative values.  I think the old behavior is correct
and the change is not.

------------------------------------------------------------------------------



More information about the hotspot-dev mailing list