Micro-GMP
paul zimmermann
Paul.Zimmermann at inria.fr
Mon Dec 10 09:46:26 UTC 2018
Dear Marco,
> mpz_cmpabs_ui (const mpz_t u, unsigned long v)
> {
> int ulongsize = GMP_ULONG_BITS / GMP_LIMB_BITS;
> mp_limb_t ulongrem = 0;
> mp_size_t un = GMP_ABS (u->_mp_size);
>
> if (GMP_ULONG_BITS % GMP_LIMB_BITS != 0)
> ulongrem = (ULONG_MAX >> GMP_LIMB_BITS * ulongsize) + 1;
is GMP_ULONG_BITS % GMP_LIMB_BITS != 0 allowed in GMP and/or asl.h?
> if (un > ulongsize && (u->_mp_d[ulongsize] >= ulongrem || un > ulongsize
> + 1))
> return 1;
> else
> {
> unsigned long uu = mpz_get_ui (u);
> return GMP_CMP(uu, v);
> }
> }
>
>
> When mp_limb_t is unsigned long, gcc -O2 compiles this code exactly as
> if (GMP_ABS (u->_mp_size) > 1)
> return 1;
> else
> GMP_CMP(mpz_get_ui (u), v)
> [...]
sounds good.
> The same as the current code. And it gets optimised also for uint16 or uint8.
>
> >> You also changed mpn_invert_3by2. Maybe a handful of (mp_limb_t) casts
> >> could be added to the original function to make it work... but your
> >> rewrite is simpler and faster. Maybe the same could be done on
> >> gmp_umul_ppmm? for speed?
> >
> > indeed, in several places I opted for simplicity, since speed was not
> > (at first) a goal. But when running "make check" of MPFR with micro-gmp-8,
> > I now realize speed is also important!
>
> A attach a possible implementation of mini-gmp that should support limbs
> of "any" size. Can you test it with MPFR? Both correctness and speed...
I'll do.
Paul
More information about the gmp-devel
mailing list