[Gmp-commit] /var/hg/gmp: Tests for mpn_mulmid.
mercurial at gmplib.org
mercurial at gmplib.org
Mon Oct 3 15:34:36 CEST 2011
details: /var/hg/gmp/rev/0a1ed0805710
changeset: 14253:0a1ed0805710
user: Niels M?ller <nisse at lysator.liu.se>
date: Mon Oct 03 15:34:25 2011 +0200
description:
Tests for mpn_mulmid.
diffstat:
ChangeLog | 3 +
tests/mpn/Makefile.am | 2 +-
tests/mpn/t-mulmid.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 1 deletions(-)
diffs (121 lines):
diff -r 799b8e61a84e -r 0a1ed0805710 ChangeLog
--- a/ChangeLog Mon Oct 03 13:52:31 2011 +0200
+++ b/ChangeLog Mon Oct 03 15:34:25 2011 +0200
@@ -1,5 +1,8 @@
2011-10-03 Niels Möller <nisse at lysator.liu.se>
+ * tests/mpn/Makefile.am (check_PROGRAMS): Added t-mulmid.
+ * tests/mpn/t-mulmid.c: New file.
+
mulmid-related assembly for x86_64, from David Harvey:
* mpn/asm-defs.m4 (define_mpn): Added [add,sub]_err[1,2,3]_n and
mulmid_basecase. Also use m4_not_for_expansion on the
diff -r 799b8e61a84e -r 0a1ed0805710 tests/mpn/Makefile.am
--- a/tests/mpn/Makefile.am Mon Oct 03 13:52:31 2011 +0200
+++ b/tests/mpn/Makefile.am Mon Oct 03 15:34:25 2011 +0200
@@ -26,7 +26,7 @@
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
+ t-mulmid t-invert t-div t-bdiv
EXTRA_DIST = toom-shared.h
diff -r 799b8e61a84e -r 0a1ed0805710 tests/mpn/t-mulmid.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpn/t-mulmid.c Mon Oct 03 15:34:25 2011 +0200
@@ -0,0 +1,93 @@
+/* Test for mulmid function.
+
+Copyright 2009 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"
+
+/* Sizes are up to 2^SIZE_LOG limbs */
+#ifndef SIZE_LOG
+#define SIZE_LOG 9
+#endif
+
+#ifndef COUNT
+#define COUNT 5000
+#endif
+
+#define MAX_N (1L << SIZE_LOG)
+
+int
+main (int argc, char **argv)
+{
+ mp_ptr ap, bp, rp, refp;
+ gmp_randstate_ptr rands;
+ int test;
+ TMP_DECL;
+ TMP_MARK;
+
+ tests_start ();
+ rands = RANDS;
+
+ ap = TMP_ALLOC_LIMBS (MAX_N);
+ bp = TMP_ALLOC_LIMBS (MAX_N);
+ rp = TMP_ALLOC_LIMBS (MAX_N + 2);
+ refp = TMP_ALLOC_LIMBS (MAX_N + 2);
+
+ for (test = 0; test < COUNT; test++)
+ {
+ mp_size_t an, bn, rn;
+ unsigned size_log;
+
+ size_log = 1 + gmp_urandomm_ui (rands, SIZE_LOG);
+ an = 1 + gmp_urandomm_ui(rands, 1L << size_log);
+
+ size_log = 1 + gmp_urandomm_ui (rands, SIZE_LOG);
+ bn = 1 + gmp_urandomm_ui(rands, 1L << size_log);
+
+ /* Make sure an >= bn */
+ if (an < bn)
+ MP_SIZE_T_SWAP (an, bn);
+
+ mpn_random2 (ap, an);
+ mpn_random2 (bp, bn);
+
+ refmpn_mulmid (refp, ap, an, bp, bn);
+ mpn_mulmid (rp, ap, an, bp, bn);
+
+ rn = an + 3 - bn;
+ if (mpn_cmp (refp, rp, rn))
+ {
+ printf ("ERROR in test %d, an = %d, bn = %d, rn = %d\n",
+ test, an, bn, 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