t-mulmid.c revision 1.1 1 1.1 mrg /* Test for mulmid function.
2 1.1 mrg
3 1.1 mrg Copyright 2011 Free Software Foundation, Inc.
4 1.1 mrg
5 1.1 mrg This file is part of the GNU MP Library test suite.
6 1.1 mrg
7 1.1 mrg The GNU MP Library test suite is free software; you can redistribute it
8 1.1 mrg and/or modify it under the terms of the GNU General Public License as
9 1.1 mrg published by the Free Software Foundation; either version 3 of the License,
10 1.1 mrg or (at your option) any later version.
11 1.1 mrg
12 1.1 mrg The GNU MP Library test suite is distributed in the hope that it will be
13 1.1 mrg useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 1.1 mrg Public License for more details.
16 1.1 mrg
17 1.1 mrg You should have received a copy of the GNU General Public License along with
18 1.1 mrg the GNU MP Library test suite. If not, see http://www.gnu.org/licenses/. */
19 1.1 mrg
20 1.1 mrg
21 1.1 mrg #include <stdlib.h>
22 1.1 mrg #include <stdio.h>
23 1.1 mrg
24 1.1 mrg #include "gmp.h"
25 1.1 mrg #include "gmp-impl.h"
26 1.1 mrg #include "tests.h"
27 1.1 mrg
28 1.1 mrg /* Sizes are up to 2^SIZE_LOG limbs */
29 1.1 mrg #ifndef SIZE_LOG
30 1.1 mrg #define SIZE_LOG 9
31 1.1 mrg #endif
32 1.1 mrg
33 1.1 mrg #ifndef COUNT
34 1.1 mrg #define COUNT 5000
35 1.1 mrg #endif
36 1.1 mrg
37 1.1 mrg #define MAX_N (1L << SIZE_LOG)
38 1.1 mrg
39 1.1 mrg int
40 1.1 mrg main (int argc, char **argv)
41 1.1 mrg {
42 1.1 mrg mp_ptr ap, bp, rp, refp;
43 1.1 mrg gmp_randstate_ptr rands;
44 1.1 mrg int test;
45 1.1 mrg TMP_DECL;
46 1.1 mrg TMP_MARK;
47 1.1 mrg
48 1.1 mrg tests_start ();
49 1.1 mrg rands = RANDS;
50 1.1 mrg
51 1.1 mrg ap = TMP_ALLOC_LIMBS (MAX_N);
52 1.1 mrg bp = TMP_ALLOC_LIMBS (MAX_N);
53 1.1 mrg rp = TMP_ALLOC_LIMBS (MAX_N + 2);
54 1.1 mrg refp = TMP_ALLOC_LIMBS (MAX_N + 2);
55 1.1 mrg
56 1.1 mrg for (test = 0; test < COUNT; test++)
57 1.1 mrg {
58 1.1 mrg mp_size_t an, bn, rn;
59 1.1 mrg unsigned size_log;
60 1.1 mrg
61 1.1 mrg size_log = 1 + gmp_urandomm_ui (rands, SIZE_LOG);
62 1.1 mrg an = 1 + gmp_urandomm_ui(rands, 1L << size_log);
63 1.1 mrg
64 1.1 mrg size_log = 1 + gmp_urandomm_ui (rands, SIZE_LOG);
65 1.1 mrg bn = 1 + gmp_urandomm_ui(rands, 1L << size_log);
66 1.1 mrg
67 1.1 mrg /* Make sure an >= bn */
68 1.1 mrg if (an < bn)
69 1.1 mrg MP_SIZE_T_SWAP (an, bn);
70 1.1 mrg
71 1.1 mrg mpn_random2 (ap, an);
72 1.1 mrg mpn_random2 (bp, bn);
73 1.1 mrg
74 1.1 mrg refmpn_mulmid (refp, ap, an, bp, bn);
75 1.1 mrg mpn_mulmid (rp, ap, an, bp, bn);
76 1.1 mrg
77 1.1 mrg rn = an + 3 - bn;
78 1.1 mrg if (mpn_cmp (refp, rp, rn))
79 1.1 mrg {
80 1.1 mrg printf ("ERROR in test %d, an = %d, bn = %d, rn = %d\n",
81 1.1 mrg test, an, bn, rn);
82 1.1 mrg printf("a: "); mpn_dump (ap, an);
83 1.1 mrg printf("b: "); mpn_dump (bp, bn);
84 1.1 mrg printf("r: "); mpn_dump (rp, rn);
85 1.1 mrg printf("ref: "); mpn_dump (refp, rn);
86 1.1 mrg
87 1.1 mrg abort();
88 1.1 mrg }
89 1.1 mrg }
90 1.1 mrg TMP_FREE;
91 1.1 mrg tests_end ();
92 1.1 mrg return 0;
93 1.1 mrg }
94