[Gmp-commit] /var/hg/gmp: Store small temporary mpq on the stack.

mercurial at gmplib.org mercurial at gmplib.org
Tue Mar 15 11:16:51 CET 2011


details:   /var/hg/gmp/rev/65ebe713fc77
changeset: 14064:65ebe713fc77
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Tue Mar 15 11:16:47 2011 +0100
description:
Store small temporary mpq on the stack.

diffstat:

 ChangeLog |   7 +++++
 gmpxx.h   |  83 ++++++++++++++++++++------------------------------------------
 2 files changed, 34 insertions(+), 56 deletions(-)

diffs (127 lines):

diff -r 146163eb4b3b -r 65ebe713fc77 ChangeLog
--- a/ChangeLog	Tue Mar 15 08:10:18 2011 +0100
+++ b/ChangeLog	Tue Mar 15 11:16:47 2011 +0100
@@ -1,3 +1,10 @@
+2011-03-15  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (__GMPXX_TMPQ_UI): New macro.
+	(__GMPXX_TMPQ_SI): New macro.
+	(struct __gmp_binary_multiplies): Rewrite, using the new macros.
+	(struct __gmp_binary_divides): Likewise.
+
 2011-03-15 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mpn/generic/toom_interpolate_16pts.c: Remove ambiguity.
diff -r 146163eb4b3b -r 65ebe713fc77 gmpxx.h
--- a/gmpxx.h	Tue Mar 15 08:10:18 2011 +0100
+++ b/gmpxx.h	Tue Mar 15 11:16:47 2011 +0100
@@ -63,6 +63,25 @@
   temp->_mp_alloc = __GMPZ_DBL_LIMBS;					\
   mpz_set_d (temp, d)
 
+#define __GMPXX_TMPQ_UI							\
+  mpq_t temp;								\
+  mp_limb_t limbs[__GMPZ_ULI_LIMBS+1];					\
+  mpq_numref(temp)->_mp_d = limbs;					\
+  mpq_numref(temp)->_mp_alloc = __GMPZ_ULI_LIMBS;			\
+  mpz_set_ui (mpq_numref(temp), l);					\
+  mpq_denref(temp)->_mp_d = limbs + __GMPZ_ULI_LIMBS;			\
+  mpq_denref(temp)->_mp_size = 1;					\
+  mpq_denref(temp)->_mp_d[0] = 1
+#define __GMPXX_TMPQ_SI							\
+  mpq_t temp;								\
+  mp_limb_t limbs[__GMPZ_ULI_LIMBS+1];					\
+  mpq_numref(temp)->_mp_d = limbs;					\
+  mpq_numref(temp)->_mp_alloc = __GMPZ_ULI_LIMBS;			\
+  mpz_set_si (mpq_numref(temp), l);					\
+  mpq_denref(temp)->_mp_d = limbs + __GMPZ_ULI_LIMBS;			\
+  mpq_denref(temp)->_mp_size = 1;					\
+  mpq_denref(temp)->_mp_d[0] = 1
+
 
 /**************** Function objects ****************/
 /* Any evaluation of a __gmp_expr ends up calling one of these functions
@@ -339,37 +358,13 @@
   { mpq_mul(q, r, s); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_ui(temp, l, 1);
-    mpq_mul(q, r, temp);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_UI;   mpq_mul (q, r, temp); }
   static void eval(mpq_ptr q, unsigned long int l, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_ui(temp, l, 1);
-    mpq_mul(q, temp, r);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_UI;   mpq_mul (q, temp, r); }
   static void eval(mpq_ptr q, mpq_srcptr r, signed long int l)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_si(temp, l, 1);
-    mpq_mul(q, r, temp);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_SI;   mpq_mul (q, r, temp); }
   static void eval(mpq_ptr q, signed long int l, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_si(temp, l, 1);
-    mpq_mul(q, temp, r);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_SI;   mpq_mul (q, temp, r); }
   static void eval(mpq_ptr q, mpq_srcptr r, double d)
   {
     mpq_t temp;
@@ -490,37 +485,13 @@
   { mpq_div(q, r, s); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, unsigned long int l)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_ui(temp, l, 1);
-    mpq_div(q, r, temp);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_UI;   mpq_div (q, r, temp); }
   static void eval(mpq_ptr q, unsigned long int l, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_ui(temp, l, 1);
-    mpq_div(q, temp, r);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_UI;   mpq_div (q, temp, r); }
   static void eval(mpq_ptr q, mpq_srcptr r, signed long int l)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_si(temp, l, 1);
-    mpq_div(q, r, temp);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_SI;   mpq_div (q, r, temp); }
   static void eval(mpq_ptr q, signed long int l, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_si(temp, l, 1);
-    mpq_div(q, temp, r);
-    mpq_clear(temp);
-  }
+  {  __GMPXX_TMPQ_SI;   mpq_div (q, temp, r); }
   static void eval(mpq_ptr q, mpq_srcptr r, double d)
   {
     mpq_t temp;


More information about the gmp-commit mailing list