Annotation of OpenXM/src/kan96xx/gmp-2.0.2-ssh-2/mpn/tests/divmod_1.c, Revision 1.1
1.1 ! takayama 1: #include <stdio.h>
! 2: #include "gmp.h"
! 3: #include "gmp-impl.h"
! 4: #include "longlong.h"
! 5:
! 6: #ifndef USG
! 7: #include <sys/time.h>
! 8: #include <sys/resource.h>
! 9:
! 10: unsigned long
! 11: cputime ()
! 12: {
! 13: struct rusage rus;
! 14:
! 15: getrusage (0, &rus);
! 16: return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
! 17: }
! 18: #else
! 19: #include <time.h>
! 20:
! 21: #ifndef CLOCKS_PER_SEC
! 22: #define CLOCKS_PER_SEC 1000000
! 23: #endif
! 24:
! 25: #if CLOCKS_PER_SEC >= 10000
! 26: #define CLOCK_TO_MILLISEC(cl) ((cl) / (CLOCKS_PER_SEC / 1000))
! 27: #else
! 28: #define CLOCK_TO_MILLISEC(cl) ((cl) * 1000 / CLOCKS_PER_SEC)
! 29: #endif
! 30:
! 31: unsigned long
! 32: cputime ()
! 33: {
! 34: return CLOCK_TO_MILLISEC (clock ());
! 35: }
! 36: #endif
! 37:
! 38: #define M * 1000000
! 39:
! 40: #ifndef CLOCK
! 41: #if defined (__m88k__)
! 42: #define CLOCK 20 M
! 43: #elif defined (__i386__)
! 44: #define CLOCK (16.666667 M)
! 45: #elif defined (__m68k__)
! 46: #define CLOCK (20 M)
! 47: #elif defined (_IBMR2)
! 48: #define CLOCK (25 M)
! 49: #elif defined (__sparc__)
! 50: #define CLOCK (20 M)
! 51: #elif defined (__sun__)
! 52: #define CLOCK (20 M)
! 53: #elif defined (__mips)
! 54: #define CLOCK (40 M)
! 55: #elif defined (__hppa__)
! 56: #define CLOCK (50 M)
! 57: #elif defined (__alpha)
! 58: #define CLOCK (133 M)
! 59: #else
! 60: #error "Don't know CLOCK of your machine"
! 61: #endif
! 62: #endif
! 63:
! 64: #ifndef OPS
! 65: #define OPS 20000000
! 66: #endif
! 67: #ifndef SIZE
! 68: #define SIZE 1000
! 69: #endif
! 70: #ifndef TIMES
! 71: #define TIMES OPS/SIZE
! 72: #else
! 73: #undef OPS
! 74: #define OPS (SIZE*TIMES)
! 75: #endif
! 76:
! 77: main ()
! 78: {
! 79: mp_limb_t nptr[SIZE];
! 80: mp_limb_t qptr[SIZE];
! 81: mp_limb_t pptr[SIZE];
! 82: mp_limb_t dlimb, rlimb, plimb;
! 83: mp_size_t nsize, qsize, psize;
! 84: int test;
! 85:
! 86: for (test = 0; ; test++)
! 87: {
! 88: #ifdef RANDOM
! 89: nsize = random () % SIZE + 1;
! 90: #else
! 91: nsize = SIZE;
! 92: #endif
! 93:
! 94: mpn_random2 (nptr, nsize);
! 95:
! 96: mpn_random2 (&dlimb, 1);
! 97: if (dlimb == 0)
! 98: abort ();
! 99:
! 100: rlimb = mpn_divmod_1 (qptr, nptr, nsize, dlimb);
! 101: qsize = nsize - (qptr[nsize - 1] == 0);
! 102: if (qsize == 0)
! 103: {
! 104: plimb = rlimb;
! 105: psize = qsize;
! 106: }
! 107: else
! 108: {
! 109: plimb = mpn_mul_1 (pptr, qptr, qsize, dlimb);
! 110: psize = qsize;
! 111: plimb += mpn_add_1 (pptr, pptr, psize, rlimb);
! 112: }
! 113: if (plimb != 0)
! 114: pptr[psize++] = plimb;
! 115:
! 116:
! 117: if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0)
! 118: abort ();
! 119: }
! 120: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>