mpn_tdiv_qr vs mpn_divrem
Torbjorn Granlund
tg at gmplib.org
Mon Aug 31 13:14:14 CEST 2009
Paul Zimmermann <Paul.Zimmermann at loria.fr> writes:
1) the documentation of mpn_tdiv_qr says "No overlap is permitted between
arguments". However line 325 of mpn/generic/hgcd.c (in GMP 4.3.0) writes
the remainder in place of the dividend:
mpn_tdiv_qr (tp, ap, 0, ap, an, bp, bn);
I believe either the documentation should be fixed, telling which overlap is
allowed, or hgcd.c should be fixed to avoid overlap.
I disagree.
Internally, GMP uses undocumented functions as well as undocumented
features of documnented functions. This is quite intensional.
2) We are still using mpn_divrem instead of mpn_tdiv_qr in MPFR. The reason
is that mpn_tdiv_qr requires one extra limb for the quotient, whereas in some
cases with mpn_divrem we can directly store the result in the destination
variable. Thus we avoid an unnecessary copy. The documentation of mpn_divrem
says "Please call `mpn_tdiv_qr' instead for best performance". In which cases
is mpn_tdiv_qr faster than mpn_divrem?
I don't recall.
We will soon introduce new documented main calling points for division.
One such calling point will probably be mpn_div_qr. It will probably
return the most significant quotient word so that an (m+n)-word dividend
divided by an n-word divisor will write just m words to the quotient
operand (not m+1 as mpn_tdiv_qr does).
Se also http://gmplib.org/list-archives/gmp-discuss/2006-April/002224.html.
:-)
--
Torbjörn
More information about the gmp-devel
mailing list