gmpxx and allocation

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Tue Mar 6 19:41:28 CET 2012


Ciao,

Il Mar, 6 Marzo 2012 5:08 pm, Marc Glisse ha scritto:
> On Tue, 6 Mar 2012, bodrato at mail.dm.unipi.it wrote:
>> 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 current functions, indeed reimplementing the constructors inline
> could help. On the other hand, now that gcc can do link-time optimization,
> it somehow allows it to inline the _init_set_ functions (though I kind
> of doubt that would be enough).

It could help because after it you can get "true" form
__builtin_constant_p in the code above...
Of course it is not a big optimisation. It can only save some cases and
does not save any allocation, but it can be done without changing the
library.

> On the other hand, mpz_init_set_ui could be split in
> mpz_init_really_allocate (opaque) and mpz_set_ui_safe (inline).

Sounds interesting.

>> -    mpz_neg(p, p);
>> +    p->_mp_size = - p->_mp_size;

> There should be no difference in generated code.

You are right, I forgot that we have an inline version for mpz_neg.

Regards,
m

-- 
http://bodrato.it/



More information about the gmp-discuss mailing list