1 /* Test MPN_INCR_U and MPN_DECR_U.
3 Copyright 2001, 2002 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
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 3 of the License, or (at your
10 option) any later version.
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.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
28 /* The i386 MPN_INCR_U and MPN_DECR_U have special cases for "n" being a
29 compile-time constant 1, so that's exercised explicitly. */
32 #define M GMP_NUMB_MAX
33 #define SIZE ((mp_size_t) 10)
37 check_one (const char *name, int i,
38 mp_srcptr src, mp_limb_t n,
39 mp_srcptr got, mp_srcptr want, mp_size_t size)
41 if (! refmpn_equal_anynail (got, want, size))
43 printf ("Wrong at %s i=%d\n", name, i);
44 mpn_trace (" src", src, size);
45 mpn_trace (" n", &n, (mp_size_t) 1);
46 mpn_trace (" got", got, size);
47 mpn_trace (" want", want, size);
54 check_incr_data (void)
58 const mp_limb_t src[SIZE];
59 const mp_limb_t want[SIZE];
62 { 1, { 123 }, { 124 } },
64 { 2, { 123 }, { 125 } },
67 { 1, { M, 0 }, { 0, 1 } },
68 { 1, { M, 123 }, { 0, 124 } },
69 { 2, { M, 0 }, { 1, 1 } },
70 { 2, { M, 123 }, { 1, 124 } },
71 { M, { M, 0 }, { M-1, 1 } },
72 { M, { M, 123 }, { M-1, 124 } },
74 { 1, { M, M, 0 }, { 0, 0, 1 } },
75 { 1, { M, M, 123 }, { 0, 0, 124 } },
76 { 2, { M, M, 0 }, { 1, 0, 1 } },
77 { 2, { M, M, 123 }, { 1, 0, 124 } },
78 { M, { M, M, 0 }, { M-1, 0, 1 } },
79 { M, { M, M, 123 }, { M-1, 0, 124 } },
81 { 1, { M, M, M, 0 }, { 0, 0, 0, 1 } },
82 { 1, { M, M, M, 123 }, { 0, 0, 0, 124 } },
83 { 2, { M, M, M, 0 }, { 1, 0, 0, 1 } },
84 { 2, { M, M, M, 123 }, { 1, 0, 0, 124 } },
85 { M, { M, M, M, 0 }, { M-1, 0, 0, 1 } },
86 { M, { M, M, M, 123 }, { M-1, 0, 0, 124 } },
88 { 1, { M, M, M, M, 0 }, { 0, 0, 0, 0, 1 } },
89 { 1, { M, M, M, M, 123 }, { 0, 0, 0, 0, 124 } },
90 { 2, { M, M, M, M, 0 }, { 1, 0, 0, 0, 1 } },
91 { 2, { M, M, M, M, 123 }, { 1, 0, 0, 0, 124 } },
92 { M, { M, M, M, M, 0 }, { M-1, 0, 0, 0, 1 } },
93 { M, { M, M, M, M, 123 }, { M-1, 0, 0, 0, 124
94 #if defined (__hpux) && ! defined (__GNUC__)
95 /* Some versions (at least HP92453-01 B.11.11.23709.GP) of the
96 HP C compilers fail to zero-fill aggregates as the ISO C standard
97 requires (cf 6.5.7 Initialization). Compensate here: */
106 for (i = 0; i < numberof (data); i++)
108 refmpn_copyi (got, data[i].src, SIZE);
109 MPN_INCR_U (got, SIZE, data[i].n);
110 check_one ("check_incr (general)", i,
111 data[i].src, data[i].n,
112 got, data[i].want, SIZE);
116 refmpn_copyi (got, data[i].src, SIZE);
117 MPN_INCR_U (got, SIZE, CNST_LIMB(1));
118 check_one ("check_incr (const 1)", i,
119 data[i].src, data[i].n,
120 got, data[i].want, SIZE);
126 check_decr_data (void)
128 static const struct {
130 const mp_limb_t src[SIZE];
131 const mp_limb_t want[SIZE];
134 { 1, { 123 }, { 122 } },
135 { 1, { M }, { M-1 } },
137 { 2, { 123 }, { 121 } },
139 { M-1, { M }, { 1 } },
141 { 1, { 0, 1 }, { M, 0 } },
142 { 1, { 0, 123 }, { M, 122 } },
143 { 1, { 0, M }, { M, M-1 } },
144 { 2, { 0, 123 }, { M-1, 122 } },
145 { 2, { 1, 123 }, { M, 122 } },
146 { M, { 0, 123 }, { 1, 122 } },
147 { M, { M-1, M }, { M, M-1 } },
149 { 1, { 0, 0, 1 }, { M, M, 0 } },
150 { 1, { 0, 0, 123 }, { M, M, 122 } },
151 { 1, { 0, 0, M }, { M, M, M-1 } },
152 { 2, { 0, 0, 123 }, { M-1, M, 122 } },
153 { 2, { 1, 0, 123 }, { M, M, 122 } },
154 { M, { 0, 0, 123 }, { 1, M, 122 } },
155 { M, { M-1, 0, M }, { M, M, M-1 } },
157 { 1, { 0, 0, 0, 1 }, { M, M, M, 0 } },
158 { 1, { 0, 0, 0, 123 }, { M, M, M, 122 } },
159 { 1, { 0, 0, 0, M }, { M, M, M, M-1 } },
160 { 2, { 0, 0, 0, 123 }, { M-1, M, M, 122 } },
161 { 2, { 1, 0, 0, 123 }, { M, M, M, 122 } },
162 { M, { 0, 0, 0, 123 }, { 1, M, M, 122 } },
163 { M, { M-1, 0, 0, M }, { M, M, M, M-1 } },
165 { 1, { 0, 0, 0, 0, 1 }, { M, M, M, M, 0 } },
166 { 1, { 0, 0, 0, 0, 123 }, { M, M, M, M, 122 } },
167 { 1, { 0, 0, 0, 0, M }, { M, M, M, M, M-1 } },
168 { 2, { 0, 0, 0, 0, 123 }, { M-1, M, M, M, 122 } },
169 { 2, { 1, 0, 0, 0, 123 }, { M, M, M, M, 122 } },
170 { M, { 0, 0, 0, 0, 123 }, { 1, M, M, M, 122 } },
171 { M, { M-1, 0, 0, 0, M }, { M, M, M, M, M-1 } },
173 { 1, { 0, 0, 0, 0, 0, 1 }, { M, M, M, M, M, 0 } },
174 { 1, { 0, 0, 0, 0, 0, 123 }, { M, M, M, M, M, 122 } },
175 { 1, { 0, 0, 0, 0, 0, M }, { M, M, M, M, M, M-1 } },
176 { 2, { 0, 0, 0, 0, 0, 123 }, { M-1, M, M, M, M, 122 } },
177 { 2, { 1, 0, 0, 0, 0, 123 }, { M, M, M, M, M, 122 } },
178 { M, { 0, 0, 0, 0, 0, 123 }, { 1, M, M, M, M, 122 } },
179 { M, { M-1, 0, 0, 0, 0, M }, { M, M, M, M, M, M-1
180 #if defined (__hpux) && ! defined (__GNUC__)
181 /* For explanation of this garbage, see previous function. */
190 for (i = 0; i < numberof (data); i++)
192 refmpn_copyi (got, data[i].src, SIZE);
193 MPN_DECR_U (got, SIZE, data[i].n);
194 check_one ("check_decr_data", i,
195 data[i].src, data[i].n,
196 got, data[i].want, SIZE);
200 refmpn_copyi (got, data[i].src, SIZE);
201 MPN_DECR_U (got, SIZE, CNST_LIMB(1));
202 check_one ("check_decr (const 1)", i,
203 data[i].src, data[i].n,
204 got, data[i].want, SIZE);