blob: 4aa827a60f4e6bbed52d00becf354b54f47179ac [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001/* Copyright 1996, 2001 Free Software Foundation, Inc.
2
3This file is part of the GNU MP Library test suite.
4
5The GNU MP Library test suite is free software; you can redistribute it
6and/or modify it under the terms of the GNU General Public License as
7published by the Free Software Foundation; either version 3 of the License,
8or (at your option) any later version.
9
10The GNU MP Library test suite is distributed in the hope that it will be
11useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13Public License for more details.
14
15You should have received a copy of the GNU General Public License along with
16the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include "gmp-impl.h"
21#include "tests.h"
22
23#define ADD 1
24#define SUB 2
25
26#ifndef METHOD
27#define METHOD ADD
28#endif
29
30#if METHOD == ADD
31#define REFCALL refmpn_add_n
32#define TESTCALL mpn_add_n
33#endif
34
35#if METHOD == SUB
36#define REFCALL refmpn_sub_n
37#define TESTCALL mpn_sub_n
38#endif
39
40#define SIZE 100
41
42int
43main (int argc, char **argv)
44{
45 mp_size_t alloc_size, max_size, size, i, cumul_size;
46 mp_ptr s1, s2, dx, dy;
47 int s1_align, s2_align, d_align;
48 long pass, n_passes;
49 mp_limb_t cx, cy;
50
51 max_size = SIZE;
52 n_passes = 1000000;
53
54 argc--; argv++;
55 if (argc)
56 {
57 max_size = atol (*argv);
58 argc--; argv++;
59 }
60
61 alloc_size = max_size + 32;
62 s1 = malloc (alloc_size * GMP_LIMB_BYTES);
63 s2 = malloc (alloc_size * GMP_LIMB_BYTES);
64 dx = malloc (alloc_size * GMP_LIMB_BYTES);
65 dy = malloc (alloc_size * GMP_LIMB_BYTES);
66
67 cumul_size = 0;
68 for (pass = 0; pass < n_passes; pass++)
69 {
70 size = random () % max_size + 1;
71
72 cumul_size += size;
73 if (cumul_size >= 1000000)
74 {
75 cumul_size -= 1000000;
76 printf ("\r%ld", pass); fflush (stdout);
77 }
78 s1_align = random () % 32;
79 s2_align = random () % 32;
80 d_align = random () % 32;
81
82 mpn_random2 (s1 + s1_align, size);
83 mpn_random2 (s2 + s2_align, size);
84
85 for (i = 0; i < alloc_size; i++)
86 dx[i] = dy[i] = i + 0x9876500;
87
88 cx = TESTCALL (dx + d_align, s1 + s1_align, s2 + s2_align, size);
89 cy = REFCALL (dy + d_align, s1 + s1_align, s2 + s2_align, size);
90
91 if (cx != cy || mpn_cmp (dx, dy, alloc_size) != 0)
92 abort ();
93 }
94
95 printf ("%ld passes OK\n", n_passes);
96 exit (0);
97}