[Gmp-commit] /var/hg/gmp: Replace d=a+b+c with (d=a+b)+=c when c!=d.

mercurial at gmplib.org mercurial at gmplib.org
Mon Jan 30 11:31:53 CET 2012


details:   /var/hg/gmp/rev/266f945dc222
changeset: 14589:266f945dc222
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Mon Jan 30 11:31:45 2012 +0100
description:
Replace d=a+b+c with (d=a+b)+=c when c!=d.
TODO:
* same thing for the mixed mpq/mpz operations
* finish the generic code I have that generalizes all these small optimizations (may not be ready for 5.1)

diffstat:

 ChangeLog |   5 +++++
 gmpxx.h   |  48 ++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 45 insertions(+), 8 deletions(-)

diffs (91 lines):

diff -r fba311ff3884 -r 266f945dc222 ChangeLog
--- a/ChangeLog	Sat Jan 28 22:35:44 2012 +0100
+++ b/ChangeLog	Mon Jan 30 11:31:45 2012 +0100
@@ -1,3 +1,8 @@
+2012-01-30  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (__gmp_binary_expr): Let things happen in place: d=a+b+c
+	when d != c.
+
 2012-01-28  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h: Don't compute -LONG_MIN.
diff -r fba311ff3884 -r 266f945dc222 gmpxx.h
--- a/gmpxx.h	Sat Jan 28 22:35:44 2012 +0100
+++ b/gmpxx.h	Mon Jan 30 11:31:45 2012 +0100
@@ -2190,8 +2190,16 @@
     : expr(val1, val2) { }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p) const
   {
-    __gmp_expr<T, T> temp(expr.val2);
-    Op::eval(p, expr.val1.__get_mp(), temp.__get_mp());
+    if(p != expr.val1.__get_mp())
+    {
+      __gmp_set_expr(p, expr.val2);
+      Op::eval(p, expr.val1.__get_mp(), p);
+    }
+    else
+    {
+      __gmp_expr<T, T> temp(expr.val2);
+      Op::eval(p, expr.val1.__get_mp(), temp.__get_mp());
+    }
   }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p,
 	    mp_bitcnt_t prec) const
@@ -2223,8 +2231,16 @@
     : expr(val1, val2) { }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p) const
   {
-    __gmp_expr<T, T> temp(expr.val1);
-    Op::eval(p, temp.__get_mp(), expr.val2.__get_mp());
+    if(p != expr.val2.__get_mp())
+    {
+      __gmp_set_expr(p, expr.val1);
+      Op::eval(p, p, expr.val2.__get_mp());
+    }
+    else
+    {
+      __gmp_expr<T, T> temp(expr.val1);
+      Op::eval(p, temp.__get_mp(), expr.val2.__get_mp());
+    }
   }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p,
 	    mp_bitcnt_t prec) const
@@ -2256,8 +2272,16 @@
     : expr(val1, val2) { }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p) const
   {
-    __gmp_expr<T, T> temp(expr.val2);
-    Op::eval(p, expr.val1.__get_mp(), temp.__get_mp());
+    if(p != expr.val1.__get_mp())
+    {
+      __gmp_set_expr(p, expr.val2);
+      Op::eval(p, expr.val1.__get_mp(), p);
+    }
+    else
+    {
+      __gmp_expr<T, T> temp(expr.val2);
+      Op::eval(p, expr.val1.__get_mp(), temp.__get_mp());
+    }
   }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p,
 	    mp_bitcnt_t prec) const
@@ -2289,8 +2313,16 @@
     : expr(val1, val2) { }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p) const
   {
-    __gmp_expr<T, T> temp(expr.val1);
-    Op::eval(p, temp.__get_mp(), expr.val2.__get_mp());
+    if(p != expr.val2.__get_mp())
+    {
+      __gmp_set_expr(p, expr.val1);
+      Op::eval(p, p, expr.val2.__get_mp());
+    }
+    else
+    {
+      __gmp_expr<T, T> temp(expr.val1);
+      Op::eval(p, temp.__get_mp(), expr.val2.__get_mp());
+    }
   }
   void eval(typename __gmp_resolve_expr<T>::ptr_type p,
 	    mp_bitcnt_t prec) const


More information about the gmp-commit mailing list