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

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

1.1.1.2 ! maekawa     1: /*
        !             2: Copyright (C) 1996, 1997, 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: #include "longlong.h"
                     26:
1.1.1.2 ! maekawa    27: #if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
        !            28: #include <time.h>
1.1       maekawa    29:
1.1.1.2 ! maekawa    30: int
1.1       maekawa    31: cputime ()
                     32: {
1.1.1.2 ! maekawa    33:   if (CLOCKS_PER_SEC < 100000)
        !            34:     return clock () * 1000 / CLOCKS_PER_SEC;
        !            35:   return clock () / (CLOCKS_PER_SEC / 1000);
1.1       maekawa    36: }
                     37: #else
1.1.1.2 ! maekawa    38: #include <sys/types.h>
        !            39: #include <sys/time.h>
        !            40: #include <sys/resource.h>
1.1       maekawa    41:
1.1.1.2 ! maekawa    42: int
1.1       maekawa    43: cputime ()
                     44: {
1.1.1.2 ! maekawa    45:   struct rusage rus;
        !            46:
        !            47:   getrusage (0, &rus);
        !            48:   return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
1.1       maekawa    49: }
                     50: #endif
                     51:
                     52: #define M * 1000000
                     53:
                     54: #ifndef CLOCK
                     55: #if defined (__m88k__)
                     56: #define CLOCK 20 M
                     57: #elif defined (__i386__)
1.1.1.2 ! maekawa    58: #define CLOCK (16666667)
1.1       maekawa    59: #elif defined (__m68k__)
                     60: #define CLOCK (20 M)
                     61: #elif defined (_IBMR2)
                     62: #define CLOCK (25 M)
                     63: #elif defined (__sparc__)
                     64: #define CLOCK (20 M)
                     65: #elif defined (__sun__)
                     66: #define CLOCK (20 M)
                     67: #elif defined (__mips)
                     68: #define CLOCK (40 M)
                     69: #elif defined (__hppa__)
                     70: #define CLOCK (50 M)
                     71: #elif defined (__alpha)
                     72: #define CLOCK (133 M)
                     73: #else
                     74: #error "Don't know CLOCK of your machine"
                     75: #endif
                     76: #endif
                     77:
                     78: #ifndef OPS
1.1.1.2 ! maekawa    79: #define OPS (CLOCK/5)
1.1       maekawa    80: #endif
                     81: #ifndef SIZE
                     82: #define SIZE 496
                     83: #endif
                     84: #ifndef TIMES
                     85: #define TIMES OPS/SIZE
                     86: #else
                     87: #undef OPS
                     88: #define OPS (SIZE*TIMES)
                     89: #endif
                     90:
                     91: mp_limb_t
                     92: refmpn_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb)
                     93:      register mp_ptr res_ptr;
                     94:      register mp_srcptr s1_ptr;
                     95:      mp_size_t s1_size;
                     96:      register mp_limb_t s2_limb;
                     97: {
                     98:   register mp_limb_t cy_limb;
                     99:   register mp_size_t j;
                    100:   register mp_limb_t prod_high, prod_low;
                    101:
                    102:   /* The loop counter and index J goes from -S1_SIZE to -1.  This way
                    103:      the loop becomes faster.  */
                    104:   j = -s1_size;
                    105:
                    106:   /* Offset the base pointers to compensate for the negative indices.  */
                    107:   s1_ptr -= j;
                    108:   res_ptr -= j;
                    109:
                    110:   cy_limb = 0;
                    111:   do
                    112:     {
                    113:       umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
                    114:
                    115:       prod_low += cy_limb;
                    116:       cy_limb = (prod_low < cy_limb) + prod_high;
                    117:
                    118:       res_ptr[j] = prod_low;
                    119:     }
                    120:   while (++j != 0);
                    121:
                    122:   return cy_limb;
                    123: }
                    124:
                    125: main (argc, argv)
                    126:      int argc;
                    127:      char **argv;
                    128: {
                    129:   mp_limb_t s1[SIZE];
                    130:   mp_limb_t dx[SIZE+2];
                    131:   mp_limb_t dy[SIZE+2];
                    132:   mp_limb_t cyx, cyy;
                    133:   int i;
                    134:   long t0, t;
                    135:   int test;
                    136:   mp_limb_t xlimb;
                    137:   mp_size_t size;
1.1.1.2 ! maekawa   138:   double cyc;
1.1       maekawa   139:
                    140:   for (test = 0; ; test++)
                    141:     {
1.1.1.2 ! maekawa   142: #if TIMES == 1 && ! defined (PRINT)
        !           143:       if (test % (SIZE > 10000 ? 1 : 10000 / SIZE) == 0)
        !           144:        {
        !           145:          printf ("\r%d", test);
        !           146:          fflush (stdout);
        !           147:        }
        !           148: #endif
        !           149:
1.1       maekawa   150: #ifdef RANDOM
1.1.1.2 ! maekawa   151:       size = random () % SIZE + 1;
1.1       maekawa   152: #else
                    153:       size = SIZE;
                    154: #endif
                    155:
                    156:       dy[size+1] = 0x12345678;
                    157:       dy[0] = 0x87654321;
                    158:
1.1.1.2 ! maekawa   159:       mpn_random2 (&xlimb, 1);
1.1       maekawa   160:
1.1.1.2 ! maekawa   161: #if TIMES != 1
        !           162:       mpn_random (s1, size);
        !           163:       mpn_random (dy+1, size);
        !           164:
        !           165: #ifndef NOCHECK
1.1       maekawa   166:       MPN_COPY (dx, dy, size+2);
                    167:       t0 = cputime();
                    168:       for (i = 0; i < TIMES; i++)
1.1.1.2 ! maekawa   169:        refmpn_mul_1 (dx+1, s1, size, xlimb);
1.1       maekawa   170:       t = cputime() - t0;
1.1.1.2 ! maekawa   171:       cyc = ((double) t * CLOCK) / (OPS * 1000.0);
        !           172:       printf ("refmpn_mul_1: %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
        !           173:              t, cyc,
        !           174:              CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
1.1       maekawa   175: #endif
                    176:
                    177:       MPN_COPY (dx, dy, size+2);
                    178:       t0 = cputime();
                    179:       for (i = 0; i < TIMES; i++)
1.1.1.2 ! maekawa   180:        mpn_mul_1 (dx+1, s1, size, xlimb);
1.1       maekawa   181:       t = cputime() - t0;
1.1.1.2 ! maekawa   182:       cyc = ((double) t * CLOCK) / (OPS * 1000.0);
        !           183:       printf ("mpn_mul_1:    %5ldms (%.2f cycles/limb) [%.2f Gb/s]\n",
        !           184:              t, cyc,
        !           185:              CLOCK/cyc*BITS_PER_MP_LIMB*BITS_PER_MP_LIMB/1e9);
1.1       maekawa   186: #endif
                    187:
1.1.1.2 ! maekawa   188:       mpn_random2 (s1, size);
        !           189:       mpn_random2 (dy+1, size);
        !           190: #if defined (PRINT) || defined (XPRINT)
        !           191:       printf ("xlimb=");
        !           192:       mpn_print (&xlimb, 1);
        !           193: #endif
        !           194: #ifdef PRINT
        !           195:       mpn_print (s1, size);
        !           196: #endif
        !           197:
        !           198:       MPN_COPY (dx, dy, size+2);
1.1       maekawa   199:       cyx = refmpn_mul_1 (dx+1, s1, size, xlimb);
                    200:       cyy = mpn_mul_1 (dy+1, s1, size, xlimb);
                    201:
                    202: #ifdef 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:
                    209: #ifndef NOCHECK
                    210:       if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
                    211:          || dx[size+1] != 0x12345678 || dx[0] != 0x87654321)
                    212:        {
1.1.1.2 ! maekawa   213: #if ! (defined (PRINT) || defined (XPRINT))
        !           214:          printf ("xlimb=%*lX\n", (int) (2 * sizeof(mp_limb_t)), xlimb);
        !           215: #endif
1.1       maekawa   216: #ifndef PRINT
                    217:          printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyx);
                    218:          mpn_print (dx+1, size);
                    219:          printf ("%*lX ", (int) (2 * sizeof(mp_limb_t)), cyy);
                    220:          mpn_print (dy+1, size);
                    221: #endif
1.1.1.2 ! maekawa   222:          printf ("TEST NUMBER %d\n", test);
1.1       maekawa   223:          abort();
                    224:        }
                    225: #endif
                    226:     }
                    227: }
                    228:
                    229: mpn_print (mp_ptr p, mp_size_t size)
                    230: {
                    231:   mp_size_t i;
                    232:
                    233:   for (i = size - 1; i >= 0; i--)
                    234:     {
1.1.1.2 ! maekawa   235: #ifdef _LONG_LONG_LIMB
        !           236:       printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
        !           237:              (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
        !           238:               (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
        !           239: #else
1.1       maekawa   240:       printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
1.1.1.2 ! maekawa   241: #endif
1.1       maekawa   242: #ifdef SPACE
                    243:       if (i != 0)
                    244:        printf (" ");
                    245: #endif
                    246:     }
                    247:   puts ("");
                    248: }

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