Annotation of OpenXM/src/kan96xx/gmp-2.0.2/mpn/tests/rshift.c, Revision 1.1
1.1 ! maekawa 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 10000000
! 66: #endif
! 67: #ifndef SIZE
! 68: #define SIZE 496
! 69: #endif
! 70: #ifndef TIMES
! 71: #define TIMES OPS/SIZE
! 72: #else
! 73: #undef OPS
! 74: #define OPS (SIZE*TIMES)
! 75: #endif
! 76:
! 77: mp_limb_t
! 78: refmpn_rshift (wp, up, usize, cnt)
! 79: register mp_ptr wp;
! 80: register mp_srcptr up;
! 81: mp_size_t usize;
! 82: register unsigned int cnt;
! 83: {
! 84: register mp_limb_t high_limb, low_limb;
! 85: register unsigned sh_1, sh_2;
! 86: register mp_size_t i;
! 87: mp_limb_t retval;
! 88:
! 89: #ifdef DEBUG
! 90: if (usize == 0 || cnt == 0)
! 91: abort ();
! 92: #endif
! 93:
! 94: sh_1 = cnt;
! 95: #if 0
! 96: if (sh_1 == 0)
! 97: {
! 98: if (wp != up)
! 99: {
! 100: /* Copy from low end to high end, to allow specified input/output
! 101: overlapping. */
! 102: for (i = 0; i < usize; i++)
! 103: wp[i] = up[i];
! 104: }
! 105: return 0;
! 106: }
! 107: #endif
! 108:
! 109: wp -= 1;
! 110: sh_2 = BITS_PER_MP_LIMB - sh_1;
! 111: high_limb = up[0];
! 112: retval = high_limb << sh_2;
! 113: low_limb = high_limb;
! 114:
! 115: for (i = 1; i < usize; i++)
! 116: {
! 117: high_limb = up[i];
! 118: wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
! 119: low_limb = high_limb;
! 120: }
! 121: low_limb >>= sh_1;
! 122: wp[i] = low_limb;
! 123:
! 124: return retval;
! 125: }
! 126:
! 127: #ifndef CNT
! 128: #define CNT 4
! 129: #endif
! 130:
! 131: main (argc, argv)
! 132: int argc;
! 133: char **argv;
! 134: {
! 135: mp_limb_t s1[SIZE];
! 136: mp_limb_t dx[SIZE+2];
! 137: mp_limb_t dy[SIZE+2];
! 138: mp_limb_t cyx, cyy;
! 139: int i;
! 140: long t0, t;
! 141: int test;
! 142: int cnt = CNT;
! 143: mp_size_t size;
! 144:
! 145: for (test = 0; ; test++)
! 146: {
! 147: #ifdef RANDOM
! 148: size = (random () % SIZE + 1);
! 149: #else
! 150: size = SIZE;
! 151: #endif
! 152: mpn_random2 (s1, size);
! 153:
! 154: dx[size+1] = 0x12345678;
! 155: dy[size+1] = 0x12345678;
! 156: dx[0] = 0x87654321;
! 157: dy[0] = 0x87654321;
! 158:
! 159: #ifdef PRINT
! 160: mpn_print (s1, size);
! 161: #endif
! 162: t0 = cputime();
! 163: for (i = 0; i < TIMES; i++)
! 164: cyx = refmpn_rshift (dx+1, s1, size, cnt);
! 165: t = cputime() - t0;
! 166: #if TIMES != 1
! 167: printf ("refmpn_rshift: %5ldms (%.2f cycles/limb)\n",
! 168: t,
! 169: ((double) t * CLOCK) / (OPS * 1000.0));
! 170: #endif
! 171: #ifdef PRINT
! 172: printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx); mpn_print (dx+1, size);
! 173: #endif
! 174:
! 175: t0 = cputime();
! 176: for (i = 0; i < TIMES; i++)
! 177: cyy = mpn_rshift (dx+1, s1, size, cnt);
! 178: t = cputime() - t0;
! 179: #if TIMES != 1
! 180: printf ("mpn_rshift: %5ldms (%.2f cycles/limb)\n",
! 181: t,
! 182: ((double) t * CLOCK) / (OPS * 1000.0));
! 183: #endif
! 184: #ifdef PRINT
! 185: printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy); mpn_print (dx+1, size);
! 186: #endif
! 187:
! 188: #ifndef NOCHECK
! 189: /* Put garbage in the destination. */
! 190: for (i = 1; i <= size; i++)
! 191: {
! 192: dx[i] = 0x7654321;
! 193: dy[i] = 0x1234567;
! 194: }
! 195:
! 196: cyx = refmpn_rshift (dx+1, s1, size, cnt);
! 197: cyy = mpn_rshift (dy+1, s1, size, cnt);
! 198:
! 199: if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
! 200: || dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
! 201: {
! 202: #ifndef PRINT
! 203: printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
! 204: mpn_print (dx+1, size);
! 205: printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
! 206: mpn_print (dy+1, size);
! 207: #endif
! 208: abort();
! 209: }
! 210: #endif
! 211: }
! 212: }
! 213:
! 214: mpn_print (mp_ptr p, mp_size_t size)
! 215: {
! 216: mp_size_t i;
! 217:
! 218: for (i = size - 1; i >= 0; i--)
! 219: {
! 220: printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
! 221: #ifdef SPACE
! 222: if (i != 0)
! 223: printf (" ");
! 224: #endif
! 225: }
! 226: puts ("");
! 227: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>