Annotation of OpenXM_contrib/gmp/mpn/tests/divrem.c, Revision 1.1.1.2
1.1.1.2 ! maekawa 1: /*
! 2: Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
! 3:
! 4: This file is part of the GNU MP Library.
! 5:
! 6: The GNU MP Library is free software; you can redistribute it and/or modify
! 7: it under the terms of the GNU Lesser General Public License as published by
! 8: the Free Software Foundation; either version 2.1 of the License, or (at your
! 9: option) any later version.
! 10:
! 11: The GNU MP Library is distributed in the hope that it will be useful, but
! 12: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 13: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
! 14: License for more details.
! 15:
! 16: You should have received a copy of the GNU Lesser General Public License
! 17: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
! 18: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
! 19: MA 02111-1307, USA.
! 20: */
! 21:
1.1 maekawa 22: #include <stdio.h>
23: #include "gmp.h"
24: #include "gmp-impl.h"
25:
1.1.1.2 ! maekawa 26: #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
! 27: #include <time.h>
1.1 maekawa 28:
1.1.1.2 ! maekawa 29: int
1.1 maekawa 30: cputime ()
31: {
1.1.1.2 ! maekawa 32: if (CLOCKS_PER_SEC < 100000)
! 33: return clock () * 1000 / CLOCKS_PER_SEC;
! 34: return clock () / (CLOCKS_PER_SEC / 1000);
1.1 maekawa 35: }
36: #else
1.1.1.2 ! maekawa 37: #include <sys/types.h>
! 38: #include <sys/time.h>
! 39: #include <sys/resource.h>
1.1 maekawa 40:
1.1.1.2 ! maekawa 41: int
1.1 maekawa 42: cputime ()
43: {
1.1.1.2 ! maekawa 44: struct rusage rus;
! 45:
! 46: getrusage (0, &rus);
! 47: return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
1.1 maekawa 48: }
49: #endif
50:
51: #define M * 1000000
52:
53: #ifndef CLOCK
54: #if defined (__m88k__)
55: #define CLOCK 20 M
56: #elif defined (__i386__)
1.1.1.2 ! maekawa 57: #define CLOCK (16666667)
1.1 maekawa 58: #elif defined (__m68k__)
59: #define CLOCK (20 M)
60: #elif defined (_IBMR2)
61: #define CLOCK (25 M)
62: #elif defined (__sparc__)
63: #define CLOCK (20 M)
64: #elif defined (__sun__)
65: #define CLOCK (20 M)
66: #elif defined (__mips)
67: #define CLOCK (40 M)
68: #elif defined (__hppa__)
69: #define CLOCK (50 M)
70: #elif defined (__alpha)
71: #define CLOCK (133 M)
72: #else
73: #error "Don't know CLOCK of your machine"
74: #endif
75: #endif
76:
77: #ifndef OPS
78: #define OPS 20000000
79: #endif
80: #ifndef SIZE
81: #define SIZE 100
82: #endif
83: #ifndef TIMES
84: #define TIMES OPS/SIZE
85: #else
86: #undef OPS
87: #define OPS (SIZE*TIMES)
88: #endif
89:
90: main ()
91: {
92: mp_limb_t nptr[2 * SIZE];
1.1.1.2 ! maekawa 93: mp_limb_t dptr[2 * SIZE];
1.1 maekawa 94: mp_limb_t qptr[2 * SIZE];
1.1.1.2 ! maekawa 95: mp_limb_t pptr[2 * SIZE + 1];
1.1 maekawa 96: mp_limb_t rptr[2 * SIZE];
97: mp_size_t nsize, dsize, qsize, rsize, psize;
98: int test;
99: mp_limb_t qlimb;
100:
101: for (test = 0; ; test++)
102: {
1.1.1.2 ! maekawa 103: printf ("%d\n", test);
1.1 maekawa 104: #ifdef RANDOM
105: nsize = random () % (2 * SIZE) + 1;
106: dsize = random () % nsize + 1;
107: #else
108: nsize = 2 * SIZE;
109: dsize = SIZE;
110: #endif
111:
112: mpn_random2 (nptr, nsize);
113: mpn_random2 (dptr, dsize);
114: dptr[dsize - 1] |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1);
115:
116: MPN_COPY (rptr, nptr, nsize);
117: qlimb = mpn_divrem (qptr, (mp_size_t) 0, rptr, nsize, dptr, dsize);
118: rsize = dsize;
119: qsize = nsize - dsize;
120: qptr[qsize] = qlimb;
121: qsize += qlimb;
122: if (qsize == 0 || qsize > 2 * SIZE)
123: {
124: continue; /* bogus */
125: }
126: else
127: {
128: mp_limb_t cy;
129: if (qsize > dsize)
130: mpn_mul (pptr, qptr, qsize, dptr, dsize);
131: else
132: mpn_mul (pptr, dptr, dsize, qptr, qsize);
133: psize = qsize + dsize;
134: psize -= pptr[psize - 1] == 0;
135: cy = mpn_add (pptr, pptr, psize, rptr, rsize);
136: pptr[psize] = cy;
137: psize += cy;
138: }
139:
140: if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0)
141: abort ();
142: }
143: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>