[Gmp-commit] /var/hg/gmp: mp?/*strong*: Composite are unlikely, with the curr...

mercurial at gmplib.org mercurial at gmplib.org
Fri Nov 16 06:52:28 UTC 2018


details:   /var/hg/gmp/rev/52bae415aab0
changeset: 17707:52bae415aab0
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Nov 16 07:47:53 2018 +0100
description:
mp?/*strong*: Composite are unlikely, with the current use-case.

diffstat:

 mpn/generic/strongfibo.c |   6 +++---
 mpz/stronglucas.c        |  10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

diffs (74 lines):

diff -r 204e6427d536 -r 52bae415aab0 mpn/generic/strongfibo.c
--- a/mpn/generic/strongfibo.c	Mon Nov 12 23:13:39 2018 +0100
+++ b/mpn/generic/strongfibo.c	Fri Nov 16 07:47:53 2018 +0100
@@ -139,7 +139,7 @@
 	cy += mpn_add_n (lp, lp, mp, mn);
 #else
       cy = mpn_lshift (scratch, scratch, mn, 1); /* 2F[n-1] */
-      if (cy)
+      if (UNLIKELY (cy))
 	cy -= mpn_sub_n (lp, scratch, lp, mn); /* L[n] = +/-(2F[n-1]-(-F[n])) */
       else
 	abs_sub_n (lp, lp, scratch, mn);
@@ -201,7 +201,7 @@
   lp = TMP_ALLOC_LIMBS (4 * mn + 6);
   sp = lp + 2 * mn + 3;
   en = mpn_lucm (sp, scratch, en, mp, mn, lp);
-  if (en != 0 && --b0 != 0)
+  if (en != 0 && LIKELY (--b0 != 0))
     {
       mpn_sqr (lp, sp, en);
       lp [0] |= 2; /* V^2 + 2 */
@@ -209,7 +209,7 @@
 	mpn_tdiv_qr (sp, lp, 0, lp, 2 * en, mp, mn);
       else
 	MPN_ZERO (lp + 2 * en, mn - 2 * en);
-      if (! mpn_zero_p (lp, mn) && --b0 != 0)
+      if (! mpn_zero_p (lp, mn) && LIKELY (--b0 != 0))
 	b0 = mpn_llriter (lp, mp, mn, b0, lp + mn + 1);
     }
   TMP_FREE;
diff -r 204e6427d536 -r 52bae415aab0 mpz/stronglucas.c
--- a/mpz/stronglucas.c	Mon Nov 12 23:13:39 2018 +0100
+++ b/mpz/stronglucas.c	Fri Nov 16 07:47:53 2018 +0100
@@ -113,7 +113,7 @@
     mp_limb_t maxD;
     int jac_bit1;
 
-    if (mpz_perfect_square_p (n))
+    if (UNLIKELY (mpz_perfect_square_p (n)))
       return 0; /* A square is composite. */
 
     /* Check Ds up to square root (in case, n is prime)
@@ -134,12 +134,12 @@
     /* The only interesting composite D is 15.	*/
     do
       {
-	if (D >= maxD)
+	if (UNLIKELY (D >= maxD))
 	  return 1;
 	D += 2;
 	jac_bit1 = 0;
 	JACOBI_MOD_OR_MODEXACT_1_ODD (jac_bit1, tl, PTR (n), SIZ (n), D);
-	if (tl == 0)
+	if (UNLIKELY (tl == 0))
 	  return 0;
       }
     while (mpn_jacobi_base (tl, D, jac_bit1) == 1);
@@ -157,14 +157,14 @@
 
   /* If Ud != 0 && Vd != 0 */
   if (mpz_lucas_mod (V, Qk, Q, b0, n, T1, T2) == 0)
-    if (--b0 != 0)
+    if (LIKELY (--b0 != 0))
       do
 	{
 	  /* V_{2k} <- V_k ^ 2 - 2Q^k */
 	  mpz_mul (T2, V, V);
 	  mpz_submul_ui (T2, Qk, 2);
 	  mpz_tdiv_r (V, T2, n);
-	  if (SIZ (V) == 0 || --b0 == 0)
+	  if (SIZ (V) == 0 || UNLIKELY (--b0 == 0))
 	    break;
 	  /* Q^{2k} = (Q^k)^2 */
 	  mpz_mul (T2, Qk, Qk);


More information about the gmp-commit mailing list