Re: mpz_prevprime

2020-02-11 Thread Niels Möller
Marco Bodrato writes: > Maybe my estimates are wrong. If they are not, the limit for trial > division should be increased more than linearly on the size of the > numbers that are tested. And current code uses prime_limit = nbits / 2; And here "prime_limit" is a limit on the number of primes

Re: mpz_prevprime

2020-02-11 Thread Seth Troisi
I worked your math and tested against some Constants I had, everything agrees. This also matches much of my analysis in my prime gap search where I scale my sieve much more than linearly. On Tue, Feb 11, 2020, 2:13 PM Marco Bodrato wrote: > Ciao, > > Il 2020-02-10 21:01 ni...@lysator.liu.se ha

Re: mpz_prevprime

2020-02-11 Thread Marco Bodrato
Ciao, Il 2020-02-10 21:01 ni...@lysator.liu.se ha scritto: On my laptop, it gives a speedup of about 25% for larger sizes. Not sure how to tune for small sizes, but clearly the old code clamping the size of the prime table based on the bit size is better than doing nothing. The computation of

Re: Overflow in mpz_cmp

2020-02-11 Thread Marco Bodrato
Ciao, Il 2020-02-11 14:56 Marc Glisse ha scritto: On Tue, 11 Feb 2020, Niels Möller wrote: if (usize != vsize) return (usize > vsize) ? 1 : -1; On x86_64, both gcc and clang optimize (usize > vsize) ? 1 : -1 to 2 * (usize > vsize) - 1 (as a single LEA for gcc, 2 ADD for llvm). So the gen

Re: Overflow in mpz_cmp

2020-02-11 Thread Marco Bodrato
Ciao, Il 2020-02-11 14:42 ni...@lysator.liu.se ha scritto: Marco Bodrato writes: diff -r f5601c2a8b11 mpz/cmp.c --- a/mpz/cmp.c Sun Feb 09 16:16:19 2020 +0100 +++ b/mpz/cmp.c Tue Feb 11 14:20:39 2020 +0100 @@ -35,15 +35,15 @@ + cmp = (usize > vsize) - (usize < vsize); + if (cmp != 0) +

Re: Overflow in mpz_cmp

2020-02-11 Thread Marc Glisse
On Tue, 11 Feb 2020, Niels Möller wrote: Marco Bodrato writes: Ciao, Il 2020-02-10 18:25 Guillaume Melquiond ha scritto: When the operand sizes do not match, the mpz_cmp function function just returns the difference of the signed sizes. Unfortunately, this difference might not fit inside th

Re: Overflow in mpz_cmp

2020-02-11 Thread Niels Möller
Marco Bodrato writes: > Ciao, > > Il 2020-02-10 18:25 Guillaume Melquiond ha scritto: >> When the operand sizes do not match, the mpz_cmp function function just >> returns the difference of the signed sizes. Unfortunately, this >> difference might not fit inside the "int" return type, when the nu

Re: Overflow in mpz_cmp

2020-02-11 Thread Marco Bodrato
Ciao, Il 2020-02-10 18:25 Guillaume Melquiond ha scritto: When the operand sizes do not match, the mpz_cmp function function just returns the difference of the signed sizes. Unfortunately, this difference might not fit inside the "int" return type, when the numbers are of opposite sign. In min