[Gmp-commit] /home/hgfiles/gmp: Avid a copy (assume we do not need mpn_divexa...

mercurial at gmplib.org mercurial at gmplib.org
Sat Jan 15 08:25:34 CET 2011


details:   /home/hgfiles/gmp/rev/2eb47368ef96
changeset: 13745:2eb47368ef96
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Jan 15 08:25:10 2011 +0100
description:
Avid a copy (assume we do not need mpn_divexact(X,X,n,Y,m) )

diffstat:

 ChangeLog              |   4 ++++
 mpn/generic/divexact.c |  14 ++++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)

diffs (55 lines):

diff -r e1809cb73c65 -r 2eb47368ef96 ChangeLog
--- a/ChangeLog	Fri Jan 14 10:19:39 2011 +0100
+++ b/ChangeLog	Sat Jan 15 08:25:10 2011 +0100
@@ -1,3 +1,7 @@
+2011-01-15 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpn/generic/divexact.c: Avoid COPY if not needed.
+
 2011-01-14  Torbjorn Granlund  <tege at gmplib.org>
 
 	* gmp-impl.h (struct cpuvec_t): Add field bmod_1_to_mod_1_threshold.
diff -r e1809cb73c65 -r 2eb47368ef96 mpn/generic/divexact.c
--- a/mpn/generic/divexact.c	Fri Jan 14 10:19:39 2011 +0100
+++ b/mpn/generic/divexact.c	Sat Jan 15 08:25:10 2011 +0100
@@ -38,7 +38,7 @@
 {
   unsigned shift;
   mp_size_t qn;
-  mp_ptr tp, wp;
+  mp_ptr tp;
   TMP_DECL;
 
   ASSERT (dn > 0);
@@ -67,7 +67,9 @@
 
   if (shift > 0)
     {
-      mp_size_t ss = (dn > qn) ? qn + 1 : dn;
+      mp_ptr wp;
+      mp_size_t ss;
+      ss = (dn > qn) ? qn + 1 : dn;
 
       tp = TMP_ALLOC_LIMBS (ss);
       mpn_rshift (tp, dp, ss, shift);
@@ -77,18 +79,14 @@
 	 to shift one limb beyond qn. */
       wp = TMP_ALLOC_LIMBS (qn + 1);
       mpn_rshift (wp, np, qn + 1, shift);
-    }
-  else
-    {
-      wp = TMP_ALLOC_LIMBS (qn);
-      MPN_COPY (wp, np, qn);
+      np = wp;
     }
 
   if (dn > qn)
     dn = qn;
 
   tp = TMP_ALLOC_LIMBS (mpn_bdiv_q_itch (qn, dn));
-  mpn_bdiv_q (qp, wp, qn, dp, dn, tp);
+  mpn_bdiv_q (qp, np, qn, dp, dn, tp);
   TMP_FREE;
 }
 


More information about the gmp-commit mailing list