[Gmp-commit] /var/hg/gmp: 10 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Wed Dec 28 17:41:49 UTC 2016


details:   /var/hg/gmp/rev/15c15a81ad46
changeset: 17169:15c15a81ad46
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:20:00 2016 +0100
description:
tune/speed: support mpz_mfac_uiui

details:   /var/hg/gmp/rev/b3d9196f3247
changeset: 17170:b3d9196f3247
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:24:03 2016 +0100
description:
tests/mpz/t-primorial_ui.c: Add randomization to the test

details:   /var/hg/gmp/rev/76521003b199
changeset: 17171:76521003b199
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:30:06 2016 +0100
description:
mpz/tdiv_r.c: Avoid allocating too much space in some corner-case conditions

details:   /var/hg/gmp/rev/233dc5ac07aa
changeset: 17172:233dc5ac07aa
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:30:57 2016 +0100
description:
mpz/tdiv_r_2exp.c: Rearrange counting non-zero limbs.

details:   /var/hg/gmp/rev/2fb3c61ea4d8
changeset: 17173:2fb3c61ea4d8
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:31:55 2016 +0100
description:
mpz/tdiv_q.c: factor some code in different branches

details:   /var/hg/gmp/rev/67499db1cb1a
changeset: 17174:67499db1cb1a
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:32:48 2016 +0100
description:
mpz/powm_ui.c: Use TMP_ALLOC_LIMBS_x macros

details:   /var/hg/gmp/rev/e4a02235c42e
changeset: 17175:e4a02235c42e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:33:53 2016 +0100
description:
mpz/powm_sec.c: Use TMP_ALLOC_LIMBS_x macros

details:   /var/hg/gmp/rev/3f0feaa9b145
changeset: 17176:3f0feaa9b145
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:34:51 2016 +0100
description:
mpz/mfac_uiui.c: Avoid a warning

details:   /var/hg/gmp/rev/be5965a12192
changeset: 17177:be5965a12192
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:38:23 2016 +0100
description:
mpz/and.c: Alloc only when needed

details:   /var/hg/gmp/rev/668d5f284a44
changeset: 17178:668d5f284a44
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed Dec 28 18:39:40 2016 +0100
description:
Use MPZ_NEWALLOC and other macros result

diffstat:

 mpz/and.c                  |   8 +++-----
 mpz/divexact.c             |   5 ++---
 mpz/fdiv_qr_ui.c           |   3 +--
 mpz/gcd_ui.c               |   2 +-
 mpz/inp_str.c              |   2 +-
 mpz/iset.c                 |   4 ++--
 mpz/lucnum2_ui.c           |   4 ++--
 mpz/lucnum_ui.c            |   2 +-
 mpz/mfac_uiui.c            |   7 ++++---
 mpz/mul_i.h                |   2 +-
 mpz/n_pow_ui.c             |   2 +-
 mpz/powm.c                 |   2 +-
 mpz/powm_sec.c             |   7 +++----
 mpz/powm_ui.c              |   9 +++------
 mpz/random2.c              |   2 +-
 mpz/root.c                 |   2 +-
 mpz/rootrem.c              |   4 ++--
 mpz/set_f.c                |   2 +-
 mpz/sqrtrem.c              |   3 ++-
 mpz/tdiv_q.c               |  17 ++++++-----------
 mpz/tdiv_r.c               |  12 ++++++------
 mpz/tdiv_r_2exp.c          |  13 ++++++-------
 mpz/tdiv_r_ui.c            |   2 +-
 tests/mpz/t-primorial_ui.c |  33 ++++++++++++++++++++++++++++++++-
 tune/common.c              |  36 +++++++++++++++++++++++++++++++++---
 tune/speed.c               |   3 ++-
 tune/speed.h               |   3 ++-
 27 files changed, 121 insertions(+), 70 deletions(-)

diffs (truncated from 631 to 300 lines):

diff -r afcb4e293a00 -r 668d5f284a44 mpz/and.c
--- a/mpz/and.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/and.c	Wed Dec 28 18:39:40 2016 +0100
@@ -1,7 +1,7 @@
 /* mpz_and -- Logical and.
 
 Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2003, 2005, 2012,
-2015 Free Software Foundation, Inc.
+2015, 2016 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -61,14 +61,13 @@
 
 	  /* Handle allocation, now then we know exactly how much space is
 	     needed for the result.  */
