[Gmp-commit] /var/hg/gmp: Mark failing branches with UNLIKELY.

mercurial at gmplib.org mercurial at gmplib.org
Wed May 23 23:21:30 CEST 2012


details:   /var/hg/gmp/rev/035b9bc70f68
changeset: 14999:035b9bc70f68
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Wed May 23 23:21:13 2012 +0200
description:
Mark failing branches with UNLIKELY.

diffstat:

 ChangeLog          |   2 ++
 mpf/div.c          |  11 ++++++-----
 mpf/div_ui.c       |  13 +++++++------
 mpf/sqrt.c         |   2 +-
 mpf/ui_div.c       |   5 +++--
 mpq/canonicalize.c |   2 +-
 mpq/cmp_ui.c       |   2 +-
 mpq/div.c          |  14 ++++++++------
 mpq/inv.c          |   2 +-
 mpz/cdiv_q_ui.c    |   2 +-
 mpz/cdiv_qr_ui.c   |   2 +-
 mpz/cdiv_r_ui.c    |   2 +-
 mpz/cdiv_ui.c      |   2 +-
 mpz/dive_ui.c      |   2 +-
 mpz/fdiv_q_ui.c    |   2 +-
 mpz/fdiv_qr_ui.c   |   2 +-
 mpz/fdiv_r_ui.c    |   2 +-
 mpz/fdiv_ui.c      |   2 +-
 mpz/powm.c         |   4 ++--
 mpz/powm_sec.c     |   4 +---
 mpz/powm_ui.c      |   2 +-
 mpz/remove.c       |   2 +-
 mpz/root.c         |   4 ++--
 mpz/rootrem.c      |   4 ++--
 mpz/tdiv_q.c       |   2 +-
 mpz/tdiv_q_ui.c    |   2 +-
 mpz/tdiv_qr.c      |   2 +-
 mpz/tdiv_qr_ui.c   |   2 +-
 mpz/tdiv_r.c       |   2 +-
 mpz/tdiv_r_ui.c    |   2 +-
 mpz/tdiv_ui.c      |   2 +-
 mpz/urandomm.c     |   2 +-
 32 files changed, 56 insertions(+), 51 deletions(-)

diffs (truncated from 476 to 300 lines):

diff -r eed01cabb120 -r 035b9bc70f68 ChangeLog
--- a/ChangeLog	Wed May 23 12:03:30 2012 +0200
+++ b/ChangeLog	Wed May 23 23:21:13 2012 +0200
@@ -3,6 +3,8 @@
 	* mpz/sqrt.c: Further simplify.
 	* mpz/sqrtrem.c: Likewise.
 
+	* Mark failing branches with UNLIKELY. Many files affected.
+
 2012-05-22  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpz/sqrt.c: Allocate less for overlapping operands, simplify.
diff -r eed01cabb120 -r 035b9bc70f68 mpf/div.c
--- a/mpf/div.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpf/div.c	Wed May 23 23:21:13 2012 +0200
@@ -55,12 +55,8 @@
 
   usize = SIZ(u);
   vsize = SIZ(v);
-  sign_quotient = usize ^ vsize;
-  usize = ABS (usize);
-  vsize = ABS (vsize);
-  prec = PREC(r);
 
-  if (vsize == 0)
+  if (UNLIKELY (vsize == 0))
     DIVIDE_BY_ZERO;
 
   if (usize == 0)
@@ -70,6 +66,11 @@
       return;
     }
 
+  sign_quotient = usize ^ vsize;
+  usize = ABS (usize);
+  vsize = ABS (vsize);
+  prec = PREC(r);
+
   TMP_MARK;
   rexp = EXP(u) - EXP(v) + 1;
 
diff -r eed01cabb120 -r 035b9bc70f68 mpf/div_ui.c
--- a/mpf/div_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpf/div_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -50,13 +50,10 @@
     }
 #endif
 
+  if (UNLIKELY (v == 0))
+    DIVIDE_BY_ZERO;
+
   usize = u->_mp_size;
-  sign_quotient = usize;
-  usize = ABS (usize);
-  prec = r->_mp_prec;
-
-  if (v == 0)
-    DIVIDE_BY_ZERO;
 
   if (usize == 0)
     {
@@ -65,6 +62,10 @@
       return;
     }
 
+  sign_quotient = usize;
+  usize = ABS (usize);
+  prec = r->_mp_prec;
+
   TMP_MARK;
 
   rp = r->_mp_d;
diff -r eed01cabb120 -r 035b9bc70f68 mpf/sqrt.c
--- a/mpf/sqrt.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpf/sqrt.c	Wed May 23 23:21:13 2012 +0200
@@ -59,7 +59,7 @@
   TMP_DECL;
 
   usize = u->_mp_size;
-  if (usize <= 0)
+  if (UNLIKELY (usize <= 0))
     {
       if (usize < 0)
         SQRT_OF_NEGATIVE;
diff -r eed01cabb120 -r 035b9bc70f68 mpf/ui_div.c
--- a/mpf/ui_div.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpf/ui_div.c	Wed May 23 23:21:13 2012 +0200
@@ -38,8 +38,6 @@
 
   vsize = v->_mp_size;
   sign_quotient = vsize;
-  vsize = ABS (vsize);
-  prec = r->_mp_prec;
 
   if (UNLIKELY (vsize == 0))
     DIVIDE_BY_ZERO;
@@ -51,6 +49,9 @@
       return;
     }
 
