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

mercurial at gmplib.org mercurial at gmplib.org
Fri Jun 26 13:49:37 CEST 2026


details:   /var/hg/gmp/rev/5d07d3134916
changeset: 18531:5d07d3134916
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 25 11:36:35 2026 +0200
description:
mpn/generic/bsqrtinv.c: Support (unused) code with no table.

details:   /var/hg/gmp/rev/e703c40a2b75
changeset: 18532:e703c40a2b75
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 25 12:49:05 2026 +0200
description:
mpn/generic/sqrtrem.c: Microoptimization

details:   /var/hg/gmp/rev/e5f0f38ed289
changeset: 18533:e5f0f38ed289
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 25 12:50:29 2026 +0200
description:
mpn/generic/bsqrtinv.c: Some multiplications are smaller...

details:   /var/hg/gmp/rev/3273cc0d5ca9
changeset: 18534:3273cc0d5ca9
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 12:23:07 2026 +0200
description:
mpz/millerrabin.c: Update limit for checked values to 289*10^13.

details:   /var/hg/gmp/rev/31faf15601ac
changeset: 18535:31faf15601ac
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 12:46:32 2026 +0200
description:
mpz/isetbit.c: New file with the function mpz_init_setbit

details:   /var/hg/gmp/rev/3279ab5bc5eb
changeset: 18536:3279ab5bc5eb
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 12:57:40 2026 +0200
description:
doc/gmp.texi: Document the new function mpz_init_setbit.

details:   /var/hg/gmp/rev/d01dc34689d8
changeset: 18537:d01dc34689d8
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 12:58:01 2026 +0200
description:
rand/randmts.c: Use the new function mpz_init_setbit.

details:   /var/hg/gmp/rev/0e69998bea3b
changeset: 18538:0e69998bea3b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 13:03:14 2026 +0200
description:
mini-gmp/mini-gmp.[ch]: Add and use the new function mpz_init_setbit

details:   /var/hg/gmp/rev/7baa4e48b405
changeset: 18539:7baa4e48b405
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 13:07:39 2026 +0200
description:
Use the new mpz_init_setbit function in various helper programs.

details:   /var/hg/gmp/rev/d317bf486270
changeset: 18540:d317bf486270
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 13:20:49 2026 +0200
description:
mini-gmp/mini-gmp.c: Use mpz_clear earlier if possible

details:   /var/hg/gmp/rev/e6b225bb467c
changeset: 18541:e6b225bb467c
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 13:33:36 2026 +0200
description:
ChangeLog and copyright years

details:   /var/hg/gmp/rev/05ed7e126732
changeset: 18542:05ed7e126732
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Jun 26 13:34:23 2026 +0200
description:
Copyright years

diffstat:

 ChangeLog              |  14 ++++++++++++++
 Makefile.am            |   1 +
 bootstrap.c            |   6 ++----
 doc/gmp.texi           |   4 ++++
 gen-bases.c            |   6 ++----
 gen-fac.c              |   3 +--
 gen-trialdivtab.c      |   6 ++----
 gmp-h.in               |   3 +++
 mini-gmp/ChangeLog     |   8 ++++++++
 mini-gmp/mini-gmp.c    |  35 +++++++++++++++++++++++------------
 mini-gmp/mini-gmp.h    |   4 +++-
 mpn/generic/bsqrtinv.c |  16 +++++++++-------
 mpn/generic/sqrtrem.c  |   3 +--
 mpz/Makefile.am        |   2 +-
 mpz/isetbit.c          |  44 ++++++++++++++++++++++++++++++++++++++++++++
 mpz/millerrabin.c      |  14 +++++++-------
 rand/randmts.c         |   3 +--
 17 files changed, 126 insertions(+), 46 deletions(-)

diffs (truncated from 453 to 300 lines):

