RFR: 8234331: Add robust and optimized utility for rounding up to next power of two+
David Holmes
david.holmes at oracle.com
Tue Nov 26 10:23:12 UTC 2019
On 26/11/2019 8:06 pm, Claes Redestad wrote:
>
>
> On 2019-11-26 10:50, David Holmes wrote:
>> Hi Claes,
>>
>> Just some high-level comments
>>
>> - should next_power_of_two be defined in globalDefinitions.hpp along
>> side the related functionality ie is_power_of_two ?
>
> I thought we are trying to move things _out_ of globalDefinitions. I
We are? I don't recall hearing that. But wherever these go seems they
all belong together.
> agree align.hpp might not be the best place, either, though..
I thought align.hpp as strange place too. :)
>>
>> - can next_power_of_two build on the existing log2_* functions (or
>> vice versa)?
>
> Yes, log2_intptr et al could probably be tamed to do a single step
> operation, although we'd need to add 64-bit implementations in
> count_leading_zeros. At least these log2_* functions already deal with
> overflows without looping forever.
>
>>
>> - do the existing ZUtils not cover the same general area?
>>
>> ./share/gc/z/zUtils.inline.hpp
>>
>> inline size_t ZUtils::round_up_power_of_2(size_t value) {
>> assert(value != 0, "Invalid value");
>>
>> if (is_power_of_2(value)) {
>> return value;
>> }
>>
>> return (size_t)1 << (log2_intptr(value) + 1);
>> }
>>
>> inline size_t ZUtils::round_down_power_of_2(size_t value) {
>> assert(value != 0, "Invalid value");
>> return (size_t)1 << log2_intptr(value);
>> }
>
> round_up_power_of_2 is similar, but not identical (next_power_of_two
> doesn't care if the value is already a power of 2, nor should it).
Okay but seems perhaps these should also be moved out of ZUtils and
co-located with the other "power of two" functions.
Cheers,
David
-----
> /Claes
More information about the hotspot-runtime-dev
mailing list