3 THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES. IT IS ONLY
4 SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST
5 GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
7 Copyright 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
28 /* Used when mpn_hgcd or mpn_hgcd2 has failed. Then either one of a or
29 b is small, or the difference is small. Perform one subtraction
30 followed by one division. If the gcd is found, stores it in gp and
31 *gn, and returns zero. Otherwise, compute the reduced a and b, and
32 return the new size. */
34 /* FIXME: Check when the smaller number is a single limb, and invoke
37 mpn_gcd_subdiv_step (mp_ptr gp, mp_size_t *gn,
38 mp_ptr ap, mp_ptr bp, mp_size_t n, mp_ptr tp)
43 ASSERT (ap[n-1] > 0 || bp[n-1] > 0);
46 MPN_NORMALIZE (ap, an);
47 MPN_NORMALIZE (bp, bn);
49 if (UNLIKELY (an == 0))
52 MPN_COPY (gp, bp, bn);
56 else if (UNLIKELY (bn == 0))
59 MPN_COPY (gp, ap, an);
64 /* Arrange so that a > b, subtract an -= bn, and maintain
67 MPN_PTR_SWAP (ap, an, bp, bn);
71 MPN_CMP (c, ap, bp, an);
72 if (UNLIKELY (c == 0))
78 ASSERT_NOCARRY (mpn_sub (ap, ap, an, bp, bn));
79 MPN_NORMALIZE (ap, an);
82 /* Arrange so that a > b, and divide a = q b + r */
83 /* FIXME: an < bn happens when we have cancellation. If that is the
84 common case, then we could reverse the roles of a and b to avoid
87 MPN_PTR_SWAP (ap, an, bp, bn);
91 MPN_CMP (c, ap, bp, an);
92 if (UNLIKELY (c == 0))
98 mpn_tdiv_qr (tp, ap, 0, ap, an, bp, bn);
100 if (mpn_zero_p (ap, bn))