summaryrefslogtreecommitdiff
path: root/mpn/generic/gcdext.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2009-12-03 12:33:03 +0100
committerNiels Möller <nisse@lysator.liu.se>2009-12-03 12:33:03 +0100
commitcdea47bd8ff634e603e4c401eb94daf13645c345 (patch)
treee7532514e67adc9f0b3f22349cab1a104c25abc7 /mpn/generic/gcdext.c
parent806e4ca8069166db50a52dcc6dd9670f3d8880c9 (diff)
downloadgmp-cdea47bd8ff634e603e4c401eb94daf13645c345.tar.gz
Better cofactor selection in outer gcdext loop.
Diffstat (limited to 'mpn/generic/gcdext.c')
-rw-r--r--mpn/generic/gcdext.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/mpn/generic/gcdext.c b/mpn/generic/gcdext.c
index 645cdff5a..6b5509f18 100644
--- a/mpn/generic/gcdext.c
+++ b/mpn/generic/gcdext.c
@@ -388,25 +388,29 @@ mpn_gcdext (mp_ptr gp, mp_ptr up, mp_size_t *usizep,
}
}
- if (mpn_zero_p (ap, n))
+ if (UNLIKELY (mpn_cmp (ap, bp, n) == 0))
{
- MPN_COPY (gp, bp, n);
- MPN_NORMALIZE_NOT_ZERO (u0, un);
- MPN_COPY (up, u0, un);
- *usizep = -un;
+ /* Must return the smallest cofactor, +u1 or -u0 */
+ int c;
- TMP_FREE;
- return n;
- }
- else if (mpn_zero_p (bp, n))
- {
MPN_COPY (gp, ap, n);
- MPN_NORMALIZE_NOT_ZERO (u1, un);
- MPN_COPY (up, u1, un);
- *usizep = un;
- TMP_FREE;
- return n;
+ MPN_CMP (c, u0, u1, un);
+ ASSERT (c != 0);
+ if (c < 0)
+ {
+ MPN_NORMALIZE (u0, un);
+ MPN_COPY (up, u0, un);
+ *usizep = -un;
+ }
+ else
+ {
+ MPN_NORMALIZE_NOT_ZERO (u1, un);
+ MPN_COPY (up, u1, un);
+ *usizep = un;
+ }
+
+ return n;
}
else if (mpn_zero_p (u0, un))
{