From 2da88ed1795201384296b105ee70c3c0f1b3ed55 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 25 Sep 2024 17:55:00 -0700 Subject: [PATCH] factor: tweak prime_p zero counting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/factor.c (prime_p): Use stdc_trailing_zero here too. This doesn’t make much of a performance difference but we might as well be consistent. --- src/factor.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/factor.c b/src/factor.c index 081bb0d57c..80757c0837 100644 --- a/src/factor.c +++ b/src/factor.c @@ -1166,7 +1166,6 @@ mp_millerrabin (mpz_srcptr n, mpz_srcptr nm1, mpz_ptr x, mpz_ptr y, static bool ATTRIBUTE_PURE prime_p (uintmax_t n) { - mp_bitcnt_t k; bool is_prime; uintmax_t a_prim, one, ni; struct factors factors; @@ -1179,9 +1178,8 @@ prime_p (uintmax_t n) return true; /* Precomputation for Miller-Rabin. */ - uintmax_t q = n - 1; - for (k = 0; (q & 1) == 0; k++) - q >>= 1; + int k = stdc_trailing_zeros (n - 1); + uintmax_t q = (n - 1) >> k; uintmax_t a = 2; binv (ni, n); /* ni <- 1/n mod B */ -- 2.47.2