summaryrefslogtreecommitdiff
path: root/mpz/gcd.c
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2011-01-03 20:00:11 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2011-01-03 20:00:11 +0100
commitbb0d5b1f6b37144d9cde4d95144290ee9b3faea4 (patch)
treebdd6f6aba6a6d8181e2972fb21a04ee57bf751e2 /mpz/gcd.c
parent37d49aca5da88720e54d9c965daa1798be53faf6 (diff)
downloadgmp-bb0d5b1f6b37144d9cde4d95144290ee9b3faea4.tar.gz
Removed all #ifdef BERKELEY_MP.
Diffstat (limited to 'mpz/gcd.c')
-rw-r--r--mpz/gcd.c65
1 files changed, 29 insertions, 36 deletions
diff --git a/mpz/gcd.c b/mpz/gcd.c
index 18787699d..688b7397d 100644
--- a/mpz/gcd.c
+++ b/mpz/gcd.c
@@ -1,7 +1,7 @@
/* mpz/gcd.c: Calculate the greatest common divisor of two integers.
-Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002, 2005 Free Software
-Foundation, Inc.
+Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002, 2005, 2010 Free
+Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -21,63 +21,58 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
-#ifdef BERKELEY_MP
-#include "mp.h"
-#endif
void
-#ifndef BERKELEY_MP
mpz_gcd (mpz_ptr g, mpz_srcptr u, mpz_srcptr v)
-#else /* BERKELEY_MP */
-gcd (mpz_srcptr u, mpz_srcptr v, mpz_ptr g)
-#endif /* BERKELEY_MP */
{
unsigned long int g_zero_bits, u_zero_bits, v_zero_bits;
mp_size_t g_zero_limbs, u_zero_limbs, v_zero_limbs;
mp_ptr tp;
- mp_ptr up = u->_mp_d;
- mp_size_t usize = ABS (u->_mp_size);
- mp_ptr vp = v->_mp_d;
- mp_size_t vsize = ABS (v->_mp_size);
+ mp_ptr up;
+ mp_size_t usize;
+ mp_ptr vp;
+ mp_size_t vsize;
mp_size_t gsize;
TMP_DECL;
+ up = PTR(u);
+ usize = ABSIZ (u);
+ vp = PTR(v);
+ vsize = ABSIZ (v);
/* GCD(0, V) == V. */
if (usize == 0)
{
- g->_mp_size = vsize;
+ SIZ (g) = vsize;
if (g == v)
return;
- if (g->_mp_alloc < vsize)
- _mpz_realloc (g, vsize);
- MPN_COPY (g->_mp_d, vp, vsize);
+ MPZ_REALLOC (g, vsize);
+ MPN_COPY (PTR (g), vp, vsize);
return;
}
/* GCD(U, 0) == U. */
if (vsize == 0)
{
- g->_mp_size = usize;
+ SIZ (g) = usize;
if (g == u)
return;
- if (g->_mp_alloc < usize)
- _mpz_realloc (g, usize);
- MPN_COPY (g->_mp_d, up, usize);
+ MPZ_REALLOC (g, usize);
+ MPN_COPY (PTR (g), up, usize);
return;
}
if (usize == 1)
{
- g->_mp_size = 1;
- g->_mp_d[0] = mpn_gcd_1 (vp, vsize, up[0]);
+ SIZ (g) = 1;
+ PTR (g)[0] = mpn_gcd_1 (vp, vsize, up[0]);
return;
}
if (vsize == 1)
{
- g->_mp_size = 1;
- g->_mp_d[0] = mpn_gcd_1 (up, usize, vp[0]);
+ SIZ(g) = 1;
+ PTR (g)[0] = mpn_gcd_1 (up, usize, vp[0]);
return;
}
@@ -86,7 +81,7 @@ gcd (mpz_srcptr u, mpz_srcptr v, mpz_ptr g)
/* Eliminate low zero bits from U and V and move to temporary storage. */
while (*up == 0)
up++;
- u_zero_limbs = up - u->_mp_d;
+ u_zero_limbs = up - PTR(u);
usize -= u_zero_limbs;
count_trailing_zeros (u_zero_bits, *up);
tp = up;
@@ -101,7 +96,7 @@ gcd (mpz_srcptr u, mpz_srcptr v, mpz_ptr g)
while (*vp == 0)
vp++;
- v_zero_limbs = vp - v->_mp_d;
+ v_zero_limbs = vp - PTR (v);
vsize -= v_zero_limbs;
count_trailing_zeros (v_zero_bits, *vp);
tp = vp;
@@ -141,23 +136,21 @@ gcd (mpz_srcptr u, mpz_srcptr v, mpz_ptr g)
{
mp_limb_t cy_limb;
gsize += (vp[vsize - 1] >> (GMP_NUMB_BITS - g_zero_bits)) != 0;
- if (g->_mp_alloc < gsize)
- _mpz_realloc (g, gsize);
- MPN_ZERO (g->_mp_d, g_zero_limbs);
+ MPZ_REALLOC (g, gsize);
+ MPN_ZERO (PTR (g), g_zero_limbs);
- tp = g->_mp_d + g_zero_limbs;
+ tp = PTR(g) + g_zero_limbs;
cy_limb = mpn_lshift (tp, vp, vsize, g_zero_bits);
if (cy_limb != 0)
tp[vsize] = cy_limb;
}
else
{
- if (g->_mp_alloc < gsize)
- _mpz_realloc (g, gsize);
- MPN_ZERO (g->_mp_d, g_zero_limbs);
- MPN_COPY (g->_mp_d + g_zero_limbs, vp, vsize);
+ MPZ_REALLOC (g, gsize);
+ MPN_ZERO (PTR (g), g_zero_limbs);
+ MPN_COPY (PTR (g) + g_zero_limbs, vp, vsize);
}
- g->_mp_size = gsize;
+ SIZ (g) = gsize;
TMP_FREE;
}