From: Paul Eggert Date: Sun, 8 Jun 2025 18:34:51 +0000 (-0700) Subject: factor: omit unnecessary divisions by small primes X-Git-Tag: v9.8~219 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6e87c9b3a359e9ae5d2c1c430408c936e8b18a5b;p=thirdparty%2Fcoreutils.git factor: omit unnecessary divisions by small primes * src/factor.c (mp_factor_using_division): When continuing in single precision, don’t divide by primes that were already cast out in multiple precision. On my platform this gave a 2.5% speedup when factoring 2**128 + 172261 = 4999 * 68070087401668026297934508388031283, as W_TYPE_SIZE == 64 and 4999 is the last prime in the primes table. --- diff --git a/src/factor.c b/src/factor.c index 52209eb7e8..fb7c47fd9a 100644 --- a/src/factor.c +++ b/src/factor.c @@ -913,7 +913,7 @@ mp_factor_using_division (mpz_t t, struct mp_factors *factors) for (m = 0; mpz_divisible_ui_p (t, d); m++) { mpz_tdiv_q_ui (t, t, d); - if (mp_finish_in_single (t, factors)) + if (mp_finish_up_in_single (t, factors, i, d)) { mp_factor_insert_ui (factors, d, m + 1); return;