RFR: 8334755: Asymptotically faster implementation of square root algorithm [v32]

fabioromano1 duke at openjdk.org
Thu Jul 18 16:16:35 UTC 2024


On Thu, 18 Jul 2024 16:06:31 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>>> Experimentally, the following seems a bit faster. In some cases, it avoids a full multiplication, some updates, and has one less test. I hope it is correct as well ;-)
>> 
>> It's a nice code, but I'm afraid that if `s == LONG_MASK` and `Long.compareUnsigned(x, s * s) >= 0`, the overflow check is unavoidable...
>
> I guess you are concerned about an overflow in `s2 + 2 * s`?
> 
> If s = 2^32 - 1, then s2 = 2^64 - 2·2^32 + 1 and 2s = 2·2^32 - 2, without overflows.
> Thus, s2 + 2s = 2^64 - 1, without overflows.

@rgiulietti True, it's almost borderline code...

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19710#discussion_r1683135335


More information about the core-libs-dev mailing list