Moving LOOP_ON_SIEVE_* macros to gmp-impl.h

Seth Troisi braintwo at gmail.com
Wed Mar 25 07:20:32 UTC 2020


I added n_to_bit_start and after some misadventure with mistyping I got it
working.

One quick question: in this code block should the SWING_ON_PRIME be
indented?

LOOP_ON_SIEVE_BEGIN (prime, ...);
SH_SWING_A_PRIME (prime, ...);
LOOP_ON_SIEVE_END;

One thing I don't like about the patch is that most of the
LOOP_ON_SIEVE_BEGIN lines are now 90-100 characters
It's possible that I should pull out `mp_limb_t start =
sieve_n_to_bit_start(n);` in a number of places

One thing I do like is
7 files changed, 106 insertions(+), 250 deletions(-)
with all the addition in gmp-impl.h which is already HUGE


On Tue, Mar 17, 2020 at 11:10 AM Marco Bodrato <bodrato at mail.dm.unipi.it>
wrote:

> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LOOP_ON_S_macros3.patch
Type: text/x-patch
Size: 17206 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20200325/eb6f060b/attachment.bin>


More information about the gmp-devel mailing list