[RFC][PATCH] mini-gmp: move memory allocation out of loops
Marco Bodrato
bodrato at mail.dm.unipi.it
Fri Feb 9 20:51:21 UTC 2018
Ciao!
Il Mar, 6 Febbraio 2018 7:21 pm, Ilya Yanok ha scritto:
> I did a small patch for mini-gmp, that removes memory allocations in loop,
> when mpz_get_str gets called. This might be undesired behaviour in the
May I suggest a different approach?
Modify mpn_div_qr_1_preinv to work in-place, whenever the funcion is
called to overwrite its input anyway.
I mean:
------8<------
diff -r c9ee97d5775c mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Thu Feb 08 13:11:17 2018 +0100
+++ b/mini-gmp/mini-gmp.c Fri Feb 09 21:31:11 2018 +0100
@@ -930,7 +930,7 @@
if (inv->shift > 0)
{
- tp = gmp_xalloc_limbs (nn);
+ tp = (qp == np) ? qp : gmp_xalloc_limbs (nn);
r = mpn_lshift (tp, np, nn, inv->shift);
np = tp;
}
@@ -947,7 +947,7 @@
if (qp)
qp[nn] = q;
}
- if (inv->shift > 0)
+ if (inv->shift > 0 && (tp != qp))
gmp_free (tp);
return r >> inv->shift;
------8<------
Can you check if this gives you the desired result? I did not test it widely.
Ĝis,
m
--
http://bodrato.it/papers/
More information about the gmp-devel
mailing list