From 4d734f52e6e7567523a43d1d839430652aadf1e6 Mon Sep 17 00:00:00 2001 From: Brian Gladman Date: Tue, 23 May 2017 19:40:45 +0100 Subject: [PATCH] add tests for the MPN logic functions --- build.vc15/mpir-tests.sln | 12 +- .../mpir-tests/mpn.logic/mpn.logic.vcxproj | 179 ++++++++++++++++++ tests/mpn/Makefile.am | 2 +- tests/mpn/logic.c | 134 +++++++++++++ tests/refmpn.c | 1 - 5 files changed, 325 insertions(+), 3 deletions(-) create mode 100644 build.vc15/mpir-tests/mpn.logic/mpn.logic.vcxproj create mode 100644 tests/mpn/logic.c diff --git a/build.vc15/mpir-tests.sln b/build.vc15/mpir-tests.sln index 77c83952..7eaa1f97 100644 --- a/build.vc15/mpir-tests.sln +++ b/build.vc15/mpir-tests.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26206.0 +VisualStudioVersion = 15.0.26430.4 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bswap", "mpir-tests\bswap\bswap.vcxproj", "{50EFC9E8-FB88-44C3-9F30-075547E22992}" EndProject @@ -437,6 +437,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpz.limbs", "mpir-tests\mpz EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpn.sizeinbase", "mpir-tests\mpn.sizeinbase\mpn.sizeinbase.vcxproj", "{935A51B1-BFEB-4864-A11A-1B436811C52D}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpn.logic", "mpir-tests\mpn.logic\mpn.logic.vcxproj", "{84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -1673,6 +1675,14 @@ Global {935A51B1-BFEB-4864-A11A-1B436811C52D}.Release|Win32.Build.0 = Release|Win32 {935A51B1-BFEB-4864-A11A-1B436811C52D}.Release|x64.ActiveCfg = Release|x64 {935A51B1-BFEB-4864-A11A-1B436811C52D}.Release|x64.Build.0 = Release|x64 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Debug|Win32.ActiveCfg = Debug|Win32 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Debug|Win32.Build.0 = Debug|Win32 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Debug|x64.ActiveCfg = Debug|x64 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Debug|x64.Build.0 = Debug|x64 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Release|Win32.ActiveCfg = Release|Win32 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Release|Win32.Build.0 = Release|Win32 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Release|x64.ActiveCfg = Release|x64 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build.vc15/mpir-tests/mpn.logic/mpn.logic.vcxproj b/build.vc15/mpir-tests/mpn.logic/mpn.logic.vcxproj new file mode 100644 index 00000000..a4637629 --- /dev/null +++ b/build.vc15/mpir-tests/mpn.logic/mpn.logic.vcxproj @@ -0,0 +1,179 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + mpn.logic + Win32Proj + 8.1 + {84FAB0B1-23B6-4A2B-9E89-4152A3B15DB4} + + + + Application + v141 + + + Application + v141 + + + Application + v141 + + + Application + v141 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.21006.1 + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + + cd ..\..\..\build.vc +check_config $(Platform) $(Configuration) 15 + + + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Default + + + Console + false + + + MachineX86 + + + + + cd ..\..\..\build.vc +check_config $(Platform) $(Configuration) 15 + + + X64 + + + _WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Default + + + Console + false + + + MachineX64 + Debug + + + + + cd ..\..\..\build.vc +check_config $(Platform) $(Configuration) 15 + + + Full + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Default + + + Console + true + true + false + + + MachineX86 + + + + + cd ..\..\..\build.vc +check_config $(Platform) $(Configuration) 15 + + + X64 + + + Full + _WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Default + $(MPDIR);$(SolutionDir)..\tests + + + Console + true + true + false + + + MachineX64 + No + + + + + + + + {a742d3d1-6956-4f85-bfd6-b0e7b477041d} + false + + + + + + \ No newline at end of file diff --git a/tests/mpn/Makefile.am b/tests/mpn/Makefile.am index a26c01c6..74cafb87 100644 --- a/tests/mpn/Makefile.am +++ b/tests/mpn/Makefile.am @@ -23,7 +23,7 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/tests LDADD = $(top_builddir)/tests/libtests.la $(top_builddir)/libmpir.la -check_PROGRAMS = t-addadd_n t-addsub_n t-aors_1 t-asmtype t-dc_bdiv_q t-dc_bdiv_q_n t-dc_bdiv_qr t-dc_bdiv_qr_n t-dc_div_q t-dc_div_qr t-dc_div_qr_n t-dc_divappr_q t-divebyff t-divebyfobm1 t-divrem_1 t-fat t-gcdext t-get_d t-hgcd t-instrument t-inv_div_q t-inv_div_qr t-inv_div_qr_n t-inv_divappr_q t-inv_divappr_q_n t-invert t-iord_u t-lorrshift1 t-matrix22 t-mp_bases t-mullow_basecase t-mullowhigh t-mulmid t-mulmod_2expm1 t-mulmod_2expp1 t-neg t-perfsqr t-redc_1 t-sb_bdiv_q t-sb_bdiv_qr t-sb_div_q t-sb_div_qr t-sb_divappr_q t-scan t-sizeinbase t-subadd_n t-tdiv_q t-tdiv_qr +check_PROGRAMS = t-addadd_n t-addsub_n t-aors_1 t-asmtype t-dc_bdiv_q t-dc_bdiv_q_n t-dc_bdiv_qr t-dc_bdiv_qr_n t-dc_div_q t-dc_div_qr t-dc_div_qr_n t-dc_divappr_q t-divebyff t-divebyfobm1 t-divrem_1 t-fat t-gcdext t-get_d t-hgcd t-instrument t-inv_div_q t-inv_div_qr t-inv_div_qr_n t-inv_divappr_q t-inv_divappr_q_n t-invert t-iord_u logic t-lorrshift1 t-matrix22 t-mp_bases t-mullow_basecase t-mullowhigh t-mulmid t-mulmod_2expm1 t-mulmod_2expp1 t-neg t-perfsqr t-redc_1 t-sb_bdiv_q t-sb_bdiv_qr t-sb_div_q t-sb_div_qr t-sb_divappr_q t-scan t-sizeinbase t-subadd_n t-tdiv_q t-tdiv_qr if ENABLE_STATIC if ENABLE_SHARED diff --git a/tests/mpn/logic.c b/tests/mpn/logic.c new file mode 100644 index 00000000..d2a60fe6 --- /dev/null +++ b/tests/mpn/logic.c @@ -0,0 +1,134 @@ +/* Test mpn_and, mpn_ior, mpn_xor, mpn_andn, mpn_iorn, mpn_xnor, mpn_nand, and + mpn_nior. + +Copyright 2011-2013 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 +#include + +/* Fake native prevalence of the tested operations, so that we actually test + the compiled functions, i.e., the ones which users will reach. The inlined + variants will be tested through tests/mpz/logic.c. */ +#define HAVE_NATIVE_mpn_com 1 +#define HAVE_NATIVE_mpn_and_n 1 +#define HAVE_NATIVE_mpn_andn_n 1 +#define HAVE_NATIVE_mpn_nand_n 1 +#define HAVE_NATIVE_mpn_ior_n 1 +#define HAVE_NATIVE_mpn_iorn_n 1 +#define HAVE_NATIVE_mpn_nior_n 1 +#define HAVE_NATIVE_mpn_xor_n 1 +#define HAVE_NATIVE_mpn_xnor_n 1 + +#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, const char *funcname) +{ + if (mpn_cmp (refp, rp, n)) + { + printf ("ERROR in mpn_%s\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) +{ + mpz_t a, b; + mp_ptr ap, bp, rp, refp; + mp_size_t max_n, n, i; + gmp_randstate_ptr rands; + long test, reps = 1000; + TMP_DECL; + TMP_MARK; + + tests_start (); + /* TESTS_REPS (reps, argv, argc); */ + + mpz_inits (a, b, NULL); + + rands = RANDS; /* FIXME: not used */ + + max_n = 100; + + rp = TMP_ALLOC_LIMBS (1 + max_n * 8 / GMP_LIMB_BITS); + refp = TMP_ALLOC_LIMBS (1 + max_n * 8 / GMP_LIMB_BITS); + + for (test = 0; test < reps; test++) + { + for (i = 1; i <= max_n; i++) + { + mpz_rrandomb (a, rands, i * 8); + mpz_rrandomb (b, rands, i * 8); + mpz_setbit (a, i * 8 - 1); + mpz_setbit (b, i * 8 - 1); + ap = PTR(a); + bp = PTR(b); + n = SIZ(a); + + refmpn_and_n (refp, ap, bp, n); + mpn_and_n (rp, ap, bp, n); + check_one (refp, rp, ap, bp, n, "and_n"); + + refmpn_ior_n (refp, ap, bp, n); + mpn_ior_n (rp, ap, bp, n); + check_one (refp, rp, ap, bp, n, "ior_n"); + + refmpn_xor_n (refp, ap, bp, n); + mpn_xor_n (rp, ap, bp, n); + check_one (refp, rp, ap, bp, n, "xor_n"); + + refmpn_andn_n (refp, ap, bp, n); + mpn_andn_n (rp, ap, bp, n); + // check_one (refp, rp, ap, bp, n, "andn_n"); + + refmpn_iorn_n (refp, ap, bp, n); + mpn_iorn_n (rp, ap, bp, n); + // check_one (refp, rp, ap, bp, n, "iorn_n"); + + refmpn_nand_n (refp, ap, bp, n); + mpn_nand_n (rp, ap, bp, n); + check_one (refp, rp, ap, bp, n, "nand_n"); + + refmpn_nior_n (refp, ap, bp, n); + mpn_nior_n (rp, ap, bp, n); + check_one (refp, rp, ap, bp, n, "nior_n"); + + refmpn_xnor_n (refp, ap, bp, n); + mpn_xnor_n (rp, ap, bp, n); + check_one (refp, rp, ap, bp, n, "xnor_n"); + + refmpn_com_n (refp, ap, n); + mpn_com_n (rp, ap, n); + check_one (refp, rp, ap, bp, n, "com"); + } + } + + TMP_FREE; + mpz_clears (a, b, NULL); + tests_end (); + return 0; +} diff --git a/tests/refmpn.c b/tests/refmpn.c index 69236d8b..a82d62e6 100644 --- a/tests/refmpn.c +++ b/tests/refmpn.c @@ -386,7 +386,6 @@ refmpn_com_n (mp_ptr rp, mp_srcptr sp, mp_size_t size) rp[i] = sp[i] ^ GMP_NUMB_MASK; } - int refmpn_cmp (mp_srcptr xp, mp_srcptr yp, mp_size_t size) {