[Gmp-commit] /var/hg/gmp: 4 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Tue Jan 16 06:38:42 UTC 2018
details: /var/hg/gmp/rev/77cdaf6dd973
changeset: 17537:77cdaf6dd973
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Mon Jan 15 21:27:48 2018 +0100
description:
mpz/bin_uiui.c (mul[4-8]): Use fewer multipliction in hard-coded formulas.
details: /var/hg/gmp/rev/36140eeae6a2
changeset: 17538:36140eeae6a2
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Jan 16 07:29:35 2018 +0100
description:
mpz/ior.c: Use MPZ_REALLOC
details: /var/hg/gmp/rev/30fa7f26a5be
changeset: 17539:30fa7f26a5be
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Jan 16 07:35:20 2018 +0100
description:
mpz/xor.c, mpz/and.c: Early free for temporaries, use INCR_U instead of add_1
details: /var/hg/gmp/rev/0cb65d333949
changeset: 17540:0cb65d333949
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Jan 16 07:37:51 2018 +0100
description:
Copyright year
diffstat:
mini-gmp/mini-gmp.c | 2 +-
mini-gmp/tests/t-comb.c | 2 +-
mpz/and.c | 16 +++++++---------
mpz/bin_uiui.c | 41 +++++++++++++++++------------------------
mpz/ior.c | 15 ++++-----------
mpz/xor.c | 36 ++++++++++++++----------------------
tests/mpz/t-bin.c | 2 +-
7 files changed, 45 insertions(+), 69 deletions(-)
diffs (truncated from 343 to 300 lines):
diff -r 274ed86df599 -r 0cb65d333949 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Mon Jan 15 20:42:23 2018 +0100
+++ b/mini-gmp/mini-gmp.c Tue Jan 16 07:37:51 2018 +0100
@@ -2,7 +2,7 @@
Contributed to the GNU project by Niels Möller
-Copyright 1991-1997, 1999-2017 Free Software Foundation, Inc.
+Copyright 1991-1997, 1999-2018 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
diff -r 274ed86df599 -r 0cb65d333949 mini-gmp/tests/t-comb.c
--- a/mini-gmp/tests/t-comb.c Mon Jan 15 20:42:23 2018 +0100
+++ b/mini-gmp/tests/t-comb.c Tue Jan 16 07:37:51 2018 +0100
@@ -1,6 +1,6 @@
/* Exercise mpz_fac_ui and mpz_bin_uiui.
-Copyright 2000-2002, 2012, 2013, 2017 Free Software Foundation, Inc.
+Copyright 2000-2002, 2012, 2013, 2017-2018 Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
diff -r 274ed86df599 -r 0cb65d333949 mpz/and.c
--- a/mpz/and.c Mon Jan 15 20:42:23 2018 +0100
+++ b/mpz/and.c Tue Jan 16 07:37:51 2018 +0100
@@ -1,7 +1,7 @@
/* mpz_and -- Logical and.
Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2003, 2005, 2012,
-2015-2017 Free Software Foundation, Inc.
+2015-2018 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -41,7 +41,6 @@
mp_size_t i;
TMP_DECL;
- TMP_MARK;
op1_size = SIZ(op1);
op2_size = SIZ(op2);
@@ -56,9 +55,8 @@
if (op2_size >= 0)
{
- res_size = op2_size;
/* First loop finds the size of the result. */
- for (i = res_size; --i >= 0;)
+ for (i = op2_size; --i >= 0;)
if ((op1_ptr[i] & op2_ptr[i]) != 0)
{
res_size = i + 1;
@@ -77,10 +75,10 @@
}
else
{
+ TMP_MARK;
if (op1_size < 0)
{
mp_ptr opx, opy;
- mp_limb_t cy;
/* Both operands are negative, so will be the result.
-((-OP1) & (-OP2)) = -(~(OP1 - 1) & ~(OP2 - 1)) =
@@ -110,14 +108,14 @@
MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
op2_size - op1_size);
mpn_ior_n (res_ptr, op1_ptr, op2_ptr, op1_size);
+ TMP_FREE;
res_size = op2_size;
- cy = mpn_add_1 (res_ptr, res_ptr, res_size, (mp_limb_t) 1);
- res_ptr[res_size] = cy;
- res_size += cy;
+ res_ptr[res_size] = 0;
+ MPN_INCR_U (res_ptr, res_size + 1, (mp_limb_t) 1);
+ res_size += res_ptr[res_size];
SIZ(res) = -res_size;
- TMP_FREE;
return;
}
}
diff -r 274ed86df599 -r 0cb65d333949 mpz/bin_uiui.c
--- a/mpz/bin_uiui.c Mon Jan 15 20:42:23 2018 +0100
+++ b/mpz/bin_uiui.c Tue Jan 16 07:37:51 2018 +0100
@@ -2,7 +2,7 @@
Contributed to the GNU project by Torbjorn Granlund and Marco Bodrato.
-Copyright 2010-2012, 2015-2017 Free Software Foundation, Inc.
+Copyright 2010-2012, 2015-2018 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -109,49 +109,42 @@
static mp_limb_t
mul4 (mp_limb_t m)
{
- mp_limb_t m01 = (m + 0) * (m + 1) >> 1;
- mp_limb_t m23 = (m + 2) * (m + 3) >> 1;
- return m01 * m23;
+ mp_limb_t m03 = (m + 0) * (m + 3) >> 1;
+ return m03 * (m03 + 1); /* mul2 (m03) ? */
}
static mp_limb_t
mul5 (mp_limb_t m)
{
- mp_limb_t m012 = (m + 0) * (m + 1) * (m + 2) >> 1;
- mp_limb_t m34 = (m + 3) * (m + 4) >> 1;
- return m012 * m34;
+ mp_limb_t m03 = (m + 0) * (m + 3) >> 1;
+ mp_limb_t m034 = m03 * (m + 4);
+ return (m03 + 1) * m034;
}
static mp_limb_t
mul6 (mp_limb_t m)
{
- mp_limb_t m01 = (m + 0) * (m + 1);
- mp_limb_t m23 = (m + 2) * (m + 3);
- mp_limb_t m45 = (m + 4) * (m + 5) >> 1;
- mp_limb_t m0123 = m01 * m23 >> 3;
- return m0123 * m45;
+ mp_limb_t m05 = (m + 0) * (m + 5);
+ mp_limb_t m1234 = (m05 + 5) * (m05 + 5) >> 3;
+ return m1234 * (m05 >> 1);
}
static mp_limb_t
mul7 (mp_limb_t m)
{
- mp_limb_t m01 = (m + 0) * (m + 1);
- mp_limb_t m23 = (m + 2) * (m + 3);
- mp_limb_t m456 = (m + 4) * (m + 5) * (m + 6) >> 1;
- mp_limb_t m0123 = m01 * m23 >> 3;
- return m0123 * m456;
+ mp_limb_t m05 = (m + 0) * (m + 5);
+ mp_limb_t m1234 = (m05 + 5) * (m05 + 5) >> 3;
+ mp_limb_t m056 = m05 * (m + 6) >> 1;
+ return m1234 * m056;
}
static mp_limb_t
mul8 (mp_limb_t m)
{
- mp_limb_t m01 = (m + 0) * (m + 1);
- mp_limb_t m23 = (m + 2) * (m + 3);
- mp_limb_t m45 = (m + 4) * (m + 5);
- mp_limb_t m67 = (m + 6) * (m + 7);
- mp_limb_t m0123 = m01 * m23 >> 3;
- mp_limb_t m4567 = m45 * m67 >> 3;
- return m0123 * m4567;
+ mp_limb_t m07 = (m + 0) * (m + 7);
+ mp_limb_t m0257 = m07 * (m07 + 10) >> 3;
+ mp_limb_t m1346 = m07 + 9 + m0257;
+ return m0257 * m1346;
}
typedef mp_limb_t (* mulfunc_t) (mp_limb_t);
diff -r 274ed86df599 -r 0cb65d333949 mpz/ior.c
--- a/mpz/ior.c Mon Jan 15 20:42:23 2018 +0100
+++ b/mpz/ior.c Tue Jan 16 07:37:51 2018 +0100
@@ -1,7 +1,7 @@
/* mpz_ior -- Logical inclusive or.
Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2005, 2012, 2013,
-2015-2017 Free Software Foundation, Inc.
+2015-2018 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -41,7 +41,6 @@
mp_size_t i;
TMP_DECL;
- TMP_MARK;
op1_size = SIZ(op1);
op2_size = SIZ(op2);
@@ -71,6 +70,7 @@
}
else
{
+ TMP_MARK;
if (op1_size < 0)
{
mp_ptr opx, opy;
@@ -123,7 +123,6 @@
{
mp_ptr opx;
mp_limb_t cy;
- mp_size_t res_alloc;
mp_size_t count;
/* Operand 2 negative, so will be the result.
@@ -133,20 +132,14 @@
op2_size = -op2_size;
- res_alloc = op2_size;
+ res_ptr = MPZ_REALLOC (res, op2_size);
+ op1_ptr = PTR(op1);
opx = TMP_ALLOC_LIMBS (op2_size);
mpn_sub_1 (opx, PTR(op2), op2_size, (mp_limb_t) 1);
op2_ptr = opx;
op2_size -= op2_ptr[op2_size - 1] == 0;
- if (UNLIKELY (ALLOC(res) < res_alloc))
- {
- res_ptr = (mp_ptr) _mpz_realloc (res, res_alloc);
- op1_ptr = PTR(op1);
- /* op2_ptr points to temporary space. */
- }
-
if (op1_size >= op2_size)
{
/* We can just ignore the part of OP1 that stretches above OP2,
diff -r 274ed86df599 -r 0cb65d333949 mpz/xor.c
--- a/mpz/xor.c Mon Jan 15 20:42:23 2018 +0100
+++ b/mpz/xor.c Tue Jan 16 07:37:51 2018 +0100
@@ -1,7 +1,7 @@
/* mpz_xor -- Logical xor.
Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2005, 2012,
-2015-2017 Free Software Foundation, Inc.
+2015-2018 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -37,10 +37,9 @@
mp_srcptr op1_ptr, op2_ptr;
mp_size_t op1_size, op2_size;
mp_ptr res_ptr;
- mp_size_t res_size, res_alloc;
+ mp_size_t res_size;
TMP_DECL;
- TMP_MARK;
op1_size = SIZ(op1);
op2_size = SIZ(op2);
@@ -71,6 +70,7 @@
}
else
{
+ TMP_MARK;
if (op1_size < 0)
{
mp_ptr opx, opy;
@@ -92,8 +92,7 @@
mpn_sub_1 (opy, PTR(op2), op2_size, (mp_limb_t) 1);
op2_ptr = opy;
- res_alloc = op2_size;
- res_ptr = MPZ_NEWALLOC (res, res_alloc);
+ res_ptr = MPZ_NEWALLOC (res, op2_size);
/* Don't re-read OP1_PTR and OP2_PTR. They point to temporary
space--never to the space PTR(res) used to point to before
reallocation. */
@@ -101,18 +100,17 @@
MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
op2_size - op1_size);
mpn_xor_n (res_ptr, op1_ptr, op2_ptr, op1_size);
+ TMP_FREE;
res_size = op2_size;
MPN_NORMALIZE (res_ptr, res_size);
SIZ(res) = res_size;
- TMP_FREE;
return;
}
}
{
mp_ptr opx;
- mp_limb_t cy;
/* Operand 2 negative, so will be the result.
-(OP1 ^ (-OP2)) = -(OP1 ^ ~(OP2 - 1)) =
@@ -121,38 +119,32 @@
op2_size = -op2_size;
+ res_size = MAX (op1_size, op2_size);
+ res_ptr = MPZ_REALLOC (res, res_size + 1);
+ op1_ptr = PTR(op1);
+
opx = TMP_ALLOC_LIMBS (op2_size);
mpn_sub_1 (opx, PTR(op2), op2_size, (mp_limb_t) 1);
op2_ptr = opx;
- res_alloc = MAX (op1_size, op2_size) + 1;
- if (UNLIKELY (ALLOC(res) < res_alloc))
- {
- res_ptr = (mp_ptr) _mpz_realloc (res, res_alloc);
More information about the gmp-commit
mailing list