RFR: 8234331: Add robust and optimized utility for rounding up to next power of two+
Claes Redestad
claes.redestad at oracle.com
Tue Nov 26 10:06:29 UTC 2019
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
agree align.hpp might not be the best place, either, though..
>
> - 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).
/Claes
More information about the hotspot-compiler-dev
mailing list