gmpxx patch: put small temps on stack

Marc Glisse marc.glisse at normalesup.org
Fri Sep 5 15:51:56 CEST 2008


Hello,

here is a patch to generalize the use of on-stack temporaries. Reviewing 
it should not require any C++ knowledge. I'd like someone to say whether I 
am doing it right...

 	* gmpxx.h (__GMP_DBL_NUM_LIMBS): New #define.
 	(__GMP_DBL_DEN_LIMBS): New #define.
 	(__GMP_BITS_TO_LIMBS): New macro.
 	(__GMPXX_TMP_MPQ_UI): New macro.
 	(__GMPXX_TMP_MPQ_SI): New macro.
 	(__GMPXX_TMP_MPQ_D): New macro.
 	(__GMPXX_TMP_MPF_D): New macro.
 	(__GMPXX_TMP_MPZ_UI): Renamed from __GMPXX_TMP_UI.
 	(__GMPXX_TMP_MPZ_SI): Renamed from __GMPXX_TMP_SI.
 	(__GMPXX_TMP_MPZ_D): Renamed from __GMPXX_TMP_D.
 	(struct __gmp_binary_*): Use the new macros.


-- 
Marc Glisse
-------------- next part --------------
--- orig/gmpxx.h	2008-09-04 22:56:19.000000000 +0200
+++ gmpxx.h	2008-09-04 23:25:15.000000000 +0200
@@ -37,9 +37,74 @@
 #include <cstring>  /* for strlen */
 #include <string>
 #include <stdexcept>
-#include <cfloat>
+#include <cfloat> /* for DBL_* */
 #include <gmp.h>
 
