[Gmp-commit] /var/hg/gmp-5.0: Add two more mpn tests.
mercurial at gmplib.org
mercurial at gmplib.org
Wed Feb 1 23:06:40 CET 2012
details: /var/hg/gmp-5.0/rev/2d3dce6a5eb3
changeset: 13533:2d3dce6a5eb3
user: Torbjorn Granlund <tege at gmplib.org>
date: Wed Feb 01 23:06:34 2012 +0100
description:
Add two more mpn tests.
diffstat:
ChangeLog | 10 ++++
tests/mpn/Makefile.am | 14 ++--
tests/mpn/t-mod_1.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/mpn/t-mul.c | 101 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 236 insertions(+), 7 deletions(-)
diffs (281 lines):
diff -r 8ea77456e066 -r 2d3dce6a5eb3 ChangeLog
--- a/ChangeLog Tue Jan 31 16:27:34 2012 +0100
+++ b/ChangeLog Wed Feb 01 23:06:34 2012 +0100
@@ -1,3 +1,8 @@
+2012-02-01 Torbjorn Granlund <tege at gmplib.org>
+
+ * tests/mpn/t-mul.c: New file.
+ * tests/mpn/Makefile.am: Compile it.
+
2012-01-31 Torbjorn Granlund <tege at gmplib.org>
* mpn/generic/powm_sec.c (SQR_BASECASE_LIM): New name for
@@ -419,6 +424,11 @@
touch it. Fixed the case that no assembler files are used, and
GMP_PROG_M4 is omitted.
+2010-06-15 Niels Möller <nisse at lysator.liu.se>
+
+ * tests/mpn/Makefile.am (check_PROGRAMS): Added t-mod_1.
+ * tests/mpn/t-mod_1.c: New file.
+
2010-05-24 Torbjorn Granlund <tege at gmplib.org>
* mpn/generic/mu_div_qr.c (mpn_preinv_mu_div_qr_itch): New function.
diff -r 8ea77456e066 -r 2d3dce6a5eb3 tests/mpn/Makefile.am
--- a/tests/mpn/Makefile.am Tue Jan 31 16:27:34 2012 +0100
+++ b/tests/mpn/Makefile.am Wed Feb 01 23:06:34 2012 +0100
@@ -1,6 +1,6 @@
## Process this file with automake to generate Makefile.in
-# Copyright 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+# Copyright 2001, 2002, 2003, 2009, 2010, 2012 Free Software Foundation, Inc.
#
# This file is part of the GNU MP Library.
#
@@ -21,12 +21,12 @@
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/tests
LDADD = $(top_builddir)/tests/libtests.la $(top_builddir)/libgmp.la
-check_PROGRAMS = t-asmtype t-aors_1 t-divrem_1 t-fat t-get_d \
- t-instrument t-iord_u t-mp_bases t-perfsqr t-scan \
- t-toom22 t-toom32 t-toom33 t-toom42 t-toom43 t-toom44 \
- t-toom52 t-toom53 t-toom62 t-toom63 t-toom6h t-toom8h \
- t-hgcd t-matrix22 t-mullo t-mulmod_bnm1 t-sqrmod_bnm1 \
- t-invert t-div t-bdiv
+check_PROGRAMS = t-asmtype t-aors_1 t-divrem_1 t-mod_1 t-fat t-get_d \
+ t-instrument t-iord_u t-mp_bases t-perfsqr t-scan \
+ t-toom22 t-toom32 t-toom33 t-toom42 t-toom43 t-toom44 \
+ t-toom52 t-toom53 t-toom62 t-toom63 t-toom6h t-toom8h \
+ t-mul t-mullo t-mulmod_bnm1 t-sqrmod_bnm1 \
+ t-hgcd t-matrix22 t-invert t-div t-bdiv
EXTRA_DIST = toom-shared.h
diff -r 8ea77456e066 -r 2d3dce6a5eb3 tests/mpn/t-mod_1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpn/t-mod_1.c Wed Feb 01 23:06:34 2012 +0100
@@ -0,0 +1,118 @@
+/* Test mpn_mod_1 variants.
+
+Copyright 2010 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser 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 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 Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "tests.h"
+
+static void
+check_one (mp_srcptr ap, mp_size_t n, mp_limb_t b)
+{
+ mp_limb_t r_ref = refmpn_mod_1 (ap, n, b);
+ mp_limb_t r;
+
+ if (n >= 2)
+ {
+ mp_limb_t pre[4];
+ mpn_mod_1_1p_cps (pre, b);
+ r = mpn_mod_1_1p (ap, n, b << pre[1], pre);
+ if (r != r_ref)
+ {
+ printf ("mpn_mod_1_1p failed\n");
+ goto fail;
+ }
+ }
+ if ((b & GMP_NUMB_HIGHBIT) == 0)
+ {
+ mp_limb_t pre[5];
+ mpn_mod_1s_2p_cps (pre, b);
+ r = mpn_mod_1s_2p (ap, n, b << pre[1], pre);
+ if (r != r_ref)
+ {
+ printf ("mpn_mod_1s_2p failed\n");
+ goto fail;
+ }
+ }
+ if (b <= GMP_NUMB_MASK / 4)
+ {
+ mp_limb_t pre[7];
+ mpn_mod_1s_4p_cps (pre, b);
+ r = mpn_mod_1s_4p (ap, n, b << pre[1], pre);
+ if (r != r_ref)
+ {
+ printf ("mpn_mod_1s_4p failed\n");
+ goto fail;
+ }
+ }
+ r = mpn_mod_1 (ap, n, b);
+ if (r != r_ref)
+ {
+ printf ("mpn_mod_1 failed\n");
+ fail:
+ printf ("an = %d, a: ", (int) n); mpn_dump (ap, n);
+ printf ("b : "); mpn_dump (&b, 1);
+ printf ("r (expected): "); mpn_dump (&r_ref, 1);
+ printf ("r (bad) : "); mpn_dump (&r, 1);
+ abort();
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ gmp_randstate_ptr rands;
+ int i;
+ unsigned a_bits;
+ unsigned b_bits;
+ mpz_t a;
+ mpz_t b;
+
+ tests_start ();
+ rands = RANDS;
+ mpz_init (a);
+ mpz_init (b);
+
+ for (i = 0; i < 300; i++)
+ {
+ mp_size_t asize;
+ a_bits = 1 + gmp_urandomm_ui (rands, 1000);
+ b_bits = 1 + gmp_urandomm_ui (rands, GMP_NUMB_BITS);
+
+ mpz_rrandomb (a, rands, a_bits);
+ mpz_rrandomb (b, rands, b_bits);
+
+ asize = SIZ(a);
+ if (!asize)
+ asize = 1;
+ if (mpz_sgn (b) == 0)
+ mpz_set_ui (b, 1);
+
+ check_one (PTR(a), asize, PTR(b)[0]);
+ }
+
+ mpz_clear (a);
+ mpz_clear (b);
+
+ tests_end ();
+ return 0;
+}
+
diff -r 8ea77456e066 -r 2d3dce6a5eb3 tests/mpn/t-mul.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpn/t-mul.c Wed Feb 01 23:06:34 2012 +0100
@@ -0,0 +1,101 @@
+/* Test mpn_mul function for all sizes up to a selected limit.
+
+Copyright 2011, 2012 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser 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 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 Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "tests.h"
+
+static unsigned
+isqrt (unsigned t)
+{
+ unsigned s, b;
+
+ for (b = 0, s = t; b++, s >>= 1; )
+ ;
+
+ s = 1 << (b >> 1);
+ if (b & 1)
+ s += s >> 1;
+
+ do
+ {
+ b = t / s;
+ s = (s + b) >> 1;
+ }
+ while (b < s);
+
+ return s;
+}
+
+int
+main (int argc, char **argv)
+{
+ mp_ptr ap, bp, rp, refp;
+ mp_size_t max_n, an, bn, rn;
+ gmp_randstate_ptr rands;
+ int reps;
+ TMP_DECL;
+ TMP_MARK;
+
+ reps = 1;
+
+ tests_start ();
+ TESTS_REPS (reps, argv, argc);
+
+ rands = RANDS;
+
+ /* Re-interpret reps argument as a size argument. */
+ max_n = isqrt (reps * 25000);
+
+ ap = TMP_ALLOC_LIMBS (max_n + 1);
+ bp = TMP_ALLOC_LIMBS (max_n + 1);
+ rp = TMP_ALLOC_LIMBS (2 * max_n);
+ refp = TMP_ALLOC_LIMBS (2 * max_n);
+
+ for (an = 1; an <= max_n; an += 1)
+ {
+ for (bn = 1; bn <= an; bn += 1)
+ {
+ mpn_random2 (ap, an + 1);
+ mpn_random2 (bp, bn + 1);
+
+ refmpn_mul (refp, ap, an, bp, bn);
+ mpn_mul (rp, ap, an, bp, bn);
+
+ rn = an + bn;
+ if (mpn_cmp (refp, rp, rn))
+ {
+ printf ("ERROR, an = %d, bn = %d, rn = %d\n",
+ (int) an, (int) bn, (int) rn);
+ printf ("a: "); mpn_dump (ap, an);
+ printf ("b: "); mpn_dump (bp, bn);
+ printf ("r: "); mpn_dump (rp, rn);
+ printf ("ref: "); mpn_dump (refp, rn);
+ abort();
+ }
+ }
+ }
+ TMP_FREE;
+ tests_end ();
+ return 0;
+}
More information about the gmp-commit
mailing list