Problem with gmp_randinit_set

Marco Bodrato bodrato at mail.dm.unipi.it
Sun Feb 19 05:43:55 UTC 2017


Ciao,

Il Ven, 17 Febbraio 2017 11:04 pm, Niels Möller ha scritto:

>> nisse at lysator.liu.se (Niels Möller) writes:
>>
>> Or if we want to take advantage of the structure, we need an mpn
>> function to reduce numbers modulo 2^19937 - 20023.
>
> Below is a sketch for the 64-bit case, not yet working. These things are
> a bit tricky to get right, but it's not very complex code either.

Just a typo. In

>   rp[SIZE - 1] = cy + (hi & (((mp_limb_t)1<<31) - 1))
>     + mpn_add_1 (rp, rp, SIZE - 1, (hi >> 31) * K);

replace 31 with (64-31), I mean:

  rp[SIZE - 1] = cy + (hi & (((mp_limb_t)1<<(64-31)) - 1))
    + mpn_add_1 (rp, rp, SIZE - 1, (hi >> (64-31)) * K);

and it will work.

It can not be generalised for all bit sizes. It works only if
19937%GMP_NUMB_BITS >= 15 , right?
E.g. with GMP_NUMB_BITS == 32 we shall rshift-then-addmul_1... but with
two versions we shall cover all cases GMP_NUMB_BITS >= 15.

Regards,
m

-- 
http://bodrato.it/papers/



More information about the gmp-bugs mailing list