[Gmp-commit] /var/hg/gmp: mpz/oddfac_1.c (log_n_max): Use precomputed table.

mercurial at gmplib.org mercurial at gmplib.org
Tue Mar 20 05:18:15 CET 2012


details:   /var/hg/gmp/rev/46f35c0ffc13
changeset: 14773:46f35c0ffc13
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Tue Mar 20 05:18:08 2012 +0100
description:
mpz/oddfac_1.c (log_n_max): Use precomputed table.

diffstat:

 ChangeLog      |   3 ++-
 mpz/oddfac_1.c |  11 ++---------
 2 files changed, 4 insertions(+), 10 deletions(-)

diffs (37 lines):

diff -r cc6d3a923da6 -r 46f35c0ffc13 ChangeLog
--- a/ChangeLog	Mon Mar 19 23:17:11 2012 +0100
+++ b/ChangeLog	Tue Mar 20 05:18:08 2012 +0100
@@ -7,8 +7,9 @@
 
 2012-03-19 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
+	* gen-fac_ui.c: Generate more constants (possible mini-mpz_root). 
 	* mpz/oddfac_1.c: Improve ASSERTs.
-	* gen-fac_ui.c: Generate more constants (possible mini-mpz_root). 
+	(log_n_max): Use precomputed table.
 
 	* longlong.h (_PROTO): Remove.
 
diff -r cc6d3a923da6 -r 46f35c0ffc13 mpz/oddfac_1.c
--- a/mpz/oddfac_1.c	Mon Mar 19 23:17:11 2012 +0100
+++ b/mpz/oddfac_1.c	Tue Mar 20 05:18:08 2012 +0100
@@ -465,17 +465,10 @@
 static unsigned
 log_n_max (mp_limb_t n)
 {
+  static const mp_limb_t table[] = { NTH_ROOT_NUMB_MASK_TABLE };
   unsigned log;
 
-  if (n < CNST_LIMB(1) << (GMP_NUMB_BITS/8))
-    log = 8;
-  else
-    {
-      mp_limb_t max, cur;
-      log = 1;
-      max = GMP_NUMB_MAX / n;
-      for (cur = n; cur <= max; cur *= n) log++;
-    }
+  for (log = numberof (table); n > table[log - 1]; log--);
 
   return log;
 }


More information about the gmp-commit mailing list