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

Annotation of OpenXM_contrib/gmp/mpn/tests/lshift.c, Revision 1.1.1.2

1.1.1.2 ! maekawa     1: /*
        !             2: Copyright (C) 1996, 1998, 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:
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
1.1.1.2 ! maekawa    78: #define OPS (CLOCK/5)
1.1       maekawa    79: #endif
                     80: #ifndef SIZE
                     81: #define SIZE 496
                     82: #endif
                     83: #ifndef TIMES
                     84: #define TIMES OPS/SIZE
                     85: #else
                     86: #undef OPS
                     87: #define OPS (SIZE*TIMES)
                     88: #endif
                     89:
                     90: mp_limb_t
                     91: refmpn_lshift (wp, up, usize, cnt)
                     92:      register mp_ptr wp;
                     93:      register mp_srcptr up;
                     94:      mp_size_t usize;
                     95:      register unsigned int cnt;
                     96: {
                     97:   register mp_limb_t high_limb, low_limb;
                     98:   register unsigned sh_1, sh_2;
                     99:   register mp_size_t i;
                    100:   mp_limb_t retval;
                    101:
                    102: #ifdef DEBUG
                    103:   if (usize == 0 || cnt == 0)
                    104:     abort ();
                    105: #endif
                    106:
                    107:   sh_1 = cnt;
                    108: #if 0
                    109:   if (sh_1 == 0)
                    110:     {
                    111:       if (wp != up)
                    112:        {
                    113:          /* Copy from high end to low end, to allow specified input/output
                    114:             overlapping.  */
                    115:          for (i = usize - 1; i >= 0; i--)
                    116:            wp[i] = up[i];
                    117:        }
                    118:       return 0;
                    119:     }
                    120: #endif
                    121:
                    122:   wp += 1;
                    123:   sh_2 = BITS_PER_MP_LIMB - sh_1;
                    124:   i = usize - 1;
                    125:   low_limb = up[i];
                    126:   retval = low_limb >> sh_2;
                    127:   high_limb = low_limb;
                    128:   while (--i >= 0)
                    129:     {
                    130:       low_limb = up[i];
                    131:       wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
                    132:       high_limb = low_limb;
                    133:     }
                    134:   wp[i] = high_limb << sh_1;
                    135:
                    136:   return retval;
                    137: }
                    138:
                    139: #ifndef CNT
                    140: #define CNT 4
                    141: #endif
                    142:
                    143: main (argc, argv)
                    144:      int argc;
                    145:      char **argv;
                    146: {
                    147:   mp_limb_t s1[SIZE];
                    148:   mp_limb_t dx[SIZE+2];
                    149:   mp_limb_t dy[SIZE+2];
                    150:   mp_limb_t cyx, cyy;
                    151:   int i;
                    152:   long t0, t;
                    153:   int test;
                    154:   int cnt = CNT;
                    155:   mp_size_t size;
                    156:
                    157:   for (test = 0; ; test++)
                    158:     {
1.1.1.2 ! maekawa   159: #if TIMES == 1 && ! defined (PRINT)
        !           160:       if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
        !           161:        {
        !           162:          printf ("\r%d", test);
        !           163:          fflush (stdout);
        !           164:        }
        !           165: #endif
        !           166:
        !           167: #if TIMES == 1
        !           168:       cnt = random () % (BITS_PER_MP_LIMB - 1) + 1;
        !           169: #endif
        !           170:
1.1       maekawa   171: #ifdef RANDOM
1.1.1.2 ! maekawa   172:       size = random () % SIZE + 1;
1.1       maekawa   173: #else
                    174:       size = SIZE;
                    175: #endif
                    176:       mpn_random2 (s1, size);
                    177:
                    178:       dx[size+1] = 0x12345678;
                    179:       dy[size+1] = 0x12345678;
                    180:       dx[0] = 0x87654321;
                    181:       dy[0] = 0x87654321;
                    182:
1.1.1.2 ! maekawa   183: #if TIMES != 1
        !           184:       mpn_random (s1, size);
        !           185:
        !           186: #ifndef NOCHECK
1.1       maekawa   187:       t0 = cputime();
                    188:       for (i = 0; i < TIMES; i++)
1.1.1.2 ! maekawa   189:        refmpn_lshift (dx+1, s1, size, cnt);
1.1       maekawa   190:       t = cputime() - t0;
                    191:       printf ("refmpn_lshift: %5ldms (%.2f cycles/limb)\n",
1.1.1.2 ! maekawa   192:              t, ((double) t * CLOCK) / (OPS * 1000.0));
1.1       maekawa   193: #endif
                    194:
                    195:       t0 = cputime();
                    196:       for (i = 0; i < TIMES; i++)
1.1.1.2 ! maekawa   197:        mpn_lshift (dx+1, s1, size, cnt);
1.1       maekawa   198:       t = cputime() - t0;
1.1.1.2 ! maekawa   199:       printf ("mpn_lshift:    %5ldms (%.2f cycles/limb)\n",
        !           200:              t, ((double) t * CLOCK) / (OPS * 1000.0));
1.1       maekawa   201: #endif
1.1.1.2 ! maekawa   202:
        !           203: #ifndef NOCHECK
        !           204:       mpn_random2 (s1, size);
        !           205:
1.1       maekawa   206: #ifdef PRINT
1.1.1.2 ! maekawa   207:       printf ("%-*d ", (int) (2 * sizeof(mp_limb_t)), cnt); mpn_print (s1, size);
1.1       maekawa   208: #endif
                    209:
                    210:       /* Put garbage in the destination.  */
1.1.1.2 ! maekawa   211:       for (i = 0; i < size; i++)
1.1       maekawa   212:        {
1.1.1.2 ! maekawa   213:          dx[i+1] = 0xdead;
        !           214:          dy[i+1] = 0xbeef;
1.1       maekawa   215:        }
                    216:
                    217:       cyx = refmpn_lshift (dx+1, s1, size, cnt);
                    218:       cyy = mpn_lshift (dy+1, s1, size, cnt);
1.1.1.2 ! maekawa   219: #ifdef PRINT
        !           220:       printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
        !           221:       mpn_print (dx+1, size);
        !           222:       printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
        !           223:       mpn_print (dy+1, size);
        !           224: #endif
1.1       maekawa   225:       if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
1.1.1.2 ! maekawa   226:          || dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
1.1       maekawa   227:        {
                    228: #ifndef PRINT
                    229:          printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
                    230:          mpn_print (dx+1, size);
                    231:          printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
                    232:          mpn_print (dy+1, size);
                    233: #endif
1.1.1.2 ! maekawa   234:          printf ("TEST NUMBER %d\n", test);
        !           235:          if (dy[size+1] != 0x12345678)
        !           236:            printf ("clobbered at high end\n");
        !           237:          if (dy[0] != 0x87654321)
        !           238:            printf ("clobbered at low end\n");
1.1       maekawa   239:          abort();
                    240:        }
                    241: #endif
                    242:     }
                    243: }
                    244:
                    245: mpn_print (mp_ptr p, mp_size_t size)
                    246: {
                    247:   mp_size_t i;
                    248:
                    249:   for (i = size - 1; i >= 0; i--)
                    250:     {
1.1.1.2 ! maekawa   251: #ifdef _LONG_LONG_LIMB
        !           252:       printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
        !           253:              (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
        !           254:               (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
        !           255: #else
1.1       maekawa   256:       printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
1.1.1.2 ! maekawa   257: #endif
1.1       maekawa   258: #ifdef SPACE
                    259:       if (i != 0)
                    260:        printf (" ");
                    261: #endif
                    262:     }
                    263:   puts ("");
                    264: }

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