+  vsize = ABS (vsize);
+  prec = r->_mp_prec;
+
   TMP_MARK;
   rexp = 1 - v->_mp_exp + 1;
 
diff -r eed01cabb120 -r 035b9bc70f68 mpq/canonicalize.c
--- a/mpq/canonicalize.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpq/canonicalize.c	Wed May 23 23:21:13 2012 +0200
@@ -28,7 +28,7 @@
   mpz_t gcd;
   TMP_DECL;
 
-  if (SIZ(DEN(op)) == 0)
+  if (UNLIKELY (SIZ(DEN(op)) == 0))
     DIVIDE_BY_ZERO;
 
   TMP_MARK;
diff -r eed01cabb120 -r 035b9bc70f68 mpq/cmp_ui.c
--- a/mpq/cmp_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpq/cmp_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -50,7 +50,7 @@
   /* need canonical sign to get right result */
   ASSERT (den1_size > 0);
 
-  if (den2 == 0)
+  if (UNLIKELY (den2 == 0))
     DIVIDE_BY_ZERO;
 
   if (num1_size == 0)
diff -r eed01cabb120 -r 035b9bc70f68 mpq/div.c
--- a/mpq/div.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpq/div.c	Wed May 23 23:21:13 2012 +0200
@@ -34,13 +34,12 @@
   mp_size_t alloc;
   TMP_DECL;
 
+  op2_num_size = ABSIZ(NUM(op2));
+
+  if (UNLIKELY (op2_num_size == 0))
+    DIVIDE_BY_ZERO;
+
   op1_num_size = ABSIZ(NUM(op1));
-  op1_den_size =   SIZ(DEN(op1));
-  op2_num_size = ABSIZ(NUM(op2));
-  op2_den_size =   SIZ(DEN(op2));
-
-  if (op2_num_size == 0)
-    DIVIDE_BY_ZERO;
 
   if (op1_num_size == 0)
     {
@@ -52,6 +51,9 @@
       return;
     }
 
+  op2_den_size =   SIZ(DEN(op2));
+  op1_den_size =   SIZ(DEN(op1));
+
   TMP_MARK;
 
   alloc = MIN (op1_num_size, op2_num_size);
diff -r eed01cabb120 -r 035b9bc70f68 mpq/inv.c
--- a/mpq/inv.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpq/inv.c	Wed May 23 23:21:13 2012 +0200
@@ -27,7 +27,7 @@
   mp_size_t num_size = SIZ(NUM(src));
   mp_size_t den_size = SIZ(DEN(src));
 
-  if (num_size == 0)
+  if (UNLIKELY (num_size == 0))
     DIVIDE_BY_ZERO;
 
   if (num_size < 0)
diff -r eed01cabb120 -r 035b9bc70f68 mpz/cdiv_q_ui.c
--- a/mpz/cdiv_q_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/cdiv_q_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -30,7 +30,7 @@
   mp_ptr np, qp;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/cdiv_qr_ui.c
--- a/mpz/cdiv_qr_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/cdiv_qr_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -31,7 +31,7 @@
   mp_ptr np, qp;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/cdiv_r_ui.c
--- a/mpz/cdiv_r_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/cdiv_r_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -31,7 +31,7 @@
   mp_ptr np;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/cdiv_ui.c
--- a/mpz/cdiv_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/cdiv_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -31,7 +31,7 @@
   mp_ptr np;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/dive_ui.c
--- a/mpz/dive_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/dive_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -26,7 +26,7 @@
   mp_size_t  size, abs_size;
   mp_ptr     dst_ptr;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   /* For nails don't try to be clever if d is bigger than a limb, just fake
diff -r eed01cabb120 -r 035b9bc70f68 mpz/fdiv_q_ui.c
--- a/mpz/fdiv_q_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/fdiv_q_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -29,7 +29,7 @@
   mp_ptr np, qp;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/fdiv_qr_ui.c
--- a/mpz/fdiv_qr_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/fdiv_qr_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -29,7 +29,7 @@
   mp_ptr np, qp;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/fdiv_r_ui.c
--- a/mpz/fdiv_r_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/fdiv_r_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -29,7 +29,7 @@
   mp_ptr np;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/fdiv_ui.c
--- a/mpz/fdiv_ui.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/fdiv_ui.c	Wed May 23 23:21:13 2012 +0200
@@ -29,7 +29,7 @@
   mp_ptr np;
   mp_limb_t rl;
 
-  if (divisor == 0)
+  if (UNLIKELY (divisor == 0))
     DIVIDE_BY_ZERO;
 
   ns = SIZ(dividend);
diff -r eed01cabb120 -r 035b9bc70f68 mpz/powm.c
--- a/mpz/powm.c	Wed May 23 12:03:30 2012 +0200
+++ b/mpz/powm.c	Wed May 23 23:21:13 2012 +0200
@@ -59,7 +59,7 @@
   TMP_DECL;
 
   n = ABSIZ(m);
-  if (n == 0)
+  if (UNLIKELY (n == 0))
     DIVIDE_BY_ZERO;
 
   mp = PTR(m);
@@ -82,7 +82,7 @@
 #if HANDLE_NEGATIVE_EXPONENT
       MPZ_TMP_INIT (new_b, n + 1);
 
-      if (! mpz_invert (new_b, b, m))
+      if (UNLIKELY (! mpz_invert (new_b, b, m)))


More information about the gmp-commit mailing list