[BACK]Return to copy.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpn / tests

Annotation of OpenXM_contrib/gmp/mpn/tests/copy.c, Revision 1.1.1.1

1.1       maekawa     1: /*
                      2: Copyright (C) 1999, 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:
                     22: #include <stdio.h>
                     23: #include "gmp.h"
                     24: #include "gmp-impl.h"
                     25:
                     26: #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
                     27: #include <time.h>
                     28:
                     29: int
                     30: cputime ()
                     31: {
                     32:   if (CLOCKS_PER_SEC < 100000)
                     33:     return clock () * 1000 / CLOCKS_PER_SEC;
                     34:   return clock () / (CLOCKS_PER_SEC / 1000);
                     35: }
                     36: #else
                     37: #include <sys/types.h>
                     38: #include <sys/time.h>
                     39: #include <sys/resource.h>
                     40:
                     41: int
                     42: cputime ()
                     43: {
                     44:   struct rusage rus;
                     45:
                     46:   getrusage (0, &rus);
                     47:   return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
                     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__)
                     57: #define CLOCK (16666667)
                     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 (CLOCK/2)
                     79: #endif
                     80: #ifndef SIZE
                     81: #define SIZE 328
                     82: #endif
                     83: #ifndef TIMES
                     84: #define TIMES (OPS/SIZE)
                     85: #else
                     86: #undef OPS
                     87: #define OPS (SIZE*TIMES)
                     88: #endif
                     89:
                     90:
                     91: void
                     92: #if __STDC__
                     93: refmpn_copyi (mp_ptr rptr, mp_srcptr sptr, mp_size_t n)
                     94: #else
                     95: refmpn_copyi (rptr, sptr, n)
                     96:      register mp_ptr rptr;
                     97:      register mp_srcptr sptr;
                     98:      mp_size_t n;
                     99: #endif
                    100: {
                    101:   mp_size_t i;
                    102:
                    103:   for (i = 0; i < n; i++)
                    104:     rptr[i] = sptr[i];
                    105: }
                    106:
                    107: main (argc, argv)
                    108:      int argc;
                    109:      char **argv;
                    110: {
                    111:   mp_limb_t s1[SIZE];
                    112:   mp_limb_t dx[SIZE+2];
                    113:   mp_limb_t dy[SIZE+2];
                    114:   int i;
                    115:   long t0, t;
                    116:   int test;
                    117:   mp_size_t size;
                    118:
                    119:   for (test = 0; ; test++)
                    120:     {
                    121: #if TIMES == 1 && ! defined (PRINT)
                    122:       if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
                    123:        {
                    124:          printf ("\r%d", test);
                    125:          fflush (stdout);
                    126:        }
                    127: #endif
                    128:
                    129: #ifdef RANDOM
                    130:       size = (random () % SIZE + 1);
                    131: #else
                    132:       size = SIZE;
                    133: #endif
                    134:
                    135:       dx[0] = 0x87654321;
                    136:       dy[0] = 0x87654321;
                    137:       dx[size+1] = 0x12345678;
                    138:       dy[size+1] = 0x12345678;
                    139:
                    140: #if TIMES != 1
                    141:       mpn_random (s1, size);
                    142:
                    143: #ifndef NOCHECK
                    144:       t0 = cputime();
                    145:       for (i = 0; i < TIMES; i++)
                    146:        refmpn_copyi (dx+1, s1, size);
                    147:       t = cputime() - t0;
                    148:       printf ("refmpn_copyi:   %ldms (%.2f cycles/limb)\n",
                    149:              t, ((double) t * CLOCK) / (OPS * 1000.0));
                    150: #endif
                    151:
                    152:       t0 = cputime();
                    153:       for (i = 0; i < TIMES; i++)
                    154:        MPN_COPY_INCR (dx+1, s1, size);
                    155:       t = cputime() - t0;
                    156:       printf ("MPN_COPY_INCR:   %ldms (%.2f cycles/limb)\n",
                    157:              t, ((double) t * CLOCK) / (OPS * 1000.0));
                    158: #endif
                    159:
                    160: #ifndef NOCHECK
                    161:       mpn_random2 (s1, size);
                    162:
                    163: #ifdef PRINT
                    164:       mpn_print (s1, size);
                    165: #endif
                    166:
                    167:       /* Put garbage in the destination.  */
                    168:       for (i = 0; i < size; i++)
                    169:        {
                    170:          dx[i+1] = 0xdead;
                    171:          dy[i+1] = 0xbeef;
                    172:        }
                    173:
                    174:       refmpn_copyi (dx+1, s1, size);
                    175:       MPN_COPY_INCR (dy+1, s1, size);
                    176: #ifdef PRINT
                    177:       mpn_print (dx+1, size);
                    178:       mpn_print (dy+1, size);
                    179: #endif
                    180:       if (mpn_cmp (dx, dy, size+2) != 0
                    181:          || dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
                    182:        {
                    183: #ifndef PRINT
                    184:          mpn_print (dx+1, size);
                    185:          mpn_print (dy+1, size);
                    186: #endif
                    187:          printf ("TEST NUMBER %d\n", test);
                    188:          abort();
                    189:        }
                    190: #endif
                    191:     }
                    192: }
                    193:
                    194: mpn_print (mp_ptr p, mp_size_t size)
                    195: {
                    196:   mp_size_t i;
                    197:
                    198:   for (i = size - 1; i >= 0; i--)
                    199:     {
                    200: #ifdef _LONG_LONG_LIMB
                    201:       printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
                    202:              (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
                    203:               (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
                    204: #else
                    205:       printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
                    206: #endif
                    207: #ifdef SPACE
                    208:       if (i != 0)
                    209:        printf (" ");
                    210: #endif
                    211:     }
                    212:   puts ("");
                    213: }

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