RFR: 8240829: Use a fast O(1) algorithm for exact_log2

Andrew Haley aph at redhat.com
Tue Mar 10 17:29:26 UTC 2020


exact_log2() is used a great deal in HotSpot, especially at
startup. exact_log2() uses a naive iterative algorithm. We should do
better, and in particular we should use an algorithm that compilers
commonly optimize well, so that constant expressions that use
exact_log2 are computed at compilation time.

GCC reliably does the constant propagation so that exact_log2(const)
calculations are always treated as constants, and even if the argument
is not a constant the runtime effort is no more than a multiplication,
a shift, and a load.

I also added a test. This is one of those few algorithms that can be
exhaustively tested, so I have very high confidence that it is correct.

OK?

http://cr.openjdk.java.net/~aph/8240829-1/

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the hotspot-dev mailing list