diff -r 2a809d700679 -r 05ed7e126732 ChangeLog
--- a/ChangeLog	Thu Jun 25 10:13:51 2026 +0200
+++ b/ChangeLog	Fri Jun 26 13:34:23 2026 +0200
@@ -1,3 +1,17 @@
+2026-06-26  Marco Bodrato <marco.bodrato at protonmail.com>
+
+	* mpz/isetbit.c: New file, implementing mpz_init_setbit.
+	* Makefile.am (MPZ_OBJECTS): Add it.
+	* mpz/Makefile.am (libmpz_la_SOURCES): Add it.
+	* gmp-h.in: Declare the new function mpz_init_setbit.
+	* doc/gmp.texi: Document it.
+	* rand/randmts.c: Use it.
+
+	* gen-fac.c: Use the new function defined also in mini-gmp.
+	* gen-bases.c: Likewise.
+	* gen-trialdivtab.c: Likewise.
+	* bootstrap.c: Likewise.
+
 2026-06-19  Marco Bodrato <marco.bodrato at protonmail.com>
 
 	* mpn/generic/perfpow.c (is_kth_power): Check only one possible
diff -r 2a809d700679 -r 05ed7e126732 Makefile.am
--- a/Makefile.am	Thu Jun 25 10:13:51 2026 +0200
+++ b/Makefile.am	Fri Jun 26 13:34:23 2026 +0200
@@ -199,6 +199,7 @@
   mpz/import$U.lo mpz/init$U.lo mpz/init2$U.lo mpz/inits$U.lo		\
   mpz/inp_raw$U.lo mpz/inp_str$U.lo mpz/invert$U.lo			\
   mpz/ior$U.lo mpz/iset$U.lo mpz/iset_d$U.lo mpz/iset_si$U.lo		\
+  mpz/isetbit$U.lo							\
   mpz/iset_str$U.lo mpz/iset_ui$U.lo mpz/jacobi$U.lo mpz/kronsz$U.lo	\
   mpz/kronuz$U.lo mpz/kronzs$U.lo mpz/kronzu$U.lo			\
   mpz/lcm$U.lo mpz/lcm_ui$U.lo mpz/limbs_finish$U.lo			\
diff -r 2a809d700679 -r 05ed7e126732 bootstrap.c
--- a/bootstrap.c	Thu Jun 25 10:13:51 2026 +0200
+++ b/bootstrap.c	Fri Jun 26 13:34:23 2026 +0200
@@ -97,8 +97,7 @@
 
   norm = numb_bits - mpz_sizeinbase (d, 2);
   assert (norm >= 0);
-  mpz_init (t);
-  mpz_setbit (t, 2*numb_bits - norm);
+  mpz_init_setbit (t, 2*numb_bits - norm);
   mpz_tdiv_q (inv, t, d);
   mpz_clrbit (inv, numb_bits);
 
@@ -113,8 +112,7 @@
 
   assert (mpz_odd_p (a));
 
-  mpz_init (mod);
-  mpz_setbit (mod, n);
+  mpz_init_setbit (mod, n);
 
   mpz_invert (r, a, mod);
 
diff -r 2a809d700679 -r 05ed7e126732 doc/gmp.texi
--- a/doc/gmp.texi	Thu Jun 25 10:13:51 2026 +0200
+++ b/doc/gmp.texi	Fri Jun 26 13:34:23 2026 +0200
@@ -3233,6 +3233,10 @@
 an error occurs.  (I.e., you have to call @code{mpz_clear} for it.)
 @end deftypefun
 
+ at deftypefun int mpz_init_setbit (mpz_t @var{rop}, mp_bitcnt_t @var{bit_index})
+Initialize @var{rop} with limb space and set the sinle bit @var{bit_index}.
+ at end deftypefun
+
 
 @node Converting Integers, Integer Arithmetic, Simultaneous Integer Init & Assign, Integer Functions
 @comment  node-name,  next,  previous,  up
diff -r 2a809d700679 -r 05ed7e126732 gen-bases.c
--- a/gen-bases.c	Thu Jun 25 10:13:51 2026 +0200
+++ b/gen-bases.c	Fri Jun 26 13:34:23 2026 +0200
@@ -127,13 +127,11 @@
   mpz_t t, t2, two, b;
   int i;
 
-  mpz_init (t);
-  mpz_setbit (t, prec + EXTRA);
+  mpz_init_setbit (t, prec + EXTRA);
 
   mpz_init (t2);
 
-  mpz_init (two);
-  mpz_setbit (two, prec + EXTRA + 1);
+  mpz_init_setbit (two, prec + EXTRA + 1);
 
   mpz_set_ui (r, 0);
 
