summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2000-10-24 01:37:54 +0200
committerKevin Ryde <user42@zip.com.au>2000-10-24 01:37:54 +0200
commit2a7a9cf5c9998da20a58fc0601fda1509fc24374 (patch)
treeafb401ab717b6600c3e1c53f5786fb91c5d72263
parent51ad48f633cf01f2d16b1a4d1c20e3b938902eed (diff)
downloadgmp-2a7a9cf5c9998da20a58fc0601fda1509fc24374.tar.gz
* mpq/aors.c, mpq/canonicalize.c: Skip two mpz_divexact calls if
gcd gives 1, which should be 60% of the time. * gmp-impl.h (MPZ_EQUAL_1_P): New macro.
-rw-r--r--gmp-impl.h2
-rw-r--r--mpq/aors.c12
-rw-r--r--mpq/canonicalize.c7
3 files changed, 14 insertions, 7 deletions
diff --git a/gmp-impl.h b/gmp-impl.h
index ae1f4eb03..6fef591f3 100644
--- a/gmp-impl.h
+++ b/gmp-impl.h
@@ -421,6 +421,8 @@ _MPN_COPY (d, s, n) mp_ptr d; mp_srcptr s; mp_size_t n;
_mpz_realloc (what, needed); \
} while (0)
+#define MPZ_EQUAL_1_P(z) (SIZ(z)==1 && PTR(z)[0] == 1)
+
#if defined (__GNUC__) || defined (_FORCE_INLINES)
/* n==0 is allowed and is considered a zero value. */
diff --git a/mpq/aors.c b/mpq/aors.c
index d21eb6816..0c92ffd5b 100644
--- a/mpq/aors.c
+++ b/mpq/aors.c
@@ -60,7 +60,7 @@ FUNCTION (mpq_ptr rop, mpq_srcptr op1, mpq_srcptr op2)
with the numerators of OP1 and OP2. */
mpz_gcd (gcd, &(op1->_mp_den), &(op2->_mp_den));
- if (gcd->_mp_size > 1 || gcd->_mp_d[0] != 1)
+ if (! MPZ_EQUAL_1_P (gcd))
{
mpz_t t;
@@ -74,11 +74,13 @@ FUNCTION (mpq_ptr rop, mpq_srcptr op1, mpq_srcptr op2)
VARIATION (t, tmp1, tmp2);
mpz_divexact (tmp2, &(op1->_mp_den), gcd);
- mpz_gcd (gcd, t, gcd);
-
- mpz_divexact (&(rop->_mp_num), t, gcd);
- mpz_divexact (tmp1, &(op2->_mp_den), gcd);
+ mpz_gcd (gcd, t, gcd);
+ if (! MPZ_EQUAL_1_P (gcd))
+ {
+ mpz_divexact (&(rop->_mp_num), t, gcd);
+ mpz_divexact (tmp1, &(op2->_mp_den), gcd);
+ }
mpz_mul (&(rop->_mp_den), tmp1, tmp2);
}
else
diff --git a/mpq/canonicalize.c b/mpq/canonicalize.c
index 2955fff11..256c9c6b0 100644
--- a/mpq/canonicalize.c
+++ b/mpq/canonicalize.c
@@ -41,8 +41,11 @@ mpq_canonicalize (op)
ABS (op->_mp_den._mp_size)));
mpz_gcd (gcd, &(op->_mp_num), &(op->_mp_den));
- mpz_divexact (&(op->_mp_num), &(op->_mp_num), gcd);
- mpz_divexact (&(op->_mp_den), &(op->_mp_den), gcd);
+ if (! MPZ_EQUAL_1_P (gcd))
+ {
+ mpz_divexact (&(op->_mp_num), &(op->_mp_num), gcd);
+ mpz_divexact (&(op->_mp_den), &(op->_mp_den), gcd);
+ }
if (op->_mp_den._mp_size < 0)
{