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

mercurial at gmplib.org mercurial at gmplib.org
Sun Nov 8 18:50:14 UTC 2015


details:   /var/hg/gmp/rev/4da7cf176dfe
changeset: 16950:4da7cf176dfe
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 08 19:38:29 2015 +0100
description:
mpz/urandomm.c: Use mpn_zero_p to shorten code.

details:   /var/hg/gmp/rev/e123e5d32ea2
changeset: 16951:e123e5d32ea2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Nov 08 19:50:06 2015 +0100
description:
ChangeLog

diffstat:

 ChangeLog      |  23 ++++++++++++++++++++++-
 mpz/urandomm.c |  22 ++++++++--------------
 2 files changed, 30 insertions(+), 15 deletions(-)

diffs (108 lines):

diff -r 3703a5accf53 -r e123e5d32ea2 ChangeLog
--- a/ChangeLog	Sun Nov 08 14:11:46 2015 +0100
+++ b/ChangeLog	Sun Nov 08 19:50:06 2015 +0100
@@ -1,3 +1,7 @@
+2015-11-08 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/urandomm.c: Use mpn_zero_p to shorten code.
+
 2015-11-08  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (__gmp_fac_function, __gmp_primorial_function): New classes.
@@ -37,6 +41,22 @@
 	(operator~, trunc, floor, ceil, sqrt, operator%, operator&, operator|,
 	operator^, hypot, gcd, lcm): Use them.
 
+2015-11-06 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpz/and.c: Use MPZ_NEWALLOC.
+	* mpz/ior.c: Remove duplicated branches, add branch hints.
+	* mpz/xor.c: Likewise, and use NORMALIZE_NOT_ZERO.
+
+	* mpz/init.c: Remove conditional code for __CHECKER__.
+	* mpz/init2.c: Likewise.
+	* mpz/inits.c: Likewise.
+	* mpz/iset.c: Likewise.
+	* mpz/iset_str.c: Likewise.
+
+	* mini-gmp/mini-gmp.c (mpn_com, mpn_neg): New functions.
+	* mini-gmp/mini-gmp.h: Declare them.
+	* mini-gmp/mini-gmp.c (mpz_div_r_2exp): Use mpn_neg.
+
 2015-11-04  Torbjörn Granlund  <torbjorng at google.com>
 
 	* mpz/xor.c: Use MPZ_REALLOC.
@@ -44,7 +64,8 @@
 
 2015-11-03 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
-	* mpz/ior.c, mpz/xor.x: Use the return value of _mpz_realloc.
+	* mpz/xor.c: Use the return value of _mpz_realloc.
+	* mpz/ior.c: Likewise.
 	* mpn/generic/sec_div.c: Remove unused var.
 
 2015-11-01  Torbjörn Granlund  <torbjorng at google.com>
diff -r 3703a5accf53 -r e123e5d32ea2 mpz/urandomm.c
--- a/mpz/urandomm.c	Sun Nov 08 14:11:46 2015 +0100
+++ b/mpz/urandomm.c	Sun Nov 08 19:50:06 2015 +0100
@@ -2,7 +2,7 @@
    integer in the range 0 to N-1, using STATE as the random state
    previously initialized by a call to gmp_randinit().
 
-Copyright 2000, 2002, 2012 Free Software Foundation, Inc.
+Copyright 2000, 2002, 2012, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -40,8 +40,9 @@
 void
 mpz_urandomm (mpz_ptr rop, gmp_randstate_t rstate, mpz_srcptr n)
 {
-  mp_ptr rp, np, nlast;
+  mp_ptr rp, np;
   mp_size_t nbits, size;
+  mp_limb_t nh;
   int count;
   int pow2;
   int cmp;
@@ -51,19 +52,13 @@
   if (UNLIKELY (size == 0))
     DIVIDE_BY_ZERO;
 
-  nlast = &PTR (n)[size - 1];
+  np = PTR (n);
+  nh = np[size - 1];
 
   /* Detect whether n is a power of 2.  */
-  pow2 = POW2_P (*nlast);
-  if (pow2 != 0)
-    for (np = PTR (n); np < nlast; np++)
-      if (*np != 0)
-	{
-	  pow2 = 0;		/* Mark n as `not a power of two'.  */
-	  break;
-	}
+  pow2 = POW2_P (nh) && (size == 1 || mpn_zero_p (np, size - 1));
 
-  count_leading_zeros (count, *nlast);
+  count_leading_zeros (count, nh);
   nbits = size * GMP_NUMB_BITS - (count - GMP_NAIL_BITS) - pow2;
   if (nbits == 0)		/* nbits == 0 means that n was == 1.  */
     {
@@ -72,7 +67,6 @@
     }
 
   TMP_MARK;
-  np = PTR (n);
   if (rop == n)
     {
       mp_ptr tp;
@@ -83,7 +77,7 @@
 
   /* Here the allocated size can be one too much if n is a power of
      (2^GMP_NUMB_BITS) but it's convenient for using mpn_cmp below.  */
-  rp = MPZ_REALLOC (rop, size);
+  rp = MPZ_NEWALLOC (rop, size);
   /* Clear last limb to prevent the case in which size is one too much.  */
   rp[size - 1] = 0;
 


More information about the gmp-commit mailing list