version 1.1, 2000/01/10 15:35:26 |
version 1.1.1.2, 2000/09/09 14:12:45 |
|
|
|
/* |
|
Copyright (C) 1996, 1998, 1999, 2000 Free Software Foundation, Inc. |
|
|
|
This file is part of the GNU MP Library. |
|
|
|
The GNU MP Library is free software; you can redistribute it and/or modify |
|
it under the terms of the GNU Lesser General Public License as published by |
|
the Free Software Foundation; either version 2.1 of the License, or (at your |
|
option) any later version. |
|
|
|
The GNU MP Library is distributed in the hope that it will be useful, but |
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
|
License for more details. |
|
|
|
You should have received a copy of the GNU Lesser General Public License |
|
along with the GNU MP Library; see the file COPYING.LIB. If not, write to |
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
|
MA 02111-1307, USA. |
|
*/ |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include "gmp.h" |
#include "gmp.h" |
#include "gmp-impl.h" |
#include "gmp-impl.h" |
#include "longlong.h" |
|
|
|
#ifndef USG |
#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) |
#include <sys/time.h> |
#include <time.h> |
#include <sys/resource.h> |
|
|
|
unsigned long |
int |
cputime () |
cputime () |
{ |
{ |
struct rusage rus; |
if (CLOCKS_PER_SEC < 100000) |
|
return clock () * 1000 / CLOCKS_PER_SEC; |
getrusage (0, &rus); |
return clock () / (CLOCKS_PER_SEC / 1000); |
return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; |
|
} |
} |
#else |
#else |
#include <time.h> |
#include <sys/types.h> |
|
#include <sys/time.h> |
|
#include <sys/resource.h> |
|
|
#ifndef CLOCKS_PER_SEC |
int |
#define CLOCKS_PER_SEC 1000000 |
|
#endif |
|
|
|
#if CLOCKS_PER_SEC >= 10000 |
|
#define CLOCK_TO_MILLISEC(cl) ((cl) / (CLOCKS_PER_SEC / 1000)) |
|
#else |
|
#define CLOCK_TO_MILLISEC(cl) ((cl) * 1000 / CLOCKS_PER_SEC) |
|
#endif |
|
|
|
unsigned long |
|
cputime () |
cputime () |
{ |
{ |
return CLOCK_TO_MILLISEC (clock ()); |
struct rusage rus; |
|
|
|
getrusage (0, &rus); |
|
return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; |
} |
} |
#endif |
#endif |
|
|
|
|
#if defined (__m88k__) |
#if defined (__m88k__) |
#define CLOCK 20 M |
#define CLOCK 20 M |
#elif defined (__i386__) |
#elif defined (__i386__) |
#define CLOCK (16.666667 M) |
#define CLOCK (16666667) |
#elif defined (__m68k__) |
#elif defined (__m68k__) |
#define CLOCK (20 M) |
#define CLOCK (20 M) |
#elif defined (_IBMR2) |
#elif defined (_IBMR2) |
|
|
#endif |
#endif |
|
|
#ifndef OPS |
#ifndef OPS |
#define OPS 10000000 |
#define OPS (CLOCK/5) |
#endif |
#endif |
#ifndef SIZE |
#ifndef SIZE |
#define SIZE 496 |
#define SIZE 496 |
Line 143 main (argc, argv) |
|
Line 156 main (argc, argv) |
|
|
|
for (test = 0; ; test++) |
for (test = 0; ; test++) |
{ |
{ |
|
#if TIMES == 1 && ! defined (PRINT) |
|
if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0) |
|
{ |
|
printf ("\r%d", test); |
|
fflush (stdout); |
|
} |
|
#endif |
|
|
|
#if TIMES == 1 |
|
cnt = random () % (BITS_PER_MP_LIMB - 1) + 1; |
|
#endif |
|
|
#ifdef RANDOM |
#ifdef RANDOM |
size = (random () % SIZE + 1); |
size = random () % SIZE + 1; |
#else |
#else |
size = SIZE; |
size = SIZE; |
#endif |
#endif |
Line 155 main (argc, argv) |
|
Line 180 main (argc, argv) |
|
dx[0] = 0x87654321; |
dx[0] = 0x87654321; |
dy[0] = 0x87654321; |
dy[0] = 0x87654321; |
|
|
#ifdef PRINT |
#if TIMES != 1 |
mpn_print (s1, size); |
mpn_random (s1, size); |
#endif |
|
|
#ifndef NOCHECK |
t0 = cputime(); |
t0 = cputime(); |
for (i = 0; i < TIMES; i++) |
for (i = 0; i < TIMES; i++) |
cyx = refmpn_lshift (dx+1, s1, size, cnt); |
refmpn_lshift (dx+1, s1, size, cnt); |
t = cputime() - t0; |
t = cputime() - t0; |
#if TIMES != 1 |
|
printf ("refmpn_lshift: %5ldms (%.2f cycles/limb)\n", |
printf ("refmpn_lshift: %5ldms (%.2f cycles/limb)\n", |
t, |
t, ((double) t * CLOCK) / (OPS * 1000.0)); |
((double) t * CLOCK) / (OPS * 1000.0)); |
|
#endif |
#endif |
#ifdef PRINT |
|
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); mpn_print (dx+1, size); |
|
#endif |
|
|
|
t0 = cputime(); |
t0 = cputime(); |
for (i = 0; i < TIMES; i++) |
for (i = 0; i < TIMES; i++) |
cyy = mpn_lshift (dx+1, s1, size, cnt); |
mpn_lshift (dx+1, s1, size, cnt); |
t = cputime() - t0; |
t = cputime() - t0; |
#if TIMES != 1 |
printf ("mpn_lshift: %5ldms (%.2f cycles/limb)\n", |
printf ("mpn_lshift: %5ldms (%.2f cycles/limb)\n", |
t, ((double) t * CLOCK) / (OPS * 1000.0)); |
t, |
|
((double) t * CLOCK) / (OPS * 1000.0)); |
|
#endif |
#endif |
|
|
|
#ifndef NOCHECK |
|
mpn_random2 (s1, size); |
|
|
#ifdef PRINT |
#ifdef PRINT |
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); mpn_print (dx+1, size); |
printf ("%-*d ", (int) (2 * sizeof(mp_limb_t)), cnt); mpn_print (s1, size); |
#endif |
#endif |
|
|
#ifndef NOCHECK |
|
/* Put garbage in the destination. */ |
/* Put garbage in the destination. */ |
for (i = 1; i <= size; i++) |
for (i = 0; i < size; i++) |
{ |
{ |
dx[i] = 0x7654321; |
dx[i+1] = 0xdead; |
dy[i] = 0x1234567; |
dy[i+1] = 0xbeef; |
} |
} |
|
|
cyx = refmpn_lshift (dx+1, s1, size, cnt); |
cyx = refmpn_lshift (dx+1, s1, size, cnt); |
cyy = mpn_lshift (dy+1, s1, size, cnt); |
cyy = mpn_lshift (dy+1, s1, size, cnt); |
|
#ifdef PRINT |
|
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); |
|
mpn_print (dx+1, size); |
|
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); |
|
mpn_print (dy+1, size); |
|
#endif |
if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 |
if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 |
|| dx[size+1] != 0x12345678 || dx[0] != 0x87654321) |
|| dx[0] != 0x87654321 || dx[size+1] != 0x12345678) |
{ |
{ |
#ifndef PRINT |
#ifndef PRINT |
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); |
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); |
Line 204 main (argc, argv) |
|
Line 231 main (argc, argv) |
|
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); |
printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); |
mpn_print (dy+1, size); |
mpn_print (dy+1, size); |
#endif |
#endif |
|
printf ("TEST NUMBER %d\n", test); |
|
if (dy[size+1] != 0x12345678) |
|
printf ("clobbered at high end\n"); |
|
if (dy[0] != 0x87654321) |
|
printf ("clobbered at low end\n"); |
abort(); |
abort(); |
} |
} |
#endif |
#endif |
Line 216 mpn_print (mp_ptr p, mp_size_t size) |
|
Line 248 mpn_print (mp_ptr p, mp_size_t size) |
|
|
|
for (i = size - 1; i >= 0; i--) |
for (i = size - 1; i >= 0; i--) |
{ |
{ |
|
#ifdef _LONG_LONG_LIMB |
|
printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)), |
|
(unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)), |
|
(int) (sizeof(mp_limb_t)), (unsigned long) (p[i])); |
|
#else |
printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); |
printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]); |
|
#endif |
#ifdef SPACE |
#ifdef SPACE |
if (i != 0) |
if (i != 0) |
printf (" "); |
printf (" "); |