RFR: 8349637: Integer.numberOfLeadingZeros outputs incorrectly in certain cases [v3]
Raffaello Giulietti
rgiulietti at openjdk.org
Fri Feb 14 21:29:16 UTC 2025
On Fri, 14 Feb 2025 16:26:13 GMT, Jasmine Karthikeyan <jkarthikeyan at openjdk.org> wrote:
>> Jasmine Karthikeyan has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Improve explanation of logic
>
> It seems we had to fix this before for `Integer.reverseBytes`: https://bugs.openjdk.org/browse/JDK-8305324
@jaskarth I think the implementation can be simplified like so, regardless of whether `src` < 2^P (P = 24 for `float`):
...
t = src >>> 1
t = ~t & src
dst = (float) t
...
This ensures that the leading 1 maintains its position and that the bit immediately to its right (if any) is set to 0. The other bits further to the right are irrelevant.
In this way, the subsequent conversion to `float` cannot "cross the bit boundary", as you express in the initial paragraph, while still maintaining the biased exponent intact.
WDYT?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23579#issuecomment-2660300425
More information about the hotspot-compiler-dev
mailing list