~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/tests/devel/aors_n.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
 
3
Foundation, Inc.
 
4
 
 
5
This file is part of the GNU MP Library.
 
6
 
 
7
The GNU MP Library is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU Lesser General Public License as published by
 
9
the Free Software Foundation; either version 2.1 of the License, or (at your
 
10
option) any later version.
 
11
 
 
12
The GNU MP Library is distributed in the hope that it will be useful, but
 
13
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
14
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
License for more details.
 
16
 
 
17
You should have received a copy of the GNU Lesser General Public License
 
18
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
MA 02110-1301, USA.
 
21
*/
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include "gmp.h"
 
26
#include "gmp-impl.h"
 
27
#include "tests.h"
 
28
 
 
29
#ifdef OPERATION_add_n
 
30
#define func __gmpn_add_n
 
31
#define reffunc refmpn_add_n
 
32
#define funcname "mpn_add_n"
 
33
#endif
 
34
 
 
35
#ifdef OPERATION_sub_n
 
36
#define func __gmpn_sub_n
 
37
#define reffunc refmpn_sub_n
 
38
#define funcname "mpn_sub_n"
 
39
#endif
 
40
 
 
41
#ifdef OPERATION_addlsh1_n
 
42
#define func __gmpn_addlsh1_n
 
43
#define reffunc refmpn_addlsh1_n
 
44
#define funcname "mpn_addlsh1_n"
 
45
#endif
 
46
 
 
47
#ifdef OPERATION_sublsh1_n
 
48
#define func __gmpn_sublsh1_n
 
49
#define reffunc refmpn_sublsh1_n
 
50
#define funcname "mpn_sublsh1_n"
 
51
#endif
 
52
 
 
53
#ifdef OPERATION_rsh1add_n
 
54
#define func __gmpn_rsh1add_n
 
55
#define reffunc refmpn_rsh1add_n
 
56
#define funcname "mpn_rsh1add_n"
 
57
#endif
 
58
 
 
59
#ifdef OPERATION_rsh1sub_n
 
60
#define func __gmpn_rsh1sub_n
 
61
#define reffunc refmpn_rsh1sub_n
 
62
#define funcname "mpn_rsh1sub_n"
 
63
#endif
 
64
 
 
65
#if defined (USG) || defined (__SVR4) || defined (_UNICOS) || defined (__hpux)
 
66
#include <time.h>
 
67
 
 
68
int
 
69
cputime ()
 
70
{
 
71
  if (CLOCKS_PER_SEC < 100000)
 
72
    return clock () * 1000 / CLOCKS_PER_SEC;
 
73
  return clock () / (CLOCKS_PER_SEC / 1000);
 
74
}
 
75
#else
 
76
#include <sys/types.h>
 
77
#include <sys/time.h>
 
78
#include <sys/resource.h>
 
79
 
 
80
int
 
81
cputime ()
 
82
{
 
83
  struct rusage rus;
 
84
 
 
85
  getrusage (0, &rus);
 
86
  return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
 
87
}
 
88
#endif
 
89
 
 
90
static void mpn_print (mp_ptr, mp_size_t);
 
91
 
 
92
#define M * 1000000
 
93
 
 
94
#ifndef CLOCK
 
95
#error "Don't know CLOCK of your machine"
 
96
#endif
 
97
 
 
98
#ifndef OPS
 
99
#define OPS (CLOCK/5)
 
100
#endif
 
101
#ifndef SIZE
 
102
#define SIZE 328
 
103
#endif
 
104
#ifndef TIMES
 
105
#define TIMES OPS/(SIZE+1)
 
106
#endif
 
107
 
 
108
main (int argc, char **argv)
 
