gmpxx and allocation

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Tue Mar 6 15:38:29 CET 2012


Ciao,

Il Mar, 6 Marzo 2012 9:07 am, Marc Glisse ha scritto:
>> Is it possible to write something like
>> if (__GMPXX_CONSTANT (SIZ (b)) && SIZ (b)==1) ... ?
>> I don't know if this may have some chance to be optimised...
>
> You can certainly write it, but since all those values are set in
> opaque gmp functions, __builtin_constant_p will return false. I tried
...
> With the small number optimization, if the fast path is inline and
> doesn't use any asm (or has a __builtin_constant_p branch without asm),
> the compiler should have a chance at simplifying at compile-time.

... Ok, but again the __builtin_constant_p branch can be optimised only if
initialisation is not opaque... so again the first requirement to give the
compiler a chance at simplifying is that the constructors should not be
calls to the library _init_set_ functions, but inlined code (like
__mpz_set_ui_safe). But I fear that such a change would reform the role of
cxx, from a wrapper to a partial reimplementation...

By the way, I suggest this small patch to __mpz_set_si_safe:

--- a/gmpxx.h	Sun Mar 04 22:05:13 2012 +0100
+++ b/gmpxx.h	Tue Mar 06 13:57:28 2012 +0100
@@ -80,7 +80,7 @@
   if(l < 0)
   {
     __mpz_set_ui_safe(p, -static_cast<unsigned long>(l));
-    mpz_neg(p, p);
+    p->_mp_size = - p->_mp_size;
   }
   else
     __mpz_set_ui_safe(p, l);

Regards,
m

-- 
http://bodrato.it/software/strassen.html



More information about the gmp-discuss mailing list