mpq_cmp_z

Marco Bodrato bodrato at mail.dm.unipi.it
Wed Aug 26 18:13:52 UTC 2015


Ciao,

Il Mer, 26 Agosto 2015 6:26 pm, Torbjörn Granlund ha scritto:
> nisse at lysator.liu.se (Niels Möller) writes:
>   > (SIZ(den) | PTR(den)[0]) == 1
>
>   I think it is correct, assuming that at this point in the code it is
>   known that SIZ(den) != 0 (and that den is normalized, so that SIZ(den)

At any point in mpq code (we check in the _init functions, and we ASSERT
elsewhere) we assume denominator is strictly positive and mpz's are
normalised.

> Indeed a clever condition, helping Marco's quest against branches, a
> condition which also depends on that we always allocate a limb at
> PTR(mpz).

It depends only on being able to _read_ PTR(mpz)[0].

If we change (I'd agree) mpz_init into

void
mpz_init (mpz_ptr x)
{
  ALLOC (x) = 0; /* ZERO, any MPZ_REALLOC will allocate */
  PTR (x) = & static_const_limb_shared_by_all_instances;
  SIZ (x) = 0;
}

(consequently we will have to change all functions that write a single
limb, pre-pending an MPZ_REALLOC(var,1) )

That condition will keep on being valid. The same holds for

#define mpz_odd_p(z) (((z)->_mp_size!=0)&__GMP_CAST(int,(z)->_mp_d[0]))

that we wrote a dozen years ago in gmp-h.in .

Regards,
m
-- 
http://bodrato.it/



More information about the gmp-devel mailing list