diff -r 2a809d700679 -r 05ed7e126732 gen-fac.c
--- a/gen-fac.c	Thu Jun 25 10:13:51 2026 +0200
+++ b/gen-fac.c	Fri Jun 26 13:34:23 2026 +0200
@@ -101,8 +101,7 @@
   ofl = b - 1;
   printf
     ("#define ODD_FACTORIAL_TABLE_LIMIT (%lu)\n", ofl);
-  mpz_init (mask);
-  mpz_setbit (mask, numb);
+  mpz_init_setbit (mask, numb);
   mpz_sub_ui (mask, mask, 1);
   printf
     ("\n/* Previous table, continued, values modulo 2^GMP_NUMB_BITS */\n");
diff -r 2a809d700679 -r 05ed7e126732 gen-trialdivtab.c
--- a/gen-trialdivtab.c	Thu Jun 25 10:13:51 2026 +0200
+++ b/gen-trialdivtab.c	Fri Jun 26 13:34:23 2026 +0200
@@ -91,16 +91,14 @@
   for (i = 0; i < 7; i++)
     mpz_init (pre[i]);
 
-  mpz_init (B);
-  mpz_setbit (B, limb_bits);
+  mpz_init_setbit (B, limb_bits);
   mpz_init_set (gmp_numb_max, B);
   mpz_sub_ui (gmp_numb_max, gmp_numb_max, 1);
 
   mpz_init (tmp);
   mpz_init (inv);
 
-  mpz_init (Bhalf);
-  mpz_setbit (Bhalf, limb_bits - 1);
+  mpz_init_setbit (Bhalf, limb_bits - 1);
 
   start_p = 3;
 
diff -r 2a809d700679 -r 05ed7e126732 gmp-h.in
--- a/gmp-h.in	Thu Jun 25 10:13:51 2026 +0200
+++ b/gmp-h.in	Fri Jun 26 13:34:23 2026 +0200
@@ -864,6 +864,9 @@
 #define mpz_init_set __gmpz_init_set
 __GMP_DECLSPEC void mpz_init_set (mpz_ptr, mpz_srcptr);
 
+#define mpz_init_setbit __gmpz_init_setbit
+__GMP_DECLSPEC void mpz_init_setbit (mpz_ptr, mp_bitcnt_t);
+
 #define mpz_init_set_d __gmpz_init_set_d
 __GMP_DECLSPEC void mpz_init_set_d (mpz_ptr, double);
 
diff -r 2a809d700679 -r 05ed7e126732 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Thu Jun 25 10:13:51 2026 +0200
+++ b/mini-gmp/ChangeLog	Fri Jun 26 13:34:23 2026 +0200
@@ -1,3 +1,11 @@
+2026-06-26  Marco Bodrato <marco.bodrato at protonmail.com>
+
+	* mini-gmp.c (mpz_init_setbit): New function.
+	(mpz_rootrem): Use mpz_init_setbit.
+	* mini-gmp.h: Add declaration of mpz_init_setbit.
+
+	* mini-gmp.c: Use mpz_clear earlier if possible.
+
 2026-03-15  Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* tests/hex-random.c (hex_random_clear): New function.
diff -r 2a809d700679 -r 05ed7e126732 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Thu Jun 25 10:13:51 2026 +0200
+++ b/mini-gmp/mini-gmp.c	Fri Jun 26 13:34:23 2026 +0200
@@ -3,7 +3,7 @@
    Contributed to the GNU project by Niels Möller
    Additional functionalities and improvements by Marco Bodrato.
 
-Copyright 1991-1997, 1999-2022 Free Software Foundation, Inc.
+Copyright 1991-1997, 1999-2026 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -2832,10 +2832,10 @@
     mpz_swap (tu, tv);
 
   tu->_mp_size = mpn_gcd (tu->_mp_d, tu->_mp_d, tu->_mp_size, tv->_mp_d, tv->_mp_size);
+  mpz_clear (tv);
+
   mpz_mul_2exp (g, tu, gz);
-
   mpz_clear (tu);
-  mpz_clear (tv);
 }
 
 void
@@ -2969,6 +2969,7 @@
   else
     mpz_setbit (t0, uz);
 
