logic.c revision 1.1 1 1.1 mrg /* Test mpn_and, mpn_ior, mpn_xor, mpn_andn, mpn_iorn, mpn_xnor, mpn_nand, and
2 1.1 mrg mpn_nior.
3 1.1 mrg
4 1.1 mrg Copyright 2011, 2012, 2013 Free Software Foundation, Inc.
5 1.1 mrg
6 1.1 mrg This file is part of the GNU MP Library test suite.
7 1.1 mrg
8 1.1 mrg The GNU MP Library test suite is free software; you can redistribute it
9 1.1 mrg and/or modify it under the terms of the GNU General Public License as
10 1.1 mrg published by the Free Software Foundation; either version 3 of the License,
11 1.1 mrg or (at your option) any later version.
12 1.1 mrg
13 1.1 mrg The GNU MP Library test suite is distributed in the hope that it will be
14 1.1 mrg useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 1.1 mrg Public License for more details.
17 1.1 mrg
18 1.1 mrg You should have received a copy of the GNU General Public License along with
19 1.1 mrg the GNU MP Library test suite. If not, see http://www.gnu.org/licenses/. */
20 1.1 mrg
21 1.1 mrg
22 1.1 mrg #include <stdlib.h>
23 1.1 mrg #include <stdio.h>
24 1.1 mrg
25 1.1 mrg /* Fake native prevalence of the tested operations, so that we actually test
26 1.1 mrg the compiled functions, i.e., the ones which users will reach. The inlined
27 1.1 mrg variants will be tested through tests/mpz/logic.c. */
28 1.1 mrg #define HAVE_NATIVE_mpn_com 1
29 1.1 mrg #define HAVE_NATIVE_mpn_and_n 1
30 1.1 mrg #define HAVE_NATIVE_mpn_andn_n 1
31 1.1 mrg #define HAVE_NATIVE_mpn_nand_n 1
32 1.1 mrg #define HAVE_NATIVE_mpn_ior_n 1
33 1.1 mrg #define HAVE_NATIVE_mpn_iorn_n 1
34 1.1 mrg #define HAVE_NATIVE_mpn_nior_n 1
35 1.1 mrg #define HAVE_NATIVE_mpn_xor_n 1
36 1.1 mrg #define HAVE_NATIVE_mpn_xnor_n 1
37 1.1 mrg
38 1.1 mrg #include "gmp.h"
39 1.1 mrg #include "gmp-impl.h"
40 1.1 mrg #include "tests.h"
41 1.1 mrg
42 1.1 mrg
43 1.1 mrg void
44 1.1 mrg check_one (mp_srcptr refp, mp_srcptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n, char *funcname)
45 1.1 mrg {
46 1.1 mrg if (mpn_cmp (refp, rp, n))
47 1.1 mrg {
48 1.1 mrg printf ("ERROR in mpn_%s\n", funcname);
49 1.1 mrg printf ("a: "); mpn_dump (ap, n);
50 1.1 mrg printf ("b: "); mpn_dump (bp, n);
51 1.1 mrg printf ("r: "); mpn_dump (rp, n);
52 1.1 mrg printf ("ref: "); mpn_dump (refp, n);
53 1.1 mrg abort();
54 1.1 mrg }
55 1.1 mrg }
56 1.1 mrg
57 1.1 mrg int
58 1.1 mrg main (int argc, char **argv)
59 1.1 mrg {
60 1.1 mrg mp_ptr ap, bp, rp, refp;
61 1.1 mrg mp_size_t max_n, n;
62 1.1 mrg gmp_randstate_ptr rands;
63 1.1 mrg long test, reps = 1000;
64 1.1 mrg TMP_SDECL;
65 1.1 mrg TMP_SMARK;
66 1.1 mrg
67 1.1 mrg tests_start ();
68 1.1 mrg TESTS_REPS (reps, argv, argc);
69 1.1 mrg
70 1.1 mrg rands = RANDS;
71 1.1 mrg
72 1.1 mrg max_n = 32;
73 1.1 mrg
74 1.1 mrg ap = TMP_SALLOC_LIMBS (max_n);
75 1.1 mrg bp = TMP_SALLOC_LIMBS (max_n);
76 1.1 mrg rp = TMP_SALLOC_LIMBS (max_n);
77 1.1 mrg refp = TMP_SALLOC_LIMBS (max_n);
78 1.1 mrg
79 1.1 mrg for (test = 0; test < reps; test++)
80 1.1 mrg {
81 1.1 mrg for (n = 1; n <= max_n; n++)
82 1.1 mrg {
83 1.1 mrg mpn_random2 (ap, n);
84 1.1 mrg mpn_random2 (bp, n);
85 1.1 mrg
86 1.1 mrg refmpn_and_n (refp, ap, bp, n);
87 1.1 mrg mpn_and_n (rp, ap, bp, n);
88 1.1 mrg check_one (refp, rp, ap, bp, n, "and_n");
89 1.1 mrg
90 1.1 mrg refmpn_ior_n (refp, ap, bp, n);
91 1.1 mrg mpn_ior_n (rp, ap, bp, n);
92 1.1 mrg check_one (refp, rp, ap, bp, n, "ior_n");
93 1.1 mrg
94 1.1 mrg refmpn_xor_n (refp, ap, bp, n);
95 1.1 mrg mpn_xor_n (rp, ap, bp, n);
96 1.1 mrg check_one (refp, rp, ap, bp, n, "xor_n");
97 1.1 mrg
98 1.1 mrg refmpn_andn_n (refp, ap, bp, n);
99 1.1 mrg mpn_andn_n (rp, ap, bp, n);
100 1.1 mrg check_one (refp, rp, ap, bp, n, "andn_n");
101 1.1 mrg
102 1.1 mrg refmpn_iorn_n (refp, ap, bp, n);
103 1.1 mrg mpn_iorn_n (rp, ap, bp, n);
104 1.1 mrg check_one (refp, rp, ap, bp, n, "iorn_n");
105 1.1 mrg
106 1.1 mrg refmpn_nand_n (refp, ap, bp, n);
107 1.1 mrg mpn_nand_n (rp, ap, bp, n);
108 1.1 mrg check_one (refp, rp, ap, bp, n, "nand_n");
109 1.1 mrg
110 1.1 mrg refmpn_nior_n (refp, ap, bp, n);
111 1.1 mrg mpn_nior_n (rp, ap, bp, n);
112 1.1 mrg check_one (refp, rp, ap, bp, n, "nior_n");
113 1.1 mrg
114 1.1 mrg refmpn_xnor_n (refp, ap, bp, n);
115 1.1 mrg mpn_xnor_n (rp, ap, bp, n);
116 1.1 mrg check_one (refp, rp, ap, bp, n, "xnor_n");
117 1.1 mrg
118 1.1 mrg refmpn_com (refp, ap, n);
119 1.1 mrg mpn_com (rp, ap, n);
120 1.1 mrg check_one (refp, rp, ap, bp, n, "com");
121 1.1 mrg }
122 1.1 mrg }
123 1.1 mrg
124 1.1 mrg TMP_SFREE;
125 1.1 mrg tests_end ();
126 1.1 mrg return 0;
127 1.1 mrg }
128