~ubuntu-branches/ubuntu/vivid/gcl/vivid

« back to all changes in this revision

Viewing changes to gmp/mpn/tests/divmod_1.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-03-04 14:29:59 UTC
  • Revision ID: james.westby@ubuntu.com-20020304142959-dey14w08kr7lldu3
Tags: upstream-2.5.0.cvs20020219
ImportĀ upstreamĀ versionĀ 2.5.0.cvs20020219

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 1996, 1998, 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 <stdlib.h>
 
24
#include "gmp.h"
 
25
#include "gmp-impl.h"
 
26
 
 
27
#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux) || (defined(__DECC) && defined(__VMS))
 
28
#include <time.h>
 
29
 
 
30
int
 
31
cputime ()
 
32
{
 
33
  if (CLOCKS_PER_SEC < 100000)
 
34
    return clock () * 1000 / CLOCKS_PER_SEC;
 
35
  return clock () / (CLOCKS_PER_SEC / 1000);
 
36
}
 
37
#else
 
38
#include <sys/types.h>
 
39
#include <sys/time.h>
 
40
#include <sys/resource.h>
 
41
 
 
42
int
 
43
cputime ()
 
44
{
 
45
  struct rusage rus;
 
46
 
 
47
  getrusage (0, &rus);
 
48
  return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
 
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__)
 
58
#define CLOCK (16666667)
 
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
#elif defined (__vax)
 
74
#define CLOCK (40 M)
 
75
#else
 
76
#error "Don't know CLOCK of your machine"
 
77
#endif
 
78
#endif
 
79
 
 
80
#ifndef OPS
 
81
#define OPS 20000000
 
82
#endif
 
83
#ifndef SIZE
 
84
#define SIZE 1000
 
85
#endif
 
86
#ifndef TIMES
 
87
#define TIMES OPS/SIZE
 
88
#else
 
89
#undef OPS
 
90
#define OPS (SIZE*TIMES)
 
91
#endif
 
92
 
 
93
main ()
 
94
{
 
95
  mp_limb_t nptr[SIZE];
 
96
  mp_limb_t qptr[SIZE];
 
97
  mp_limb_t pptr[SIZE];
 
98
  mp_limb_t dlimb, rlimb, plimb;
 
99
  mp_size_t nsize, qsize, psize;
 
100
  int test;
 
101
  int clock_mhz;
 
102
 
 
103
  clock_mhz = CLOCK / 1000000;
 
104
  printf("\r\nTest Times Are Based On A CPU Clock Speed Of %dMHz.\r\n\r\n",clock_mhz);
 
105
 
 
106
  for (test = 0; ; test++)
 
107
    {
 
108
#ifdef RANDOM
 
109
      nsize = random () % SIZE + 1;
 
110
#else
 
111
      nsize = SIZE;
 
112
#endif
 
113
 
 
114
      mpn_random2 (nptr, nsize);
 
115
 
 
116
      mpn_random2 (&dlimb, 1);
 
117
      if (dlimb == 0)
 
118
        abort ();
 
119
 
 
120
      rlimb = mpn_divmod_1 (qptr, nptr, nsize, dlimb);
 
121
      qsize = nsize - (qptr[nsize - 1] == 0);
 
122
      if (qsize == 0)
 
123
        {
 
124
          plimb = rlimb;
 
125
          psize = qsize;
 
126
        }
 
127
      else
 
128
        {
 
129
          plimb = mpn_mul_1 (pptr, qptr, qsize, dlimb);
 
130
          psize = qsize;
 
131
          plimb += mpn_add_1 (pptr, pptr, psize, rlimb);
 
132
        }
 
133
      if (plimb != 0)
 
134
        pptr[psize++] = plimb;
 
135
 
 
136
 
 
137
      if (nsize != psize || mpn_cmp (nptr, pptr, nsize) != 0)
 
138
        abort ();
 
139
    }
 
140
}