-	  res_ptr = MPZ_NEWALLOC (res, res_size);
 	  /* Don't re-read op1_ptr and op2_ptr.  Since res_size <=
 	     MIN(op1_size, op2_size), res is not changed when op1
 	     is identical to res or op2 is identical to res.  */
 
 	  SIZ(res) = res_size;
 	  if (LIKELY (res_size != 0))
-	    mpn_and_n (res_ptr, op1_ptr, op2_ptr, res_size);
+	    mpn_and_n (MPZ_NEWALLOC (res, res_size), op1_ptr, op2_ptr, res_size);
 	  return;
 	}
       else /* op2_size < 0 */
@@ -226,14 +225,13 @@
 
 	/* Handle allocation, now then we know exactly how much space is
 	   needed for the result.  */
-	res_ptr = MPZ_NEWALLOC (res, res_size);
 	/* Don't re-read OP1_PTR.  Since res_size <= op1_size,
 	   op1 is not changed if it is identical to res.
 	   Don't re-read OP2_PTR.  It points to temporary space--never
 	   to the space PTR(res) used to point to before reallocation.  */
 
 	if (LIKELY (res_size != 0))
-	  mpn_andn_n (res_ptr, op1_ptr, op2_ptr, res_size);
+	  mpn_andn_n (MPZ_NEWALLOC (res, res_size), op1_ptr, op2_ptr, res_size);
 
 	SIZ(res) = res_size;
       }
diff -r afcb4e293a00 -r 668d5f284a44 mpz/divexact.c
--- a/mpz/divexact.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/divexact.c	Wed Dec 28 18:39:40 2016 +0100
@@ -33,7 +33,6 @@
 
 
 #include "gmp-impl.h"
-#include "longlong.h"
 
 void
 mpz_divexact (mpz_ptr quot, mpz_srcptr num, mpz_srcptr den)
@@ -73,7 +72,7 @@
   if (quot == num || quot == den)
     qp = TMP_ALLOC_LIMBS (qn);
   else
-    qp = MPZ_REALLOC (quot, qn);
+    qp = MPZ_NEWALLOC (quot, qn);
 
   np = PTR(num);
   dp = PTR(den);
@@ -82,7 +81,7 @@
   MPN_NORMALIZE (qp, qn);
 
   if (qp != PTR(quot))
-    MPN_COPY (MPZ_REALLOC (quot, qn), qp, qn);
+    MPN_COPY (MPZ_NEWALLOC (quot, qn), qp, qn);
 
   SIZ(quot) = (SIZ(num) ^ SIZ(den)) >= 0 ? qn : -qn;
 
diff -r afcb4e293a00 -r 668d5f284a44 mpz/fdiv_qr_ui.c
--- a/mpz/fdiv_qr_ui.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/fdiv_qr_ui.c	Wed Dec 28 18:39:40 2016 +0100
@@ -61,8 +61,7 @@
       mp_ptr rp;
       mp_size_t rn;
 
