RFR: 8319822: Use a linear-time algorithm for assert_different_registers() [v11]

Kim Barrett kbarrett at openjdk.org
Wed May 29 20:06:07 UTC 2024


On Tue, 28 May 2024 15:57:19 GMT, Andrew Haley <aph at openjdk.org> wrote:

>> At the present time, `assert_different_registers()` uses an O(N**2) algorithm in assert_different_registers(). We can utilize RegSet to do it in O(N) time. This would be a useful optimization for all builds with assertions enabled.
>> 
>> In addition, it would be useful to be able to static_assert different registers. 
>> 
>> Also, I've taken the opportunity to expand the maximum size of a RegSet to 64 on 64-bit platforms.
>> 
>> I also fixed a bug: sometimes `noreg` is passed to `assert_different_registers()`, but it may only be passed once or a spurious assertion is triggered.
>
> Andrew Haley has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update src/hotspot/share/asm/register.hpp
>   
>   Co-authored-by: Stefan Karlsson <stefan.karlsson at oracle.com>

Changes requested by kbarrett (Reviewer).

src/hotspot/cpu/x86/register_x86.hpp line 395:

> 393: inline Register AbstractRegSet<Register>::first() {
> 394:   size_t first = _bitset & -_bitset;
> 395:   return first != 0 ? as_Register(exact_log2(first)) : noreg;

This could instead be

if (_bitset == 0) { return noreg; }
return as_register(count_trailing_zeros(_bitset));

which would be consistent with how `last` is being calculated.  Note that exact_log2 bottoms
out in count_trailing_zeros.

Similarly for the XMMRegister case below.

src/hotspot/share/asm/register.hpp line 256:

> 254: // Debugging support
> 255: 
> 256: template<typename R, typename... Rx>

Rx is unused.

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

PR Review: https://git.openjdk.org/jdk/pull/16617#pullrequestreview-2086193112
PR Review Comment: https://git.openjdk.org/jdk/pull/16617#discussion_r1619355839
PR Review Comment: https://git.openjdk.org/jdk/pull/16617#discussion_r1619393053


More information about the hotspot-compiler-dev mailing list