[Gmp-commit] /home/hgfiles/gmp: Rewrite mpz/mod.c.
mercurial at gmplib.org
mercurial at gmplib.org
Mon Dec 13 21:40:54 CET 2010
details: /home/hgfiles/gmp/rev/744532e847b4
changeset: 13710:744532e847b4
user: Torbjorn Granlund <tege at gmplib.org>
date: Mon Dec 13 21:40:50 2010 +0100
description:
Rewrite mpz/mod.c.
diffstat:
ChangeLog | 2 ++
mpz/mod.c | 31 ++++++++++++++++---------------
2 files changed, 18 insertions(+), 15 deletions(-)
diffs (71 lines):
diff -r 842e4ffa8fd1 -r 744532e847b4 ChangeLog
--- a/ChangeLog Mon Dec 13 21:38:23 2010 +0100
+++ b/ChangeLog Mon Dec 13 21:40:50 2010 +0100
@@ -1,5 +1,7 @@
2010-12-13 Torbjorn Granlund <tege at gmplib.org>
+ * mpz/mod.c: Rewrite.
+
* mpn/x86_64/corei/popcount.asm: New file.
* mpn/x86_64/corei/hamdist.asm: New file.
diff -r 842e4ffa8fd1 -r 744532e847b4 mpz/mod.c
--- a/mpz/mod.c Mon Dec 13 21:38:23 2010 +0100
+++ b/mpz/mod.c Mon Dec 13 21:40:50 2010 +0100
@@ -1,6 +1,6 @@
/* mpz_mod -- The mathematical mod function.
-Copyright 1991, 1993, 1994, 1995, 1996, 2001, 2002, 2005 Free Software
+Copyright 1991, 1993, 1994, 1995, 1996, 2001, 2002, 2005, 2010 Free Software
Foundation, Inc.
This file is part of the GNU MP Library.
@@ -25,33 +25,34 @@
mpz_mod (mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor)
{
mp_size_t divisor_size = divisor->_mp_size;
- mpz_t temp_divisor; /* N.B.: lives until function returns! */
+ mp_size_t rn, bn;
+ mpz_t temp_divisor;
TMP_DECL;
TMP_MARK;
+ bn = ABSIZ(divisor);
+
/* We need the original value of the divisor after the remainder has been
preliminary calculated. We have to copy it to temporary space if it's
the same variable as REM. */
if (rem == divisor)
{
- MPZ_TMP_INIT (temp_divisor, ABS (divisor_size));
- mpz_set (temp_divisor, divisor);
- divisor = temp_divisor;
+ PTR(temp_divisor) = TMP_ALLOC_LIMBS (bn);
+ MPN_COPY (PTR(temp_divisor), PTR(divisor), bn);
}
+ else
+ {
+ PTR(temp_divisor) = PTR(divisor);
+ }
+ SIZ(temp_divisor) = bn;
+ divisor = temp_divisor;
mpz_tdiv_r (rem, dividend, divisor);
- if (rem->_mp_size != 0)
- {
- if (dividend->_mp_size < 0)
- {
- if (divisor->_mp_size < 0)
- mpz_sub (rem, rem, divisor);
- else
- mpz_add (rem, rem, divisor);
- }
- }
+ rn = SIZ (rem);
+ if (rn < 0)
+ mpz_add (rem, rem, divisor);
TMP_FREE;
}
More information about the gmp-commit
mailing list