[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Mon Feb 10 07:29:54 UTC 2014
details: /var/hg/gmp/rev/a7351443295f
changeset: 16290:a7351443295f
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Mon Feb 10 08:28:14 2014 +0100
description:
mini-gmp/tests/t-limbs.c: New test program.
details: /var/hg/gmp/rev/8e41c39c9392
changeset: 16291:8e41c39c9392
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Mon Feb 10 08:29:49 2014 +0100
description:
ChangeLog
diffstat:
ChangeLog | 5 ++
mini-gmp/tests/Makefile | 2 +-
mini-gmp/tests/t-limbs.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 1 deletions(-)
diffs (119 lines):
diff -r a0e2c942ea0b -r 8e41c39c9392 ChangeLog
--- a/ChangeLog Sun Feb 09 22:27:47 2014 +0100
+++ b/ChangeLog Mon Feb 10 08:29:49 2014 +0100
@@ -1,3 +1,8 @@
+2014-02-10 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * mini-gmp/tests/t-limbs.c: New test for mpz_limbs_*.
+ * mini-gmp/tests/Makefile (CHECK_PROGRAMS): Add it.
+
2014-02-09 Niels Möller <nisse at lysator.liu.se>
* tune/tuneup.c (tune_powm_sec): Avoid timing of the nonsensical
diff -r a0e2c942ea0b -r 8e41c39c9392 mini-gmp/tests/Makefile
--- a/mini-gmp/tests/Makefile Sun Feb 09 22:27:47 2014 +0100
+++ b/mini-gmp/tests/Makefile Mon Feb 10 08:29:49 2014 +0100
@@ -30,7 +30,7 @@
CHECK_PROGRAMS = t-add t-sub t-mul t-invert t-div t-div_2exp \
t-double t-cmp_d t-gcd t-lcm t-import t-comb t-signed \
t-sqrt t-root t-powm t-logops t-bitops t-scan t-str \
- t-reuse t-aorsmul
+ t-reuse t-aorsmul t-limbs
MISC_OBJS = hex-random.o mini-random.o testutils.o
diff -r a0e2c942ea0b -r 8e41c39c9392 mini-gmp/tests/t-limbs.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mini-gmp/tests/t-limbs.c Mon Feb 10 08:29:49 2014 +0100
@@ -0,0 +1,91 @@
+/*
+
+Copyright 2012, 2014, Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library test suite.
+
+The GNU MP Library test suite is free software; you can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 3 of the License,
+or (at your option) any later version.
+
+The GNU MP Library test suite is distributed in the hope that it will be
+useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
+
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "testutils.h"
+
+#define MAXBITS 400
+#define COUNT 100
+
+static void
+dump (const char *label, const mpz_t x)
+{
+ char *buf = mpz_get_str (NULL, 16, x);
+ fprintf (stderr, "%s: %s\n", label, buf);
+ testfree (buf);
+}
+
+void
+my_mpz_mul (mpz_t r, mpz_srcptr a, mpz_srcptr b)
+{
+ mp_limb_t *tp;
+ mp_size_t tn, an, bn;
+
+ an = mpz_size (a);
+ bn = mpz_size (b);
+ tn = an + bn;
+
+ tp = mpz_limbs_write (r, tn);
+ if (mpz_sgn (a) * mpz_sgn(b) == 0)
+ mpn_zero (tp, tn);
+ else if (an > bn)
+ mpn_mul (tp, mpz_limbs_read (a), an, mpz_limbs_read (b), bn);
+ else
+ mpn_mul (tp, mpz_limbs_read (b), bn, mpz_limbs_read (a), an);
+
+ if (mpz_sgn (a) != mpz_sgn(b))
+ tn = - tn;
+
+ mpz_limbs_finish (r, tn);
+}
+
+void
+testmain (int argc, char **argv)
+{
+ unsigned i;
+ mpz_t a, b, t, res, ref;
+
+ mpz_init (a);
+ mpz_init (b);
+ mpz_init (res);
+ mpz_init (ref);
+
+ for (i = 0; i < COUNT; i++)
+ {
+ mini_random_op3 (OP_MUL, MAXBITS, a, b, ref);
+ my_mpz_mul (res, a, b);
+ if (mpz_cmp (res, ref))
+ {
+ fprintf (stderr, "my_mpz_mul failed:\n");
+ dump ("a", a);
+ dump ("b", b);
+ dump ("r", res);
+ dump ("ref", ref);
+ abort ();
+ }
+ }
+ mpz_clear (a);
+ mpz_clear (b);
+ mpz_clear (res);
+ mpz_clear (ref);
+}
More information about the gmp-commit
mailing list