[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sun Nov 27 06:59:35 UTC 2016
details: /var/hg/gmp/rev/5289d7670775
changeset: 17139:5289d7670775
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Nov 27 07:27:45 2016 +0100
description:
mini-gmp/mini-gmp.c (mpz_get_si): fewer branches and forumla for negatives from GMP
details: /var/hg/gmp/rev/3068f1d85563
changeset: 17140:3068f1d85563
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Nov 27 07:59:15 2016 +0100
description:
mpz/gcd{,ext}.c: Use NEWALLOC.
diffstat:
mini-gmp/mini-gmp.c | 11 ++++-------
mpz/gcd.c | 20 ++++++++++----------
mpz/gcdext.c | 4 ++--
3 files changed, 16 insertions(+), 19 deletions(-)
diffs (93 lines):
diff -r fd5eb90386a9 -r 3068f1d85563 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Sun Nov 27 01:17:25 2016 +0100
+++ b/mini-gmp/mini-gmp.c Sun Nov 27 07:59:15 2016 +0100
@@ -1559,14 +1559,11 @@
long int
mpz_get_si (const mpz_t u)
{
- mp_size_t us = u->_mp_size;
-
- if (us > 0)
- return (long) (u->_mp_d[0] & ~GMP_LIMB_HIGHBIT);
- else if (us < 0)
- return (long) (- u->_mp_d[0] | GMP_LIMB_HIGHBIT);
+ if (u->_mp_size < 0)
+ /* This expression is necessary to properly handle 0x80000000 */
+ return -1 - (long) ((u->_mp_d[0] - 1) & ~GMP_LIMB_HIGHBIT);
else
- return 0;
+ return (long) (mpz_get_ui (u) & ~GMP_LIMB_HIGHBIT);
}
unsigned long int
diff -r fd5eb90386a9 -r 3068f1d85563 mpz/gcd.c
--- a/mpz/gcd.c Sun Nov 27 01:17:25 2016 +0100
+++ b/mpz/gcd.c Sun Nov 27 07:59:15 2016 +0100
@@ -56,8 +56,8 @@
SIZ (g) = vsize;
if (g == v)
return;
- MPZ_REALLOC (g, vsize);
- MPN_COPY (PTR (g), vp, vsize);
+ tp = MPZ_NEWALLOC (g, vsize);
+ MPN_COPY (tp, vp, vsize);
return;
}
@@ -67,8 +67,8 @@
SIZ (g) = usize;
if (g == u)
return;
- MPZ_REALLOC (g, usize);
- MPN_COPY (PTR (g), up, usize);
+ tp = MPZ_NEWALLOC (g, usize);
+ MPN_COPY (tp, up, usize);
return;
}
@@ -146,19 +146,19 @@
{
mp_limb_t cy_limb;
gsize += (vp[vsize - 1] >> (GMP_NUMB_BITS - g_zero_bits)) != 0;
- MPZ_REALLOC (g, gsize);
- MPN_ZERO (PTR (g), g_zero_limbs);
+ tp = MPZ_NEWALLOC (g, gsize);
+ MPN_ZERO (tp, g_zero_limbs);
- tp = PTR(g) + g_zero_limbs;
+ tp = tp + g_zero_limbs;
cy_limb = mpn_lshift (tp, vp, vsize, g_zero_bits);
if (cy_limb != 0)
tp[vsize] = cy_limb;
}
else
{
- MPZ_REALLOC (g, gsize);
- MPN_ZERO (PTR (g), g_zero_limbs);
- MPN_COPY (PTR (g) + g_zero_limbs, vp, vsize);
+ tp = MPZ_NEWALLOC (g, gsize);
+ MPN_ZERO (tp, g_zero_limbs);
+ MPN_COPY (tp + g_zero_limbs, vp, vsize);
}
SIZ (g) = gsize;
diff -r fd5eb90386a9 -r 3068f1d85563 mpz/gcdext.c
--- a/mpz/gcdext.c Sun Nov 27 01:17:25 2016 +0100
+++ b/mpz/gcdext.c Sun Nov 27 07:59:15 2016 +0100
@@ -112,14 +112,14 @@
{
mp_ptr sp;
- sp = MPZ_REALLOC (s, ssize);
+ sp = MPZ_NEWALLOC (s, ssize);
MPN_COPY (sp, tmp_sp, ssize);
SIZ (s) = tmp_ssize;
}
if (g != NULL)
{
- gp = MPZ_REALLOC (g, gsize);
+ gp = MPZ_NEWALLOC (g, gsize);
MPN_COPY (gp, tmp_gp, gsize);
SIZ (g) = gsize;
}
More information about the gmp-commit
mailing list