Moving LOOP_ON_SIEVE_* macros to gmp-impl.h

Marco Bodrato bodrato at mail.dm.unipi.it
Tue Mar 17 18:10:34 UTC 2020


Ciao,

Il 2020-03-16 04:36 Seth Troisi ha scritto:
> Per Marco's comments in my prev_prime/next_prime patch
> I moved some of the primesieve macros and functions to gmp-impl.h


There are two reasons why I never moved those functions and macros to 
gmp-impl.h, two aspects of one problem: the interface is not clean.

First: I'm not sure I like macros that open a loop and don't close it...

Second: n_to_bit() is not injective, obviously.
E.g. n_to_bit(7) = 1, n_to_bit(10) = 1 .
This is not a problem when its value is used for n_to_bit (<end>), but 
generates confusion if n_to_bit(<start>) is used on a <start> value that 
is not carefully chosen...


The first, is maybe just an opinion of mine, do you think those macros 
are reasonably clean?

The second, should be healed somehow. The easier way probably is to 
write two different functions:
static mp_limb_t
n_to_bit_end (mp_limb_t n) { return ((n-5)|1)/3U; }

static mp_limb_t
n_to_bit_start (mp_limb_t n) { return (n-2-n%2)/3U; }

> bit_to_n (renamed sieve_bit_to_n)
> id_to_n (renamed sieve_id_to_n)
> n_to_bit (renamed sieve_n_to_bit)

Renaming is a good idea, IMO.

> This allows the four (soon to be five) identical copies in
> bin_uiui, oddfac_1, primorial_ui, and tests/devel/primes
> to be cleaned up.

Uhm I have (slightly) changed the macros. Not the interface.

> It's not clear where this should be documented, if someone tells

Niels' answer is perfect.

Ĝis,
m


More information about the gmp-devel mailing list