Recent changes to mpn_get_str/mpn_set_str

Marco Bodrato bodrato at
Mon Feb 27 06:53:53 UTC 2017


Il Mar, 14 Febbraio 2017 3:10 am, Torbjörn Granlund ha scritto:
> "Marco Bodrato" <bodrato at> writes:
>   A first attempt is attached.

>   It is not specialised for base 10, and it is not faster than
>   current code if only a few limbs must be converted, but around
>   10 limbs it should be a gain.
> That's expected, I think.

Well, the graphs on the paper show an earlier gain... but much depend on
the base, on architecture...

Anyway, I attach a second attempt (the full substitute for file
mpn/generic/get_str.c). I specialised code for base==10, refined some
details, and I moved some of the internal logic of mpn_div_q directly into
this code.
Now the crossover is around 5 limbs.

The code I extracted from mpn_div_q gave me the following:

      if (bkn == 1)
	mpn_divrem_1 (y0, 0L, tmp, un + 2, bkh);
      else if (bkn == 2)
	y0 [un + 1] = mpn_divrem_2 (y0, 0L, tmp, un + 3, bk);
	  gmp_pi1_t dinv;
	  invert_pi1 (dinv, bk[bkn - 1], bk[bkn - 2]);
	  y0 [un + 1] = mpn_sbpi1_div_q (y0, tmp, un + bkn + 1, bk, bkn,

Are divrem_[12] the best function we currently have to obtain the quotient
only when we divide by 1 or 2 limbs?

Best regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: get_str.c
Type: text/x-csrc
Size: 20712 bytes
Desc: not available
URL: <>

More information about the gmp-devel mailing list