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

2024-07-17 Thread Raffaello Giulietti
On Wed, 17 Jul 2024 16:39:10 GMT, fabioromano1 wrote: >> Can try with the old release and the incorrect code again? >> If the results disagree with newer releases then I'd be interested in which >> release you were using, as to analyze the generated code and possibly file a >> bug report for th

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 16:16:12 GMT, Raffaello Giulietti wrote: >> Can try with the old release and the incorrect code again? >> If the results disagree with newer releases then I'd be interested in which >> release you were using, as to analyze the generated code and possibly file a >> bug repor

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 16:16:12 GMT, Raffaello Giulietti wrote: >> Can try with the old release and the incorrect code again? >> If the results disagree with newer releases then I'd be interested in which >> release you were using, as to analyze the generated code and possibly file a >> bug repor

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

2024-07-17 Thread Raffaello Giulietti
On Wed, 17 Jul 2024 15:59:30 GMT, fabioromano1 wrote: >> Sorry, disregard the above as it doesn't work for x = 0. > > @rgiulietti Probably I used a too older release to try the incorrect code Can try with the old release and the incorrect code again? If the results disagree with newer releases t

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

2024-07-17 Thread Raffaello Giulietti
On Wed, 17 Jul 2024 16:15:47 GMT, Raffaello Giulietti wrote: >> @rgiulietti Probably I used a too older release to try the incorrect code > > Can try with the old release and the incorrect code again? > If the results disagree with newer releases then I'd be interested in which > release you we

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 15:11:36 GMT, Raffaello Giulietti wrote: >> Also, this avoids a test >> >> if (Long.compareUnsigned(x, s * s - 1) <= 0) { // benign over- >> and underflows >> s--; >> } > > Sorry, disregard the above as it doesn't work for x = 0. @r

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 15:11:36 GMT, Raffaello Giulietti wrote: >> Also, this avoids a test >> >> if (Long.compareUnsigned(x, s * s - 1) <= 0) { // benign over- >> and underflows >> s--; >> } > > Sorry, disregard the above as it doesn't work for x = 0. >

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

2024-07-17 Thread Raffaello Giulietti
On Wed, 17 Jul 2024 15:08:22 GMT, Raffaello Giulietti wrote: >> @rgiulietti This is so strange... anyway, I tried also `long x = n * n`, >> `long s = Math.round(Math.sqrt(x >= 0 ? x : x + 0x1p64))` with the test `s < >> n`, which I think it's more mathematically natural, and also this never

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

2024-07-17 Thread Raffaello Giulietti
On Wed, 17 Jul 2024 14:30:33 GMT, fabioromano1 wrote: >> I tried on older release, they all agree. > > @rgiulietti This is so strange... anyway, I tried also `long x = n * n`, > `long s = Math.round(Math.sqrt(x >= 0 ? x : x + 0x1p64))` with the test `s < > n`, which I think it's more mathemati

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

2024-07-17 Thread Raffaello Giulietti
On Wed, 17 Jul 2024 14:11:20 GMT, fabioromano1 wrote: >> There are no counterexamples for perfect squares if you write `long s = >> (long) Math.rint(Math.sqrt(x >= 0 ? x : x + 0x1p64));`. > > @rgiulietti Is it normal that the same code did not find counterexamples > until recently, and now it f

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 14:17:48 GMT, Raffaello Giulietti wrote: >> @rgiulietti Is it normal that the same code did not find counterexamples >> until recently, and now it finds them? > > I tried on older release, they all agree. @rgiulietti This is so strange... anyway, I tried also `long x = n *

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 13:57:20 GMT, Raffaello Giulietti wrote: >> I hope these errors are not due to an implementation change in the virtual >> machine instructions... > > There are no counterexamples for perfect squares if you write `long s = > (long) Math.rint(Math.sqrt(x >= 0 ? x : x + 0x1p64

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

2024-07-17 Thread Raffaello Giulietti
On Wed, 17 Jul 2024 13:57:06 GMT, fabioromano1 wrote: >> In fact, if you run this code: >> `long limit = 1L << 32; >> for (long n = 0; n < limit; n++) { >> long x = n * n; >> if (n != (long) Math.sqrt(x >= 0 ? x : x + 0x1p64)) { >> System.out.println(n); >> } >> }` >>

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 13:48:59 GMT, fabioromano1 wrote: >> src/java.base/share/classes/java/math/MutableBigInteger.java line 1978: >> >>> 1976: * is either correct, or rounded up by one if the value >>> is too high >>> 1977: * and too close to the next perfect square. >>

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

2024-07-17 Thread fabioromano1
On Wed, 17 Jul 2024 13:15:17 GMT, Raffaello Giulietti wrote: >> fabioromano1 has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Optimized shift-and-add operations > > src/java.base/share/classes/java/math/MutableBigInteger.java line 1978:

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

2024-07-17 Thread Raffaello Giulietti
On Mon, 15 Jul 2024 19:58:23 GMT, fabioromano1 wrote: >> I have implemented the Zimmermann's square root algorithm, available in >> works [here](https://inria.hal.science/inria-00072854/en/) and >> [here](https://www.researchgate.net/publication/220532560_A_proof_of_GMP_square_root). >> >> The

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

2024-07-15 Thread fabioromano1
On Mon, 15 Jul 2024 19:58:23 GMT, fabioromano1 wrote: >> I have implemented the Zimmermann's square root algorithm, available in >> works [here](https://inria.hal.science/inria-00072854/en/) and >> [here](https://www.researchgate.net/publication/220532560_A_proof_of_GMP_square_root). >> >> The

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

2024-07-15 Thread fabioromano1
> I have implemented the Zimmermann's square root algorithm, available in works > [here](https://inria.hal.science/inria-00072854/en/) and > [here](https://www.researchgate.net/publication/220532560_A_proof_of_GMP_square_root). > > The algorithm is proved to be asymptotically faster than the New