109
{
 
110
  mp_ptr s1, s2, dx, dy;
 
111
  mp_limb_t cyx, cyy;
 
112
  int i;
 
113
  long t0, t;
 
114
  unsigned int test;
 
115
  mp_size_t size;
 
116
  unsigned int ntests;
 
117
 
 
118
  s1 = malloc (SIZE * sizeof (mp_limb_t));
 
119
  s2 = malloc (SIZE * sizeof (mp_limb_t));
 
120
  dx = malloc ((SIZE + 2) * sizeof (mp_limb_t));
 
121
  dy = malloc ((SIZE + 2) * sizeof (mp_limb_t));
 
122
 
 
123
  ntests = ~(unsigned) 0;
 
124
  if (argc == 2)
 
125
    ntests = strtol (argv[1], 0, 0);
 
126
 
 
127
  for (test = 1; test <= ntests; test++)
 
128
    {
 
129
#if TIMES == 1 && ! defined (PRINT)
 
130
      if (test % (SIZE > 100000 ? 1 : 100000 / SIZE) == 0)
 
131
        {
 
132
          printf ("\r%u", test);
 
133
          fflush (stdout);
 
134
        }
 
135
#endif
 
136
 
 
137
#ifdef RANDOM
 
138
      size = random () % SIZE + 1;
 
139
#else
 
140
      size = SIZE;
 
141
#endif
 
142
 
 
143
      dx[0] = 0x87654321;
 
144
      dy[0] = 0x87654321;
 
145
      dx[size+1] = 0x12345678;
 
146
      dy[size+1] = 0x12345678;
 
147
 
 
148
#if TIMES != 1
 
149
      mpn_random (s1, size);
 
150
      mpn_random (s2, size);
 
151
 
 
152
      t0 = cputime();
 
153
      for (i = 0; i < TIMES; i++)
 
154
        func (dx+1, s1, s2, size);
 
155
      t = cputime() - t0;
 
156
      printf (funcname ":    %5ldms (%.3f cycles/limb)\n",
 
157
              t, ((double) t * CLOCK) / (TIMES * size * 1000.0));
 
158
#endif
 
159
 
 
160
#ifndef NOCHECK
 
161
      mpn_random2 (s1, size);
 
162
      mpn_random2 (s2, size);
 
163
 
 
164
#ifdef PRINT
 
165
      mpn_print (s1, size);
 
166
      mpn_print (s2, size);
 
167
#endif
 
168
 
 
169
      /* Put garbage in the destination.  */
 
170
      for (i = 0; i < size; i++)
 
171
        {
 
172
          dx[i+1] = 0xdead;
 
173
          dy[i+1] = 0xbeef;
 
174
        }
 
175
 
 
176
      cyx = reffunc (dx+1, s1, s2, size);
 
177
      cyy = func (dy+1, s1, s2, size);
 
178
 
 
179
#ifdef PRINT
 
180
      mpn_print (&cyx, 1);
 
181
      mpn_print (dx+1, size);
 
182
      mpn_print (&cyy, 1);
 
183
      mpn_print (dy+1, size);
 
184
#endif
 
185
 
 
186
      if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0
 
187
          || dx[0] != 0x87654321 || dx[size+1] != 0x12345678)
 
188
        {
 
189
#ifndef PRINT
 
190
          mpn_print (&cyx, 1);
 
191
          mpn_print (dx+1, size);
 
192
          mpn_print (&cyy, 1);
 
193
          mpn_print (dy+1, size);
 
194
#endif
 
195
          printf ("\n");
 
196
          if (dy[0] != 0x87654321)
 
197
            printf ("clobbered at low end\n");
 
198
          if (dy[size+1] != 0x12345678)
 
199
            printf ("clobbered at high end\n");
 
200
          printf ("TEST NUMBER %u\n", test);
 
201
          abort();
 
202
        }
 
203
#endif
 
204
    }
 
205
  exit (0);
 
206
}
 
207
 
 
208
static void
 
209
mpn_print (mp_ptr p, mp_size_t size)
 
210
{
 
211
  mp_size_t i;
 
212
 
 
213
  for (i = size - 1; i >= 0; i--)
 
214
    {
 
215
#ifdef _LONG_LONG_LIMB
 
216
      printf ("%0*lX%0*lX", (int) (sizeof(mp_limb_t)),
 
217
              (unsigned long) (p[i] >> (BITS_PER_MP_LIMB/2)),
 
218
              (int) (sizeof(mp_limb_t)), (unsigned long) (p[i]));
 
219
#else
 
220
      printf ("%0*lX", (int) (2 * sizeof(mp_limb_t)), p[i]);
 
221
#endif
 
222
#ifdef SPACE
 
223
      if (i != 0)
 
224
        printf (" ");
 
225
#endif
 
226
    }
 
227
  puts ("");
 
228
}