+// Max allocations for plain types when converted to mp*_t
+#define __GMP_BITS_TO_LIMBS(x) (1+((x-1)/GMP_NUMB_BITS))
+#define __GMP_ULI_LIMBS __GMP_BITS_TO_LIMBS(8 * sizeof (long))
+#define __GMP_DBL_LIMBS __GMP_BITS_TO_LIMBS(DBL_MANT_DIG)
+#define __GMP_DBL_NUM_LIMBS __GMP_BITS_TO_LIMBS(DBL_MAX_EXP)
+#define __GMP_DBL_DEN_LIMBS __GMP_BITS_TO_LIMBS(DBL_MANT_DIG+1-DBL_MIN_EXP)
+// Don't forget denormalized numbers
+
+#define __GMPXX_TMP_MPZ_UI						\
+  mpz_t temp;								\
+  mp_limb_t limbs[__GMP_ULI_LIMBS];					\
+  temp->_mp_d = limbs;							\
+  temp->_mp_alloc = __GMP_ULI_LIMBS;					\
+  mpz_set_ui (temp, l)
+#define __GMPXX_TMP_MPZ_SI						\
+  mpz_t temp;								\
+  mp_limb_t limbs[__GMP_ULI_LIMBS];					\
+  temp->_mp_d = limbs;							\
+  temp->_mp_alloc = __GMP_ULI_LIMBS;					\
+  mpz_set_si (temp, l)
+#define __GMPXX_TMP_MPZ_D						\
+  mpz_t temp;								\
+  mp_limb_t limbs[__GMP_DBL_NUM_LIMBS];					\
+  temp->_mp_d = limbs;							\
+  temp->_mp_alloc = __GMP_DBL_NUM_LIMBS;				\
+  mpz_set_d (temp, d)
+
+#define __GMPXX_TMP_MPQ_UI						\
+  mpq_t temp;								\
+  mp_limb_t limbs[__GMP_ULI_LIMBS+1];					\
+  mpq_numref(temp)->_mp_d = limbs;					\
+  mpq_numref(temp)->_mp_alloc = __GMP_ULI_LIMBS;			\
+  mpq_denref(temp)->_mp_d = limbs+__GMP_ULI_LIMBS;			\
+  mpq_denref(temp)->_mp_alloc = 1;					\
+  mpq_denref(temp)->_mp_size = 1;					\
+  mpq_denref(temp)->_mp_d[0] = 1;					\
+  mpz_set_ui (mpq_numref(temp), l)
+#define __GMPXX_TMP_MPQ_SI						\
+  mpq_t temp;								\
+  mp_limb_t limbs[__GMP_ULI_LIMBS+1];					\
+  mpq_numref(temp)->_mp_d = limbs;					\
+  mpq_numref(temp)->_mp_alloc = __GMP_ULI_LIMBS;			\
+  mpq_denref(temp)->_mp_d = limbs+__GMP_ULI_LIMBS;			\
+  mpq_denref(temp)->_mp_alloc = 1;					\
+  mpq_denref(temp)->_mp_size = 1;					\
+  mpq_denref(temp)->_mp_d[0] = 1;					\
+  mpz_set_si (mpq_numref(temp), l)
+#define __GMPXX_TMP_MPQ_D						\
+  mpq_t temp;								\
+  mp_limb_t limbs[__GMP_DBL_NUM_LIMBS+__GMP_DBL_DEN_LIMBS];		\
+  mpq_numref(temp)->_mp_d = limbs;					\
+  mpq_numref(temp)->_mp_alloc = __GMP_DBL_NUM_LIMBS;			\
+  mpq_denref(temp)->_mp_d = limbs+__GMP_DBL_NUM_LIMBS;			\
+  mpq_denref(temp)->_mp_alloc = __GMP_DBL_DEN_LIMBS;			\
+  mpq_set_d (temp, d)
+// Note that the numerator and denominator cannot both be large, so we
+// could save some memory by first comparing d to 1.
+
+#define __GMPXX_TMP_MPF_D						\
+  mpf_t temp;								\
+  mp_limb_t limbs[__GMP_DBL_LIMBS+1];					\
+  temp->_mp_d = limbs;							\
+  temp->_mp_prec = __GMP_DBL_LIMBS;					\
+  mpf_set_d (temp, d)
+// It should be sufficient to allocate one less limb?
 
 /**************** Function objects ****************/
 /* Any evaluation of a __gmp_expr ends up calling one of these functions
@@ -90,19 +155,9 @@
       mpz_sub_ui(z, w, -l);
   }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_add(z, w, temp);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_add(z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_add(z, temp, w);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_add(z, temp, w); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
   { mpq_add(q, r, s); }
@@ -128,21 +183,9 @@
       mpz_submul_ui(mpq_numref(q), mpq_denref(q), -l);
   }
   static void eval(mpq_ptr q, mpq_srcptr r, double d)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_add(q, r, temp);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_add(q, r, temp); }
   static void eval(mpq_ptr q, double d, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_add(q, temp, r);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_add(q, temp, r); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z)
   { mpq_set(q, r); mpz_addmul(mpq_numref(q), mpq_denref(q), z); }
@@ -171,21 +214,9 @@
       mpf_sub_ui(f, g, -l);
   }
   static void eval(mpf_ptr f, mpf_srcptr g, double d)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_add(f, g, temp);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_add(f, g, temp); }
   static void eval(mpf_ptr f, double d, mpf_srcptr g)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_add(f, temp, g);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_add(f, temp, g); }
 };
 
 struct __gmp_binary_minus
@@ -215,19 +246,9 @@
       }
   }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_sub(z, w, temp);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_sub(z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_sub(z, temp, w);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_sub(z, temp, w); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
   { mpq_sub(q, r, s); }
@@ -253,21 +274,9 @@
       mpz_submul_ui(mpq_numref(q), mpq_denref(q), -l);
   }
   static void eval(mpq_ptr q, mpq_srcptr r, double d)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_sub(q, r, temp);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_sub(q, r, temp); }
   static void eval(mpq_ptr q, double d, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_sub(q, temp, r);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_sub(q, temp, r); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z)
   { mpq_set(q, r); mpz_submul(mpq_numref(q), mpq_denref(q), z); }
@@ -297,21 +306,9 @@
     mpf_neg(f, f);
   }
   static void eval(mpf_ptr f, mpf_srcptr g, double d)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_sub(f, g, temp);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_sub(f, g, temp); }
   static void eval(mpf_ptr f, double d, mpf_srcptr g)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_sub(f, temp, g);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_sub(f, temp, g); }
 };
 
 struct __gmp_binary_multiplies
@@ -328,71 +325,25 @@
   static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
   { mpz_mul_si (z, w, l); }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_mul(z, w, temp);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_mul(z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_mul(z, temp, w);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_mul(z, temp, w); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
   { 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_TMP_MPQ_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_TMP_MPQ_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_TMP_MPQ_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_TMP_MPQ_SI; mpq_mul(q, temp, r); }
   static void eval(mpq_ptr q, mpq_srcptr r, double d)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_mul(q, r, temp);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_mul(q, r, temp); }
   static void eval(mpq_ptr q, double d, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_mul(q, temp, r);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_mul(q, temp, r); }
 
   static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h)
   { mpf_mul(f, g, h); }
@@ -422,21 +373,9 @@
       }
   }
   static void eval(mpf_ptr f, mpf_srcptr g, double d)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_mul(f, g, temp);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_mul(f, g, temp); }
   static void eval(mpf_ptr f, double d, mpf_srcptr g)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_mul(f, temp, g);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_mul(f, temp, g); }
 };
 
 struct __gmp_binary_divides
@@ -489,71 +428,25 @@
       }
   }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_tdiv_q(z, w, temp);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_tdiv_q(z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_tdiv_q(z, temp, w);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_tdiv_q(z, temp, w); }
 
   static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s)
   { 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_TMP_MPQ_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_TMP_MPQ_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_TMP_MPQ_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_TMP_MPQ_SI; mpq_div(q, temp, r); }
   static void eval(mpq_ptr q, mpq_srcptr r, double d)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_div(q, r, temp);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_div(q, r, temp); }
   static void eval(mpq_ptr q, double d, mpq_srcptr r)
-  {
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    mpq_div(q, temp, r);
-    mpq_clear(temp);
-  }
+  { __GMPXX_TMP_MPQ_D; mpq_div(q, temp, r); }
 
   static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h)
   { mpf_div(f, g, h); }
@@ -583,21 +476,9 @@
       }
   }
   static void eval(mpf_ptr f, mpf_srcptr g, double d)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_div(f, g, temp);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_div(f, g, temp); }
   static void eval(mpf_ptr f, double d, mpf_srcptr g)
-  {
-    mpf_t temp;
-    mpf_init2(temp, 8*sizeof(double));
-    mpf_set_d(temp, d);
-    mpf_div(f, temp, g);
-    mpf_clear(temp);
-  }
+  { __GMPXX_TMP_MPF_D; mpf_div(f, temp, g); }
 };
 
 struct __gmp_binary_modulus
@@ -641,62 +522,28 @@
       }
   }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_tdiv_r(z, w, temp);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_tdiv_r(z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {
-    mpz_t temp;
-    mpz_init_set_d(temp, d);
-    mpz_tdiv_r(z, temp, w);
-    mpz_clear(temp);
-  }
+  { __GMPXX_TMP_MPZ_D; mpz_tdiv_r(z, temp, w); }
 };
 
-// Max allocations for plain types when converted to mpz_t
-// FIXME: how do we get the proper max "double" exponent?
-#define __GMP_DBL_LIMBS (2 + DBL_MAX_EXP / GMP_NUMB_BITS)
-#define __GMP_ULI_LIMBS (1 + (8 * sizeof (long) - 1) / GMP_NUMB_BITS)
-
-#define __GMPXX_TMP_UI							\
-  mpz_t temp;								\
-  mp_limb_t limbs[__GMP_ULI_LIMBS];					\
-  temp->_mp_d = limbs;							\
-  temp->_mp_alloc = __GMP_ULI_LIMBS;					\
-  mpz_set_ui (temp, l)
-#define __GMPXX_TMP_SI							\
-  mpz_t temp;								\
-  mp_limb_t limbs[__GMP_ULI_LIMBS];					\
-  temp->_mp_d = limbs;							\
-  temp->_mp_alloc = __GMP_ULI_LIMBS;					\
-  mpz_set_si (temp, l)
-#define __GMPXX_TMP_D							\
-  mpz_t temp;								\
-  mp_limb_t limbs[__GMP_DBL_LIMBS];					\
-  temp->_mp_d = limbs;							\
-  temp->_mp_alloc = __GMP_DBL_LIMBS;					\
-  mpz_set_d (temp, d)
-
 struct __gmp_binary_and
 {
   static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
   { mpz_and(z, w, v); }
 
   static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
-  {  __GMPXX_TMP_UI;   mpz_and (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_UI;   mpz_and (z, w, temp);  }
   static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
-  {  __GMPXX_TMP_UI;   mpz_and (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_UI;   mpz_and (z, w, temp);  }
   static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
-  {  __GMPXX_TMP_SI;   mpz_and (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_SI;   mpz_and (z, w, temp);  }
   static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
-  {  __GMPXX_TMP_SI;   mpz_and (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_SI;   mpz_and (z, w, temp);  }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {  __GMPXX_TMP_D;    mpz_and (z, w, temp); }
+  {  __GMPXX_TMP_MPZ_D;    mpz_and (z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {  __GMPXX_TMP_D;    mpz_and (z, w, temp); }
+  {  __GMPXX_TMP_MPZ_D;    mpz_and (z, w, temp); }
 };
 
 struct __gmp_binary_ior
@@ -704,17 +551,17 @@
   static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
   { mpz_ior(z, w, v); }
   static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
-  {  __GMPXX_TMP_UI;   mpz_ior (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_UI;   mpz_ior (z, w, temp);  }
   static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
-  {  __GMPXX_TMP_UI;   mpz_ior (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_UI;   mpz_ior (z, w, temp);  }
   static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
-  {  __GMPXX_TMP_SI;   mpz_ior (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_SI;   mpz_ior (z, w, temp);  }
   static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
-  {  __GMPXX_TMP_SI;   mpz_ior (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_SI;   mpz_ior (z, w, temp);  }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {  __GMPXX_TMP_D;    mpz_ior (z, w, temp); }
+  {  __GMPXX_TMP_MPZ_D;    mpz_ior (z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {  __GMPXX_TMP_D;    mpz_ior (z, w, temp); }
+  {  __GMPXX_TMP_MPZ_D;    mpz_ior (z, w, temp); }
 };
 
 struct __gmp_binary_xor
@@ -722,17 +569,17 @@
   static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v)
   { mpz_xor(z, w, v); }
   static void eval(mpz_ptr z, mpz_srcptr w, unsigned long int l)
-  {  __GMPXX_TMP_UI;   mpz_xor (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_UI;   mpz_xor (z, w, temp);  }
   static void eval(mpz_ptr z, unsigned long int l, mpz_srcptr w)
-  {  __GMPXX_TMP_UI;   mpz_xor (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_UI;   mpz_xor (z, w, temp);  }
   static void eval(mpz_ptr z, mpz_srcptr w, signed long int l)
-  {  __GMPXX_TMP_SI;   mpz_xor (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_SI;   mpz_xor (z, w, temp);  }
   static void eval(mpz_ptr z, signed long int l, mpz_srcptr w)
-  {  __GMPXX_TMP_SI;   mpz_xor (z, w, temp);  }
+  {  __GMPXX_TMP_MPZ_SI;   mpz_xor (z, w, temp);  }
   static void eval(mpz_ptr z, mpz_srcptr w, double d)
-  {  __GMPXX_TMP_D;    mpz_xor (z, w, temp); }
+  {  __GMPXX_TMP_MPZ_D;    mpz_xor (z, w, temp); }
   static void eval(mpz_ptr z, double d, mpz_srcptr w)
-  {  __GMPXX_TMP_D;    mpz_xor (z, w, temp); }
+  {  __GMPXX_TMP_MPZ_D;    mpz_xor (z, w, temp); }
 };
 
 struct __gmp_binary_lshift
@@ -784,25 +631,9 @@
   static bool eval(signed long int l, mpq_srcptr q)
   { return mpq_cmp_si(q, l, 1) == 0; }
   static bool eval(mpq_srcptr q, double d)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_equal(q, temp) != 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_equal(q, temp) != 0); }
   static bool eval(double d, mpq_srcptr q)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_equal(temp, q) != 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_equal(temp, q) != 0); }
 
   static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) == 0; }
 
@@ -849,25 +680,9 @@
   static bool eval(signed long int l, mpq_srcptr q)
   { return mpq_cmp_si(q, l, 1) != 0; }
   static bool eval(mpq_srcptr q, double d)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_equal(q, temp) == 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_equal(q, temp) == 0); }
   static bool eval(double d, mpq_srcptr q)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_equal(temp, q) == 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_equal(temp, q) == 0); }
 
   static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) != 0; }
 
@@ -913,25 +728,9 @@
   static bool eval(signed long int l, mpq_srcptr q)
   { return mpq_cmp_si(q, l, 1) > 0; }
   static bool eval(mpq_srcptr q, double d)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(q, temp) < 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(q, temp) < 0); }
   static bool eval(double d, mpq_srcptr q)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(temp, q) < 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(temp, q) < 0); }
 
   static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) < 0; }
 
@@ -977,25 +776,9 @@
   static bool eval(signed long int l, mpq_srcptr q)
   { return mpq_cmp_si(q, l, 1) >= 0; }
   static bool eval(mpq_srcptr q, double d)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(q, temp) <= 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(q, temp) <= 0); }
   static bool eval(double d, mpq_srcptr q)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(temp, q) <= 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(temp, q) <= 0); }
 
   static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) <= 0; }
 
@@ -1041,25 +824,9 @@
   static bool eval(signed long int l, mpq_srcptr q)
   { return mpq_cmp_si(q, l, 1) < 0; }
   static bool eval(mpq_srcptr q, double d)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(q, temp) > 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(q, temp) > 0); }
   static bool eval(double d, mpq_srcptr q)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(temp, q) > 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(temp, q) > 0); }
 
   static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) > 0; }
 
@@ -1105,25 +872,9 @@
   static bool eval(signed long int l, mpq_srcptr q)
   { return mpq_cmp_si(q, l, 1) <= 0; }
   static bool eval(mpq_srcptr q, double d)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(q, temp) >= 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(q, temp) >= 0); }
   static bool eval(double d, mpq_srcptr q)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(temp, q) >= 0);
-    mpq_clear(temp);
-    return b;
-  }
+  { __GMPXX_TMP_MPQ_D; return (mpq_cmp(temp, q) >= 0); }
 
   static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) >= 0; }
 
@@ -1301,25 +1052,9 @@
   static int eval(signed long int l, mpq_srcptr q)
   { return -mpq_cmp_si(q, l, 1); }
   static int eval(mpq_srcptr q, double d)
-  {
-    int i;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    i = mpq_cmp(q, temp);
-    mpq_clear(temp);
-    return i;
-  }
+  { __GMPXX_TMP_MPQ_D; return mpq_cmp(q, temp); }
   static int eval(double d, mpq_srcptr q)
-  {
-    int i;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    i = mpq_cmp(temp, q);
-    mpq_clear(temp);
-    return i;
-  }
+  { __GMPXX_TMP_MPQ_D; return mpq_cmp(temp, q); }
 
   static int eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g); }
 
@@ -3325,6 +3060,19 @@
 
 /**************** #undef all private macros ****************/
 
+#undef __GMP_BITS_TO_LIMBS
+#undef __GMP_ULI_LIMBS
+#undef __GMP_DBL_LIMBS
+#undef __GMP_DBL_NUM_LIMBS
+#undef __GMP_DBL_DEN_LIMBS
+#undef __GMPXX_TMP_MPZ_UI
+#undef __GMPXX_TMP_MPZ_SI
+#undef __GMPXX_TMP_MPZ_D
+#undef __GMPXX_TMP_MPQ_UI
+#undef __GMPXX_TMP_MPQ_SI
+#undef __GMPXX_TMP_MPQ_D
+#undef __GMPXX_TMP_MPF_D
+
 #undef __GMPP_DECLARE_COMPOUND_OPERATOR
 #undef __GMPN_DECLARE_COMPOUND_OPERATOR
 #undef __GMP_DECLARE_COMPOUND_OPERATOR


More information about the gmp-bugs mailing list