[RFC][PATCH] mini-gmp: move memory allocation out of loops

Ilya Yanok ilya.yanok at gmail.com
Sat Feb 10 18:07:02 UTC 2018


Marco, Niels,

thanks a lot for your comments. You've found a much nicer solution than my
initial one.

On Sat, Feb 10, 2018 at 6:11 PM Niels Möller <nisse at lysator.liu.se> wrote:

> >> I also note that we have a very similar allocation in
> >> mpn_div_qr_2_preinv.
> >
> > Currently it is used just once in the whole mini-library, by the call:
> > mpn_div_qr_2_preinv (qp, np, np, nn, inv);
> >
> > i.e. values in np get overwritten to store the reminder. If we take this
> > single use into account, we can always shift inplace...
>
> Note that remainder is always two limbs. So reusing qp area would be
> more natural (but unlike np, qp == NULL is allowed). So not sure what
>

Correct me if I'm wrong, but I think in mpn_div_qr_2_preinv, unlike
mpn_div_qr_1_preinv, (array pointed by) qp can be smaller than np, so there
is no way it can be easily used to store the shifted np.

We can still check if np == qp or np == rp, which would mean we can do
shift in place.


> Maybe the below is a reasonable way (note that the #if:ed out
> mpn_div_qr_2 can't be easily supported with this interface).
>
>
This could be another option.

Regards, Ilya.


More information about the gmp-devel mailing list