gmpxx and allocation

bodrato at bodrato at
Tue Mar 6 08:41:56 CET 2012


Il Mar, 6 Marzo 2012 1:07 am, Marc Glisse ha scritto:
> int main(){
>    mpz_class a=1;
>    for(int i=0;i<5000000;i++){
>      mpz_class b=2;
>      a=a+b-a*b;
>    }
>    return a.get_si()-1;
> }

... If you substitute mpz_class with int, and compile it with gcc -O2, the
assembler code generated for the function main is:
        xorl    %eax, %eax

I do not know C++ very well... but it would be very nice if we could
suggest to the compiler how optimise operation when the "value" of classes
could be argued at compile time.
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...

> it seemed interesting to post it and see if people had any comments.

My comment goes in a completely orthogonal direction, but I hope it is not
meaningless :-)



More information about the gmp-discuss mailing list