C++11 classes

Marc Glisse marc.glisse at inria.fr
Wed Nov 16 12:23:20 CET 2011


On Wed, 16 Nov 2011, Hans Aberg wrote:

> I drafted some C++11 classes integer etc., using move constructors and 
> assignment operators,

Something like that is likely to eventually get standardized in C++, but 
it may be a while yet. Note that without lazy initialization, gmp doesn't 
benefit from moves as much as it could.

> and then testing with a conversion of the pi program. In the most 
> optimized version, the overhead is less than 10% relative C or C compile 
> as C++,

I believe you can get 0 overhead with gmpxx. Also, the overhead tends to 
play a comparatively larger role with small numbers (just a couple limbs, 
where even a mpz_swap is non-negligible) as opposed to huge numbers.

> and the funny thing is that it does not call any constructors or 
> assignments at all. The reason is that either the compiler can optimize 
> them away, or in a few cases, one can do some rewriting.

I am not sure what you mean by that. When you write x=y*y, the compiler 
creates a temporary in which it puts the result of the multiplication and 
then it calls the move assignment. Or do you mean you rewrote the thing to 
never use * but only *= ?

-- 
Marc Glisse


More information about the gmp-discuss mailing list