Marco Bodrato bodrato at
Sat Dec 22 08:46:24 UTC 2018

Il 2018-12-21 19:13 nisse at ha scritto:
> 2. Reduce the number of places that depend on mp_limb_t == unsigned
>    long, where that also makes code simpler. E.g, using init_set_ui or
>    roinit_ui in more of the _ui functions.

Starting from the current code:
  - for comparison functions (mpz_fits_slong_p, mpz_fits_ulong_p, 
mpz_cmp_si, mpz_cmp_ui, but also mpz_set_si), unconditionally using the 
if (GMP_LIMB_BITS < GMP_ULONG_BITS) branch and remove the following 
ones, should be enough;
  - for arithmetic functions (mpz_add_ui, mpz_mul_ui, mpz_div_qr_ui), we 
can remove all the code but the content of the branch if (value > 
  - for mpz_gcd_ui (should we change also mpz_lcm_ui?) the code you 
proposed a couple of weeks ago is better, moreover you proposed to 
remove mpn_div_qr_1 and to adapt also mpz_addmul_ui and mpz_submul_ui, 
should be done;
  - for power computations (mpz_ui_pow_ui, mpz_powm_ui) we can keep only 
the branch with init_set.

I can start with this.

Then, the functions with special code for the p_limb_t != unsigned long 
case will be only five: gmp_umul_ppmm, mpn_invert_3by2, mpz_get_ui, 
mpz_set_ui, and mpn_absfits_ulong_p.
The last one is used (directly or not) by all comparison functions, and 
reduces to a static {return un <= 1;} in the typical case.
The first two (gmp_umul_ppmm, mpn_invert_3by2) has special code for 
speed only. The compiler can choose the one to be used at compile time.

If you add also roinit_ui, there will be six, but maybe it will be worth 
rewriting mpz_set_ui to use it...

More information about the gmp-devel mailing list