[Gmp-commit] /var/hg/gmp: Ad unit tests for mpn logical functions.
mercurial at gmplib.org
mercurial at gmplib.org
Fri Feb 24 14:25:27 CET 2012
details: /var/hg/gmp/rev/88fc07a4dca2
changeset: 14673:88fc07a4dca2
user: Torbjorn Granlund <tege at gmplib.org>
date: Fri Feb 24 14:25:23 2012 +0100
description:
Ad unit tests for mpn logical functions.
diffstat:
ChangeLog | 3 +
tests/mpn/Makefile.am | 2 +-
tests/mpn/logic.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+), 1 deletions(-)
diffs (137 lines):
diff -r 6e97e3d23b38 -r 88fc07a4dca2 ChangeLog
--- a/ChangeLog Fri Feb 24 13:59:52 2012 +0100
+++ b/ChangeLog Fri Feb 24 14:25:23 2012 +0100
@@ -1,5 +1,8 @@
2012-02-24 Torbjorn Granlund <tege at gmplib.org>
+ * tests/mpn/logic.c: New file.
+ * tests/mpn/Makefile.am (check_PROGRAMS): Add logic.
+
* tests/mpz/t-invert.c: New file.
* tests/mpz/Makefile.am (check_PROGRAMS): Add t-invert.
diff -r 6e97e3d23b38 -r 88fc07a4dca2 tests/mpn/Makefile.am
--- a/tests/mpn/Makefile.am Fri Feb 24 13:59:52 2012 +0100
+++ b/tests/mpn/Makefile.am Fri Feb 24 14:25:23 2012 +0100
@@ -23,7 +23,7 @@
LDADD = $(top_builddir)/tests/libtests.la $(top_builddir)/libgmp.la
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-instrument t-iord_u t-mp_bases t-perfsqr t-scan logic \
t-toom22 t-toom32 t-toom33 t-toom42 t-toom43 t-toom44 \
t-toom52 t-toom53 t-toom54 t-toom62 t-toom63 t-toom6h t-toom8h \
t-mul t-mullo t-mulmod_bnm1 t-sqrmod_bnm1 t-mulmid \
diff -r 6e97e3d23b38 -r 88fc07a4dca2 tests/mpn/logic.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpn/logic.c Fri Feb 24 14:25:23 2012 +0100
@@ -0,0 +1,109 @@
+/* Test mpn_and, mpn_ior, mpn_xor, mpn_andm, mpn_iorn, mpn_xnor, mpn_nand, and
+ mpn_nior.
+
+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"
+
+void
+check_one (mp_srcptr refp, mp_srcptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n, char *funcname)
+{
+ if (mpn_cmp (refp, rp, n))
+ {
+ printf ("ERROR in mpn_%s_n\n", funcname);
+ printf ("a: "); mpn_dump (ap, n);
+ printf ("b: "); mpn_dump (bp, n);
+ printf ("r: "); mpn_dump (rp, n);
+ printf ("ref: "); mpn_dump (refp, n);
+ abort();
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ mp_ptr ap, bp, rp, refp;
+ mp_size_t max_n, n;
+ gmp_randstate_ptr rands;
+ long test, reps = 1000;
+ TMP_SDECL;
+ TMP_SMARK;
+
+ tests_start ();
+ TESTS_REPS (reps, argv, argc);
+
+ rands = RANDS;
+
+ max_n = 32;
+
+ ap = TMP_SALLOC_LIMBS (max_n);
+ bp = TMP_SALLOC_LIMBS (max_n);
+ rp = TMP_SALLOC_LIMBS (max_n);
+ refp = TMP_SALLOC_LIMBS (max_n);
+
+ for (test = 0; test < reps; test++)
+ {
+ for (n = 1; n <= max_n; n++)
+ {
+ mpn_random2 (ap, n);
+ mpn_random2 (bp, n);
+
+ refmpn_and_n (refp, ap, bp, n);
+ mpn_and_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "and");
+
+ refmpn_ior_n (refp, ap, bp, n);
+ mpn_ior_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "ior");
+
+ refmpn_xor_n (refp, ap, bp, n);
+ mpn_xor_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "xor");
+
+ refmpn_andn_n (refp, ap, bp, n);
+ mpn_andn_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "andn");
+
+ refmpn_iorn_n (refp, ap, bp, n);
+ mpn_iorn_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "iorn");
+
+ refmpn_nand_n (refp, ap, bp, n);
+ mpn_nand_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "nand");
+
+ refmpn_nior_n (refp, ap, bp, n);
+ mpn_nior_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "nior");
+
+ refmpn_xnor_n (refp, ap, bp, n);
+ mpn_xnor_n (rp, ap, bp, n);
+ check_one (refp, rp, ap, bp, n, "xnor");
+ }
+ }
+
+ TMP_SFREE;
+ tests_end ();
+ return 0;
+}
More information about the gmp-commit
mailing list