Austin Schuh | bb1338c | 2024-06-15 19:31:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | Copyright 1996-1998, 2000, 2001, 2007, 2009 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of the GNU MP Library test suite. |
| 5 | |
| 6 | The GNU MP Library test suite is free software; you can redistribute it |
| 7 | and/or modify it under the terms of the GNU General Public License as |
| 8 | published by the Free Software Foundation; either version 3 of the License, |
| 9 | or (at your option) any later version. |
| 10 | |
| 11 | The GNU MP Library test suite is distributed in the hope that it will be |
| 12 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 14 | Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License along with |
| 17 | the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include "gmp-impl.h" |
| 22 | |
| 23 | #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) |
| 24 | #include <time.h> |
| 25 | |
| 26 | int |
| 27 | cputime () |
| 28 | { |
| 29 | if (CLOCKS_PER_SEC < 100000) |
| 30 | return clock () * 1000 / CLOCKS_PER_SEC; |
| 31 | return clock () / (CLOCKS_PER_SEC / 1000); |
| 32 | } |
| 33 | #else |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/time.h> |
| 36 | #include <sys/resource.h> |
| 37 | |
| 38 | int |
| 39 | cputime () |
| 40 | { |
| 41 | struct rusage rus; |
| 42 | |
| 43 | getrusage (0, &rus); |
| 44 | return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; |
| 45 | } |
| 46 | #endif |
| 47 | |
| 48 | #define M * 1000000 |
| 49 | |
| 50 | #ifndef CLOCK |
| 51 | #error "Don't know CLOCK of your machine" |
| 52 | #endif |
| 53 | |
| 54 | #ifndef OPS |
| 55 | #define OPS 20000000 |
| 56 | #endif |
| 57 | #ifndef SIZE |
| 58 | #define SIZE 100 |
| 59 | #endif |
| 60 | #ifndef TIMES |
| 61 | #define TIMES OPS/(SIZE+1) |
| 62 | #endif |
| 63 | |
| 64 | int |
| 65 | main () |
| 66 | { |
| 67 | mp_limb_t nptr[2 * SIZE]; |
| 68 | mp_limb_t dptr[2 * SIZE]; |
| 69 | mp_limb_t qptr[2 * SIZE]; |
| 70 | mp_limb_t pptr[2 * SIZE + 1]; |
| 71 | mp_limb_t rptr[2 * SIZE]; |
| 72 | mp_size_t nsize, dsize, qsize, rsize, psize; |
| 73 | int test; |
| 74 | mp_limb_t qlimb; |
| 75 | |
| 76 | for (test = 0; ; test++) |
| 77 | { |
| 78 | printf ("%d\n", test); |
| 79 | #ifdef RANDOM |
| 80 | nsize = random () % (2 * SIZE) + 1; |
| 81 | dsize = random () % nsize + 1; |
| 82 | #else |
| 83 | nsize = 2 * SIZE; |
| 84 | dsize = SIZE; |
| 85 | #endif |
| 86 | |
| 87 | mpn_random2 (nptr, nsize); |
| 88 | mpn_random2 (dptr, dsize); |
| 89 | dptr[dsize - 1] |= (mp_limb_t) 1 << (GMP_LIMB_BITS - 1); |
| 90 | |
| 91 | MPN_COPY (rptr, nptr, nsize); |
| 92 | qlimb = mpn_divrem (qptr, (mp_size_t) 0, rptr, nsize, dptr, dsize); |
| 93 | rsize = dsize; |
| 94 | qsize = nsize - dsize; |
| 95 | qptr[qsize] = qlimb; |
| 96 | qsize += qlimb; |
| 97 | if (qsize == 0 || qsize > 2 * SIZE) |
| 98 | { |
| 99 | continue; /* bogus */ |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | mp_limb_t cy; |
| 104 | if (qsize > dsize) |
| 105 | mpn_mul (pptr, qptr, qsize, dptr, dsize); |
| 106 | else |
| 107 | mpn_mul (pptr, dptr, dsize, qptr, qsize); |
| 108 | psize = qsize + dsize; |
| 109 | psize -= pptr[psize - 1] == 0; |
| 110 | cy = mpn_add (pptr, pptr, psize, rptr, rsize); |
| 111 | pptr[psize] = cy; |
| 112 | psize += cy; |
| 113 | } |
| 114 | |
| 115 | if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0) |
| 116 | abort (); |
| 117 | } |
| 118 | } |