[Gmp-commit] /var/hg/gmp: fac_ui: max_prod, use constants, not divisions.

mercurial at gmplib.org mercurial at gmplib.org
Mon Jan 16 22:08:18 CET 2012


details:   /var/hg/gmp/rev/246ee5f869cd
changeset: 14570:246ee5f869cd
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jan 16 22:08:11 2012 +0100
description:
fac_ui: max_prod, use constants, not divisions.

diffstat:

 mpz/fac_ui.c |  13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diffs (37 lines):

diff -r e654dd4a9626 -r 246ee5f869cd mpz/fac_ui.c
--- a/mpz/fac_ui.c	Mon Jan 16 20:36:28 2012 +0100
+++ b/mpz/fac_ui.c	Mon Jan 16 22:08:11 2012 +0100
@@ -550,14 +550,19 @@
 	TMP_SMARK;
 	factors = TMP_SALLOC_LIMBS (1 + tn / FACTORS_PER_LIMB);
 
+#if TUNE_PROGRAM_BUILD
+	max_prod = GMP_NUMB_MAX / FAC_DSC_THRESHOLD_LIMIT;
+#else
+	max_prod = GMP_NUMB_MAX / FAC_DSC_THRESHOLD;
+#endif
 	for (; (tn - 1) >> 1 >= numberof (tabled); tn >>= 1) {
 	  i = numberof (tabled) * 2 + 1;
-	  max_prod = GMP_NUMB_MAX / tn;
 	  factors[j++] = tabled[numberof (tabled) - 1];
 	  do {
 	    FACTOR_LIST_STORE (i, prod, max_prod, factors, j);
 	    i += 2;
 	  } while (i <= tn);
+	  max_prod <<= 1;
 	}
 
 	factors[j] = prod;
@@ -638,7 +643,11 @@
       factors[0] = table[numberof (table)-1];
       j = 1;
       prod = 1;
-      max_prod = GMP_NUMB_MAX / n; /* GMP_NUMB_MAX/FAC_DSC_THRESHOLD */
+#if TUNE_PROGRAM_BUILD
+      max_prod = GMP_NUMB_MAX / FAC_DSC_THRESHOLD_LIMIT;
+#else
+      max_prod = GMP_NUMB_MAX / (FAC_ODD_THRESHOLD | 1);
+#endif
       do {
 	FACTOR_LIST_STORE (i, prod, max_prod, factors, j);
       } while (++i <= n);


More information about the gmp-commit mailing list