+  mpz_clear (tu);
   /* Now tv = odd part of gcd, and -s0 and t0 are corresponding
      cofactors. */
 
@@ -3005,13 +3006,19 @@
      the one with smallest corresponding t (this asymmetric condition
      is needed to prefer s = 0, |t| = 1 when g = |a| = |b|). */
   mpz_add (s1, s0, s1);
-  mpz_sub (t1, t0, t1);
   cmp = mpz_cmpabs (s0, s1);
-  if (cmp > 0 || (cmp == 0 && mpz_cmpabs (t0, t1) > 0))
+  if (cmp >= 0)
     {
+      mpz_sub (t1, t0, t1);
+      if (cmp > 0 || mpz_cmpabs (t0, t1) > 0)
+      {
       mpz_swap (s0, s1);
       mpz_swap (t0, t1);
+      }
     }
+  mpz_clear (s1);
+  mpz_clear (t1);
+
   if (u->_mp_size < 0)
     mpz_neg (s0, s0);
   if (v->_mp_size < 0)
@@ -3023,12 +3030,9 @@
   if (t)
     mpz_swap (t, t0);
 
-  mpz_clear (tu);
   mpz_clear (tv);
   mpz_clear (s0);
-  mpz_clear (s1);
   mpz_clear (t0);
-  mpz_clear (t1);
 }
 
 void
@@ -3081,6 +3085,7 @@
 
   mpz_gcdext (g, tr, NULL, u, m);
   invertible = (mpz_cmp_ui (g, 1) == 0);
+  mpz_clear (g);
 
   if (invertible)
     {
@@ -3094,7 +3099,6 @@
       mpz_swap (r, tr);
     }
 
-  mpz_clear (g);
   mpz_clear (tr);
   return invertible;
 }
@@ -3222,6 +3226,7 @@
 	}
       while (bit > 0);
     }
+  mpz_clear (base);
 
   /* Final reduction */
   if (tr->_mp_size >= mn)
@@ -3235,7 +3240,6 @@
 
   mpz_swap (r, tr);
   mpz_clear (tr);
-  mpz_clear (base);
 }
 
 void
@@ -3271,9 +3275,8 @@
   }
 
   mpz_init (u);
-  mpz_init (t);
   bc = (mpz_sizeinbase (y, 2) - 1) / z + 1;
-  mpz_setbit (t, bc);
+  mpz_init_setbit (t, bc);
 
   if (z == 2) /* simplify sqrt loop: z-1 == 1 */
     do {
@@ -3845,6 +3848,14 @@
 }
 
 void
+mpz_init_setbit (mpz_t r, mp_bitcnt_t b)
+{
+  mpz_init (r);
+  /* mpz_setbit (r, b); */
+  mpz_abs_add_bit (r, b);
+}
+
+void
 mpz_com (mpz_t r, const mpz_t u)
 {
   mpz_add_ui (r, u, 1);
diff -r 2a809d700679 -r 05ed7e126732 mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h	Thu Jun 25 10:13:51 2026 +0200
+++ b/mini-gmp/mini-gmp.h	Fri Jun 26 13:34:23 2026 +0200
@@ -1,6 +1,7 @@
 /* mini-gmp, a minimalistic implementation of a GNU GMP subset.
 
-Copyright 2011-2015, 2017, 2019-2021 Free Software Foundation, Inc.
+Copyright 2011-2015, 2017, 2019-2021, 2024, 2026 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -272,6 +273,7 @@
 void mpz_init_set_si (mpz_t, signed long int);
 void mpz_init_set_ui (mpz_t, unsigned long int);
 void mpz_init_set (mpz_t, const mpz_t);
+void mpz_init_setbit (mpz_t, mp_bitcnt_t);
 void mpz_init_set_d (mpz_t, double);
 
 size_t mpz_sizeinbase (const mpz_t, int);
diff -r 2a809d700679 -r 05ed7e126732 mpn/generic/bsqrtinv.c
--- a/mpn/generic/bsqrtinv.c	Thu Jun 25 10:13:51 2026 +0200
+++ b/mpn/generic/bsqrtinv.c	Fri Jun 26 13:34:23 2026 +0200


More information about the gmp-commit mailing list