count_leading_zeros on 64-bit ppc

David Harvey dmharvey at math.harvard.edu
Sun Jun 3 23:37:15 CEST 2007


On Jun 3, 2007, at 5:21 PM, Torbjorn Granlund wrote:

> You're not using the macro properly.
> Your example works wrong, perhaps because it gets a 32-bit gmp.h,
> or something else.
>
> But in a proper 64-bit gmp context, it works right.

Tobjorn,

I'm pretty sure this is a 64-bit build. To be sure, I'm now compiling  
with

gcc -m64 count-test.c -I/Users/david/gmp/install/include/ -L/Users/ 
david/gmp/install/lib/ -lgmp

I also have added the following code to check this:

int main()
{
    unsigned long x = 0x0000000001379102;
    unsigned long c;

    count_leading_zeros(c, x);
    printf("%d\n", c);

    printf("%d\n", GMP_LIMB_BITS);

    mpz_t y;
    mpz_init(y);
    mpz_set_ui(y, 1);
    mpz_mul_2exp(y, y, 50);
    printf("%d\n", mpz_size(y));
    mpz_clear(y);

    return 0;
}

It prints

40
64
1

Presumably if it was a 32-bit build then 2^50 would not fit into a  
single limb.


> I'll let you debug the exact cause of the failure.  :-)

It sounds as if you are suggesting that you know exactly what is  
wrong, and you are teasing me :-) If you do know, it would probably  
take 30 seconds of your time to give me a clue that would save many  
hours of my time, which would be much appreciated.

david



More information about the gmp-bugs mailing list