Submission of code

Kevin Ryde user42 at zip.com.au
Tue Jun 1 02:28:35 CEST 2004


"Rikard Nordgren" <rikard_nordgren at hotmail.com> writes:
>
> unsigned long int
> mpz_scan1_reverse(mpz_t op, unsigned long int bit)
> {
>
>       do
>         {
>           do
>             {
>               if (((ptr[limb] >> lb) & 1) == 1)
>                 return lb + limb*BITS_PER_MP_LIMB;
>             } while (lb-- > 0);
>             lb = BITS_PER_MP_LIMB - 1;
>         } while (limb-- > 0);

No, scan for a non-zero limb, then count_leading_zeros.

>       /* Scan the number for the last limb to add with one */
>       for (carry_pos = 0; carry_pos < limb; carry_pos++)
>         {
>           if (ptr[carry_pos] != 0)
>             break;
>         }

I'd prefer to see a single search from the starting limb downwards,
for better cache locality.


More information about the gmp-devel mailing list