-      MPZ_REALLOC (rem, 2);
-      rp = PTR(rem);
+      rp = MPZ_REALLOC (rem, 2);
 
       if (nn == 1)		/* tdiv_qr requirements; tested above for 0 */
 	{
diff -r afcb4e293a00 -r 668d5f284a44 mpz/gcd_ui.c
--- a/mpz/gcd_ui.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/gcd_ui.c	Wed Dec 28 18:39:40 2016 +0100
@@ -63,7 +63,7 @@
 	{
 	  if (u != w)
 	    {
-	      MPZ_REALLOC (w, un);
+	      MPZ_NEWALLOC (w, un);
 	      MPN_COPY (PTR(w), PTR(u), un);
 	    }
 	  SIZ(w) = un;
diff -r afcb4e293a00 -r 668d5f284a44 mpz/inp_str.c
--- a/mpz/inp_str.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/inp_str.c	Wed Dec 28 18:39:40 2016 +0100
@@ -162,7 +162,7 @@
   else
     {
       LIMBS_PER_DIGIT_IN_BASE (xsize, str_size, base);
-      MPZ_REALLOC (x, xsize);
+      MPZ_NEWALLOC (x, xsize);
 
       /* Convert the byte array in base BASE to our bignum format.  */
       xsize = mpn_set_str (PTR (x), (unsigned char *) str, str_size, base);
diff -r afcb4e293a00 -r 668d5f284a44 mpz/iset.c
--- a/mpz/iset.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/iset.c	Wed Dec 28 18:39:40 2016 +0100
@@ -42,9 +42,9 @@
   size = ABS (usize);
 
   ALLOC (w) = MAX (size, 1);
-  PTR (w) = __GMP_ALLOCATE_FUNC_LIMBS (ALLOC (w));
+  wp = __GMP_ALLOCATE_FUNC_LIMBS (ALLOC (w));
 
-  wp = PTR (w);
+  PTR (w) = wp;
   up = PTR (u);
 
   MPN_COPY (wp, up, size);
diff -r afcb4e293a00 -r 668d5f284a44 mpz/lucnum2_ui.c
--- a/mpz/lucnum2_ui.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/lucnum2_ui.c	Wed Dec 28 18:39:40 2016 +0100
@@ -63,8 +63,8 @@
   size = MPN_FIB2_SIZE (n);
   f1p = TMP_ALLOC_LIMBS (size);
 
-  lp  = MPZ_REALLOC (ln,     size+1);
-  l1p = MPZ_REALLOC (lnsub1, size+1);
+  lp  = MPZ_NEWALLOC (ln,     size+1);
+  l1p = MPZ_NEWALLOC (lnsub1, size+1);
 
   size = mpn_fib2_ui (l1p, f1p, n);
 
diff -r afcb4e293a00 -r 668d5f284a44 mpz/lucnum_ui.c
--- a/mpz/lucnum_ui.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/lucnum_ui.c	Wed Dec 28 18:39:40 2016 +0100
@@ -76,7 +76,7 @@
      since square or mul used below might need an extra limb over the true
      size */
   lalloc = MPN_FIB2_SIZE (n) + 2;
-  lp = MPZ_REALLOC (ln, lalloc);
+  lp = MPZ_NEWALLOC (ln, lalloc);
 
   TMP_MARK;
   xalloc = lalloc;
diff -r afcb4e293a00 -r 668d5f284a44 mpz/mfac_uiui.c
--- a/mpz/mfac_uiui.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/mfac_uiui.c	Wed Dec 28 18:39:40 2016 +0100
@@ -2,7 +2,7 @@
 
 Contributed to the GNU project by Marco Bodrato.
 
-Copyright 2012, 2013, 2015 Free Software Foundation, Inc.
+Copyright 2012, 2013, 2015, 2016 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -60,7 +60,7 @@
   if ((n < 3) | (n - 3 < m - 1)) { /* (n < 3 || n - 1 <= m || m == 0) */
     MPZ_NEWALLOC (x, 1)[0] = n + (n == 0);
     SIZ (x) = 1;
-  } else { /* m < n - 1 < GMP_NUMB_MAX */
+  } else { /* 0 < m < n - 1 < GMP_NUMB_MAX */
     mp_limb_t g, sn;
     mpz_t     t;
 
@@ -93,7 +93,8 @@
       }
     } else { /* m >= 3, gcd(n,m) = 1 */
       mp_limb_t *factors;
-      mp_limb_t prod, max_prod, j;
+      mp_limb_t prod, max_prod;
+      mp_size_t j;
       TMP_DECL;
 
       sn = n / m + 1;
diff -r afcb4e293a00 -r 668d5f284a44 mpz/mul_i.h
--- a/mpz/mul_i.h	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/mul_i.h	Wed Dec 28 18:39:40 2016 +0100
@@ -96,7 +96,7 @@
       tp[size + 1] = cy;
       size += 2;
       MPN_NORMALIZE_NOT_ZERO (tp, size); /* too general, need to trim one or two limb */
-      pp = MPZ_REALLOC (prod, size);
+      pp = MPZ_NEWALLOC (prod, size);
       MPN_COPY (pp, tp, size);
       TMP_FREE;
     }
diff -r afcb4e293a00 -r 668d5f284a44 mpz/n_pow_ui.c
--- a/mpz/n_pow_ui.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/n_pow_ui.c	Wed Dec 28 18:39:40 2016 +0100
@@ -371,7 +371,7 @@
   ralloc = (bsize*GMP_NUMB_BITS - cnt + GMP_NAIL_BITS) * e / GMP_NUMB_BITS + 5;
   TRACE (printf ("ralloc %ld, from bsize=%ld blimb=0x%lX cnt=%d\n",
 		 ralloc, bsize, blimb, cnt));
-  rp = MPZ_REALLOC (r, ralloc + rtwos_limbs);
+  rp = MPZ_NEWALLOC (r, ralloc + rtwos_limbs);
 
   /* Low zero limbs resulting from powers of 2. */
   MPN_ZERO (rp, rtwos_limbs);
diff -r afcb4e293a00 -r 668d5f284a44 mpz/powm.c
--- a/mpz/powm.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/powm.c	Wed Dec 28 18:39:40 2016 +0100
@@ -274,7 +274,7 @@
     }
 
  ret:
-  MPZ_REALLOC (r, rn);
+  MPZ_NEWALLOC (r, rn);
   SIZ(r) = rn;
   MPN_COPY (PTR(r), rp, rn);
 
diff -r afcb4e293a00 -r 668d5f284a44 mpz/powm_sec.c
--- a/mpz/powm_sec.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/powm_sec.c	Wed Dec 28 18:39:40 2016 +0100
@@ -75,9 +75,8 @@
     }
 
   TMP_MARK;
