1
/* Copyright 1996, 2001 Free Software Foundation, Inc.
3
This file is part of the GNU MP Library.
5
The GNU MP Library is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation; either version 2.1 of the License, or (at your
8
option) any later version.
10
The GNU MP Library is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13
License for more details.
15
You should have received a copy of the GNU Lesser General Public License
16
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
34
#define REFCALL refmpn_add_n
35
#define TESTCALL mpn_add_n
39
#define REFCALL refmpn_sub_n
40
#define TESTCALL mpn_sub_n
43
mp_limb_t refmpn_add_n ();
44
mp_limb_t refmpn_sub_n ();
52
mp_size_t alloc_size, max_size, size, i, cumul_size;
53
mp_ptr s1, s2, dx, dy;
54
int s1_align, s2_align, d_align;
64
max_size = atol (*argv);
68
alloc_size = max_size + 32;
69
s1 = malloc (alloc_size * BYTES_PER_MP_LIMB);
70
s2 = malloc (alloc_size * BYTES_PER_MP_LIMB);
71
dx = malloc (alloc_size * BYTES_PER_MP_LIMB);
72
dy = malloc (alloc_size * BYTES_PER_MP_LIMB);
75
for (pass = 0; pass < n_passes; pass++)
78
if (cumul_size >= 1000000)
80
cumul_size -= 1000000;
81
printf ("%d ", pass); fflush (stdout);
83
s1_align = random () % 32;
84
s2_align = random () % 32;
85
d_align = random () % 32;
87
size = random () % max_size + 1;
89
mpn_random2 (s1 + s1_align, size);
90
mpn_random2 (s2 + s2_align, size);
92
for (i = 0; i < alloc_size; i++)
93
dx[i] = dy[i] = i + 0x9876500;
95
cx = TESTCALL (dx + d_align, s1 + s1_align, s2 + s2_align, size);
96
cy = REFCALL (dy + d_align, s1 + s1_align, s2 + s2_align, size);
98
if (cx != cy || mpn_cmp (dx, dy, alloc_size) != 0)
102
printf ("%d passes OK\n", n_passes);
108
refmpn_add_n (mp_ptr res_ptr,
109
mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
111
refmpn_add_n (res_ptr, s1_ptr, s2_ptr, size)
112
register mp_ptr res_ptr;
113
register mp_srcptr s1_ptr;
114
register mp_srcptr s2_ptr;
118
register mp_limb_t x, y, cy;
119
register mp_size_t j;
121
/* The loop counter and index J goes from -SIZE to -1. This way
122
the loop becomes faster. */
125
/* Offset the base pointers to compensate for the negative indices. */
135
y += cy; /* add previous carry to one addend */
136
cy = (y < cy); /* get out carry from that addition */
137
y = x + y; /* add other addend */
138
cy = (y < x) + cy; /* get out carry from that add, combine */
148
refmpn_sub_n (mp_ptr res_ptr,
149
mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
151
refmpn_sub_n (res_ptr, s1_ptr, s2_ptr, size)
152
register mp_ptr res_ptr;
153
register mp_srcptr s1_ptr;
154
register mp_srcptr s2_ptr;
158
register mp_limb_t x, y, cy;
159
register mp_size_t j;
161
/* The loop counter and index J goes from -SIZE to -1. This way
162
the loop becomes faster. */
165
/* Offset the base pointers to compensate for the negative indices. */
175
y += cy; /* add previous carry to subtrahend */
176
cy = (y < cy); /* get out carry from that addition */
177
y = x - y; /* main subtract */
178
cy = (y > x) + cy; /* get out carry from the subtract, combine */