From: Paul Eggert Date: Thu, 26 Sep 2024 00:55:00 +0000 (-0700) Subject: factor: tweak prime_p zero counting X-Git-Tag: v9.6~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2da88ed1795201384296b105ee70c3c0f1b3ed55;p=thirdparty%2Fcoreutils.git factor: tweak prime_p zero counting * 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. --- 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 */