On Thu, 18 Jul 2024 16:06:31 GMT, Raffaello Giulietti <rgiulie...@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