[Gmp-commit] /var/hg/gmp: mini-gmp.c (mpn_div_qr_1_preinv): Avoid temporary a...

mercurial at gmplib.org mercurial at gmplib.org
Sat Feb 10 17:06:23 UTC 2018


details:   /var/hg/gmp/rev/164971d5c8d0
changeset: 17559:164971d5c8d0
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Sat Feb 10 18:05:32 2018 +0100
description:
mini-gmp.c (mpn_div_qr_1_preinv): Avoid temporary allocation

diffstat:

 mini-gmp/ChangeLog  |  5 +++++
 mini-gmp/mini-gmp.c |  5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diffs (34 lines):

diff -r 93d639390d6f -r 164971d5c8d0 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Fri Feb 09 16:44:49 2018 +0100
+++ b/mini-gmp/ChangeLog	Sat Feb 10 18:05:32 2018 +0100
@@ -1,3 +1,8 @@
+2018-02-10  Niels Möller  <nisse at lysator.liu.se>
+
+	* mini-gmp.c (mpn_div_qr_1_preinv): When qp is non-NULL, reuse
+	area for shifted input, to avoid an allocation.
+
 2018-01-15 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mini-gmp/mini-gmp.c (gmp_popcount_limb): Micro-optimisations.
diff -r 93d639390d6f -r 164971d5c8d0 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Fri Feb 09 16:44:49 2018 +0100
+++ b/mini-gmp/mini-gmp.c	Sat Feb 10 18:05:32 2018 +0100
@@ -930,7 +930,8 @@
 
   if (inv->shift > 0)
     {
-      tp = gmp_xalloc_limbs (nn);
+      /* Shift, reusing qp area if possible. In-place shift if qp == np. */
+      tp = qp ? qp : gmp_xalloc_limbs (nn);
       r = mpn_lshift (tp, np, nn, inv->shift);
       np = tp;
     }
@@ -947,7 +948,7 @@
       if (qp)
 	qp[nn] = q;
     }
-  if (inv->shift > 0)
+  if ((inv->shift > 0) && (tp != qp))
     gmp_free (tp);
 
   return r >> inv->shift;


More information about the gmp-commit mailing list