[Gmp-commit] /var/hg/gmp: Unit test for mpn_addaddmul_1msb0.
mercurial at gmplib.org
mercurial at gmplib.org
Fri Oct 8 14:05:27 UTC 2021
details: /var/hg/gmp/rev/3dee30523768
changeset: 18256:3dee30523768
user: Niels Möller <nisse at lysator.liu.se>
date: Fri Oct 08 16:05:05 2021 +0200
description:
Unit test for mpn_addaddmul_1msb0.
diffstat:
ChangeLog | 4 ++
tests/mpn/Makefile.am | 2 +-
tests/mpn/t-addaddmul.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+), 1 deletions(-)
diffs (125 lines):
diff -r 4e0d8bc58e24 -r 3dee30523768 ChangeLog
--- a/ChangeLog Thu Oct 07 17:04:31 2021 +0200
+++ b/ChangeLog Fri Oct 08 16:05:05 2021 +0200
@@ -1,3 +1,7 @@
+2021-10-08 Niels Möller <nisse at lysator.liu.se>
+
+ * tests/mpn/t-addaddmul.c: Unit test for mpn_addaddmul_1msb0.
+
2021-10-07 Niels Möller <nisse at lysator.liu.se>
* tune/speed.h (SPEED_ROUTINE_MPN_ADDADDMUL1_MSB0): New macro.
diff -r 4e0d8bc58e24 -r 3dee30523768 tests/mpn/Makefile.am
--- a/tests/mpn/Makefile.am Thu Oct 07 17:04:31 2021 +0200
+++ b/tests/mpn/Makefile.am Fri Oct 08 16:05:05 2021 +0200
@@ -28,7 +28,7 @@
t-toom52 t-toom53 t-toom54 t-toom62 t-toom63 t-toom6h t-toom8h \
t-toom2-sqr t-toom3-sqr t-toom4-sqr t-toom6-sqr t-toom8-sqr \
t-div t-mul t-mullo t-sqrlo t-mulmod_bnm1 t-sqrmod_bnm1 t-mulmid \
- t-hgcd t-hgcd_appr t-matrix22 t-invert t-bdiv t-fib2m \
+ t-addaddmul t-hgcd t-hgcd_appr t-matrix22 t-invert t-bdiv t-fib2m \
t-broot t-brootinv t-minvert t-sizeinbase t-gcd_11 t-gcd_22 t-gcdext_1
EXTRA_DIST = toom-shared.h toom-sqr-shared.h
diff -r 4e0d8bc58e24 -r 3dee30523768 tests/mpn/t-addaddmul.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpn/t-addaddmul.c Fri Oct 08 16:05:05 2021 +0200
@@ -0,0 +1,98 @@
+/* Test mpn_addaddmul_1msb0.
+
+Copyright 2021 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 <stdio.h>
+#include <stdlib.h>
+
+#include "gmp-impl.h"
+#include "tests.h"
+
+#if !HAVE_NATIVE_mpn_addaddmul_1msb0
+int main(int argc, char **argv) {
+ return 77; /* Test driver "SKIP" */
+}
+#else
+
+static void
+one_test (int i, mp_srcptr a, mp_srcptr b, mp_size_t n, mp_limb_t u, mp_limb_t v)
+{
+ mp_ptr r = refmpn_malloc_limbs (n + 1);
+ mp_ptr ref = refmpn_malloc_limbs (n + 1);
+
+ u &= ~GMP_NUMB_HIGHBIT;
+ v &= ~GMP_NUMB_HIGHBIT;
+ ref[n] = mpn_mul_1 (ref, a, n, u);
+ ref[n] += mpn_addmul_1 (ref, b, n, v);
+ r[n] = mpn_addaddmul_1msb0 (r, a, b, n, u, v);
+
+ if (mpn_cmp (r, ref, n+1) != 0)
+ {
+ fprintf (stderr, "ERROR in test %d\n", i);
+ fprintf (stderr, "Bad result from addaddmul_1msb0\n");
+ gmp_fprintf (stderr, "op1=%Nx\n", a, n);
+ gmp_fprintf (stderr, "op2=%Nx\n", b, n);
+ gmp_fprintf (stderr, "u = %Mx, v = %Mx\n", u, v);
+ gmp_fprintf (stderr, "res=%Nx\n", r, n + 1);
+ gmp_fprintf (stderr, "ref=%Nx\n", ref, n + 1);
+
+ abort();
+ }
+}
+
+int main (int argc, char **argv)
+{
+ mpz_t op1, op2;
+ int i;
+ gmp_randstate_ptr rands;
+ mpz_t bs;
+
+ tests_start ();
+ rands = RANDS;
+
+ mpz_inits (bs, op1, op2, NULL);
+
+ for (i = 0; i < 10000; i++)
+ {
+ unsigned long size_range;
+ mp_size_t bit_size;
+ mp_size_t limb_size;
+ mp_limb_t u, v;
+
+ mpz_urandomb (bs, rands, 32);
+ size_range = mpz_get_ui (bs) % 10 + 2;
+ mpz_urandomb (bs, rands, size_range);
+
+ bit_size = mpz_get_ui (bs) + 10;
+ mpz_rrandomb (op1, rands, bit_size);
+ mpz_rrandomb (op2, rands, bit_size);
+
+ mpz_rrandomb (bs, rands, GMP_NUMB_BITS - 1);
+ u = mpz_getlimbn (bs, 0);
+
+ mpz_rrandomb (bs, rands, GMP_NUMB_BITS - 1);
+ v = mpz_getlimbn (bs, 0);
+
+ limb_size = mpz_size (op1);
+ one_test (i, mpz_limbs_read (op1), mpz_limbs_read(op2), limb_size, u, v);
+ }
+ mpz_clears (bs, op1, op2, NULL);
+ return 0;
+}
+#endif
More information about the gmp-commit
mailing list