2
Copyright (C) 1996 Free Software Foundation, Inc.
4
This file is part of the GNU MP Library.
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.
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.
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,
35
#define REFCALL refmpn_add_n
36
#define TESTCALL mpn_add_n
40
#define REFCALL refmpn_sub_n
41
#define TESTCALL mpn_sub_n
44
mp_limb_t refmpn_add_n ();
45
mp_limb_t refmpn_sub_n ();
53
mp_size_t alloc_size, max_size, size, i, cumul_size;
54
mp_ptr s1, s2, dx, dy;
55
int s1_align, s2_align, d_align;
65
max_size = atol (*argv);
69
alloc_size = max_size + 32;
70
s1 = malloc (alloc_size * BYTES_PER_MP_LIMB);
71
s2 = malloc (alloc_size * BYTES_PER_MP_LIMB);
72
dx = malloc (alloc_size * BYTES_PER_MP_LIMB);
73
dy = malloc (alloc_size * BYTES_PER_MP_LIMB);
76
for (pass = 0; pass < n_passes; pass++)
79
if (cumul_size >= 1000000)
81
cumul_size -= 1000000;
82
printf ("%d ", pass); fflush (stdout);
84
s1_align = random () % 32;
85
s2_align = random () % 32;
86
d_align = random () % 32;
88
size = random () % max_size + 1;
90
mpn_random2 (s1 + s1_align, size);
91
mpn_random2 (s2 + s2_align, size);
93
for (i = 0; i < alloc_size; i++)
94
dx[i] = dy[i] = i + 0x9876500;
96
cx = TESTCALL (dx + d_align, s1 + s1_align, s2 + s2_align, size);
97
cy = REFCALL (dy + d_align, s1 + s1_align, s2 + s2_align, size);
99
if (cx != cy || mpn_cmp (dx, dy, alloc_size) != 0)
103
printf ("%d passes OK\n", n_passes);
109
refmpn_add_n (mp_ptr res_ptr,
110
mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
112
refmpn_add_n (res_ptr, s1_ptr, s2_ptr, size)
113
register mp_ptr res_ptr;
114
register mp_srcptr s1_ptr;
115
register mp_srcptr s2_ptr;
119
register mp_limb_t x, y, cy;
120
register mp_size_t j;
122
/* The loop counter and index J goes from -SIZE to -1. This way
123
the loop becomes faster. */
126
/* Offset the base pointers to compensate for the negative indices. */
136
y += cy; /* add previous carry to one addend */
137
cy = (y < cy); /* get out carry from that addition */
138
y = x + y; /* add other addend */
139
cy = (y < x) + cy; /* get out carry from that add, combine */
149
refmpn_sub_n (mp_ptr res_ptr,
150
mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
152
refmpn_sub_n (res_ptr, s1_ptr, s2_ptr, size)
153
register mp_ptr res_ptr;
154
register mp_srcptr s1_ptr;
155
register mp_srcptr s2_ptr;
159
register mp_limb_t x, y, cy;
160
register mp_size_t j;
162
/* The loop counter and index J goes from -SIZE to -1. This way
163
the loop becomes faster. */
166
/* Offset the base pointers to compensate for the negative indices. */
176
y += cy; /* add previous carry to subtrahend */
177
cy = (y < cy); /* get out carry from that addition */
178
y = x - y; /* main subtract */
179
cy = (y > x) + cy; /* get out carry from the subtract, combine */