-  tp = TMP_ALLOC_LIMBS (n + mpn_sec_powm_itch (bn, en * GMP_NUMB_BITS, n));
-
-  rp = tp;  tp += n;
+  TMP_ALLOC_LIMBS_2 (rp, n,
+		     tp, mpn_sec_powm_itch (bn, en * GMP_NUMB_BITS, n));
 
   bp = PTR(b);
   ep = PTR(e);
@@ -95,7 +94,7 @@
       MPN_NORMALIZE (rp, rn);
     }
 
-  MPZ_REALLOC (r, rn);
+  MPZ_NEWALLOC (r, rn);
   SIZ(r) = rn;
   MPN_COPY (PTR(r), rp, rn);
 
diff -r afcb4e293a00 -r 668d5f284a44 mpz/powm_ui.c
--- a/mpz/powm_ui.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/powm_ui.c	Wed Dec 28 18:39:40 2016 +0100
@@ -108,8 +108,7 @@
   TMP_DECL;
   TMP_MARK;
 
-  rp = TMP_ALLOC_LIMBS (an);
-  scratch = TMP_ALLOC_LIMBS (an - mn + 1);
+  TMP_ALLOC_LIMBS_2 (rp, an, scratch, an - mn + 1);
   MPN_COPY (rp, ap, an);
   mod (rp, an, mp, mn, dinv, scratch);
   MPN_COPY (tp, rp, mn);
@@ -182,9 +181,7 @@
 	  return;
 	}
 
-      tp = TMP_ALLOC_LIMBS (2 * mn + 1);
-      xp = TMP_ALLOC_LIMBS (mn);
-      scratch = TMP_ALLOC_LIMBS (mn + 1);
+      TMP_ALLOC_LIMBS_3 (xp, mn, scratch, mn + 1, tp, 2 * mn + 1);
 
       MPN_COPY (xp, bp, bn);
       xn = bn;
@@ -273,7 +270,7 @@
 	  xn = mn;
 	  MPN_NORMALIZE (xp, xn);
 	}
-      MPZ_REALLOC (r, xn);
+      MPZ_NEWALLOC (r, xn);
       SIZ (r) = xn;
       MPN_COPY (PTR(r), xp, xn);
 
diff -r afcb4e293a00 -r 668d5f284a44 mpz/random2.c
--- a/mpz/random2.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/random2.c	Wed Dec 28 18:39:40 2016 +0100
@@ -41,7 +41,7 @@
   abs_size = ABS (size);
   if (abs_size != 0)
     {
-      xp = MPZ_REALLOC (x, abs_size);
+      xp = MPZ_NEWALLOC (x, abs_size);
 
       mpn_random2 (xp, abs_size);
     }
diff -r afcb4e293a00 -r 668d5f284a44 mpz/root.c
--- a/mpz/root.c	Mon Dec 26 18:06:47 2016 +0100
+++ b/mpz/root.c	Wed Dec 28 18:39:40 2016 +0100
@@ -64,7 +64,7 @@
 
   /* FIXME: Perhaps disallow root == NULL */
   if (root != NULL && u != root)
-    rootp = MPZ_REALLOC (root, rootn);
+    rootp = MPZ_NEWALLOC (root, rootn);
   else
     rootp = TMP_ALLOC_LIMBS (rootn);
 
diff -r afcb4e293a00 -r 668d5f284a44 mpz/rootrem.c


More information about the gmp-commit mailing list