Recent changes to mpn_get_str/mpn_set_str

Torbjörn Granlund tg at
Thu Jan 26 12:31:19 UTC 2017

Each of mpn_get_str and mpn_set_str used to have a private function for
computing a series of powers of the conversion base.  These functions
were similar, except that they stored the results in opposite order and
that one relied on mpn_divexact_1 for adjusting the exact power and the
other relied on several mpn_mul_1 (in a rather simple-minded manner).

With my changes, mpn_get_str and mpn_set_str use a common function which
use mpn_divexact_1 or mpn_mul_1 depending which is faster.  If either is
always faster, only one variant is compiled.

The speedup should be pretty minor since my changes affect the linear
term of a superlinear function.  On many machines, the compiled size is
smaller (the final library is a whole 0.1% smaller on a modern 64-bit

It would be possible to improve the general speed for binary-to-string
conversion (i.e., mpn_get_str).  One idea is to pre-invert the larger
powers.  The highest power is used just once, so nothing to improve
there.  The 2nd highest power is used twice and is now thererby
implicitly inverted twice.  The 3rd highest power is used four times,
and is therefore implicitly inverted four times, etc.

Please encrypt, key id 0xC8601622

More information about the gmp-devel mailing list