RFR: 8360192: C2: Make the type of count leading/trailing zero nodes more precise [v3]
Qizheng Xing
qxing at openjdk.org
Tue Jun 24 07:37:30 UTC 2025
On Mon, 23 Jun 2025 10:54:57 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
>> 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)
> 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?
@eme64 The explanation of @merykitty is right, the implementation of `count_leading_zeros` and `count_trailing_zeros` reject zero as the input.
Perhaps we could open another PR to add zero support for these functions, since it's less relevant to this node type change and might require other changes to the code that calls them.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25928#discussion_r2163180590
More information about the hotspot-compiler-dev
mailing list