Annotation of OpenXM_contrib/gmp/mpn/tests/divmod_1.c, Revision 1.1.1.2
1.1.1.2 ! maekawa 1: /*
! 2: Copyright (C) 1996, 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 1000
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[SIZE];
93: mp_limb_t qptr[SIZE];
94: mp_limb_t pptr[SIZE];
95: mp_limb_t dlimb, rlimb, plimb;
96: mp_size_t nsize, qsize, psize;
97: int test;
98:
99: for (test = 0; ; test++)
100: {
101: #ifdef RANDOM
102: nsize = random () % SIZE + 1;
103: #else
104: nsize = SIZE;
105: #endif
106:
107: mpn_random2 (nptr, nsize);
108:
109: mpn_random2 (&dlimb, 1);
110: if (dlimb == 0)
111: abort ();
112:
113: rlimb = mpn_divmod_1 (qptr, nptr, nsize, dlimb);
114: qsize = nsize - (qptr[nsize - 1] == 0);
115: if (qsize == 0)
116: {
117: plimb = rlimb;
118: psize = qsize;
119: }
120: else
121: {
122: plimb = mpn_mul_1 (pptr, qptr, qsize, dlimb);
123: psize = qsize;
124: plimb += mpn_add_1 (pptr, pptr, psize, rlimb);
125: }
126: if (plimb != 0)
127: pptr[psize++] = plimb;
128:
129:
130: if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0)
131: abort ();
132: }
133: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>