[Gmp-commit] /var/hg/gmp: 5 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Tue Feb 19 16:29:51 CET 2013
details: /var/hg/gmp/rev/daae017de36e
changeset: 15463:daae017de36e
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Feb 19 16:07:11 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_export): Reorder branches.
details: /var/hg/gmp/rev/b01cdd380097
changeset: 15464:b01cdd380097
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Feb 19 16:07:55 2013 +0100
description:
mini-gmp/tests/t-reuse.c: Fix typo causing the same negation condition to be applied to all operands.
details: /var/hg/gmp/rev/f8ac523b744e
changeset: 15465:f8ac523b744e
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Feb 19 16:24:42 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_mul_ui): Avoid temporary allocation (mpn_mul_1 can work in-place).
details: /var/hg/gmp/rev/03e76cc0513f
changeset: 15466:03e76cc0513f
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Feb 19 16:24:46 2013 +0100
description:
ChangeLog
details: /var/hg/gmp/rev/693ac3cb4f8d
changeset: 15467:693ac3cb4f8d
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Feb 19 16:29:41 2013 +0100
description:
ChangeLog
diffstat:
ChangeLog | 7 ++-
mini-gmp/mini-gmp.c | 141 +++++++++++++++++++++++------------------------
mini-gmp/tests/t-reuse.c | 4 +-
3 files changed, 77 insertions(+), 75 deletions(-)
diffs (212 lines):
diff -r f3b3bd788ddb -r 693ac3cb4f8d ChangeLog
--- a/ChangeLog Tue Feb 19 07:41:36 2013 +0100
+++ b/ChangeLog Tue Feb 19 16:29:41 2013 +0100
@@ -1,6 +1,11 @@
2013-02-19 Marco Bodrato <bodrato at mail.dm.unipi.it>
- * mini-gmp/mini-gmp.c: Move asserts to work-around a compiler bug.
+ * mini-gmp/mini-gmp.c: Move asserts to work-around a compiler bug.
+ (mpz_export): Reorder branches.
+ (mpz_mul_ui): Avoid temporary allocation (mpn_mul_1 can work in-place).
+
+ * mini-gmp/tests/t-reuse.c: Fix typo causing the same negation condition
+ to be applied to all operands. (See 2013-02-03, Torbjorn)
2013-02-17 Marco Bodrato <bodrato at mail.dm.unipi.it>
diff -r f3b3bd788ddb -r 693ac3cb4f8d mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Tue Feb 19 07:41:36 2013 +0100
+++ b/mini-gmp/mini-gmp.c Tue Feb 19 16:29:41 2013 +0100
@@ -1877,7 +1877,6 @@
mpz_mul_ui (mpz_t r, const mpz_t u, unsigned long int v)
{
mp_size_t un, us;
- mpz_t t;
mp_ptr tp;
mp_limb_t cy;
@@ -1891,17 +1890,12 @@
un = GMP_ABS (us);
- mpz_init2 (t, (un + 1) * GMP_LIMB_BITS);
-
- tp = t->_mp_d;
+ tp = MPZ_REALLOC (r, un + 1);
cy = mpn_mul_1 (tp, u->_mp_d, un, v);
tp[un] = cy;
un += (cy > 0);
- t->_mp_size = (us < 0) ? - un : un;
-
- mpz_swap (r, t);
- mpz_clear (t);
+ r->_mp_size = (us < 0) ? - un : un;
}
void
@@ -4016,18 +4010,9 @@
mpz_export (void *r, size_t *countp, int order, size_t size, int endian,
size_t nails, const mpz_t u)
{
- unsigned char *p;
- ptrdiff_t word_step;
- size_t count, k;
+ size_t count;
mp_size_t un;
- /* The current (partial) limb. */
- mp_limb_t limb;
- /* The number of bytes left to to in this limb. */
- size_t bytes;
- /* The index where the limb was read. */
- mp_size_t i;
-
if (nails != 0)
gmp_die ("mpz_import: Nails not supported.");
@@ -4035,63 +4020,75 @@
assert (endian >= -1 && endian <= 1);
assert (size > 0 || u->_mp_size == 0);
- un = GMP_ABS (u->_mp_size);
- if (un == 0)
+ un = u->_mp_size;
+ count = 0;
+ if (un != 0)
{
- if (countp)
- *countp = 0;
- return r;
+ size_t k;
+ unsigned char *p;
+ ptrdiff_t word_step;
+ /* The current (partial) limb. */
+ mp_limb_t limb;
+ /* The number of bytes left to to in this limb. */
+ size_t bytes;
+ /* The index where the limb was read. */
+ mp_size_t i;
+
+ un = GMP_ABS (un);
+
+ /* Count bytes in top limb. */
+ limb = u->_mp_d[un-1];
+ assert (limb != 0);
+
+ k = 0;
+ do {
+ k++; limb >>= CHAR_BIT;
+ } while (limb != 0);
+
+ count = (k + (un-1) * sizeof (mp_limb_t) + size - 1) / size;
+
+ if (!r)
+ r = gmp_xalloc (count * size);
+
+ if (endian == 0)
+ endian = gmp_detect_endian ();
+
+ p = (unsigned char *) r;
+
+ word_step = (order != endian) ? 2 * size : 0;
+
+ /* Process bytes from the least significant end, so point p at the
+ least significant word. */
+ if (order == 1)
+ {
+ p += size * (count - 1);
+ word_step = - word_step;
+ }
+
+ /* And at least significant byte of that word. */
+ if (endian == 1)
+ p += (size - 1);
+
+ for (bytes = 0, i = 0, k = 0; k < count; k++, p += word_step)
+ {
+ size_t j;
+ for (j = 0; j < size; j++, p -= (ptrdiff_t) endian)
+ {
+ if (bytes == 0)
+ {
+ if (i < un)
+ limb = u->_mp_d[i++];
+ bytes = sizeof (mp_limb_t);
+ }
+ *p = limb;
+ limb >>= CHAR_BIT;
+ bytes--;
+ }
+ }
+ assert (i == un);
+ assert (k == count);
}
- /* Count bytes in top limb. */
- for (limb = u->_mp_d[un-1], k = 0; limb > 0; k++, limb >>= CHAR_BIT)
- ;
-
- assert (k > 0);
-
- count = (k + (un-1) * sizeof (mp_limb_t) + size - 1) / size;
-
- if (!r)
- r = gmp_xalloc (count * size);
-
- if (endian == 0)
- endian = gmp_detect_endian ();
-
- p = (unsigned char *) r;
-
- word_step = (order != endian) ? 2 * size : 0;
-
- /* Process bytes from the least significant end, so point p at the
- least significant word. */
- if (order == 1)
- {
- p += size * (count - 1);
- word_step = - word_step;
- }
-
- /* And at least significant byte of that word. */
- if (endian == 1)
- p += (size - 1);
-
- for (bytes = 0, i = 0, k = 0; k < count; k++, p += word_step)
- {
- size_t j;
- for (j = 0; j < size; j++, p -= (ptrdiff_t) endian)
- {
- if (bytes == 0)
- {
- if (i < un)
- limb = u->_mp_d[i++];
- bytes = sizeof (mp_limb_t);
- }
- *p = limb;
- limb >>= CHAR_BIT;
- bytes--;
- }
- }
- assert (i == un);
- assert (k == count);
-
if (countp)
*countp = count;
diff -r f3b3bd788ddb -r 693ac3cb4f8d mini-gmp/tests/t-reuse.c
--- a/mini-gmp/tests/t-reuse.c Tue Feb 19 07:41:36 2013 +0100
+++ b/mini-gmp/tests/t-reuse.c Tue Feb 19 16:29:41 2013 +0100
@@ -192,9 +192,9 @@
bsi = mpz_get_ui (bs);
if ((bsi & 1) != 0)
mpz_neg (in1, in1);
- if ((bsi & 1) != 0)
+ if ((bsi & 2) != 0)
mpz_neg (in2, in2);
- if ((bsi & 1) != 0)
+ if ((bsi & 4) != 0)
mpz_neg (in3, in3);
for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
More information about the gmp-commit
mailing list