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.1.2 mrg the GNU MP Library test suite. If not, see https://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-impl.h" 25 1.1 mrg #include "tests.h" 26 1.1 mrg 27 1.1 mrg /* Sizes are up to 2^SIZE_LOG limbs */ 28 1.1 mrg #ifndef SIZE_LOG 29 1.1 mrg #define SIZE_LOG 9 30 1.1 mrg #endif 31 1.1 mrg 32 1.1 mrg #ifndef COUNT 33 1.1 mrg #define COUNT 5000 34 1.1 mrg #endif 35 1.1 mrg 36 1.1 mrg #define MAX_N (1L << SIZE_LOG) 37 1.1 mrg 38 1.1 mrg int 39 1.1 mrg main (int argc, char **argv) 40 1.1 mrg { 41 1.1 mrg mp_ptr ap, bp, rp, refp; 42 1.1 mrg gmp_randstate_ptr rands; 43 1.1 mrg int test; 44 1.1 mrg TMP_DECL; 45 1.1 mrg TMP_MARK; 46 1.1 mrg 47 1.1 mrg tests_start (); 48 1.1 mrg rands = RANDS; 49 1.1 mrg 50 1.1 mrg ap = TMP_ALLOC_LIMBS (MAX_N); 51 1.1 mrg bp = TMP_ALLOC_LIMBS (MAX_N); 52 1.1 mrg rp = TMP_ALLOC_LIMBS (MAX_N + 2); 53 1.1 mrg refp = TMP_ALLOC_LIMBS (MAX_N + 2); 54 1.1 mrg 55 1.1 mrg for (test = 0; test < COUNT; test++) 56 1.1 mrg { 57 1.1 mrg mp_size_t an, bn, rn; 58 1.1 mrg unsigned size_log; 59 1.1 mrg 60 1.1 mrg size_log = 1 + gmp_urandomm_ui (rands, SIZE_LOG); 61 1.1 mrg an = 1 + gmp_urandomm_ui(rands, 1L << size_log); 62 1.1 mrg 63 1.1 mrg size_log = 1 + gmp_urandomm_ui (rands, SIZE_LOG); 64 1.1 mrg bn = 1 + gmp_urandomm_ui(rands, 1L << size_log); 65 1.1 mrg 66 1.1 mrg /* Make sure an >= bn */ 67 1.1 mrg if (an < bn) 68 1.1 mrg MP_SIZE_T_SWAP (an, bn); 69 1.1 mrg 70 1.1 mrg mpn_random2 (ap, an); 71 1.1 mrg mpn_random2 (bp, bn); 72 1.1 mrg 73 1.1 mrg refmpn_mulmid (refp, ap, an, bp, bn); 74 1.1 mrg mpn_mulmid (rp, ap, an, bp, bn); 75 1.1 mrg 76 1.1 mrg rn = an + 3 - bn; 77 1.1 mrg if (mpn_cmp (refp, rp, rn)) 78 1.1 mrg { 79 1.1 mrg printf ("ERROR in test %d, an = %d, bn = %d, rn = %d\n", 80 1.1.1.2 mrg test, (int) an, (int) bn, (int) rn); 81 1.1 mrg printf("a: "); mpn_dump (ap, an); 82 1.1 mrg printf("b: "); mpn_dump (bp, bn); 83 1.1 mrg printf("r: "); mpn_dump (rp, rn); 84 1.1 mrg printf("ref: "); mpn_dump (refp, rn); 85 1.1 mrg 86 1.1 mrg abort(); 87 1.1 mrg } 88 1.1 mrg } 89 1.1 mrg TMP_FREE; 90 1.1 mrg tests_end (); 91 1.1 mrg return 0; 92 1.1 mrg } 93