summaryrefslogtreecommitdiff
path: root/Build/source/libs/gmp/gmp-src/mpn/generic/sbpi1_bdiv_q.c
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2015-12-28 12:26:00 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2015-12-28 12:26:00 +0000
commitcf483bef74e67ba3d39108df4864121c887f95e6 (patch)
tree40af58d96b6c98f2c5a5c02ccfef80b1ff7b3305 /Build/source/libs/gmp/gmp-src/mpn/generic/sbpi1_bdiv_q.c
parent1fff76f0c267ade1406b5a8a9a8c48c7cab1ad4f (diff)
gmp-6.1.0
git-svn-id: svn://tug.org/texlive/trunk@39212 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/gmp/gmp-src/mpn/generic/sbpi1_bdiv_q.c')
-rw-r--r--Build/source/libs/gmp/gmp-src/mpn/generic/sbpi1_bdiv_q.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/Build/source/libs/gmp/gmp-src/mpn/generic/sbpi1_bdiv_q.c b/Build/source/libs/gmp/gmp-src/mpn/generic/sbpi1_bdiv_q.c
new file mode 100644
index 00000000000..645b1d9b6a4
--- /dev/null
+++ b/Build/source/libs/gmp/gmp-src/mpn/generic/sbpi1_bdiv_q.c
@@ -0,0 +1,100 @@
+/* mpn_sbpi1_bdiv_q -- schoolbook Hensel division with precomputed inverse,
+ returning quotient only.
+
+ Contributed to the GNU project by Niels Möller.
+
+ THE FUNCTIONS IN THIS FILE ARE INTERNAL FUNCTIONS WITH MUTABLE INTERFACES.
+ IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS
+ ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE.
+
+Copyright 2005, 2006, 2009, 2011, 2012 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of either:
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+or
+
+ * the GNU General Public License as published by the Free Software
+ Foundation; either version 2 of the License, or (at your option) any
+ later version.
+
+or both in parallel, as here.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received copies of the GNU General Public License and the
+GNU Lesser General Public License along with the GNU MP Library. If not,
+see https://www.gnu.org/licenses/. */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+
+
+/* Computes Q = N / D mod B^nn, destroys N.
+
+ D must be odd. dinv is (-D)^-1 mod B.
+
+
+ The straightforward way to compute Q is to cancel one limb at a time, using
+
+ qp[i] = D^{-1} * np[i] (mod B)
+ N -= B^i * qp[i] * D
+
+ But we prefer addition to subtraction, since mpn_addmul_1 is often faster
+ than mpn_submul_1. Q = - N / D can be computed by iterating
+
+ qp[i] = (-D)^{-1} * np[i] (mod B)
+ N += B^i * qp[i] * D
+
+ And then we flip the sign, -Q = (not Q) + 1. */
+
+void
+mpn_sbpi1_bdiv_q (mp_ptr qp,
+ mp_ptr np, mp_size_t nn,
+ mp_srcptr dp, mp_size_t dn,
+ mp_limb_t dinv)
+{
+ mp_size_t i;
+ mp_limb_t cy, q;
+
+ ASSERT (dn > 0);
+ ASSERT (nn >= dn);
+ ASSERT ((dp[0] & 1) != 0);
+ /* FIXME: Add ASSERTs for allowable overlapping; i.e., that qp = np is OK,
+ but some over N/Q overlaps will not work. */
+
+ for (i = nn - dn; i > 0; i--)
+ {
+ q = dinv * np[0];
+ cy = mpn_addmul_1 (np, dp, dn, q);
+ mpn_add_1 (np + dn, np + dn, i, cy);
+ ASSERT (np[0] == 0);
+ qp[0] = ~q;
+ qp++;
+ np++;
+ }
+
+ for (i = dn; i > 1; i--)
+ {
+ q = dinv * np[0];
+ mpn_addmul_1 (np, dp, i, q);
+ ASSERT (np[0] == 0);
+ qp[0] = ~q;
+ qp++;
+ np++;
+ }
+
+ /* Final limb */
+ q = dinv * np[0];
+ qp[0] = ~q;
+ mpn_add_1 (qp - nn + 1, qp - nn + 1, nn, 1);
+}