[BACK]Return to divrem.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / gmp-2.0.2-ssh-2 / mpn / tests

Annotation of OpenXM/src/kan96xx/gmp-2.0.2-ssh-2/mpn/tests/divrem.c, Revision 1.1.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 100
                     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[2 * SIZE];
                     80:   mp_limb_t dptr[SIZE];
                     81:   mp_limb_t qptr[2 * SIZE];
                     82:   mp_limb_t pptr[2 * SIZE];
                     83:   mp_limb_t rptr[2 * SIZE];
                     84:   mp_size_t nsize, dsize, qsize, rsize, psize;
                     85:   int test;
                     86:   mp_limb_t qlimb;
                     87:
                     88:   for (test = 0; ; test++)
                     89:     {
                     90: #ifdef RANDOM
                     91:       nsize = random () % (2 * SIZE) + 1;
                     92:       dsize = random () % nsize + 1;
                     93: #else
                     94:       nsize = 2 * SIZE;
                     95:       dsize = SIZE;
                     96: #endif
                     97:
                     98:       mpn_random2 (nptr, nsize);
                     99:       mpn_random2 (dptr, dsize);
                    100:       dptr[dsize - 1] |= (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1);
                    101:
                    102:       MPN_COPY (rptr, nptr, nsize);
                    103:       qlimb = mpn_divrem (qptr, (mp_size_t) 0, rptr, nsize, dptr, dsize);
                    104:       rsize = dsize;
                    105:       qsize = nsize - dsize;
                    106:       qptr[qsize] = qlimb;
                    107:       qsize += qlimb;
                    108:       if (qsize == 0 || qsize > 2 * SIZE)
                    109:        {
                    110:          continue;             /* bogus */
                    111:        }
                    112:       else
                    113:        {
                    114:          mp_limb_t cy;
                    115:          if (qsize > dsize)
                    116:            mpn_mul (pptr, qptr, qsize, dptr, dsize);
                    117:          else
                    118:            mpn_mul (pptr, dptr, dsize, qptr, qsize);
                    119:          psize = qsize + dsize;
                    120:          psize -= pptr[psize - 1] == 0;
                    121:          cy = mpn_add (pptr, pptr, psize, rptr, rsize);
                    122:          pptr[psize] = cy;
                    123:          psize += cy;
                    124:        }
                    125:
                    126:       if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0)
                    127:        abort ();
                    128:     }
                    129: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>