RFR: 8360192: C2: Make the type of count leading/trailing zero nodes more precise [v3]

Quan Anh Mai qamai at openjdk.org
Mon Jun 23 10:57:27 UTC 2025


On Mon, 23 Jun 2025 10:38:37 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Qizheng Xing has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Narrow type bound
>
> src/hotspot/share/opto/countbitsnode.cpp line 46:
> 
>> 44: static int count_trailing_zeros_long(jlong l) {
>> 45:   return l == 0 ? BitsPerLong : count_trailing_zeros(l);
>> 46: }
> 
> Can you explain why you need this?
> Why is `count_trailing_zeros` and `count_leading_zeros` not enough, when you cast at the use-site?

This is because our implementation does not accept 0 as an input. I suggest doing this at `count_leading_zeros`, it makes more sense and also aligns our behaviour with the well-known [`countr_zero`](https://en.cppreference.com/w/cpp/numeric/countr_zero.html) and [`countl_zero`](https://en.cppreference.com/w/cpp/numeric/countl_zero.html)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25928#discussion_r2161319626


More information about the hotspot-compiler-dev mailing list