Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/poly-int-tests.h

raw
1 /* This file contains templated tests that are then instantiated in
2 multiple plugin tests, in order to reduce the size of each test. */
3
4 #define ASSERT_FALSE(X) gcc_assert (!(X))
5 #define ASSERT_TRUE(X) gcc_assert (X)
6 #define ASSERT_EQ(X, Y) gcc_assert ((X) == (Y))
7 #define ASSERT_KNOWN_EQ(X, Y) gcc_assert (known_eq (X, Y))
8 #define ASSERT_MAYBE_NE(X, Y) gcc_assert (maybe_ne (X, Y))
9
10 /* make (X) converts an X of type int into T, using an arbitrary
11 precision for wide_int. It passes other types of X through as-is. */
12 template<typename T>
13 struct coeff_helper
14 {
15 static inline const T &make (const T &x) { return x; }
16 };
17
18 template<>
19 struct coeff_helper<wide_int>
20 {
21 template<typename T>
22 static inline const T &make (const T &x) { return x; }
23 static inline wide_int make (int i) { return wi::shwi (i, 77); }
24 };
25
26 /* make (C1, C2, C3) constructs a T using coefficients from C1, C2 and C3,
27 picking only enough to fill the T. */
28 template<typename T>
29 struct poly_helper
30 {
31 typedef typename poly_int_traits<T>::coeff_type C;
32 template<typename T1, typename T2, typename T3>
33 static T make (const T1 &a, const T2 &b, const T3 &c);
34 };
35
36 template<typename T>
37 template<typename T1, typename T2, typename T3>
38 inline T
39 poly_helper<T>::make (const T1 &a, const T2 &b, const T3 &c)
40 {
41 T res;
42 res = coeff_helper<C>::make (a);
43 if (poly_int_traits<T>::num_coeffs >= 2)
44 res.coeffs[1] = coeff_helper<C>::make (b);
45 if (poly_int_traits<T>::num_coeffs >= 3)
46 res.coeffs[2] = coeff_helper<C>::make (c);
47 return res;
48 }
49
50 /* Test the helper, */
51
52 static void
53 test_helper ()
54 {
55 typedef poly_helper< poly_int<1, int> > p1;
56 typedef poly_helper< poly_int<2, int> > p2;
57 typedef poly_helper< poly_int<3, int> > p3;
58
59 ASSERT_MAYBE_NE (p1::make (1, 2, 3), 0);
60 ASSERT_KNOWN_EQ (p1::make (1, 2, 3) - p1::make (1, 0, 0), 0);
61 ASSERT_KNOWN_EQ (p1::make (1, 2, 3) - p1::make (1, 2, 0), 0);
62 ASSERT_KNOWN_EQ (p1::make (1, 2, 3) - p1::make (1, 2, 3), 0);
63
64 ASSERT_MAYBE_NE (p2::make (1, 2, 3), 0);
65 ASSERT_MAYBE_NE (p2::make (1, 2, 3) - p2::make (1, 0, 0), 0);
66 ASSERT_KNOWN_EQ (p2::make (1, 2, 3) - p2::make (1, 2, 0), 0);
67 ASSERT_KNOWN_EQ (p2::make (1, 2, 3) - p2::make (1, 2, 3), 0);
68
69 ASSERT_MAYBE_NE (p3::make (1, 2, 3), 0);
70 ASSERT_MAYBE_NE (p3::make (1, 2, 3) - p3::make (1, 0, 0), 0);
71 ASSERT_MAYBE_NE (p3::make (1, 2, 3) - p3::make (1, 2, 0), 0);
72 ASSERT_KNOWN_EQ (p3::make (1, 2, 3) - p3::make (1, 2, 3), 0);
73 }
74
75 /* Test poly_coeff_traits. */
76
77 static void
78 test_poly_coeff_traits ()
79 {
80 ASSERT_EQ (poly_coeff_traits<unsigned short>::signedness, 0);
81 ASSERT_EQ (poly_coeff_traits<unsigned short>::max_value, 0xffff);
82
83 ASSERT_EQ (poly_coeff_traits<int>::signedness, 1);
84 ASSERT_EQ (poly_coeff_traits<int>::max_value, INT_MAX);
85
86 ASSERT_EQ (poly_coeff_traits<unsigned int>::signedness, 0);
87 ASSERT_EQ (poly_coeff_traits<unsigned int>::max_value, UINT_MAX);
88
89 ASSERT_EQ (poly_coeff_traits<HOST_WIDE_INT>::signedness, 1);
90 ASSERT_EQ (poly_coeff_traits<HOST_WIDE_INT>::max_value, HOST_WIDE_INT_MAX);
91
92 ASSERT_EQ (poly_coeff_traits<unsigned HOST_WIDE_INT>::signedness, 0);
93 ASSERT_EQ (poly_coeff_traits<unsigned HOST_WIDE_INT>::max_value,
94 HOST_WIDE_INT_M1U);
95
96 ASSERT_EQ (poly_coeff_traits<wide_int>::signedness, -1);
97 ASSERT_EQ (poly_coeff_traits<offset_int>::signedness, 1);
98 ASSERT_EQ (poly_coeff_traits<widest_int>::signedness, 1);
99 }
100
101 /* Test poly_int_traits. */
102
103 template<unsigned int N, typename C, typename T>
104 static void
105 test_poly_int_traits ()
106 {
107 /* Check the properties of poly_int_traits<C>. */
108 ASSERT_FALSE (poly_int_traits<C>::is_poly);
109 ASSERT_EQ (poly_int_traits<C>::num_coeffs, 1);
110 ASSERT_EQ ((C *) 0 - (typename poly_int_traits<C>::coeff_type *) 0, 0);
111
112 /* Check the properties of poly_int_traits<T>. */
113 ASSERT_TRUE (poly_int_traits<T>::is_poly);
114 ASSERT_EQ (poly_int_traits<T>::num_coeffs, N);
115 ASSERT_EQ ((C *) 0 - (typename poly_int_traits<T>::coeff_type *) 0, 0);
116 }
117
118 /* Test the handling of constants. */
119
120 template<unsigned int N, typename C, typename T>
121 static void
122 test_constants ()
123 {
124 typedef coeff_helper<C> ch;
125 T zero, one, two;
126 poly_int<N, unsigned char> two_uc = 2;
127
128 /* Test operator = on C. */
129 zero = ch::make (0);
130 one = ch::make (1);
131 two = ch::make (2);
132
133 /* Basic tests of known_eq and maybe_ne. */
134 ASSERT_KNOWN_EQ (zero, ch::make (0));
135 ASSERT_MAYBE_NE (one, ch::make (0));
136 ASSERT_MAYBE_NE (two, ch::make (0));
137 ASSERT_KNOWN_EQ (ch::make (0), zero);
138 ASSERT_MAYBE_NE (ch::make (0), one);
139 ASSERT_MAYBE_NE (ch::make (0), two);
140 ASSERT_KNOWN_EQ (zero, zero);
141 ASSERT_MAYBE_NE (one, zero);
142 ASSERT_MAYBE_NE (two, zero);
143
144 ASSERT_MAYBE_NE (zero, ch::make (1));
145 ASSERT_KNOWN_EQ (one, ch::make (1));
146 ASSERT_MAYBE_NE (two, ch::make (1));
147 ASSERT_MAYBE_NE (ch::make (1), zero);
148 ASSERT_KNOWN_EQ (ch::make (1), one);
149 ASSERT_MAYBE_NE (ch::make (1), two);
150 ASSERT_MAYBE_NE (zero, one);
151 ASSERT_KNOWN_EQ (one, one);
152 ASSERT_MAYBE_NE (two, one);
153
154 ASSERT_MAYBE_NE (zero, ch::make (2));
155 ASSERT_MAYBE_NE (one, ch::make (2));
156 ASSERT_KNOWN_EQ (two, ch::make (2));
157 ASSERT_MAYBE_NE (ch::make (2), zero);
158 ASSERT_MAYBE_NE (ch::make (2), one);
159 ASSERT_KNOWN_EQ (ch::make (2), two);
160 ASSERT_MAYBE_NE (zero, two);
161 ASSERT_MAYBE_NE (one, two);
162 ASSERT_KNOWN_EQ (two, two);
163
164 ASSERT_MAYBE_NE (zero, two_uc);
165 ASSERT_MAYBE_NE (one, two_uc);
166 ASSERT_KNOWN_EQ (two, two_uc);
167 ASSERT_MAYBE_NE (two_uc, zero);
168 ASSERT_MAYBE_NE (two_uc, one);
169 ASSERT_KNOWN_EQ (two_uc, two);
170 }
171
172 /* Test operator +=. */
173
174 template<unsigned int N, typename C, typename T>
175 static void
176 test_plus_equals ()
177 {
178 typedef poly_helper<T> ph;
179
180 /* Test += on int. */
181 T add_cm = ph::make (17, 11, 9);
182 add_cm += 14;
183 ASSERT_KNOWN_EQ (add_cm, ph::make (31, 11, 9));
184
185 /* Test += on T. */
186 T add_pm = ph::make (100, 44, 11);
187 add_pm += ph::make (1, 2, 3);
188 ASSERT_KNOWN_EQ (add_pm, ph::make (101, 46, 14));
189 }
190
191 /* Test operator -=. */
192
193 template<unsigned int N, typename C, typename T>
194 static void
195 test_minus_equals ()
196 {
197 typedef poly_helper<T> ph;
198
199 /* Test -= on int. */
200 T sub_cm = ph::make (82, 13, 61);
201 sub_cm -= 76;
202 ASSERT_KNOWN_EQ (sub_cm, ph::make (6, 13, 61));
203
204 /* Test -= on T. */
205 T sub_pm = ph::make (82, 13, 61);
206 sub_pm -= ph::make (19, 12, 14);
207 ASSERT_KNOWN_EQ (sub_pm, ph::make (63, 1, 47));
208 }
209
210 /* Test operator *=. */
211
212 template<unsigned int N, typename C, typename T>
213 static void
214 test_times_equals ()
215 {
216 typedef poly_helper<T> ph;
217
218 /* Test *= on int. */
219 T mul_cm = ph::make (11, 22, 33);
220 mul_cm *= 3;
221 ASSERT_KNOWN_EQ (mul_cm, ph::make (33, 66, 99));
222 }
223
224 /* Test operator <<=. */
225
226 template<unsigned int N, typename C, typename T>
227 static void
228 test_shl_equals ()
229 {
230 typedef poly_helper<T> ph;
231
232 /* Test <<= on int. */
233 T shl_cm = ph::make (10, 11, 13);
234 shl_cm <<= 2;
235 ASSERT_KNOWN_EQ (shl_cm, ph::make (40, 44, 52));
236 }
237
238 /* Test is_constant. */
239
240 template<unsigned int N, typename C, typename T>
241 static void
242 test_is_constant ()
243 {
244 typedef poly_helper<T> ph;
245
246 /* Test is_constant without arguments. */
247 ASSERT_TRUE (ph::make (1, 0, 0).is_constant ());
248 ASSERT_EQ (ph::make (2, 0, 1).is_constant (), N <= 2);
249 ASSERT_EQ (ph::make (3, 1, 0).is_constant (), N == 1);
250
251 /* Test is_constant with an argument. */
252 C const_value;
253 ASSERT_TRUE (ph::make (1, 0, 0).is_constant (&const_value));
254 ASSERT_EQ (const_value, 1);
255 ASSERT_EQ (ph::make (2, 0, 1).is_constant (&const_value), N <= 2);
256 ASSERT_EQ (const_value, N <= 2 ? 2 : 1);
257 ASSERT_EQ (ph::make (3, 1, 0).is_constant (&const_value), N == 1);
258 ASSERT_EQ (const_value, 4 - N);
259 }
260
261 /* Test to_constant. */
262
263 template<unsigned int N, typename C, typename T>
264 static void
265 test_to_constant ()
266 {
267 typedef poly_helper<T> ph;
268
269 ASSERT_TRUE (ph::make (1, 0, 0).to_constant () == 1);
270 ASSERT_TRUE (ph::make (111, 0, 0).to_constant () == 111);
271 }
272
273 /* Test addition, both via operators and wi::. */
274
275 template<unsigned int N, typename C, typename T>
276 static void
277 test_addition ()
278 {
279 typedef poly_helper<T> ph;
280
281 /* Test +. */
282 ASSERT_KNOWN_EQ (ph::make (55, 43, 30) + 1,
283 ph::make (56, 43, 30));
284 ASSERT_KNOWN_EQ (100 + ph::make (5, 15, 26),
285 ph::make (105, 15, 26));
286 ASSERT_KNOWN_EQ (ph::make (7, 100, 41) + ph::make (96, 9, 21),
287 ph::make (103, 109, 62));
288
289 /* Test wi::add. */
290 ASSERT_KNOWN_EQ (wi::add (ph::make (55, 43, 30), 1),
291 ph::make (56, 43, 30));
292 ASSERT_KNOWN_EQ (wi::add (100, ph::make (5, 15, 26)),
293 ph::make (105, 15, 26));
294 ASSERT_KNOWN_EQ (wi::add (ph::make (7, 100, 41), ph::make (96, 9, 21)),
295 ph::make (103, 109, 62));
296 }
297
298 /* Test subtraction, both via operators and wi::. */
299
300 template<unsigned int N, typename C, typename RC, typename T>
301 static void
302 test_subtraction ()
303 {
304 typedef poly_helper<T> ph;
305 typedef poly_helper< poly_int<N, RC> > rph;
306 typedef poly_helper< poly_int<N, int> > iph;
307
308 /* Test -. Cs with a rank lower than HOST_WIDE_INT promote to
309 HOST_WIDE_INT; use rph to capture this. */
310 ASSERT_KNOWN_EQ (ph::make (64, 49, 36) - 42,
311 rph::make (22, 49, 36));
312 ASSERT_KNOWN_EQ (11 - ph::make (9, 3, 4),
313 rph::make (2, -3, -4));
314 ASSERT_KNOWN_EQ (ph::make (100, 200, 300) - ph::make (99, 197, 305),
315 rph::make (1, 3, -5));
316
317 /* Test wi::sub. Primitive Cs promote to widest_int; use iph to capture
318 this. */
319 ASSERT_KNOWN_EQ (wi::sub (ph::make (64, 49, 36), 42),
320 iph::make (22, 49, 36));
321 ASSERT_KNOWN_EQ (wi::sub (11, ph::make (9, 3, 4)),
322 iph::make (2, -3, -4));
323 ASSERT_KNOWN_EQ (wi::sub (ph::make (100, 200, 300), ph::make (99, 197, 305)),
324 iph::make (1, 3, -5));
325 }
326
327 /* Test negation, both via operators and wi::. */
328
329 template<unsigned int N, typename C, typename RC, typename T>
330 static void
331 test_negation ()
332 {
333 typedef poly_helper<T> ph;
334 typedef poly_helper< poly_int<N, RC> > rph;
335 typedef poly_helper< poly_int<N, int> > iph;
336
337 /* Test unary -. */
338 ASSERT_KNOWN_EQ (-ph::make (10, 20, 30),
339 rph::make (-10, -20, -30));
340
341 /* Test wi::neg. */
342 ASSERT_KNOWN_EQ (wi::neg (ph::make (10, 20, 30)),
343 iph::make (-10, -20, -30));
344 }
345
346 /* Test multiplication, both via operators and wi::. */
347
348 template<unsigned int N, typename C, typename T>
349 static void
350 test_multiplication ()
351 {
352 typedef poly_helper<T> ph;
353
354 /* Test *. */
355 ASSERT_KNOWN_EQ (ph::make (5, 20, 25) * 10,
356 ph::make (50, 200, 250));
357 ASSERT_KNOWN_EQ (111 * ph::make (7, 6, 5),
358 ph::make (777, 666, 555));
359
360 /* Test wi::mul. */
361 ASSERT_KNOWN_EQ (wi::mul (ph::make (5, 20, 25), 10),
362 ph::make (50, 200, 250));
363 ASSERT_KNOWN_EQ (wi::mul (111, ph::make (7, 6, 5)),
364 ph::make (777, 666, 555));
365 }
366
367 /* Test shift left, both via operators and wi::. */
368
369 template<unsigned int N, typename C, typename T>
370 static void
371 test_shift_left ()
372 {
373 typedef poly_helper<T> ph;
374
375 /* Test <<. */
376 ASSERT_KNOWN_EQ (ph::make (1, 20, 300) << 4,
377 ph::make (16, 320, 4800));
378
379 /* Test wi::lshift. */
380 ASSERT_KNOWN_EQ (wi::lshift (ph::make (9, 15, 50), 3),
381 ph::make (72, 120, 400));
382 }
383
384 /* Test maybe_ne. */
385
386 template<unsigned int N, typename C, typename T>
387 static void
388 test_maybe_ne ()
389 {
390 typedef coeff_helper<C> ch;
391 typedef poly_helper<T> ph;
392
393 /* Test maybe_ne (T, C). */
394 ASSERT_EQ (maybe_ne (ph::make (1, 0, 2), ch::make (1)), N == 3);
395 ASSERT_EQ (maybe_ne (ph::make (-11, -2, 0), ch::make (-11)), N >= 2);
396 ASSERT_TRUE (maybe_ne (ph::make (199, 0, 0), ch::make (200)));
397
398 /* Test maybe_ne (C, T). */
399 ASSERT_EQ (maybe_ne (ch::make (-22), ph::make (-22, 0, -1)), N == 3);
400 ASSERT_EQ (maybe_ne (ch::make (5), ph::make (5, 4, 0)), N >= 2);
401 ASSERT_TRUE (maybe_ne (ch::make (-3), ph::make (-4, 0, 0)));
402
403 /* Test maybe_ne (T, T). */
404 ASSERT_EQ (maybe_ne (ph::make (1, 3, 5),
405 ph::make (1, 3, 6)), N == 3);
406 ASSERT_EQ (maybe_ne (ph::make (1, 3, 5),
407 ph::make (1, 4, 5)), N >= 2);
408 ASSERT_TRUE (maybe_ne (ph::make (1, 3, 5),
409 ph::make (0, 3, 5)));
410 }
411
412 /* Test known_eq. */
413
414 template<unsigned int N, typename C, typename T>
415 static void
416 test_known_eq ()
417 {
418 typedef coeff_helper<C> ch;
419 typedef poly_helper<T> ph;
420
421 /* Test known_eq (T, C). */
422 ASSERT_EQ (known_eq (ph::make (1, 0, 2), ch::make (1)), N <= 2);
423 ASSERT_EQ (known_eq (ph::make (-11, -2, 0), ch::make (-11)), N == 1);
424 ASSERT_FALSE (known_eq (ph::make (199, 0, 0), ch::make (200)));
425
426 /* Test known_eq (C, T). */
427 ASSERT_EQ (known_eq (ch::make (-22), ph::make (-22, 0, -1)), N <= 2);
428 ASSERT_EQ (known_eq (ch::make (5), ph::make (5, 4, 0)), N == 1);
429 ASSERT_FALSE (known_eq (ch::make (-3), ph::make (-4, 0, 0)));
430
431 /* Test known_eq (T, T). */
432 ASSERT_EQ (known_eq (ph::make (1, 3, 5),
433 ph::make (1, 3, 6)), N <= 2);
434 ASSERT_EQ (known_eq (ph::make (1, 3, 5),
435 ph::make (1, 4, 5)), N == 1);
436 ASSERT_FALSE (known_eq (ph::make (1, 3, 5),
437 ph::make (0, 3, 5)));
438 }
439
440 /* Test can_align_p. */
441
442 template<unsigned int N, typename C, typename T>
443 static void
444 test_can_align_p ()
445 {
446 typedef poly_helper<T> ph;
447
448 ASSERT_TRUE (can_align_p (ph::make (41, 32, 16), 16));
449 ASSERT_EQ (can_align_p (ph::make (15, 64, 8), 16), N <= 2);
450 ASSERT_EQ (can_align_p (ph::make (17, 8, 80), 16), N == 1);
451 ASSERT_TRUE (can_align_p (ph::make (-39, -64, -32), 32));
452 ASSERT_EQ (can_align_p (ph::make (-32, -96, -31), 32), N <= 2);
453 ASSERT_EQ (can_align_p (ph::make (-31, -31, -128), 32), N == 1);
454 ASSERT_TRUE (can_align_p (ph::make (17, 0, 0), 16));
455 ASSERT_TRUE (can_align_p (ph::make (16, 0, 0), 16));
456 ASSERT_TRUE (can_align_p (ph::make (15, 0, 0), 16));
457 ASSERT_TRUE (can_align_p (ph::make (-17, 0, 0), 16));
458 ASSERT_TRUE (can_align_p (ph::make (-16, 0, 0), 16));
459 ASSERT_TRUE (can_align_p (ph::make (-15, 0, 0), 16));
460 }
461
462 /* Test can_align_up. */
463
464 template<unsigned int N, typename C, typename T>
465 static void
466 test_can_align_up ()
467 {
468 typedef coeff_helper<C> ch;
469 typedef poly_helper<T> ph;
470
471 T aligned;
472 ASSERT_TRUE (can_align_up (ph::make (41, 32, 16), 16, &aligned));
473 ASSERT_KNOWN_EQ (aligned, ph::make (48, 32, 16));
474 ASSERT_EQ (can_align_up (ph::make (15, 64, 8), 16, &aligned), N <= 2);
475 if (N <= 2)
476 ASSERT_KNOWN_EQ (aligned, ph::make (16, 64, 0));
477 ASSERT_EQ (can_align_up (ph::make (17, 8, 80), 16, &aligned), N == 1);
478 if (N == 1)
479 ASSERT_KNOWN_EQ (aligned, ch::make (32));
480 ASSERT_TRUE (can_align_up (ph::make (-39, -64, -32), 32, &aligned));
481 ASSERT_KNOWN_EQ (aligned, ph::make (-32, -64, -32));
482 ASSERT_EQ (can_align_up (ph::make (-32, -96, -31), 32, &aligned), N <= 2);
483 if (N <= 2)
484 ASSERT_KNOWN_EQ (aligned, ph::make (-32, -96, 0));
485 ASSERT_EQ (can_align_up (ph::make (-31, -31, -128), 32, &aligned), N == 1);
486 if (N == 1)
487 ASSERT_KNOWN_EQ (aligned, ch::make (0));
488 ASSERT_TRUE (can_align_up (ph::make (17, 0, 0), 16, &aligned));
489 ASSERT_KNOWN_EQ (aligned, ch::make (32));
490 ASSERT_TRUE (can_align_up (ph::make (16, 0, 0), 16, &aligned));
491 ASSERT_KNOWN_EQ (aligned, ch::make (16));
492 ASSERT_TRUE (can_align_up (ph::make (15, 0, 0), 16, &aligned));
493 ASSERT_KNOWN_EQ (aligned, ch::make (16));
494 ASSERT_TRUE (can_align_up (ph::make (-17, 0, 0), 16, &aligned));
495 ASSERT_KNOWN_EQ (aligned, ch::make (-16));
496 ASSERT_TRUE (can_align_up (ph::make (-16, 0, 0), 16, &aligned));
497 ASSERT_KNOWN_EQ (aligned, ch::make (-16));
498 ASSERT_TRUE (can_align_up (ph::make (-15, 0, 0), 16, &aligned));
499 ASSERT_KNOWN_EQ (aligned, ch::make (0));
500 }
501
502 /* Test can_align_down. */
503
504 template<unsigned int N, typename C, typename T>
505 static void
506 test_can_align_down ()
507 {
508 typedef coeff_helper<C> ch;
509 typedef poly_helper<T> ph;
510
511 T aligned;
512 ASSERT_TRUE (can_align_down (ph::make (41, 32, 16), 16, &aligned));
513 ASSERT_KNOWN_EQ (aligned, ph::make (32, 32, 16));
514 ASSERT_EQ (can_align_down (ph::make (15, 64, 8), 16, &aligned), N <= 2);
515 if (N <= 2)
516 ASSERT_KNOWN_EQ (aligned, ph::make (0, 64, 0));
517 ASSERT_EQ (can_align_down (ph::make (17, 8, 80), 16, &aligned), N == 1);
518 if (N == 1)
519 ASSERT_KNOWN_EQ (aligned, ch::make (16));
520 ASSERT_TRUE (can_align_down (ph::make (-39, -64, -32), 32, &aligned));
521 ASSERT_KNOWN_EQ (aligned, ph::make (-64, -64, -32));
522 ASSERT_EQ (can_align_down (ph::make (-32, -96, -31), 32, &aligned), N <= 2);
523 if (N <= 2)
524 ASSERT_KNOWN_EQ (aligned, ph::make (-32, -96, 0));
525 ASSERT_EQ (can_align_down (ph::make (-31, -31, -128), 32, &aligned), N == 1);
526 if (N == 1)
527 ASSERT_KNOWN_EQ (aligned, ch::make (-32));
528 ASSERT_TRUE (can_align_down (ph::make (17, 0, 0), 16, &aligned));
529 ASSERT_KNOWN_EQ (aligned, ch::make (16));
530 ASSERT_TRUE (can_align_down (ph::make (16, 0, 0), 16, &aligned));
531 ASSERT_KNOWN_EQ (aligned, ch::make (16));
532 ASSERT_TRUE (can_align_down (ph::make (15, 0, 0), 16, &aligned));
533 ASSERT_KNOWN_EQ (aligned, ch::make (0));
534 ASSERT_TRUE (can_align_down (ph::make (-17, 0, 0), 16, &aligned));
535 ASSERT_KNOWN_EQ (aligned, ch::make (-32));
536 ASSERT_TRUE (can_align_down (ph::make (-16, 0, 0), 16, &aligned));
537 ASSERT_KNOWN_EQ (aligned, ch::make (-16));
538 ASSERT_TRUE (can_align_down (ph::make (-15, 0, 0), 16, &aligned));
539 ASSERT_KNOWN_EQ (aligned, ch::make (-16));
540 }
541
542 /* Test known_equal_after_align_up. */
543
544 template<unsigned int N, typename C, typename T>
545 static void
546 test_known_equal_after_align_up ()
547 {
548 typedef poly_helper<T> ph;
549
550 ASSERT_EQ (known_equal_after_align_up (ph::make (15, 15, 32),
551 ph::make (16, 15, 32), 16), N == 1);
552 ASSERT_EQ (known_equal_after_align_up (ph::make (16, 16, 15),
553 ph::make (15, 16, 15), 16), N <= 2);
554 ASSERT_EQ (known_equal_after_align_up (ph::make (15, 16, 32),
555 ph::make (7, 16, 48), 16), N <= 2);
556 ASSERT_EQ (known_equal_after_align_up (ph::make (7, 32, 16),
557 ph::make (15, 48, 16), 16), N == 1);
558 ASSERT_TRUE (known_equal_after_align_up (ph::make (16, 16, 32),
559 ph::make (15, 16, 32), 16));
560 ASSERT_TRUE (known_equal_after_align_up (ph::make (32, 0, 0),
561 ph::make (31, 0, 0), 16));
562 ASSERT_TRUE (known_equal_after_align_up (ph::make (32, 0, 0),
563 ph::make (32, 0, 0), 32));
564 ASSERT_FALSE (known_equal_after_align_up (ph::make (32, 0, 0),
565 ph::make (33, 0, 0), 16));
566 ASSERT_FALSE (known_equal_after_align_up (ph::make (-31, 0, 0),
567 ph::make (-32, 0, 0), 16));
568 ASSERT_TRUE (known_equal_after_align_up (ph::make (-32, 0, 0),
569 ph::make (-32, 0, 0), 32));
570 ASSERT_TRUE (known_equal_after_align_up (ph::make (-33, 0, 0),
571 ph::make (-32, 0, 0), 16));
572 }
573
574 /* Test known_equal_after_align_down. */
575
576 template<unsigned int N, typename C, typename T>
577 static void
578 test_known_equal_after_align_down ()
579 {
580 typedef poly_helper<T> ph;
581
582 ASSERT_EQ (known_equal_after_align_down (ph::make (17, 15, 32),
583 ph::make (16, 15, 32), 16), N == 1);
584 ASSERT_EQ (known_equal_after_align_down (ph::make (16, 16, 15),
585 ph::make (17, 16, 15), 16), N <= 2);
586 ASSERT_EQ (known_equal_after_align_down (ph::make (15, 16, 32),
587 ph::make (7, 16, 48), 16), N <= 2);
588 ASSERT_EQ (known_equal_after_align_down (ph::make (15, 32, 16),
589 ph::make (7, 48, 16), 16), N == 1);
590 ASSERT_TRUE (known_equal_after_align_down (ph::make (16, 16, 32),
591 ph::make (17, 16, 32), 16));
592 ASSERT_FALSE (known_equal_after_align_down (ph::make (32, 0, 0),
593 ph::make (31, 0, 0), 16));
594 ASSERT_TRUE (known_equal_after_align_down (ph::make (32, 0, 0),
595 ph::make (32, 0, 0), 32));
596 ASSERT_TRUE (known_equal_after_align_down (ph::make (32, 0, 0),
597 ph::make (33, 0, 0), 16));
598 ASSERT_TRUE (known_equal_after_align_down (ph::make (-31, 0, 0),
599 ph::make (-32, 0, 0), 16));
600 ASSERT_TRUE (known_equal_after_align_down (ph::make (-32, 0, 0),
601 ph::make (-32, 0, 0), 32));
602 ASSERT_FALSE (known_equal_after_align_down (ph::make (-33, 0, 0),
603 ph::make (-32, 0, 0), 16));
604 }
605
606 /* Test force_align_up. */
607
608 template<unsigned int N, typename C, typename T>
609 static void
610 test_force_align_up ()
611 {
612 typedef coeff_helper<C> ch;
613 typedef poly_helper<T> ph;
614
615 /* Test force_align_up. */
616 ASSERT_KNOWN_EQ (force_align_up (ph::make (41, 32, 16), 16),
617 ph::make (48, 32, 16));
618 ASSERT_KNOWN_EQ (force_align_up (ph::make (-39, -64, -32), 32),
619 ph::make (-32, -64, -32));
620 ASSERT_KNOWN_EQ (force_align_up (ph::make (17, 0, 0), 16),
621 ch::make (32));
622 ASSERT_KNOWN_EQ (force_align_up (ph::make (16, 0, 0), 16),
623 ch::make (16));
624 ASSERT_KNOWN_EQ (force_align_up (ph::make (15, 0, 0), 16),
625 ch::make (16));
626 ASSERT_KNOWN_EQ (force_align_up (ph::make (-17, 0, 0), 16),
627 ch::make (-16));
628 ASSERT_KNOWN_EQ (force_align_up (ph::make (-16, 0, 0), 16),
629 ch::make (-16));
630 ASSERT_KNOWN_EQ (force_align_up (ph::make (-15, 0, 0), 16),
631 ch::make (0));
632 }
633
634 /* Test force_align_down. */
635
636 template<unsigned int N, typename C, typename T>
637 static void
638 test_force_align_down ()
639 {
640 typedef coeff_helper<C> ch;
641 typedef poly_helper<T> ph;
642
643 ASSERT_KNOWN_EQ (force_align_down (ph::make (41, 32, 16), 16),
644 ph::make (32, 32, 16));
645 ASSERT_KNOWN_EQ (force_align_down (ph::make (-39, -64, -32), 32),
646 ph::make (-64, -64, -32));
647 ASSERT_KNOWN_EQ (force_align_down (ph::make (17, 0, 0), 16),
648 ch::make (16));
649 ASSERT_KNOWN_EQ (force_align_down (ph::make (16, 0, 0), 16),
650 ch::make (16));
651 ASSERT_KNOWN_EQ (force_align_down (ph::make (15, 0, 0), 16),
652 ch::make (0));
653 ASSERT_KNOWN_EQ (force_align_down (ph::make (-17, 0, 0), 16),
654 ch::make (-32));
655 ASSERT_KNOWN_EQ (force_align_down (ph::make (-16, 0, 0), 16),
656 ch::make (-16));
657 ASSERT_KNOWN_EQ (force_align_down (ph::make (-15, 0, 0), 16),
658 ch::make (-16));
659 }
660
661 /* Test aligned_lower_bound. */
662
663 template<unsigned int N, typename C, typename T>
664 static void
665 test_aligned_lower_bound ()
666 {
667 typedef poly_helper<T> ph;
668
669 ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (17, 63, 33), 16),
670 ph::make (16, 48, 32));
671 ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (11, -33, 64), 32),
672 ph::make (0, -64, 64));
673 ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (-9, 16, -31), 8),
674 ph::make (-16, 16, -32));
675 ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (-8, -12, 16), 4),
676 ph::make (-8, -12, 16));
677 }
678
679 /* Test aligned_upper_bound. */
680
681 template<unsigned int N, typename C, typename T>
682 static void
683 test_aligned_upper_bound ()
684 {
685 typedef poly_helper<T> ph;
686
687 ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (17, 63, 33), 16),
688 ph::make (32, 64, 48));
689 ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (11, -33, 64), 32),
690 ph::make (32, -32, 64));
691 ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (-9, 16, -31), 8),
692 ph::make (-8, 16, -24));
693 ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (-8, -12, 16), 4),
694 ph::make (-8, -12, 16));
695 }
696
697 /* Test known_misalignment. */
698
699 template<unsigned int N, typename C, typename T>
700 static void
701 test_known_misalignment ()
702 {
703 typedef poly_helper<T> ph;
704
705 C misalignment;
706 ASSERT_TRUE (known_misalignment (ph::make (45, 8, 24), 8, &misalignment));
707 ASSERT_EQ (misalignment, 5);
708 ASSERT_EQ (known_misalignment (ph::make (17, 16, 23), 8, &misalignment),
709 N <= 2);
710 ASSERT_EQ (misalignment, N <= 2 ? 1 : 5);
711 ASSERT_EQ (known_misalignment (ph::make (31, 15, 0), 16, &misalignment),
712 N == 1);
713 ASSERT_EQ (misalignment, N == 1 ? 15 : N == 2 ? 1 : 5);
714 ASSERT_TRUE (known_misalignment (ph::make (-45, -8, -24), 8, &misalignment));
715 ASSERT_EQ (misalignment, 3);
716 ASSERT_TRUE (known_misalignment (ph::make (-11, 0, 0), 32, &misalignment));
717 ASSERT_EQ (misalignment, 21);
718 }
719
720 /* Test force_get_misalignment. */
721
722 template<unsigned int N, typename C, typename T>
723 static void
724 test_force_get_misalignment ()
725 {
726 typedef poly_helper<T> ph;
727
728 ASSERT_EQ (force_get_misalignment (ph::make (45, 8, 24), 8), 5);
729 ASSERT_EQ (force_get_misalignment (ph::make (17, 16, 24), 8), 1);
730 ASSERT_EQ (force_get_misalignment (ph::make (31, -16, 0), 16), 15);
731 ASSERT_EQ (force_get_misalignment (ph::make (-45, -8, -24), 8), 3);
732 ASSERT_EQ (force_get_misalignment (ph::make (-11, 0, 0), 32), 21);
733 }
734
735 /* Test known_alignment. */
736
737 template<unsigned int N, typename C, typename T>
738 static void
739 test_known_alignment ()
740 {
741 typedef poly_helper<T> ph;
742
743 ASSERT_EQ (known_alignment (ph::make (16, 24, 30)),
744 N == 1 ? 16 : N == 2 ? 8 : 2);
745 ASSERT_EQ (known_alignment (ph::make (30, 0, 31)),
746 N <= 2 ? 2 : 1);
747 ASSERT_EQ (known_alignment (ph::make (20, 16, 24)), 4);
748 ASSERT_EQ (known_alignment (ph::make (24, 0, 0)), 8);
749 ASSERT_EQ (known_alignment (ph::make (0, 0, 0)), 0);
750 ASSERT_EQ (known_alignment (ph::make (0, 12, 0)),
751 N == 1 ? 0 : 4);
752 ASSERT_EQ (known_alignment (ph::make (0, 12, 6)),
753 N == 1 ? 0 : N == 2 ? 4 : 2);
754 ASSERT_EQ (known_alignment (ph::make (-40, -80, -12)),
755 N <= 2 ? 8 : 4);
756 }
757
758 /* Test can_ior_p. */
759
760 template<unsigned int N, typename C, typename T>
761 static void
762 test_can_ior_p ()
763 {
764 typedef coeff_helper<C> ch;
765 typedef poly_helper<T> ph;
766
767 T ior;
768 ASSERT_TRUE (can_ior_p (ph::make (0x87, 0x60, 0xa0), 0x13, &ior));
769 ASSERT_KNOWN_EQ (ior, ph::make (0x97, 0x60, 0xa0));
770 ASSERT_EQ (can_ior_p (ph::make (9, 96, 48), 28, &ior), N <= 2);
771 if (N <= 2)
772 ASSERT_KNOWN_EQ (ior, ph::make (29, 96, 0));
773 ASSERT_EQ (can_ior_p (ph::make (0x81, 0x20, 0), 0x44, &ior), N == 1);
774 if (N == 1)
775 ASSERT_KNOWN_EQ (ior, ch::make (0xc5));
776 }
777
778 /* Test maybe_eq for poly_int<2, C>. */
779
780 template<typename C>
781 static void
782 test_maybe_eq_2 ()
783 {
784 typedef poly_int<2, C> T;
785
786 /* Test maybe_eq (T, C). */
787 ASSERT_TRUE (maybe_eq (T (1, 4), 41));
788 ASSERT_FALSE (maybe_eq (T (1, 4), 42));
789 ASSERT_FALSE (maybe_eq (T (1, 4), 40));
790 ASSERT_TRUE (maybe_eq (T (1, 4), 1));
791 ASSERT_FALSE (maybe_eq (T (1, 4), 0));
792 ASSERT_FALSE (maybe_eq (T (1, 4), 2));
793
794 /* Test maybe_eq (C, T). */
795 ASSERT_TRUE (maybe_eq (20, T (5, 3)));
796 ASSERT_FALSE (maybe_eq (21, T (5, 3)));
797 ASSERT_FALSE (maybe_eq (19, T (5, 3)));
798 ASSERT_TRUE (maybe_eq (5, T (5, 3)));
799 ASSERT_FALSE (maybe_eq (2, T (5, 3)));
800 ASSERT_FALSE (maybe_eq (6, T (5, 3)));
801
802 /* Test maybe_eq (T, T). */
803 ASSERT_TRUE (maybe_eq (T (2, 5), T (22, 3)));
804 ASSERT_FALSE (maybe_eq (T (3, 5), T (22, 3)));
805 ASSERT_FALSE (maybe_eq (T (2, 5), T (23, 3)));
806 ASSERT_FALSE (maybe_eq (T (2, 5), T (3, 5)));
807 ASSERT_TRUE (maybe_eq (T (10, 3), T (19, 0)));
808 ASSERT_FALSE (maybe_eq (T (10, 3), T (20, 0)));
809 ASSERT_TRUE (maybe_eq (T (10, 0), T (4, 2)));
810 ASSERT_FALSE (maybe_eq (T (11, 0), T (4, 2)));
811 }
812
813 /* Test known_ne for poly_int<2, C>. */
814
815 template<typename C>
816 static void
817 test_known_ne_2 ()
818 {
819 typedef poly_int<2, C> T;
820
821 /* Test known_ne (T, C). */
822 ASSERT_FALSE (known_ne (T (1, 4), 41));
823 ASSERT_TRUE (known_ne (T (1, 4), 42));
824 ASSERT_TRUE (known_ne (T (1, 4), 40));
825 ASSERT_FALSE (known_ne (T (1, 4), 1));
826 ASSERT_TRUE (known_ne (T (1, 4), 0));
827 ASSERT_TRUE (known_ne (T (1, 4), 2));
828
829 /* Test known_ne (C, T). */
830 ASSERT_FALSE (known_ne (20, T (5, 3)));
831 ASSERT_TRUE (known_ne (21, T (5, 3)));
832 ASSERT_TRUE (known_ne (19, T (5, 3)));
833 ASSERT_FALSE (known_ne (5, T (5, 3)));
834 ASSERT_TRUE (known_ne (2, T (5, 3)));
835 ASSERT_TRUE (known_ne (6, T (5, 3)));
836
837 /* Test known_ne (T, T). */
838 ASSERT_FALSE (known_ne (T (2, 5), T (22, 3)));
839 ASSERT_TRUE (known_ne (T (3, 5), T (22, 3)));
840 ASSERT_TRUE (known_ne (T (2, 5), T (23, 3)));
841 ASSERT_TRUE (known_ne (T (2, 5), T (3, 5)));
842 ASSERT_FALSE (known_ne (T (10, 3), T (19, 0)));
843 ASSERT_TRUE (known_ne (T (10, 3), T (20, 0)));
844 ASSERT_FALSE (known_ne (T (10, 0), T (4, 2)));
845 ASSERT_TRUE (known_ne (T (11, 0), T (4, 2)));
846 }
847
848 /* Test maybe_le for both signed and unsigned C. */
849
850 template<unsigned int N, typename C, typename T>
851 static void
852 test_maybe_le ()
853 {
854 typedef coeff_helper<C> ch;
855 typedef poly_helper<T> ph;
856
857 /* Test maybe_le (T, C). */
858 ASSERT_FALSE (maybe_le (ph::make (7, 5, 4), ch::make (6)));
859 ASSERT_FALSE (maybe_le (ph::make (7, 0, 0), ch::make (6)));
860 ASSERT_TRUE (maybe_le (ph::make (60, 1, 2), ch::make (60)));
861 ASSERT_TRUE (maybe_le (ph::make (60, 0, 0), ch::make (60)));
862 ASSERT_TRUE (maybe_le (ph::make (30, 9, 4), ch::make (31)));
863 ASSERT_TRUE (maybe_le (ph::make (30, 0, 0), ch::make (31)));
864
865 /* Test maybe_le (C, T). */
866 ASSERT_TRUE (maybe_le (ch::make (6), ph::make (7, 5, 4)));
867 ASSERT_TRUE (maybe_le (ch::make (6), ph::make (7, 0, 0)));
868 ASSERT_TRUE (maybe_le (ch::make (60), ph::make (60, 1, 2)));
869 ASSERT_TRUE (maybe_le (ch::make (60), ph::make (60, 0, 0)));
870 ASSERT_EQ (maybe_le (ch::make (31), ph::make (30, 9, 4)), N >= 2);
871 ASSERT_EQ (maybe_le (ch::make (31), ph::make (30, 0, 4)), N == 3);
872 ASSERT_FALSE (maybe_le (ch::make (31), ph::make (30, 0, 0)));
873
874 /* Test maybe_le (T, T). */
875 ASSERT_EQ (maybe_le (ph::make (3, 14, 99), ph::make (2, 15, 100)), N >= 2);
876 ASSERT_EQ (maybe_le (ph::make (3, 14, 99), ph::make (2, 13, 100)), N == 3);
877 ASSERT_EQ (maybe_le (ph::make (3, 14, 99), ph::make (2, 15, 98)), N >= 2);
878 ASSERT_FALSE (maybe_le (ph::make (3, 14, 99), ph::make (2, 14, 99)));
879 ASSERT_FALSE (maybe_le (ph::make (3, 14, 99), ph::make (2, 13, 98)));
880 ASSERT_TRUE (maybe_le (ph::make (2, 14, 99), ph::make (2, 15, 100)));
881 ASSERT_TRUE (maybe_le (ph::make (2, 14, 99), ph::make (2, 14, 99)));
882 ASSERT_TRUE (maybe_le (ph::make (2, 14, 99), ph::make (2, 13, 98)));
883 ASSERT_TRUE (maybe_le (ph::make (1, 14, 99), ph::make (2, 15, 100)));
884 ASSERT_TRUE (maybe_le (ph::make (1, 14, 99), ph::make (2, 14, 99)));
885 ASSERT_TRUE (maybe_le (ph::make (1, 14, 99), ph::make (2, 13, 98)));
886 }
887
888 /* Test maybe_lt for both signed and unsigned C. */
889
890 template<unsigned int N, typename C, typename T>
891 static void
892 test_maybe_lt ()
893 {
894 typedef coeff_helper<C> ch;
895 typedef poly_helper<T> ph;
896
897 /* Test maybe_lt (T, C). */
898 ASSERT_FALSE (maybe_lt (ph::make (7, 5, 4), ch::make (6)));
899 ASSERT_FALSE (maybe_lt (ph::make (7, 0, 0), ch::make (6)));
900 ASSERT_FALSE (maybe_lt (ph::make (60, 1, 2), ch::make (60)));
901 ASSERT_FALSE (maybe_lt (ph::make (60, 0, 0), ch::make (60)));
902 ASSERT_TRUE (maybe_lt (ph::make (30, 9, 4), ch::make (31)));
903 ASSERT_TRUE (maybe_lt (ph::make (30, 0, 0), ch::make (31)));
904
905 /* Test maybe_lt (C, T). */
906 ASSERT_TRUE (maybe_lt (ch::make (6), ph::make (7, 5, 4)));
907 ASSERT_TRUE (maybe_lt (ch::make (6), ph::make (7, 0, 0)));
908 ASSERT_EQ (maybe_lt (ch::make (60), ph::make (60, 1, 2)), N >= 2);
909 ASSERT_EQ (maybe_lt (ch::make (60), ph::make (60, 0, 2)), N == 3);
910 ASSERT_FALSE (maybe_lt (ch::make (60), ph::make (60, 0, 0)));
911 ASSERT_EQ (maybe_lt (ch::make (31), ph::make (30, 9, 4)), N >= 2);
912 ASSERT_EQ (maybe_lt (ch::make (31), ph::make (30, 0, 4)), N == 3);
913 ASSERT_FALSE (maybe_lt (ch::make (31), ph::make (30, 0, 0)));
914
915 /* Test maybe_lt (T, T). */
916 ASSERT_EQ (maybe_lt (ph::make (3, 14, 99), ph::make (2, 15, 100)), N >= 2);
917 ASSERT_EQ (maybe_lt (ph::make (3, 14, 99), ph::make (2, 13, 100)), N == 3);
918 ASSERT_EQ (maybe_lt (ph::make (3, 14, 99), ph::make (2, 15, 98)), N >= 2);
919 ASSERT_FALSE (maybe_lt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
920 ASSERT_FALSE (maybe_lt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
921 ASSERT_EQ (maybe_lt (ph::make (2, 14, 99), ph::make (2, 15, 100)), N >= 2);
922 ASSERT_EQ (maybe_lt (ph::make (2, 14, 99), ph::make (2, 13, 100)), N == 3);
923 ASSERT_EQ (maybe_lt (ph::make (2, 14, 99), ph::make (2, 15, 98)), N >= 2);
924 ASSERT_FALSE (maybe_lt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
925 ASSERT_FALSE (maybe_lt (ph::make (2, 14, 99), ph::make (2, 13, 98)));
926 ASSERT_TRUE (maybe_lt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
927 ASSERT_TRUE (maybe_lt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
928 ASSERT_TRUE (maybe_lt (ph::make (1, 14, 99), ph::make (2, 13, 98)));
929 }
930
931 /* Test maybe_ge for both signed and unsigned C. */
932
933 template<unsigned int N, typename C, typename T>
934 static void
935 test_maybe_ge ()
936 {
937 typedef coeff_helper<C> ch;
938 typedef poly_helper<T> ph;
939
940 /* Test maybe_ge (T, C). */
941 ASSERT_TRUE (maybe_ge (ph::make (7, 5, 4), ch::make (6)));
942 ASSERT_TRUE (maybe_ge (ph::make (7, 0, 0), ch::make (6)));
943 ASSERT_TRUE (maybe_ge (ph::make (60, 1, 2), ch::make (60)));
944 ASSERT_TRUE (maybe_ge (ph::make (60, 0, 0), ch::make (60)));
945 ASSERT_EQ (maybe_ge (ph::make (30, 9, 4), ch::make (31)), N >= 2);
946 ASSERT_EQ (maybe_ge (ph::make (30, 0, 4), ch::make (31)), N == 3);
947 ASSERT_FALSE (maybe_ge (ph::make (30, 0, 0), ch::make (31)));
948
949 /* Test maybe_ge (C, T). */
950 ASSERT_FALSE (maybe_ge (ch::make (6), ph::make (7, 5, 4)));
951 ASSERT_FALSE (maybe_ge (ch::make (6), ph::make (7, 0, 0)));
952 ASSERT_TRUE (maybe_ge (ch::make (60), ph::make (60, 1, 2)));
953 ASSERT_TRUE (maybe_ge (ch::make (60), ph::make (60, 0, 0)));
954 ASSERT_TRUE (maybe_ge (ch::make (31), ph::make (30, 9, 4)));
955 ASSERT_TRUE (maybe_ge (ch::make (31), ph::make (30, 0, 0)));
956
957 /* Test maybe_ge (T, T). */
958 ASSERT_TRUE (maybe_ge (ph::make (3, 14, 99), ph::make (2, 15, 100)));
959 ASSERT_TRUE (maybe_ge (ph::make (3, 14, 99), ph::make (2, 14, 99)));
960 ASSERT_TRUE (maybe_ge (ph::make (3, 14, 99), ph::make (2, 13, 98)));
961 ASSERT_TRUE (maybe_ge (ph::make (2, 14, 99), ph::make (2, 15, 100)));
962 ASSERT_TRUE (maybe_ge (ph::make (2, 14, 99), ph::make (2, 14, 99)));
963 ASSERT_TRUE (maybe_ge (ph::make (2, 14, 99), ph::make (2, 13, 98)));
964 ASSERT_FALSE (maybe_ge (ph::make (1, 14, 99), ph::make (2, 15, 100)));
965 ASSERT_FALSE (maybe_ge (ph::make (1, 14, 99), ph::make (2, 14, 99)));
966 ASSERT_EQ (maybe_ge (ph::make (1, 14, 99), ph::make (2, 15, 98)), N == 3);
967 ASSERT_EQ (maybe_ge (ph::make (1, 14, 99), ph::make (2, 13, 100)), N >= 2);
968 ASSERT_EQ (maybe_ge (ph::make (1, 14, 99), ph::make (2, 13, 98)), N >= 2);
969 }
970
971 /* Test maybe_gt for both signed and unsigned C. */
972
973 template<unsigned int N, typename C, typename T>
974 static void
975 test_maybe_gt ()
976 {
977 typedef coeff_helper<C> ch;
978 typedef poly_helper<T> ph;
979
980 /* Test maybe_gt (T, C). */
981 ASSERT_TRUE (maybe_gt (ph::make (7, 5, 4), ch::make (6)));
982 ASSERT_TRUE (maybe_gt (ph::make (7, 0, 0), ch::make (6)));
983 ASSERT_EQ (maybe_gt (ph::make (60, 1, 2), ch::make (60)), N >= 2);
984 ASSERT_EQ (maybe_gt (ph::make (60, 0, 2), ch::make (60)), N == 3);
985 ASSERT_FALSE (maybe_gt (ph::make (60, 0, 0), ch::make (60)));
986 ASSERT_EQ (maybe_gt (ph::make (30, 9, 4), ch::make (31)), N >= 2);
987 ASSERT_EQ (maybe_gt (ph::make (30, 0, 4), ch::make (31)), N == 3);
988 ASSERT_FALSE (maybe_gt (ph::make (30, 0, 0), ch::make (31)));
989
990 /* Test maybe_gt (C, T). */
991 ASSERT_FALSE (maybe_gt (ch::make (6), ph::make (7, 5, 4)));
992 ASSERT_FALSE (maybe_gt (ch::make (6), ph::make (7, 0, 0)));
993 ASSERT_FALSE (maybe_gt (ch::make (60), ph::make (60, 1, 2)));
994 ASSERT_FALSE (maybe_gt (ch::make (60), ph::make (60, 0, 0)));
995 ASSERT_TRUE (maybe_gt (ch::make (31), ph::make (30, 9, 4)));
996 ASSERT_TRUE (maybe_gt (ch::make (31), ph::make (30, 0, 0)));
997
998 /* Test maybe_gt (T, T). */
999 ASSERT_TRUE (maybe_gt (ph::make (3, 14, 99), ph::make (2, 15, 100)));
1000 ASSERT_TRUE (maybe_gt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
1001 ASSERT_TRUE (maybe_gt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
1002 ASSERT_FALSE (maybe_gt (ph::make (2, 14, 99), ph::make (2, 15, 100)));
1003 ASSERT_FALSE (maybe_gt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
1004 ASSERT_EQ (maybe_gt (ph::make (2, 14, 99), ph::make (2, 15, 98)), N == 3);
1005 ASSERT_EQ (maybe_gt (ph::make (2, 14, 99), ph::make (2, 13, 100)), N >= 2);
1006 ASSERT_EQ (maybe_gt (ph::make (2, 14, 99), ph::make (2, 13, 98)), N >= 2);
1007 ASSERT_FALSE (maybe_gt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
1008 ASSERT_FALSE (maybe_gt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
1009 ASSERT_EQ (maybe_gt (ph::make (1, 14, 99), ph::make (2, 15, 98)), N == 3);
1010 ASSERT_EQ (maybe_gt (ph::make (1, 14, 99), ph::make (2, 13, 100)), N >= 2);
1011 ASSERT_EQ (maybe_gt (ph::make (1, 14, 99), ph::make (2, 13, 98)), N >= 2);
1012 }
1013
1014 /* Test known_gt for both signed and unsigned C. */
1015
1016 template<unsigned int N, typename C, typename T>
1017 static void
1018 test_known_gt ()
1019 {
1020 typedef coeff_helper<C> ch;
1021 typedef poly_helper<T> ph;
1022
1023 /* Test known_gt (T, C). */
1024 ASSERT_TRUE (known_gt (ph::make (7, 5, 4), ch::make (6)));
1025 ASSERT_TRUE (known_gt (ph::make (7, 0, 0), ch::make (6)));
1026 ASSERT_FALSE (known_gt (ph::make (60, 1, 2), ch::make (60)));
1027 ASSERT_FALSE (known_gt (ph::make (60, 0, 0), ch::make (60)));
1028 ASSERT_FALSE (known_gt (ph::make (30, 9, 4), ch::make (31)));
1029 ASSERT_FALSE (known_gt (ph::make (30, 0, 0), ch::make (31)));
1030
1031 /* Test known_gt (C, T). */
1032 ASSERT_FALSE (known_gt (ch::make (6), ph::make (7, 5, 4)));
1033 ASSERT_FALSE (known_gt (ch::make (6), ph::make (7, 0, 0)));
1034 ASSERT_FALSE (known_gt (ch::make (60), ph::make (60, 1, 2)));
1035 ASSERT_FALSE (known_gt (ch::make (60), ph::make (60, 0, 0)));
1036 ASSERT_EQ (known_gt (ch::make (31), ph::make (30, 9, 4)), N == 1);
1037 ASSERT_EQ (known_gt (ch::make (31), ph::make (30, 0, 4)), N <= 2);
1038 ASSERT_TRUE (known_gt (ch::make (31), ph::make (30, 0, 0)));
1039
1040 /* Test known_gt (T, T). */
1041 ASSERT_EQ (known_gt (ph::make (3, 14, 99), ph::make (2, 15, 100)), N == 1);
1042 ASSERT_EQ (known_gt (ph::make (3, 14, 99), ph::make (2, 13, 100)), N <= 2);
1043 ASSERT_EQ (known_gt (ph::make (3, 14, 99), ph::make (2, 15, 98)), N == 1);
1044 ASSERT_TRUE (known_gt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
1045 ASSERT_TRUE (known_gt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
1046 ASSERT_FALSE (known_gt (ph::make (2, 14, 99), ph::make (2, 15, 100)));
1047 ASSERT_FALSE (known_gt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
1048 ASSERT_FALSE (known_gt (ph::make (2, 14, 99), ph::make (2, 13, 98)));
1049 ASSERT_FALSE (known_gt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
1050 ASSERT_FALSE (known_gt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
1051 ASSERT_FALSE (known_gt (ph::make (1, 14, 99), ph::make (2, 13, 98)));
1052 }
1053
1054 /* Test known_ge for both signed and unsigned C. */
1055
1056 template<unsigned int N, typename C, typename T>
1057 static void
1058 test_known_ge ()
1059 {
1060 typedef coeff_helper<C> ch;
1061 typedef poly_helper<T> ph;
1062
1063 /* Test known_ge (T, C). */
1064 ASSERT_TRUE (known_ge (ph::make (7, 5, 4), ch::make (6)));
1065 ASSERT_TRUE (known_ge (ph::make (7, 0, 0), ch::make (6)));
1066 ASSERT_TRUE (known_ge (ph::make (60, 1, 2), ch::make (60)));
1067 ASSERT_TRUE (known_ge (ph::make (60, 0, 0), ch::make (60)));
1068 ASSERT_FALSE (known_ge (ph::make (30, 9, 4), ch::make (31)));
1069 ASSERT_FALSE (known_ge (ph::make (30, 0, 0), ch::make (31)));
1070
1071 /* Test known_ge (C, T). */
1072 ASSERT_FALSE (known_ge (ch::make (6), ph::make (7, 5, 4)));
1073 ASSERT_FALSE (known_ge (ch::make (6), ph::make (7, 0, 0)));
1074 ASSERT_EQ (known_ge (ch::make (60), ph::make (60, 1, 2)), N == 1);
1075 ASSERT_EQ (known_ge (ch::make (60), ph::make (60, 0, 2)), N <= 2);
1076 ASSERT_TRUE (known_ge (ch::make (60), ph::make (60, 0, 0)));
1077 ASSERT_EQ (known_ge (ch::make (31), ph::make (30, 9, 4)), N == 1);
1078 ASSERT_EQ (known_ge (ch::make (31), ph::make (30, 0, 4)), N <= 2);
1079 ASSERT_TRUE (known_ge (ch::make (31), ph::make (30, 0, 0)));
1080
1081 /* Test known_ge (T, T). */
1082 ASSERT_EQ (known_ge (ph::make (3, 14, 99), ph::make (2, 15, 100)), N == 1);
1083 ASSERT_EQ (known_ge (ph::make (3, 14, 99), ph::make (2, 13, 100)), N <= 2);
1084 ASSERT_EQ (known_ge (ph::make (3, 14, 99), ph::make (2, 15, 98)), N == 1);
1085 ASSERT_TRUE (known_ge (ph::make (3, 14, 99), ph::make (2, 14, 99)));
1086 ASSERT_TRUE (known_ge (ph::make (3, 14, 99), ph::make (2, 13, 98)));
1087 ASSERT_EQ (known_ge (ph::make (2, 14, 99), ph::make (2, 15, 100)), N == 1);
1088 ASSERT_EQ (known_ge (ph::make (2, 14, 99), ph::make (2, 13, 100)), N <= 2);
1089 ASSERT_EQ (known_ge (ph::make (2, 14, 99), ph::make (2, 15, 98)), N == 1);
1090 ASSERT_TRUE (known_ge (ph::make (2, 14, 99), ph::make (2, 14, 99)));
1091 ASSERT_TRUE (known_ge (ph::make (2, 14, 99), ph::make (2, 13, 98)));
1092 ASSERT_FALSE (known_ge (ph::make (1, 14, 99), ph::make (2, 15, 100)));
1093 ASSERT_FALSE (known_ge (ph::make (1, 14, 99), ph::make (2, 14, 99)));
1094 ASSERT_FALSE (known_ge (ph::make (1, 14, 99), ph::make (2, 13, 98)));
1095 }
1096
1097 /* Test known_lt for both signed and unsigned C. */
1098
1099 template<unsigned int N, typename C, typename T>
1100 static void
1101 test_known_lt ()
1102 {
1103 typedef coeff_helper<C> ch;
1104 typedef poly_helper<T> ph;
1105
1106 /* Test known_lt (T, C). */
1107 ASSERT_FALSE (known_lt (ph::make (7, 5, 4), ch::make (6)));
1108 ASSERT_FALSE (known_lt (ph::make (7, 0, 0), ch::make (6)));
1109 ASSERT_FALSE (known_lt (ph::make (60, 1, 2), ch::make (60)));
1110 ASSERT_FALSE (known_lt (ph::make (60, 0, 0), ch::make (60)));
1111 ASSERT_EQ (known_lt (ph::make (30, 9, 4), ch::make (31)), N == 1);
1112 ASSERT_EQ (known_lt (ph::make (30, 0, 4), ch::make (31)), N <= 2);
1113 ASSERT_TRUE (known_lt (ph::make (30, 0, 0), ch::make (31)));
1114
1115 /* Test known_lt (C, T). */
1116 ASSERT_TRUE (known_lt (ch::make (6), ph::make (7, 5, 4)));
1117 ASSERT_TRUE (known_lt (ch::make (6), ph::make (7, 0, 0)));
1118 ASSERT_FALSE (known_lt (ch::make (60), ph::make (60, 1, 2)));
1119 ASSERT_FALSE (known_lt (ch::make (60), ph::make (60, 0, 0)));
1120 ASSERT_FALSE (known_lt (ch::make (31), ph::make (30, 9, 4)));
1121 ASSERT_FALSE (known_lt (ch::make (31), ph::make (30, 0, 0)));
1122
1123 /* Test known_lt (T, T). */
1124 ASSERT_FALSE (known_lt (ph::make (3, 14, 99), ph::make (2, 15, 100)));
1125 ASSERT_FALSE (known_lt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
1126 ASSERT_FALSE (known_lt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
1127 ASSERT_FALSE (known_lt (ph::make (2, 14, 99), ph::make (2, 15, 100)));
1128 ASSERT_FALSE (known_lt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
1129 ASSERT_FALSE (known_lt (ph::make (2, 14, 99), ph::make (2, 13, 98)));
1130 ASSERT_TRUE (known_lt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
1131 ASSERT_TRUE (known_lt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
1132 ASSERT_EQ (known_lt (ph::make (1, 14, 99), ph::make (2, 15, 98)), N <= 2);
1133 ASSERT_EQ (known_lt (ph::make (1, 14, 99), ph::make (2, 13, 100)), N == 1);
1134 ASSERT_EQ (known_lt (ph::make (1, 14, 99), ph::make (2, 13, 98)), N == 1);
1135 }
1136
1137 /* Test known_le for both signed and unsigned C. */
1138
1139 template<unsigned int N, typename C, typename T>
1140 static void
1141 test_known_le ()
1142 {
1143 typedef coeff_helper<C> ch;
1144 typedef poly_helper<T> ph;
1145
1146 /* Test known_le (T, C). */
1147 ASSERT_FALSE (known_le (ph::make (7, 5, 4), ch::make (6)));
1148 ASSERT_FALSE (known_le (ph::make (7, 0, 0), ch::make (6)));
1149 ASSERT_EQ (known_le (ph::make (60, 1, 2), ch::make (60)), N == 1);
1150 ASSERT_EQ (known_le (ph::make (60, 0, 2), ch::make (60)), N <= 2);
1151 ASSERT_TRUE (known_le (ph::make (60, 0, 0), ch::make (60)));
1152 ASSERT_EQ (known_le (ph::make (30, 9, 4), ch::make (31)), N == 1);
1153 ASSERT_EQ (known_le (ph::make (30, 0, 4), ch::make (31)), N <= 2);
1154 ASSERT_TRUE (known_le (ph::make (30, 0, 0), ch::make (31)));
1155
1156 /* Test known_le (C, T). */
1157 ASSERT_TRUE (known_le (ch::make (6), ph::make (7, 5, 4)));
1158 ASSERT_TRUE (known_le (ch::make (6), ph::make (7, 0, 0)));
1159 ASSERT_TRUE (known_le (ch::make (60), ph::make (60, 1, 2)));
1160 ASSERT_TRUE (known_le (ch::make (60), ph::make (60, 0, 0)));
1161 ASSERT_FALSE (known_le (ch::make (31), ph::make (30, 9, 4)));
1162 ASSERT_FALSE (known_le (ch::make (31), ph::make (30, 0, 0)));
1163
1164 /* Test known_le (T, T). */
1165 ASSERT_FALSE (known_le (ph::make (3, 14, 99), ph::make (2, 15, 100)));
1166 ASSERT_FALSE (known_le (ph::make (3, 14, 99), ph::make (2, 14, 99)));
1167 ASSERT_FALSE (known_le (ph::make (3, 14, 99), ph::make (2, 13, 98)));
1168 ASSERT_TRUE (known_le (ph::make (2, 14, 99), ph::make (2, 15, 100)));
1169 ASSERT_TRUE (known_le (ph::make (2, 14, 99), ph::make (2, 14, 99)));
1170 ASSERT_EQ (known_le (ph::make (2, 14, 99), ph::make (2, 15, 98)), N <= 2);
1171 ASSERT_EQ (known_le (ph::make (2, 14, 99), ph::make (2, 13, 100)), N == 1);
1172 ASSERT_EQ (known_le (ph::make (2, 14, 99), ph::make (2, 13, 98)), N == 1);
1173 ASSERT_TRUE (known_le (ph::make (1, 14, 99), ph::make (2, 15, 100)));
1174 ASSERT_TRUE (known_le (ph::make (1, 14, 99), ph::make (2, 14, 99)));
1175 ASSERT_EQ (known_le (ph::make (1, 14, 99), ph::make (2, 15, 98)), N <= 2);
1176 ASSERT_EQ (known_le (ph::make (1, 14, 99), ph::make (2, 13, 100)), N == 1);
1177 ASSERT_EQ (known_le (ph::make (1, 14, 99), ph::make (2, 13, 98)), N == 1);
1178 }
1179
1180 /* Test ordered_p for both signed and unsigned C. */
1181
1182 template<unsigned int N, typename C, typename T>
1183 static void
1184 test_ordered_p ()
1185 {
1186 typedef coeff_helper<C> ch;
1187 typedef poly_helper<T> ph;
1188
1189 /* Test ordered_p (T, C). */
1190 ASSERT_EQ (ordered_p (ph::make (4, 1, 2), ch::make (5)), N == 1);
1191 ASSERT_EQ (ordered_p (ph::make (4, 0, 2), ch::make (5)), N <= 2);
1192 ASSERT_TRUE (ordered_p (ph::make (4, 0, 0), ch::make (5)));
1193 ASSERT_TRUE (ordered_p (ph::make (4, 1, 2), ch::make (4)));
1194 ASSERT_TRUE (ordered_p (ph::make (4, 0, 0), ch::make (4)));
1195 ASSERT_TRUE (ordered_p (ph::make (4, 1, 2), ch::make (3)));
1196 ASSERT_TRUE (ordered_p (ph::make (4, 0, 0), ch::make (3)));
1197 ASSERT_TRUE (ordered_p (ph::make (4, 4, 4), ch::make (0)));
1198 ASSERT_TRUE (ordered_p (ph::make (4, 4, 0), ch::make (0)));
1199 ASSERT_TRUE (ordered_p (ph::make (4, 0, 4), ch::make (0)));
1200 ASSERT_TRUE (ordered_p (ph::make (-4, -4, -4), ch::make (0)));
1201 ASSERT_TRUE (ordered_p (ph::make (-4, -4, 0), ch::make (0)));
1202 ASSERT_TRUE (ordered_p (ph::make (-4, 0, -4), ch::make (0)));
1203
1204 /* Test ordered_p (C, T). */
1205 ASSERT_EQ (ordered_p (ch::make (5), ph::make (4, 1, 2)), N == 1);
1206 ASSERT_EQ (ordered_p (ch::make (5), ph::make (4, 0, 2)), N <= 2);
1207 ASSERT_TRUE (ordered_p (ch::make (5), ph::make (4, 0, 0)));
1208 ASSERT_TRUE (ordered_p (ch::make (4), ph::make (4, 1, 2)));
1209 ASSERT_TRUE (ordered_p (ch::make (4), ph::make (4, 0, 0)));
1210 ASSERT_TRUE (ordered_p (ch::make (3), ph::make (4, 1, 2)));
1211 ASSERT_TRUE (ordered_p (ch::make (3), ph::make (4, 0, 0)));
1212 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 4, 4)));
1213 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 4, 0)));
1214 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 0, 4)));
1215 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, -4, -4)));
1216 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, -4, 0)));
1217 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, 0, -4)));
1218
1219 /* Test ordered_p (T, T). */
1220 ASSERT_EQ (ordered_p (ph::make (3, 14, 99), ph::make (2, 15, 100)), N == 1);
1221 ASSERT_EQ (ordered_p (ph::make (3, 14, 99), ph::make (2, 13, 100)), N <= 2);
1222 ASSERT_EQ (ordered_p (ph::make (3, 14, 99), ph::make (2, 15, 98)), N == 1);
1223 ASSERT_TRUE (ordered_p (ph::make (3, 14, 99), ph::make (2, 14, 99)));
1224 ASSERT_TRUE (ordered_p (ph::make (3, 14, 99), ph::make (2, 13, 98)));
1225 ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 15, 100)));
1226 ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 14, 100)));
1227 ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 15, 99)));
1228 ASSERT_EQ (ordered_p (ph::make (2, 14, 99), ph::make (2, 13, 100)), N <= 2);
1229 ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 14, 99)));
1230 ASSERT_EQ (ordered_p (ph::make (2, 14, 99), ph::make (2, 15, 98)), N <= 2);
1231 ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 13, 99)));
1232 ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 14, 98)));
1233 ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 13, 98)));
1234 ASSERT_TRUE (ordered_p (ph::make (1, 14, 99), ph::make (2, 15, 100)));
1235 ASSERT_TRUE (ordered_p (ph::make (1, 14, 99), ph::make (2, 14, 99)));
1236 ASSERT_EQ (ordered_p (ph::make (1, 14, 99), ph::make (2, 15, 98)), N <= 2);
1237 ASSERT_EQ (ordered_p (ph::make (1, 14, 99), ph::make (2, 13, 100)), N == 1);
1238 ASSERT_EQ (ordered_p (ph::make (1, 14, 99), ph::make (2, 13, 98)), N == 1);
1239 }
1240
1241 /* Test ordered_min for both signed and unsigned C. */
1242
1243 template<unsigned int N, typename C, typename T>
1244 static void
1245 test_ordered_min ()
1246 {
1247 typedef coeff_helper<C> ch;
1248 typedef poly_helper<T> ph;
1249
1250 /* Test ordered_min (T, C). */
1251 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 0, 0), ch::make (5)),
1252 ch::make (4));
1253 ASSERT_KNOWN_EQ (ordered_min (ph::make (12, 0, 0), ch::make (11)),
1254 ch::make (11));
1255 ASSERT_KNOWN_EQ (ordered_min (ph::make (12, 6, 4), ch::make (11)),
1256 ch::make (11));
1257
1258 /* Test ordered_min (C, T). */
1259 ASSERT_KNOWN_EQ (ordered_min (ch::make (5), ph::make (4, 0, 0)),
1260 ch::make (4));
1261 ASSERT_KNOWN_EQ (ordered_min (ch::make (11), ph::make (12, 0, 0)),
1262 ch::make (11));
1263 ASSERT_KNOWN_EQ (ordered_min (ch::make (11), ph::make (12, 6, 4)),
1264 ch::make (11));
1265
1266 /* Test ordered_min (T, T). */
1267 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 6, 14), ph::make (5, 6, 19)),
1268 ph::make (4, 6, 14));
1269 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 9, 17), ph::make (3, 9, 0)),
1270 ph::make (3, 9, 0));
1271 ASSERT_KNOWN_EQ (ordered_min (ph::make (-4, -5, 12), ph::make (-3, -5, 12)),
1272 ph::make (-4, -5, 12));
1273 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, -9, 6), ph::make (4, -8, 6)),
1274 ph::make (4, -9, 6));
1275 ASSERT_KNOWN_EQ (ordered_min (ph::make (5, -1, -14), ph::make (5, -1, -16)),
1276 ph::make (5, -1, -16));
1277 }
1278
1279 /* Test ordered_max for both signed and unsigned C. */
1280
1281 template<unsigned int N, typename C, typename T>
1282 static void
1283 test_ordered_max ()
1284 {
1285 typedef coeff_helper<C> ch;
1286 typedef poly_helper<T> ph;
1287
1288 /* Test ordered_max (T, C). */
1289 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 0, 0), ch::make (5)),
1290 ch::make (5));
1291 ASSERT_KNOWN_EQ (ordered_max (ph::make (12, 0, 0), ch::make (11)),
1292 ch::make (12));
1293 ASSERT_KNOWN_EQ (ordered_max (ph::make (12, 6, 4), ch::make (11)),
1294 ph::make (12, 6, 4));
1295
1296 /* Test ordered_max (C, T). */
1297 ASSERT_KNOWN_EQ (ordered_max (ch::make (5), ph::make (4, 0, 0)),
1298 ch::make (5));
1299 ASSERT_KNOWN_EQ (ordered_max (ch::make (11), ph::make (12, 0, 0)),
1300 ch::make (12));
1301 ASSERT_KNOWN_EQ (ordered_max (ch::make (11), ph::make (12, 6, 4)),
1302 ph::make (12, 6, 4));
1303
1304 /* Test ordered_max (T, T). */
1305 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 6, 14), ph::make (5, 6, 19)),
1306 ph::make (5, 6, 19));
1307 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 9, 17), ph::make (3, 9, 0)),
1308 ph::make (4, 9, 17));
1309 ASSERT_KNOWN_EQ (ordered_max (ph::make (-4, -5, 12), ph::make (-3, -5, 12)),
1310 ph::make (-3, -5, 12));
1311 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, -9, 6), ph::make (4, -8, 6)),
1312 ph::make (4, -8, 6));
1313 ASSERT_KNOWN_EQ (ordered_max (ph::make (5, -1, -14), ph::make (5, -1, -16)),
1314 ph::make (5, -1, -14));
1315 }
1316
1317 /* Test constant_lower_bound for both signed and unsigned C. */
1318
1319 template<unsigned int N, typename C, typename T>
1320 static void
1321 test_constant_lower_bound ()
1322 {
1323 typedef poly_helper<T> ph;
1324
1325 ASSERT_EQ (constant_lower_bound (ph::make (4, 1, 2)), 4);
1326 ASSERT_EQ (constant_lower_bound (ph::make (5, 0, 1)), 5);
1327 ASSERT_EQ (constant_lower_bound (ph::make (6, 1, 0)), 6);
1328 ASSERT_EQ (constant_lower_bound (ph::make (7, 0, 0)), 7);
1329 }
1330
1331 /* Test lower_bound for both signed and unsigned C. */
1332
1333 template<unsigned int N, typename C, typename T>
1334 static void
1335 test_lower_bound ()
1336 {
1337 typedef coeff_helper<C> ch;
1338 typedef poly_helper<T> ph;
1339
1340 /* Test lower_bound (T, C). */
1341 ASSERT_KNOWN_EQ (lower_bound (ph::make (7, 2, 15), ch::make (4)),
1342 ch::make (4));
1343 ASSERT_KNOWN_EQ (lower_bound (ph::make (100, 5, 50), ch::make (200)),
1344 ch::make (100));
1345
1346 /* Test lower_bound (C, T). */
1347 ASSERT_KNOWN_EQ (lower_bound (ch::make (4), ph::make (7, 2, 15)),
1348 ch::make (4));
1349 ASSERT_KNOWN_EQ (lower_bound (ch::make (200), ph::make (100, 5, 50)),
1350 ch::make (100));
1351
1352 /* Test lower_bound (T, T). */
1353 ASSERT_KNOWN_EQ (lower_bound (ph::make (7, 2, 15), ph::make (5, 19, 14)),
1354 ph::make (5, 2, 14));
1355 ASSERT_KNOWN_EQ (lower_bound (ph::make (100, 5, 50), ph::make (200, 0, 80)),
1356 ph::make (100, 0, 50));
1357 }
1358
1359 /* Test upper_bound for both signed and unsigned C. */
1360
1361 template<unsigned int N, typename C, typename T>
1362 static void
1363 test_upper_bound ()
1364 {
1365 typedef coeff_helper<C> ch;
1366 typedef poly_helper<T> ph;
1367
1368 /* Test upper_bound (T, C). */
1369 ASSERT_KNOWN_EQ (upper_bound (ph::make (7, 2, 15), ch::make (4)),
1370 ph::make (7, 2, 15));
1371 ASSERT_KNOWN_EQ (upper_bound (ph::make (100, 5, 50), ch::make (200)),
1372 ph::make (200, 5, 50));
1373
1374 /* Test upper_bound (C, T). */
1375 ASSERT_KNOWN_EQ (upper_bound (ch::make (4), ph::make (7, 2, 15)),
1376 ph::make (7, 2, 15));
1377 ASSERT_KNOWN_EQ (upper_bound (ch::make (200), ph::make (100, 5, 50)),
1378 ph::make (200, 5, 50));
1379
1380 /* Test upper_bound (T, T). */
1381 ASSERT_KNOWN_EQ (upper_bound (ph::make (7, 2, 15), ph::make (5, 19, 14)),
1382 ph::make (7, 19, 15));
1383 ASSERT_KNOWN_EQ (upper_bound (ph::make (100, 5, 50), ph::make (200, 0, 80)),
1384 ph::make (200, 5, 80));
1385 }
1386
1387 /* Test compare_sizes_for_sort for both signed and unsigned C. */
1388
1389 template<unsigned int N, typename C, typename T>
1390 static void
1391 test_compare_sizes_for_sort ()
1392 {
1393 typedef poly_helper<T> ph;
1394
1395 ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 10, 8),
1396 ph::make (7, 9, 11)),
1397 N == 2 ? 1 : -1);
1398 ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 9, 8),
1399 ph::make (7, 9, 11)),
1400 -1);
1401 ASSERT_EQ (compare_sizes_for_sort (ph::make (19, 9, 13),
1402 ph::make (7, 9, 13)),
1403 1);
1404 ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 9, 7),
1405 ph::make (5, 10, 5)),
1406 N == 1 ? 0 : N == 2 ? -1 : 1);
1407 ASSERT_EQ (compare_sizes_for_sort (ph::make (10, 9, 10),
1408 ph::make (10, 9, 6)),
1409 N <= 2 ? 0 : 1);
1410 ASSERT_EQ (compare_sizes_for_sort (ph::make (10, 9, 6),
1411 ph::make (10, 9, 6)),
1412 0);
1413 }
1414
1415 /* Test force_align_up_and_div for both signed and unsigned C. */
1416
1417 template<unsigned int N, typename C, typename T>
1418 static void
1419 test_force_align_up_and_div ()
1420 {
1421 typedef coeff_helper<C> ch;
1422 typedef poly_helper<T> ph;
1423
1424 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (41, 32, 16), 16),
1425 ph::make (3, 2, 1));
1426 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-39, -64, -32), 32),
1427 ph::make (C (-32) / 32, C (-64) / 32, C (-32) / 32));
1428 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (17, 0, 0), 16),
1429 ch::make (2));
1430 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (16, 0, 0), 16),
1431 ch::make (1));
1432 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (15, 0, 0), 16),
1433 ch::make (1));
1434 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-17, 0, 0), 16),
1435 ch::make (C (-16) / 16));
1436 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-16, 0, 0), 16),
1437 ch::make (C (-16) / 16));
1438 /* For unsigned short C this gives 0x10000 / 16. */
1439 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-15, 0, 0), 16),
1440 ch::make ((C (-1) + 1) / 16));
1441 }
1442
1443 /* Test force_align_down_and_div for both signed and unsigned C. */
1444
1445 template<unsigned int N, typename C, typename T>
1446 static void
1447 test_force_align_down_and_div ()
1448 {
1449 typedef coeff_helper<C> ch;
1450 typedef poly_helper<T> ph;
1451
1452 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (41, 32, 16), 16),
1453 ph::make (2, 2, 1));
1454 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-39, -64, -32), 32),
1455 ph::make (C (-64) / 32, C (-64) / 32, C (-32) / 32));
1456 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (17, 0, 0), 16),
1457 ch::make (1));
1458 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (16, 0, 0), 16),
1459 ch::make (1));
1460 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (15, 0, 0), 16),
1461 ch::make (0));
1462 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-17, 0, 0), 16),
1463 ch::make (C (-32) / 16));
1464 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-16, 0, 0), 16),
1465 ch::make (C (-16) / 16));
1466 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-15, 0, 0), 16),
1467 ch::make (C (-16) / 16));
1468 }
1469
1470 /* Test constant_multiple_p for both signed and unsigned C. */
1471
1472 template<unsigned int N, typename C, typename T>
1473 static void
1474 test_constant_multiple_p ()
1475 {
1476 typedef poly_helper<T> ph;
1477
1478 /* Test constant_multiple_p (T, C). */
1479 C const_multiple;
1480 ASSERT_TRUE (constant_multiple_p (ph::make (15, 0, 0), 5,
1481 &const_multiple));
1482 ASSERT_EQ (const_multiple, 3);
1483 ASSERT_FALSE (constant_multiple_p (ph::make (16, 0, 0), 5,
1484 &const_multiple));
1485 ASSERT_FALSE (constant_multiple_p (ph::make (14, 5, 5), 5,
1486 &const_multiple));
1487 ASSERT_EQ (constant_multiple_p (ph::make (44, 0, 55), 11,
1488 &const_multiple), N <= 2);
1489 ASSERT_EQ (const_multiple, N <= 2 ? 4 : 3);
1490 ASSERT_EQ (constant_multiple_p (ph::make (30, 30, 0), 6,
1491 &const_multiple), N == 1);
1492 ASSERT_EQ (const_multiple, N == 1 ? 5 : N == 2 ? 4 : 3);
1493 ASSERT_TRUE (constant_multiple_p (ph::make (0, 0, 0), 5,
1494 &const_multiple));
1495
1496 /* Test constant_multiple_p (C, T). */
1497 ASSERT_TRUE (constant_multiple_p (15, ph::make (5, 0, 0),
1498 &const_multiple));
1499 ASSERT_EQ (const_multiple, 3);
1500 ASSERT_FALSE (constant_multiple_p (16, ph::make (5, 0, 0),
1501 &const_multiple));
1502 ASSERT_FALSE (constant_multiple_p (14, ph::make (5, 5, 5),
1503 &const_multiple));
1504 ASSERT_EQ (constant_multiple_p (44, ph::make (11, 0, 4),
1505 &const_multiple), N <= 2);
1506 ASSERT_EQ (const_multiple, N <= 2 ? 4 : 3);
1507 ASSERT_EQ (constant_multiple_p (30, ph::make (6, 6, 6),
1508 &const_multiple), N == 1);
1509 ASSERT_EQ (const_multiple, N == 1 ? 5 : N == 2 ? 4 : 3);
1510 ASSERT_TRUE (constant_multiple_p (0, ph::make (5, 4, 11),
1511 &const_multiple));
1512 ASSERT_EQ (const_multiple, 0);
1513
1514 /* Test constant_multiple_p (T, T). */
1515 ASSERT_TRUE (constant_multiple_p (ph::make (5, 15, 25),
1516 ph::make (1, 3, 5),
1517 &const_multiple));
1518 ASSERT_EQ (const_multiple, 5);
1519 ASSERT_EQ (constant_multiple_p (ph::make (18, 30, 7),
1520 ph::make (6, 10, 2),
1521 &const_multiple), N <= 2);
1522 ASSERT_EQ (const_multiple, N <= 2 ? 3 : 5);
1523 ASSERT_EQ (constant_multiple_p (ph::make (54, 19, 0),
1524 ph::make (9, 3, 0),
1525 &const_multiple), N == 1);
1526 ASSERT_EQ (const_multiple, N == 1 ? 6 : N == 2 ? 3: 5);
1527 ASSERT_TRUE (constant_multiple_p (ph::make (120, 0, 90),
1528 ph::make (12, 0, 9),
1529 &const_multiple));
1530 ASSERT_EQ (const_multiple, 10);
1531 ASSERT_EQ (constant_multiple_p (ph::make (110, 1, 22),
1532 ph::make (10, 0, 2),
1533 &const_multiple), N == 1);
1534 ASSERT_EQ (const_multiple, N == 1 ? 11 : 10);
1535 ASSERT_EQ (constant_multiple_p (ph::make (120, -1, 22),
1536 ph::make (10, 0, 2),
1537 &const_multiple), N == 1);
1538 ASSERT_EQ (const_multiple, N == 1 ? 12 : 10);
1539 ASSERT_EQ (constant_multiple_p (ph::make (130, 0, 26),
1540 ph::make (10, 1, 2),
1541 &const_multiple), N == 1);
1542 ASSERT_EQ (const_multiple, N == 1 ? 13 : 10);
1543 ASSERT_EQ (constant_multiple_p (ph::make (140, 0, 28),
1544 ph::make (10, -1, 2),
1545 &const_multiple), N == 1);
1546 ASSERT_EQ (const_multiple, N == 1 ? 14 : 10);
1547 ASSERT_FALSE (constant_multiple_p (ph::make (89, 0, 0),
1548 ph::make (11, 0, 0),
1549 &const_multiple));
1550 ASSERT_TRUE (constant_multiple_p (ph::make (88, 0, 0),
1551 ph::make (11, 0, 0),
1552 &const_multiple));
1553 ASSERT_EQ (const_multiple, 8);
1554 ASSERT_FALSE (constant_multiple_p (ph::make (87, 0, 0),
1555 ph::make (11, 0, 0),
1556 &const_multiple));
1557 ASSERT_TRUE (constant_multiple_p (ph::make (35, 63, 0),
1558 ph::make (5, 9, 0),
1559 &const_multiple));
1560 ASSERT_EQ (const_multiple, 7);
1561 ASSERT_TRUE (constant_multiple_p (ph::make (0, 0, 0),
1562 ph::make (11, -24, 25),
1563 &const_multiple));
1564 ASSERT_EQ (const_multiple, 0);
1565 }
1566
1567 /* Test multiple_p for both signed and unsigned C. */
1568
1569 template<unsigned int N, typename C, typename T>
1570 static void
1571 test_multiple_p ()
1572 {
1573 typedef poly_helper<T> ph;
1574
1575 /* Test multiple_p (T, C). */
1576 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0), 5));
1577 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0), 5));
1578 ASSERT_FALSE (multiple_p (ph::make (14, 5, 5), 5));
1579 ASSERT_TRUE (multiple_p (ph::make (44, 0, 55), 11));
1580 ASSERT_TRUE (multiple_p (ph::make (30, 30, 0), 6));
1581 ASSERT_TRUE (multiple_p (ph::make (30, 35, 45), 5));
1582 ASSERT_EQ (multiple_p (ph::make (30, 35, 44), 5), N <= 2);
1583 ASSERT_EQ (multiple_p (ph::make (30, 34, 45), 5), N == 1);
1584 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0), 5));
1585
1586 /* Test multiple_p (C, T). */
1587 ASSERT_TRUE (multiple_p (15, ph::make (5, 0, 0)));
1588 ASSERT_FALSE (multiple_p (16, ph::make (5, 0, 0)));
1589 ASSERT_FALSE (multiple_p (14, ph::make (5, 5, 5)));
1590 ASSERT_EQ (multiple_p (44, ph::make (11, 0, 4)), N <= 2);
1591 ASSERT_EQ (multiple_p (30, ph::make (6, 6, 6)), N == 1);
1592 ASSERT_TRUE (multiple_p (0, ph::make (5, 4, 11)));
1593
1594 /* Test multiple_p (T, T). */
1595 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
1596 ph::make (5, 0, 0)));
1597 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
1598 ph::make (5, 0, 0)));
1599 ASSERT_FALSE (multiple_p (ph::make (14, 5, 5),
1600 ph::make (5, 0, 0)));
1601 ASSERT_TRUE (multiple_p (ph::make (44, 0, 55),
1602 ph::make (11, 0, 0)));
1603 ASSERT_TRUE (multiple_p (ph::make (30, 30, 0),
1604 ph::make (6, 0, 0)));
1605 ASSERT_TRUE (multiple_p (ph::make (30, 35, 45),
1606 ph::make (5, 0, 0)));
1607 ASSERT_EQ (multiple_p (ph::make (30, 35, 44),
1608 ph::make (5, 0, 0)), N <= 2);
1609 ASSERT_EQ (multiple_p (ph::make (30, 34, 45),
1610 ph::make (5, 0, 0)), N == 1);
1611 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1612 ph::make (5, 0, 0)));
1613 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
1614 ph::make (5, 0, 0)));
1615 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
1616 ph::make (5, 0, 0)));
1617 ASSERT_FALSE (multiple_p (ph::make (14, 0, 0),
1618 ph::make (5, 5, 5)));
1619 ASSERT_EQ (multiple_p (ph::make (44, 0, 0),
1620 ph::make (11, 0, 4)), N <= 2);
1621 ASSERT_EQ (multiple_p (ph::make (30, 0, 0),
1622 ph::make (6, 6, 6)), N == 1);
1623 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1624 ph::make (5, 4, 11)));
1625 ASSERT_TRUE (multiple_p (ph::make (5, 15, 25),
1626 ph::make (1, 3, 5)));
1627 ASSERT_EQ (multiple_p (ph::make (18, 30, 7),
1628 ph::make (6, 10, 2)), N <= 2);
1629 ASSERT_EQ (multiple_p (ph::make (54, 19, 0),
1630 ph::make (9, 3, 0)), N == 1);
1631 ASSERT_TRUE (multiple_p (ph::make (120, 0, 90),
1632 ph::make (12, 0, 9)));
1633 ASSERT_EQ (multiple_p (ph::make (110, 1, 22),
1634 ph::make (10, 0, 2)), N == 1);
1635 ASSERT_EQ (multiple_p (ph::make (120, -1, 22),
1636 ph::make (10, 0, 2)), N == 1);
1637 ASSERT_EQ (multiple_p (ph::make (130, 0, 26),
1638 ph::make (10, 1, 2)), N == 1);
1639 ASSERT_EQ (multiple_p (ph::make (140, 0, 28),
1640 ph::make (10, -1, 2)), N == 1);
1641 ASSERT_FALSE (multiple_p (ph::make (89, 0, 0),
1642 ph::make (11, 0, 0)));
1643 ASSERT_TRUE (multiple_p (ph::make (88, 0, 0),
1644 ph::make (11, 0, 0)));
1645 ASSERT_FALSE (multiple_p (ph::make (87, 0, 0),
1646 ph::make (11, 0, 0)));
1647 ASSERT_TRUE (multiple_p (ph::make (35, 63, 0),
1648 ph::make (5, 9, 0)));
1649 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1650 ph::make (11, -24, 25)));
1651 }
1652
1653 /* Test the 3-operand form of multiple_p for both signed and unsigned C. */
1654
1655 template<unsigned int N, typename C, typename T>
1656 static void
1657 test_multiple_p_with_result ()
1658 {
1659 typedef coeff_helper<C> ch;
1660 typedef poly_helper<T> ph;
1661
1662 /* Test multiple_p (T, C) -> T. */
1663 T multiple;
1664 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0), 5, &multiple));
1665 ASSERT_KNOWN_EQ (multiple, ch::make (3));
1666 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0), 5, &multiple));
1667 ASSERT_FALSE (multiple_p (ph::make (14, 5, 5), 5, &multiple));
1668 ASSERT_TRUE (multiple_p (ph::make (44, 0, 55), 11, &multiple));
1669 ASSERT_KNOWN_EQ (multiple, ph::make (4, 0, 5));
1670 ASSERT_TRUE (multiple_p (ph::make (30, 30, 0), 6, &multiple));
1671 ASSERT_KNOWN_EQ (multiple, ph::make (5, 5, 0));
1672 ASSERT_TRUE (multiple_p (ph::make (30, 35, 45), 5, &multiple));
1673 ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 9));
1674 ASSERT_EQ (multiple_p (ph::make (30, 35, 44), 5, &multiple), N <= 2);
1675 if (N <= 2)
1676 ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 0));
1677 ASSERT_EQ (multiple_p (ph::make (30, 34, 45), 5, &multiple), N == 1);
1678 if (N == 1)
1679 ASSERT_KNOWN_EQ (multiple, ch::make (6));
1680 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0), 5, &multiple));
1681 ASSERT_KNOWN_EQ (multiple, ch::make (0));
1682
1683 /* Test multiple_p (C, T) -> T. */
1684 ASSERT_TRUE (multiple_p (15, ph::make (5, 0, 0), &multiple));
1685 ASSERT_KNOWN_EQ (multiple, ch::make (3));
1686 ASSERT_FALSE (multiple_p (16, ph::make (5, 0, 0), &multiple));
1687 ASSERT_FALSE (multiple_p (14, ph::make (5, 5, 5), &multiple));
1688 ASSERT_EQ (multiple_p (44, ph::make (11, 0, 4), &multiple), N <= 2);
1689 ASSERT_KNOWN_EQ (multiple, ch::make (N <= 2 ? 4 : 3));
1690 ASSERT_EQ (multiple_p (30, ph::make (6, 6, 6), &multiple), N == 1);
1691 ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 5 : N == 2 ? 4 : 3));
1692 ASSERT_TRUE (multiple_p (0, ph::make (5, 4, 11), &multiple));
1693 ASSERT_KNOWN_EQ (multiple, ch::make (0));
1694
1695 /* Test multiple_p (T, T) -> T. */
1696 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
1697 ph::make (5, 0, 0),
1698 &multiple));
1699 ASSERT_KNOWN_EQ (multiple, ch::make (3));
1700 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
1701 ph::make (5, 0, 0),
1702 &multiple));
1703 ASSERT_FALSE (multiple_p (ph::make (14, 5, 5),
1704 ph::make (5, 0, 0),
1705 &multiple));
1706 ASSERT_TRUE (multiple_p (ph::make (44, 0, 55),
1707 ph::make (11, 0, 0),
1708 &multiple));
1709 ASSERT_KNOWN_EQ (multiple, ph::make (4, 0, 5));
1710 ASSERT_TRUE (multiple_p (ph::make (30, 30, 0),
1711 ph::make (6, 0, 0),
1712 &multiple));
1713 ASSERT_KNOWN_EQ (multiple, ph::make (5, 5, 0));
1714 ASSERT_TRUE (multiple_p (ph::make (30, 35, 45),
1715 ph::make (5, 0, 0),
1716 &multiple));
1717 ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 9));
1718 ASSERT_EQ (multiple_p (ph::make (30, 35, 44),
1719 ph::make (5, 0, 0),
1720 &multiple), N <= 2);
1721 if (N <= 2)
1722 ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 0));
1723 ASSERT_EQ (multiple_p (ph::make (30, 34, 45),
1724 ph::make (5, 0, 0),
1725 &multiple), N == 1);
1726 if (N == 1)
1727 ASSERT_KNOWN_EQ (multiple, ch::make (6));
1728 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1729 ph::make (5, 0, 0),
1730 &multiple));
1731 ASSERT_KNOWN_EQ (multiple, ch::make (0));
1732 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
1733 ph::make (5, 0, 0),
1734 &multiple));
1735 ASSERT_KNOWN_EQ (multiple, ch::make (3));
1736 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
1737 ph::make (5, 0, 0),
1738 &multiple));
1739 ASSERT_FALSE (multiple_p (ph::make (14, 0, 0),
1740 ph::make (5, 5, 5),
1741 &multiple));
1742 ASSERT_EQ (multiple_p (ph::make (44, 0, 0),
1743 ph::make (11, 0, 4),
1744 &multiple), N <= 2);
1745 if (N <= 2)
1746 ASSERT_KNOWN_EQ (multiple, ch::make (4));
1747 ASSERT_EQ (multiple_p (ph::make (30, 0, 0),
1748 ph::make (6, 6, 6),
1749 &multiple), N == 1);
1750 if (N == 1)
1751 ASSERT_KNOWN_EQ (multiple, ch::make (5));
1752 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1753 ph::make (5, 4, 11),
1754 &multiple));
1755 ASSERT_KNOWN_EQ (multiple, ch::make (0));
1756 ASSERT_TRUE (multiple_p (ph::make (5, 15, 25),
1757 ph::make (1, 3, 5),
1758 &multiple));
1759 ASSERT_KNOWN_EQ (multiple, ch::make (5));
1760 ASSERT_EQ (multiple_p (ph::make (18, 30, 7),
1761 ph::make (6, 10, 2),
1762 &multiple), N <= 2);
1763 if (N <= 2)
1764 ASSERT_KNOWN_EQ (multiple, ch::make (3));
1765 ASSERT_EQ (multiple_p (ph::make (54, 19, 0),
1766 ph::make (9, 3, 0),
1767 &multiple), N == 1);
1768 if (N == 1)
1769 ASSERT_KNOWN_EQ (multiple, ch::make (6));
1770 ASSERT_TRUE (multiple_p (ph::make (120, 0, 90),
1771 ph::make (12, 0, 9),
1772 &multiple));
1773 ASSERT_KNOWN_EQ (multiple, ch::make (10));
1774 ASSERT_EQ (multiple_p (ph::make (110, 1, 22),
1775 ph::make (10, 0, 2),
1776 &multiple), N == 1);
1777 ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 11 : 10));
1778 ASSERT_EQ (multiple_p (ph::make (120, -1, 22),
1779 ph::make (10, 0, 2),
1780 &multiple), N == 1);
1781 ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 12 : 10));
1782 ASSERT_EQ (multiple_p (ph::make (130, 0, 26),
1783 ph::make (10, 1, 2),
1784 &multiple), N == 1);
1785 ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 13 : 10));
1786 ASSERT_EQ (multiple_p (ph::make (140, 0, 28),
1787 ph::make (10, -1, 2),
1788 &multiple), N == 1);
1789 ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 14 : 10));
1790 ASSERT_FALSE (multiple_p (ph::make (89, 0, 0),
1791 ph::make (11, 0, 0),
1792 &multiple));
1793 ASSERT_TRUE (multiple_p (ph::make (88, 0, 0),
1794 ph::make (11, 0, 0),
1795 &multiple));
1796 ASSERT_KNOWN_EQ (multiple, ch::make (8));
1797 ASSERT_FALSE (multiple_p (ph::make (87, 0, 0),
1798 ph::make (11, 0, 0),
1799 &multiple));
1800 ASSERT_TRUE (multiple_p (ph::make (35, 63, 0),
1801 ph::make (5, 9, 0),
1802 &multiple));
1803 ASSERT_KNOWN_EQ (multiple, ch::make (7));
1804 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1805 ph::make (11, -24, 25),
1806 &multiple));
1807 ASSERT_KNOWN_EQ (multiple, ch::make (0));
1808 }
1809
1810 /* Test exact_div for both signed and unsigned C. */
1811
1812 template<unsigned int N, typename C, typename T>
1813 static void
1814 test_exact_div ()
1815 {
1816 typedef coeff_helper<C> ch;
1817 typedef poly_helper<T> ph;
1818
1819 /* Test exact_div (T, C). */
1820 ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0), 5),
1821 ch::make (3));
1822 ASSERT_KNOWN_EQ (exact_div (ph::make (44, 0, 55), 11),
1823 ph::make (4, 0, 5));
1824 ASSERT_KNOWN_EQ (exact_div (ph::make (30, 30, 0), 6),
1825 ph::make (5, 5, 0));
1826 ASSERT_KNOWN_EQ (exact_div (ph::make (30, 35, 45), 5),
1827 ph::make (6, 7, 9));
1828 ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0), 5),
1829 ch::make (0));
1830
1831 /* Test exact_div (T, T). */
1832 ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0),
1833 ph::make (5, 0, 0)),
1834 ch::make (3));
1835 ASSERT_KNOWN_EQ (exact_div (ph::make (44, 0, 55),
1836 ph::make (11, 0, 0)),
1837 ph::make (4, 0, 5));
1838 ASSERT_KNOWN_EQ (exact_div (ph::make (30, 30, 0),
1839 ph::make (6, 0, 0)),
1840 ph::make (5, 5, 0));
1841 ASSERT_KNOWN_EQ (exact_div (ph::make (30, 35, 45),
1842 ph::make (5, 0, 0)),
1843 ph::make (6, 7, 9));
1844 ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
1845 ph::make (5, 0, 0)),
1846 ch::make (0));
1847 ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0),
1848 ph::make (5, 0, 0)),
1849 ch::make (3));
1850 ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
1851 ph::make (5, 4, 11)),
1852 ch::make (0));
1853 ASSERT_KNOWN_EQ (exact_div (ph::make (5, 15, 25),
1854 ph::make (1, 3, 5)),
1855 ch::make (5));
1856 ASSERT_KNOWN_EQ (exact_div (ph::make (120, 0, 90),
1857 ph::make (12, 0, 9)),
1858 ch::make (10));
1859 ASSERT_KNOWN_EQ (exact_div (ph::make (88, 0, 0),
1860 ph::make (11, 0, 0)),
1861 ch::make (8));
1862 ASSERT_KNOWN_EQ (exact_div (ph::make (35, 63, 0),
1863 ph::make (5, 9, 0)),
1864 ch::make (7));
1865 ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
1866 ph::make (11, -24, 25)),
1867 ch::make (0));
1868 }
1869
1870 /* Test the form of can_div_trunc_p that returns a constant quotient,
1871 for both signed and unsigned C. */
1872
1873 template<unsigned int N, typename C, typename T>
1874 static void
1875 test_can_div_trunc_p_const ()
1876 {
1877 typedef coeff_helper<C> ch;
1878 typedef poly_helper<T> ph;
1879
1880 /* Test can_div_trunc_p (T, C) -> C. */
1881 C const_quot;
1882 ASSERT_TRUE (can_div_trunc_p (ph::make (22, 0, 0), 5, &const_quot));
1883 ASSERT_KNOWN_EQ (const_quot, C (4));
1884 ASSERT_EQ (can_div_trunc_p (ph::make (44, 0, 1), 5, &const_quot), N <= 2);
1885 ASSERT_KNOWN_EQ (const_quot, C (N <= 2 ? 8 : 4));
1886 ASSERT_EQ (can_div_trunc_p (ph::make (88, 1, 0), 5, &const_quot), N == 1);
1887 ASSERT_KNOWN_EQ (const_quot, C (N == 1 ? 17 : N == 2 ? 8 : 4));
1888 ASSERT_TRUE (can_div_trunc_p (ph::make (20, 0, 0), 5, &const_quot));
1889 ASSERT_KNOWN_EQ (const_quot, C (4));
1890 ASSERT_TRUE (can_div_trunc_p (ph::make (19, 0, 0), 5, &const_quot));
1891 ASSERT_KNOWN_EQ (const_quot, C (3));
1892
1893 /* Test can_div_trunc_p (T, T) -> C. */
1894 ASSERT_TRUE (can_div_trunc_p (ph::make (8, 44, 28),
1895 ph::make (2, 11, 7),
1896 &const_quot));
1897 ASSERT_EQ (const_quot, C (4));
1898 ASSERT_TRUE (can_div_trunc_p (ph::make (9, 23, 30),
1899 ph::make (4, 8, 12),
1900 &const_quot));
1901 ASSERT_EQ (const_quot, C (2));
1902 ASSERT_TRUE (can_div_trunc_p (ph::make (15, 25, 40),
1903 ph::make (4, 8, 10),
1904 &const_quot));
1905 ASSERT_EQ (const_quot, C (3));
1906 const_quot = 0;
1907 ASSERT_EQ (can_div_trunc_p (ph::make (15, 25, 41),
1908 ph::make (4, 8, 10),
1909 &const_quot), N <= 2);
1910 ASSERT_EQ (const_quot, C (N <= 2 ? 3 : 0));
1911 ASSERT_EQ (can_div_trunc_p (ph::make (43, 79, 80),
1912 ph::make (4, 8, 10),
1913 &const_quot), N == 1);
1914 ASSERT_EQ (const_quot, C (N == 1 ? 10 : N == 2 ? 3 : 0));
1915 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 5),
1916 ph::make (4, 5, 6),
1917 &const_quot));
1918 ASSERT_EQ (const_quot, C (0));
1919 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 6),
1920 ph::make (4, 5, 6),
1921 &const_quot));
1922 ASSERT_EQ (const_quot, C (0));
1923 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 5, 5),
1924 ph::make (4, 5, 6),
1925 &const_quot));
1926 ASSERT_EQ (const_quot, C (0));
1927 ASSERT_EQ (can_div_trunc_p (ph::make (3, 4, 7),
1928 ph::make (4, 5, 6),
1929 &const_quot), N <= 2);
1930 ASSERT_EQ (const_quot, C (0));
1931 ASSERT_EQ (can_div_trunc_p (ph::make (3, 6, 0),
1932 ph::make (4, 5, 6),
1933 &const_quot), N == 1);
1934 ASSERT_EQ (const_quot, C (0));
1935 ASSERT_TRUE (can_div_trunc_p (ph::make (56, 0, 11),
1936 ph::make (11, 0, 2),
1937 &const_quot));
1938 ASSERT_EQ (const_quot, C (5));
1939 ASSERT_EQ (can_div_trunc_p (ph::make (66, 1, 12),
1940 ph::make (11, 0, 2),
1941 &const_quot), N == 1);
1942 ASSERT_EQ (const_quot, C (N == 1 ? 6 : 5));
1943 ASSERT_EQ (can_div_trunc_p (ph::make (77, -1, 14),
1944 ph::make (11, 0, 2),
1945 &const_quot), N == 1);
1946 ASSERT_EQ (const_quot, C (N == 1 ? 7 : 5));
1947 ASSERT_TRUE (can_div_trunc_p (ph::make (89, 0, 0),
1948 ph::make (11, 0, 0),
1949 &const_quot));
1950 ASSERT_EQ (const_quot, C (8));
1951 ASSERT_EQ (can_div_trunc_p (ph::make (101, 0, 1),
1952 ph::make (11, 0, 0),
1953 &const_quot), N <= 2);
1954 ASSERT_EQ (const_quot, C (N <= 2 ? 9 : 8));
1955 ASSERT_TRUE (can_div_trunc_p (ph::make (0, 0, 0),
1956 ph::make (4, 5, 6),
1957 &const_quot));
1958 ASSERT_EQ (const_quot, C (0));
1959
1960 /* Test can_div_trunc_p (T, T) -> C, T. */
1961 T rem;
1962 ASSERT_TRUE (can_div_trunc_p (ph::make (8, 44, 28),
1963 ph::make (2, 11, 7),
1964 &const_quot, &rem));
1965 ASSERT_EQ (const_quot, C (4));
1966 ASSERT_KNOWN_EQ (rem, ch::make (0));
1967 ASSERT_TRUE (can_div_trunc_p (ph::make (9, 23, 30),
1968 ph::make (4, 8, 12),
1969 &const_quot, &rem));
1970 ASSERT_EQ (const_quot, C (2));
1971 ASSERT_KNOWN_EQ (rem, ph::make (1, 7, 6));
1972 ASSERT_TRUE (can_div_trunc_p (ph::make (15, 25, 40),
1973 ph::make (4, 8, 10),
1974 &const_quot, &rem));
1975 ASSERT_EQ (const_quot, C (3));
1976 ASSERT_KNOWN_EQ (rem, ph::make (3, 1, 10));
1977 const_quot = 0, rem = 0;
1978 ASSERT_EQ (can_div_trunc_p (ph::make (15, 25, 41),
1979 ph::make (4, 8, 10),
1980 &const_quot, &rem), N <= 2);
1981 ASSERT_EQ (const_quot, C (N <= 2 ? 3 : 0));
1982 if (N <= 2)
1983 ASSERT_KNOWN_EQ (rem, ph::make (3, 1, 0));
1984 ASSERT_EQ (can_div_trunc_p (ph::make (43, 79, 80),
1985 ph::make (4, 8, 10),
1986 &const_quot, &rem), N == 1);
1987 ASSERT_EQ (const_quot, C (N == 1 ? 10 : N == 2 ? 3 : 0));
1988 if (N == 1)
1989 ASSERT_KNOWN_EQ (rem, ch::make (3));
1990 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 5),
1991 ph::make (4, 5, 6),
1992 &const_quot, &rem));
1993 ASSERT_EQ (const_quot, C (0));
1994 ASSERT_KNOWN_EQ (rem, ph::make (3, 4, 5));
1995 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 6),
1996 ph::make (4, 5, 6),
1997 &const_quot, &rem));
1998 ASSERT_EQ (const_quot, C (0));
1999 ASSERT_KNOWN_EQ (rem, ph::make (3, 4, 6));
2000 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 5, 5),
2001 ph::make (4, 5, 6),
2002 &const_quot, &rem));
2003 ASSERT_EQ (const_quot, C (0));
2004 ASSERT_KNOWN_EQ (rem, ph::make (3, 5, 5));
2005 ASSERT_TRUE (can_div_trunc_p (ph::make (56, 0, 11),
2006 ph::make (11, 0, 2),
2007 &const_quot, &rem));
2008 ASSERT_EQ (const_quot, C (5));
2009 ASSERT_KNOWN_EQ (rem, ph::make (1, 0, 1));
2010 ASSERT_EQ (can_div_trunc_p (ph::make (66, 1, 12),
2011 ph::make (11, 0, 2),
2012 &const_quot, &rem), N == 1);
2013 ASSERT_EQ (const_quot, C (N == 1 ? 6 : 5));
2014 if (N == 1)
2015 ASSERT_KNOWN_EQ (rem, ch::make (0));
2016 ASSERT_EQ (can_div_trunc_p (ph::make (77, -1, 14),
2017 ph::make (11, 0, 2),
2018 &const_quot, &rem), N == 1);
2019 ASSERT_EQ (const_quot, C (N == 1 ? 7 : 5));
2020 if (N == 1)
2021 ASSERT_KNOWN_EQ (rem, ch::make (0));
2022 ASSERT_TRUE (can_div_trunc_p (ph::make (89, 0, 0),
2023 ph::make (11, 0, 0),
2024 &const_quot, &rem));
2025 ASSERT_EQ (const_quot, C (8));
2026 ASSERT_KNOWN_EQ (rem, ch::make (1));
2027 ASSERT_EQ (can_div_trunc_p (ph::make (101, 0, 1),
2028 ph::make (11, 0, 0),
2029 &const_quot, &rem), N <= 2);
2030 ASSERT_EQ (const_quot, C (N <= 2 ? 9 : 8));
2031 if (N <= 2)
2032 ASSERT_KNOWN_EQ (rem, ch::make (2));
2033 ASSERT_TRUE (can_div_trunc_p (ph::make (0, 0, 0),
2034 ph::make (4, 5, 6),
2035 &const_quot, &rem));
2036 ASSERT_EQ (const_quot, C (0));
2037 ASSERT_KNOWN_EQ (rem, ch::make (0));
2038 ASSERT_TRUE (can_div_trunc_p (ph::make (9, 10, 20),
2039 ph::make (5, 5, 20),
2040 &const_quot, &rem));
2041 ASSERT_EQ (const_quot, C (1));
2042 ASSERT_KNOWN_EQ (rem, ph::make (4, 5, 0));
2043 ASSERT_EQ (can_div_trunc_p (ph::make (9, 11, 20),
2044 ph::make (5, 5, 20),
2045 &const_quot, &rem), N == 1);
2046 if (N == 1)
2047 {
2048 ASSERT_EQ (const_quot, C (1));
2049 ASSERT_KNOWN_EQ (rem, C (4));
2050 }
2051 }
2052
2053 /* Test the form of can_div_trunc_p that returns a polynomail quotient,
2054 for both signed and unsigned C. */
2055
2056 template<unsigned int N, typename C, typename T>
2057 static void
2058 test_can_div_trunc_p_poly ()
2059 {
2060 typedef coeff_helper<C> ch;
2061 typedef poly_helper<T> ph;
2062
2063 /* Test can_div_trunc_p (T, C) -> T. */
2064 T quot;
2065 ASSERT_TRUE (can_div_trunc_p (ph::make (22, 0, 0), 5, &quot));
2066 ASSERT_KNOWN_EQ (quot, ch::make (4));
2067 ASSERT_TRUE (can_div_trunc_p (ph::make (45, 40, 24), 4, &quot));
2068 ASSERT_KNOWN_EQ (quot, ph::make (11, 10, 6));
2069 ASSERT_EQ (can_div_trunc_p (ph::make (13, 18, 19), 6, &quot), N <= 2);
2070 if (N <= 2)
2071 ASSERT_KNOWN_EQ (quot, ph::make (2, 3, 0));
2072 ASSERT_EQ (can_div_trunc_p (ph::make (55, 11, 10), 10, &quot), N == 1);
2073 if (N == 1)
2074 ASSERT_KNOWN_EQ (quot, ch::make (5));
2075
2076 /* Test can_div_trunc_p (T, C) -> T, C. */
2077 C const_rem;
2078 ASSERT_TRUE (can_div_trunc_p (ph::make (22, 0, 0), 5,
2079 &quot, &const_rem));
2080 ASSERT_KNOWN_EQ (quot, ch::make (4));
2081 ASSERT_EQ (const_rem, C (2));
2082 ASSERT_TRUE (can_div_trunc_p (ph::make (45, 40, 24), 4,
2083 &quot, &const_rem));
2084 ASSERT_KNOWN_EQ (quot, ph::make (11, 10, 6));
2085 ASSERT_EQ (const_rem, C (1));
2086 ASSERT_EQ (can_div_trunc_p (ph::make (13, 18, 19), 6,
2087 &quot, &const_rem), N <= 2);
2088 if (N <= 2)
2089 {
2090 ASSERT_KNOWN_EQ (quot, ph::make (2, 3, 0));
2091 ASSERT_EQ (const_rem, C (1));
2092 }
2093 ASSERT_EQ (can_div_trunc_p (ph::make (55, 11, 10), 10,
2094 &quot, &const_rem), N == 1);
2095 if (N == 1)
2096 {
2097 ASSERT_KNOWN_EQ (quot, ch::make (5));
2098 ASSERT_EQ (const_rem, C (5));
2099 }
2100 }
2101
2102 /* Test can_div_away_from_zero_p for both signed and unsigned C. */
2103
2104 template<unsigned int N, typename C, typename T>
2105 static void
2106 test_can_div_away_from_zero_p ()
2107 {
2108 typedef poly_helper<T> ph;
2109
2110 /* Test can_div_away_from_zero_p (T, T) -> C. */
2111 C const_quot;
2112 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (8, 44, 28),
2113 ph::make (2, 11, 7),
2114 &const_quot));
2115 ASSERT_EQ (const_quot, C (4));
2116 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (9, 23, 30),
2117 ph::make (4, 8, 12),
2118 &const_quot));
2119 ASSERT_EQ (const_quot, C (3));
2120 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (15, 25, 40),
2121 ph::make (4, 8, 10),
2122 &const_quot));
2123 ASSERT_EQ (const_quot, C (4));
2124 ASSERT_EQ (can_div_away_from_zero_p (ph::make (43, 79, 80),
2125 ph::make (4, 8, 10),
2126 &const_quot), N == 1);
2127 ASSERT_EQ (const_quot, C (N == 1 ? 11 : 4));
2128 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (3, 4, 5),
2129 ph::make (4, 5, 6),
2130 &const_quot));
2131 ASSERT_EQ (const_quot, C (1));
2132 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (3, 4, 6),
2133 ph::make (4, 5, 6),
2134 &const_quot));
2135 ASSERT_EQ (const_quot, C (1));
2136 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (3, 5, 5),
2137 ph::make (4, 5, 6),
2138 &const_quot));
2139 ASSERT_EQ (const_quot, C (1));
2140 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (56, 0, 11),
2141 ph::make (11, 0, 2),
2142 &const_quot));
2143 ASSERT_EQ (const_quot, C (6));
2144 ASSERT_EQ (can_div_away_from_zero_p (ph::make (66, 1, 12),
2145 ph::make (11, 0, 2),
2146 &const_quot), N == 1);
2147 ASSERT_EQ (const_quot, C (6));
2148 ASSERT_EQ (can_div_away_from_zero_p (ph::make (77, -1, 14),
2149 ph::make (11, 0, 2),
2150 &const_quot), N == 1);
2151 ASSERT_EQ (const_quot, C (N == 1 ? 7 : 6));
2152 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (89, 0, 0),
2153 ph::make (11, 0, 0),
2154 &const_quot));
2155 ASSERT_EQ (const_quot, C (9));
2156 ASSERT_EQ (can_div_away_from_zero_p (ph::make (101, 0, 1),
2157 ph::make (11, 0, 0),
2158 &const_quot), N <= 2);
2159 ASSERT_EQ (const_quot, C (N <= 2 ? 10 : 9));
2160 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (0, 0, 0),
2161 ph::make (4, 5, 6),
2162 &const_quot));
2163 ASSERT_EQ (const_quot, C (0));
2164 }
2165
2166 /* Test known_size_p. */
2167
2168 template<unsigned int N, typename C, typename T>
2169 static void
2170 test_known_size_p ()
2171 {
2172 typedef poly_helper<T> ph;
2173
2174 ASSERT_EQ (known_size_p (ph::make (-1, 0, -1)), N == 3);
2175 ASSERT_EQ (known_size_p (ph::make (-1, -1, 0)), N >= 2);
2176 ASSERT_EQ (known_size_p (ph::make (-1, -1, -1)), N >= 2);
2177 ASSERT_FALSE (known_size_p (ph::make (-1, 0, 0)));
2178 ASSERT_TRUE (known_size_p (ph::make (0, 0, 0)));
2179 ASSERT_TRUE (known_size_p (ph::make (1, 0, 0)));
2180 }
2181
2182 /* Test maybe_in_range_p for both signed and unsigned C. */
2183
2184 template<unsigned int N, typename C, typename T>
2185 static void
2186 test_maybe_in_range_p ()
2187 {
2188 typedef coeff_helper<C> ch;
2189 typedef poly_helper<T> ph;
2190
2191 ASSERT_FALSE (maybe_in_range_p (ch::make (4),
2192 ph::make (5, 1, 2),
2193 ch::make (-1)));
2194 ASSERT_FALSE (maybe_in_range_p (ph::make (4, 0, 0),
2195 ph::make (5, 1, 2),
2196 ch::make (-1)));
2197 ASSERT_FALSE (maybe_in_range_p (ph::make (4, 1, 2),
2198 ph::make (5, 1, 2),
2199 ch::make (-1)));
2200 ASSERT_TRUE (maybe_in_range_p (ph::make (5, 1, 2),
2201 ph::make (5, 1, 2),
2202 ch::make (-1)));
2203 ASSERT_EQ (maybe_in_range_p (ph::make (4, 0, 3),
2204 ph::make (5, 1, 2),
2205 ch::make (-1)), N == 3);
2206 ASSERT_EQ (maybe_in_range_p (ph::make (4, 2, 0),
2207 ph::make (5, 1, 2),
2208 ch::make (-1)), N >= 2);
2209 ASSERT_TRUE (maybe_in_range_p (ph::make (500, 100, 200),
2210 ph::make (5, 1, 2),
2211 ch::make (-1)));
2212 ASSERT_EQ (maybe_in_range_p (ph::make (6, 1, 0),
2213 ph::make (5, 1, 1),
2214 ch::make (1)), N == 3);
2215 ASSERT_EQ (maybe_in_range_p (ph::make (6, 0, 1),
2216 ph::make (5, 1, 1),
2217 ch::make (1)), N >= 2);
2218 ASSERT_FALSE (maybe_in_range_p (ph::make (14, 1, 2),
2219 ph::make (5, 1, 2),
2220 ch::make (9)));
2221 ASSERT_FALSE (maybe_in_range_p (ph::make (14, 1, 2),
2222 ch::make (5),
2223 ph::make (9, 1, 2)));
2224 ASSERT_FALSE (maybe_in_range_p (ph::make (15, 15, 17),
2225 ph::make (8, 10, 11),
2226 ph::make (7, 5, 6)));
2227 ASSERT_EQ (maybe_in_range_p (ph::make (15, 15, 16),
2228 ph::make (8, 10, 11),
2229 ph::make (7, 5, 6)), N == 3);
2230 ASSERT_EQ (maybe_in_range_p (ph::make (15, 14, 17),
2231 ph::make (8, 10, 11),
2232 ph::make (7, 5, 6)), N >= 2);
2233 ASSERT_TRUE (maybe_in_range_p (ph::make (6, 100, 1000),
2234 ph::make (5, 10, 11),
2235 ph::make (2, 1, 2)));
2236 ASSERT_FALSE (maybe_in_range_p (ph::make (6, 8, 2),
2237 ph::make (6, 8, 2),
2238 ch::make (0)));
2239 ASSERT_EQ (maybe_in_range_p (ph::make (6, 8, 1),
2240 ph::make (6, 7, 2),
2241 ph::make (0, 1, 2)), N == 3);
2242 }
2243
2244 /* Test known_in_range_p for both signed and unsigned C. */
2245
2246 template<unsigned int N, typename C, typename T>
2247 static void
2248 test_known_in_range_p ()
2249 {
2250 typedef coeff_helper<C> ch;
2251 typedef poly_helper<T> ph;
2252
2253 ASSERT_FALSE (known_in_range_p (ch::make (4),
2254 ph::make (5, 1, 2),
2255 ch::make (-1)));
2256 ASSERT_FALSE (known_in_range_p (ph::make (5, 1, 2),
2257 ph::make (5, 1, 2),
2258 ch::make (-1)));
2259 ASSERT_FALSE (known_in_range_p (ph::make (6, 2, 3),
2260 ph::make (5, 1, 2),
2261 ch::make (-1)));
2262 ASSERT_FALSE (known_in_range_p (ph::make (6, 1, 0),
2263 ph::make (5, 1, 1),
2264 ch::make (1)));
2265 ASSERT_FALSE (known_in_range_p (ph::make (6, 0, 1),
2266 ph::make (5, 1, 1),
2267 ch::make (1)));
2268 ASSERT_EQ (known_in_range_p (ph::make (6, 1, 0),
2269 ph::make (5, 1, 1),
2270 ch::make (2)), N <= 2);
2271 ASSERT_EQ (known_in_range_p (ph::make (6, 0, 1),
2272 ph::make (5, 1, 1),
2273 ch::make (2)), N == 1);
2274 ASSERT_TRUE (known_in_range_p (ph::make (6, 4, 5),
2275 ph::make (5, 1, 2),
2276 ph::make (2, 3, 3)));
2277 ASSERT_EQ (known_in_range_p (ph::make (6, 4, 6),
2278 ph::make (5, 1, 2),
2279 ph::make (2, 3, 3)), N <= 2);
2280 ASSERT_EQ (known_in_range_p (ph::make (6, 5, 5),
2281 ph::make (5, 1, 2),
2282 ph::make (2, 3, 3)), N == 1);
2283 ASSERT_FALSE (known_in_range_p (ph::make (6, 8, 2),
2284 ph::make (6, 8, 2),
2285 ch::make (0)));
2286 ASSERT_FALSE (known_in_range_p (ph::make (6, 8, 1),
2287 ph::make (6, 7, 2),
2288 ph::make (0, 1, 2)));
2289 }
2290
2291 /* Test ranges_maybe_overlap_p for both signed and unsigned C. */
2292
2293 template<unsigned int N, typename C, typename T>
2294 static void
2295 test_ranges_maybe_overlap_p ()
2296 {
2297 typedef coeff_helper<C> ch;
2298 typedef poly_helper<T> ph;
2299
2300 ASSERT_TRUE (ranges_maybe_overlap_p (ph::make (4, 1, 2),
2301 ch::make (-1),
2302 ph::make (500, 3, 5),
2303 ch::make (1)));
2304 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (100, 1, 5),
2305 ch::make (-1),
2306 ph::make (50, 1, 5),
2307 ch::make (50)));
2308 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (100, 1, 5),
2309 ch::make (-1),
2310 ph::make (50, 0, 6),
2311 ch::make (50)), N == 3);
2312 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (100, 1, 5),
2313 ch::make (-1),
2314 ph::make (50, 2, 0),
2315 ch::make (50)), N >= 2);
2316 ASSERT_TRUE (ranges_maybe_overlap_p (ph::make (500, 3, 5),
2317 ch::make (1),
2318 ph::make (4, 1, 2),
2319 ch::make (-1)));
2320 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (50, 1, 5),
2321 ch::make (50),
2322 ph::make (100, 1, 5),
2323 ch::make (-1)));
2324 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (10, 2, 3),
2325 ch::make (0),
2326 ch::make (0),
2327 ph::make (20, 30, 40)));
2328 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (10, 2, 3),
2329 ph::make (0, 1, 1),
2330 ph::make (0, 1, 1),
2331 ph::make (20, 30, 40)), N >= 2);
2332 ASSERT_FALSE (ranges_maybe_overlap_p (ch::make (0),
2333 ph::make (20, 30, 40),
2334 ph::make (10, 2, 3),
2335 ch::make (0)));
2336 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (0, 1, 1),
2337 ph::make (20, 30, 40),
2338 ph::make (10, 2, 3),
2339 ph::make (0, 1, 0)), N >= 2);
2340 ASSERT_TRUE (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2341 ph::make (2, 6, 20),
2342 ch::make (7),
2343 ch::make (2)));
2344 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2345 ph::make (2, 6, 20),
2346 ch::make (6),
2347 ph::make (2, 10, 15)));
2348 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2349 ph::make (2, 6, 20),
2350 ch::make (6),
2351 ph::make (0, 0, 16)), N == 3);
2352 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2353 ph::make (2, 6, 20),
2354 ch::make (6),
2355 ph::make (0, 11, 0)), N >= 2);
2356 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (80, 4, 5),
2357 ph::make (10, 6, 7),
2358 ph::make (100, 10, 12),
2359 ph::make (20, 1, 2)));
2360 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (80, 4, 5),
2361 ph::make (10, 6, 7),
2362 ph::make (100, 10, 11),
2363 ph::make (0, 0, 2)), N == 3);
2364 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (80, 5, 5),
2365 ph::make (0, 6, 0),
2366 ph::make (100, 10, 12),
2367 ph::make (20, 1, 2)), N >= 2);
2368 }
2369
2370 /* Test ranges_known_overlap_p for both signed and unsigned C. */
2371
2372 template<unsigned int N, typename C, typename T>
2373 static void
2374 test_ranges_known_overlap_p ()
2375 {
2376 typedef coeff_helper<C> ch;
2377 typedef poly_helper<T> ph;
2378
2379 ASSERT_FALSE (ranges_known_overlap_p (ph::make (5, 1, 2),
2380 ch::make (-1),
2381 ch::make (4),
2382 ch::make (2)));
2383 ASSERT_FALSE (ranges_known_overlap_p (ch::make (9),
2384 ph::make (2, 3, 4),
2385 ch::make (10),
2386 ch::make (-1)));
2387 ASSERT_FALSE (ranges_known_overlap_p (ph::make (10, 2, 3),
2388 ch::make (0),
2389 ch::make (0),
2390 ph::make (20, 30, 40)));
2391 ASSERT_FALSE (ranges_known_overlap_p (ph::make (10, 2, 3),
2392 ph::make (0, 1, 1),
2393 ph::make (0, 1, 1),
2394 ph::make (20, 30, 40)));
2395 ASSERT_FALSE (ranges_known_overlap_p (ch::make (0),
2396 ph::make (20, 30, 40),
2397 ph::make (10, 2, 3),
2398 ch::make (0)));
2399 ASSERT_FALSE (ranges_known_overlap_p (ph::make (0, 1, 1),
2400 ph::make (20, 30, 40),
2401 ph::make (10, 2, 3),
2402 ph::make (0, 1, 0)));
2403 ASSERT_EQ (ranges_known_overlap_p (ph::make (5, 1, 2),
2404 ch::make (1),
2405 ch::make (4),
2406 ch::make (2)), N == 1);
2407 ASSERT_TRUE (ranges_known_overlap_p (ph::make (5, 1, 2),
2408 ch::make (1),
2409 ph::make (4, 1, 2),
2410 ch::make (2)));
2411 ASSERT_TRUE (ranges_known_overlap_p (ch::make (9),
2412 ph::make (2, 3, 4),
2413 ch::make (10),
2414 ch::make (1)));
2415 ASSERT_FALSE (ranges_known_overlap_p (ph::make (10, 11, 12),
2416 ph::make (20, 30, 40),
2417 ch::make (30),
2418 ch::make (1)));
2419 ASSERT_TRUE (ranges_known_overlap_p (ph::make (10, 11, 12),
2420 ph::make (20, 30, 40),
2421 ph::make (29, 41, 52),
2422 ch::make (1)));
2423 ASSERT_EQ (ranges_known_overlap_p (ph::make (10, 11, 12),
2424 ph::make (20, 30, 40),
2425 ph::make (29, 41, 53),
2426 ch::make (1)), N <= 2);
2427 ASSERT_EQ (ranges_known_overlap_p (ph::make (10, 11, 12),
2428 ph::make (20, 30, 40),
2429 ph::make (29, 42, 52),
2430 ch::make (1)), N == 1);
2431 ASSERT_TRUE (ranges_known_overlap_p (ph::make (29, 41, 52),
2432 ch::make (1),
2433 ph::make (10, 11, 12),
2434 ph::make (20, 30, 40)));
2435 ASSERT_EQ (ranges_known_overlap_p (ph::make (29, 41, 53),
2436 ch::make (1),
2437 ph::make (10, 11, 12),
2438 ph::make (20, 30, 40)), N <= 2);
2439 ASSERT_EQ (ranges_known_overlap_p (ph::make (29, 42, 52),
2440 ch::make (1),
2441 ph::make (10, 11, 12),
2442 ph::make (20, 30, 40)), N == 1);
2443 ASSERT_TRUE (ranges_known_overlap_p (ph::make (10, 0, 20),
2444 ph::make (4, 4, 4),
2445 ph::make (7, 3, 20),
2446 ph::make (4, 4, 4)));
2447 }
2448
2449 /* Test known_subrange_p for both signed and unsigned C. */
2450
2451 template<unsigned int N, typename C, typename T>
2452 static void
2453 test_known_subrange_p ()
2454 {
2455 typedef coeff_helper<C> ch;
2456 typedef poly_helper<T> ph;
2457
2458 ASSERT_FALSE (known_subrange_p (ph::make (5, 1, 2),
2459 ch::make (-1),
2460 ch::make (4),
2461 ph::make (2, 2, 2)));
2462 ASSERT_FALSE (known_subrange_p (ph::make (5, 2, 3),
2463 ch::make (2),
2464 ph::make (4, 1, 2),
2465 ch::make (-1)));
2466 ASSERT_FALSE (known_subrange_p (ph::make (6, 2, 3),
2467 ph::make (0, 1, 1),
2468 ch::make (4),
2469 ph::make (3, 4, 11)));
2470 ASSERT_TRUE (known_subrange_p (ph::make (6, 2, 3),
2471 ph::make (1, 1, 1),
2472 ch::make (4),
2473 ph::make (3, 4, 11)));
2474 ASSERT_FALSE (known_subrange_p (ph::make (6, 2, 3),
2475 ph::make (1, 1, 1),
2476 ch::make (4),
2477 ph::make (2, 4, 11)));
2478 ASSERT_TRUE (known_subrange_p (ph::make (10, 20, 30),
2479 ph::make (5, 6, 7),
2480 ph::make (9, 19, 29),
2481 ph::make (6, 7, 8)));
2482 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 31),
2483 ph::make (5, 6, 7),
2484 ph::make (9, 19, 29),
2485 ph::make (6, 7, 8)), N <= 2);
2486 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 30),
2487 ph::make (5, 7, 7),
2488 ph::make (9, 19, 29),
2489 ph::make (6, 7, 8)), N == 1);
2490 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 30),
2491 ph::make (5, 6, 7),
2492 ph::make (9, 18, 29),
2493 ph::make (6, 7, 8)), N == 1);
2494 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 30),
2495 ph::make (5, 6, 7),
2496 ph::make (9, 19, 29),
2497 ph::make (6, 6, 8)), N == 1);
2498 }
2499
2500 /* Test coeffs_in_range_p for both signed and unsigned C. */
2501
2502 template<unsigned int N, typename C, typename T>
2503 static void
2504 test_coeffs_in_range_p (void)
2505 {
2506 typedef coeff_helper<C> ch;
2507 typedef poly_helper<T> ph;
2508
2509 ASSERT_TRUE (coeffs_in_range_p (ph::make (10, 20, 30), 10, 30));
2510 ASSERT_EQ (coeffs_in_range_p (ph::make (1, 10, 19), 0, 11), N <= 2);
2511 ASSERT_EQ (coeffs_in_range_p (ph::make (100, 1, 102), 10, 100), N == 1);
2512 ASSERT_FALSE (coeffs_in_range_p (ph::make (10, 11, 12), 7, 9));
2513 ASSERT_FALSE (coeffs_in_range_p (ph::make (10, 11, 12), 13, 15));
2514 }
2515
2516 /* Test maybe_eq for poly_int<2, C>, given that C is signed. */
2517
2518 template<typename C>
2519 static void
2520 test_signed_maybe_eq_2 ()
2521 {
2522 typedef poly_int<2, C> T;
2523
2524 /* Test maybe_eq (T, C). */
2525 ASSERT_TRUE (maybe_eq (T (4, -4), 0));
2526 ASSERT_FALSE (maybe_eq (T (4, -4), 1));
2527 ASSERT_TRUE (maybe_eq (T (4, -4), 4));
2528 ASSERT_FALSE (maybe_eq (T (4, -4), 8));
2529 ASSERT_TRUE (maybe_eq (T (4, -4), -4));
2530 ASSERT_FALSE (maybe_eq (T (4, -4), -3));
2531
2532 /* Test maybe_eq (C, T). */
2533 ASSERT_FALSE (maybe_eq (0, T (4, -3)));
2534 ASSERT_TRUE (maybe_eq (1, T (4, -3)));
2535 ASSERT_TRUE (maybe_eq (4, T (4, -3)));
2536 ASSERT_FALSE (maybe_eq (7, T (4, -3)));
2537 ASSERT_FALSE (maybe_eq (T (4, -3), -3));
2538 ASSERT_TRUE (maybe_eq (T (4, -3), -2));
2539
2540 /* Test maybe_eq (T, T). */
2541 ASSERT_TRUE (maybe_eq (T (0, 3), T (6, 1)));
2542 ASSERT_FALSE (maybe_eq (T (0, -3), T (6, 1)));
2543 ASSERT_FALSE (maybe_eq (T (0, 3), T (7, 1)));
2544 ASSERT_TRUE (maybe_eq (T (-3, 4), T (7, -1)));
2545 ASSERT_FALSE (maybe_eq (T (-3, 4), T (6, -1)));
2546 }
2547
2548 /* Test known_ne for poly_int<2, C>, given that C is signed. */
2549
2550 template<typename C>
2551 static void
2552 test_signed_known_ne_2 ()
2553 {
2554 typedef poly_int<2, C> T;
2555
2556 /* Test known_ne (T, C). */
2557 ASSERT_FALSE (known_ne (T (4, -4), 0));
2558 ASSERT_TRUE (known_ne (T (4, -4), 1));
2559 ASSERT_FALSE (known_ne (T (4, -4), 4));
2560 ASSERT_TRUE (known_ne (T (4, -4), 8));
2561 ASSERT_FALSE (known_ne (T (4, -4), -4));
2562 ASSERT_TRUE (known_ne (T (4, -4), -3));
2563
2564 /* Test known_ne (C, T). */
2565 ASSERT_TRUE (known_ne (0, T (4, -3)));
2566 ASSERT_FALSE (known_ne (1, T (4, -3)));
2567 ASSERT_FALSE (known_ne (4, T (4, -3)));
2568 ASSERT_TRUE (known_ne (7, T (4, -3)));
2569 ASSERT_TRUE (known_ne (T (4, -3), -3));
2570 ASSERT_FALSE (known_ne (T (4, -3), -2));
2571
2572 /* Test known_ne (T, T). */
2573 ASSERT_FALSE (known_ne (T (0, 3), T (6, 1)));
2574 ASSERT_TRUE (known_ne (T (0, -3), T (6, 1)));
2575 ASSERT_TRUE (known_ne (T (0, 3), T (7, 1)));
2576 ASSERT_FALSE (known_ne (T (-3, 4), T (7, -1)));
2577 ASSERT_TRUE (known_ne (T (-3, 4), T (6, -1)));
2578 }
2579
2580 /* Test negation for signed C, both via operators and wi::. */
2581
2582 template<unsigned int N, typename C, typename RC, typename T>
2583 static void
2584 test_signed_negation ()
2585 {
2586 typedef poly_helper<T> ph;
2587 typedef poly_helper< poly_int<N, RC> > rph;
2588 typedef poly_helper< poly_int<N, int> > iph;
2589
2590 /* Test unary -. */
2591 ASSERT_KNOWN_EQ (-ph::make (-11, 22, -33),
2592 rph::make (11, -22, 33));
2593
2594 /* Test wi::neg. */
2595 ASSERT_KNOWN_EQ (wi::neg (ph::make (-11, 22, -33)),
2596 iph::make (11, -22, 33));
2597 }
2598
2599 /* Test maybe_le for signed C. */
2600
2601 template<unsigned int N, typename C, typename T>
2602 static void
2603 test_signed_maybe_le ()
2604 {
2605 typedef coeff_helper<C> ch;
2606 typedef poly_helper<T> ph;
2607
2608 /* Test maybe_le (T, C). */
2609 ASSERT_EQ (maybe_le (ph::make (3, 5, -1), ch::make (2)), N == 3);
2610 ASSERT_EQ (maybe_le (ph::make (40, -10, 60), ch::make (15)), N >= 2);
2611 ASSERT_TRUE (maybe_le (ph::make (-14, 0, 0), ch::make (13)));
2612
2613 /* Test maybe_le (C, T). */
2614 ASSERT_EQ (maybe_le (ch::make (4), ph::make (3, 5, -1)), N >= 2);
2615 ASSERT_EQ (maybe_le (ch::make (41), ph::make (40, -10, 60)), N == 3);
2616 ASSERT_TRUE (maybe_le (ch::make (-15), ph::make (11, 0, 0)));
2617
2618 /* Test maybe_le (T, T). */
2619 ASSERT_EQ (maybe_le (ph::make (-2, 4, -2),
2620 ph::make (-3, -5, -1)), N == 3);
2621 ASSERT_EQ (maybe_le (ph::make (-2, -6, 0),
2622 ph::make (-3, 0, 100)), N >= 2);
2623 ASSERT_FALSE (maybe_le (ph::make (-2, 5, 1),
2624 ph::make (-3, 4, 0)));
2625 }
2626
2627 /* Test maybe_lt for signed C. */
2628
2629 template<unsigned int N, typename C, typename T>
2630 static void
2631 test_signed_maybe_lt ()
2632 {
2633 typedef coeff_helper<C> ch;
2634 typedef poly_helper<T> ph;
2635
2636 /* Test maybe_lt (T, C). */
2637 ASSERT_EQ (maybe_lt (ph::make (3, 5, -1), ch::make (2)), N == 3);
2638 ASSERT_EQ (maybe_lt (ph::make (40, -10, 60), ch::make (15)), N >= 2);
2639 ASSERT_TRUE (maybe_lt (ph::make (-18, 0, 0), ch::make (18)));
2640 ASSERT_EQ (maybe_lt (ph::make (-2, -2, -2), ch::make (-2)), N >= 2);
2641
2642 /* Test maybe_lt (C, T). */
2643 ASSERT_EQ (maybe_lt (ch::make (4), ph::make (3, 5, -1)), N >= 2);
2644 ASSERT_EQ (maybe_lt (ch::make (41), ph::make (40, -10, 60)), N == 3);
2645 ASSERT_TRUE (maybe_lt (ch::make (-45), ph::make (40, 0, 0)));
2646 ASSERT_FALSE (maybe_lt (ch::make (-2), ph::make (-2, -2, -2)));
2647
2648 /* Test maybe_lt (T, T). */
2649 ASSERT_EQ (maybe_lt (ph::make (-3, 4, -2),
2650 ph::make (-3, -5, -1)), N == 3);
2651 ASSERT_EQ (maybe_lt (ph::make (-3, -6, 0),
2652 ph::make (-3, 0, 100)), N >= 2);
2653 ASSERT_FALSE (maybe_lt (ph::make (-3, 5, 1),
2654 ph::make (-3, 4, 0)));
2655 }
2656
2657 /* Test maybe_ge for signed C. */
2658
2659 template<unsigned int N, typename C, typename T>
2660 static void
2661 test_signed_maybe_ge ()
2662 {
2663 typedef coeff_helper<C> ch;
2664 typedef poly_helper<T> ph;
2665
2666 /* Test maybe_ge (T, C). */
2667 ASSERT_EQ (maybe_ge (ph::make (3, 5, -1), ch::make (4)), N >= 2);
2668 ASSERT_EQ (maybe_ge (ph::make (40, -10, 60), ch::make (41)), N == 3);
2669 ASSERT_TRUE (maybe_ge (ph::make (11, 0, 0), ch::make (-15)));
2670
2671 /* Test maybe_ge (C, T). */
2672 ASSERT_EQ (maybe_ge (ch::make (2), ph::make (3, 5, -1)), N == 3);
2673 ASSERT_EQ (maybe_ge (ch::make (15), ph::make (40, -10, 60)), N >= 2);
2674 ASSERT_TRUE (maybe_ge (ch::make (13), ph::make (-14, 0, 0)));
2675
2676 /* Test maybe_ge (T, T). */
2677 ASSERT_EQ (maybe_ge (ph::make (-3, -5, -1),
2678 ph::make (-2, 4, -2)), N == 3);
2679 ASSERT_EQ (maybe_ge (ph::make (-3, 0, 100),
2680 ph::make (-2, -6, 0)), N >= 2);
2681 ASSERT_FALSE (maybe_ge (ph::make (-3, 4, 0),
2682 ph::make (-2, 5, 1)));
2683 }
2684
2685 /* Test maybe_gt for signed C. */
2686
2687 template<unsigned int N, typename C, typename T>
2688 static void
2689 test_signed_maybe_gt ()
2690 {
2691 typedef coeff_helper<C> ch;
2692 typedef poly_helper<T> ph;
2693
2694 /* Test maybe_gt (T, C). */
2695 ASSERT_EQ (maybe_gt (ph::make (3, 5, -1), ch::make (4)), N >= 2);
2696 ASSERT_EQ (maybe_gt (ph::make (40, -10, 60), ch::make (41)), N == 3);
2697 ASSERT_TRUE (maybe_gt (ph::make (40, 0, 0), ch::make (-45)));
2698 ASSERT_FALSE (maybe_gt (ph::make (-2, -2, -2), ch::make (-2)));
2699
2700 /* Test maybe_gt (C, T). */
2701 ASSERT_EQ (maybe_gt (ch::make (2), ph::make (3, 5, -1)), N == 3);
2702 ASSERT_EQ (maybe_gt (ch::make (15), ph::make (40, -10, 60)), N >= 2);
2703 ASSERT_TRUE (maybe_gt (ch::make (18), ph::make (-18, 0, 0)));
2704 ASSERT_EQ (maybe_gt (ch::make (-2), ph::make (-2, -2, -2)), N >= 2);
2705
2706 /* Test maybe_gt (T, T). */
2707 ASSERT_EQ (maybe_gt (ph::make (-3, -5, -1),
2708 ph::make (-3, 4, -2)), N == 3);
2709 ASSERT_EQ (maybe_gt (ph::make (-3, 0, 100),
2710 ph::make (-3, -6, 0)), N >= 2);
2711 ASSERT_FALSE (maybe_gt (ph::make (-3, 4, 0),
2712 ph::make (-3, 5, 1)));
2713 }
2714
2715 /* Test known_gt for signed C. */
2716
2717 template<unsigned int N, typename C, typename T>
2718 static void
2719 test_signed_known_gt ()
2720 {
2721 typedef coeff_helper<C> ch;
2722 typedef poly_helper<T> ph;
2723
2724 /* Test known_gt (T, C). */
2725 ASSERT_EQ (known_gt (ph::make (3, 5, -1), ch::make (2)), N <= 2);
2726 ASSERT_EQ (known_gt (ph::make (40, -10, 60), ch::make (15)), N == 1);
2727 ASSERT_FALSE (known_gt (ph::make (-14, 0, 0), ch::make (13)));
2728
2729 /* Test known_gt (C, T). */
2730 ASSERT_EQ (known_gt (ch::make (4), ph::make (3, 5, -1)), N == 1);
2731 ASSERT_EQ (known_gt (ch::make (41), ph::make (40, -10, 60)), N <= 2);
2732 ASSERT_FALSE (known_gt (ch::make (-15), ph::make (11, 0, 0)));
2733
2734 /* Test known_gt (T, T). */
2735 ASSERT_EQ (known_gt (ph::make (-2, 4, -2),
2736 ph::make (-3, -5, -1)), N <= 2);
2737 ASSERT_EQ (known_gt (ph::make (-2, -6, 0),
2738 ph::make (-3, 0, 100)), N == 1);
2739 ASSERT_TRUE (known_gt (ph::make (-2, 5, 1),
2740 ph::make (-3, 4, 0)));
2741 }
2742
2743 /* Test known_ge for signed C. */
2744
2745 template<unsigned int N, typename C, typename T>
2746 static void
2747 test_signed_known_ge ()
2748 {
2749 typedef coeff_helper<C> ch;
2750 typedef poly_helper<T> ph;
2751
2752 /* Test known_ge (T, C). */
2753 ASSERT_EQ (known_ge (ph::make (3, 5, -1), ch::make (2)), N <= 2);
2754 ASSERT_EQ (known_ge (ph::make (40, -10, 60), ch::make (15)), N == 1);
2755 ASSERT_FALSE (known_ge (ph::make (-18, 0, 0), ch::make (18)));
2756 ASSERT_EQ (known_ge (ph::make (-2, -2, -2), ch::make (-2)), N == 1);
2757
2758 /* Test known_ge (C, T). */
2759 ASSERT_EQ (known_ge (ch::make (4), ph::make (3, 5, -1)), N == 1);
2760 ASSERT_EQ (known_ge (ch::make (41), ph::make (40, -10, 60)), N <= 2);
2761 ASSERT_FALSE (known_ge (ch::make (-45), ph::make (40, 0, 0)));
2762 ASSERT_TRUE (known_ge (ch::make (-2), ph::make (-2, -2, -2)));
2763
2764 /* Test known_ge (T, T). */
2765 ASSERT_EQ (known_ge (ph::make (-3, 4, -2),
2766 ph::make (-3, -5, -1)), N <= 2);
2767 ASSERT_EQ (known_ge (ph::make (-3, -6, 0),
2768 ph::make (-3, 0, 100)), N == 1);
2769 ASSERT_TRUE (known_ge (ph::make (-3, 5, 1),
2770 ph::make (-3, 4, 0)));
2771 }
2772
2773 /* Test known_lt for signed C. */
2774
2775 template<unsigned int N, typename C, typename T>
2776 static void
2777 test_signed_known_lt ()
2778 {
2779 typedef coeff_helper<C> ch;
2780 typedef poly_helper<T> ph;
2781
2782 /* Test known_lt (T, C). */
2783 ASSERT_EQ (known_lt (ph::make (3, 5, -1), ch::make (4)), N == 1);
2784 ASSERT_EQ (known_lt (ph::make (40, -10, 60), ch::make (41)), N <= 2);
2785 ASSERT_FALSE (known_lt (ph::make (11, 0, 0), ch::make (-15)));
2786
2787 /* Test known_lt (C, T). */
2788 ASSERT_EQ (known_lt (ch::make (2), ph::make (3, 5, -1)), N <= 2);
2789 ASSERT_EQ (known_lt (ch::make (15), ph::make (40, -10, 60)), N == 1);
2790 ASSERT_FALSE (known_lt (ch::make (13), ph::make (-14, 0, 0)));
2791
2792 /* Test known_lt (T, T). */
2793 ASSERT_EQ (known_lt (ph::make (-3, -5, -1),
2794 ph::make (-2, 4, -2)), N <= 2);
2795 ASSERT_EQ (known_lt (ph::make (-3, 0, 100),
2796 ph::make (-2, -6, 0)), N == 1);
2797 ASSERT_TRUE (known_lt (ph::make (-3, 4, 0),
2798 ph::make (-2, 5, 1)));
2799 }
2800
2801 /* Test known_le for signed C. */
2802
2803 template<unsigned int N, typename C, typename T>
2804 static void
2805 test_signed_known_le ()
2806 {
2807 typedef coeff_helper<C> ch;
2808 typedef poly_helper<T> ph;
2809
2810 /* Test known_le (T, C). */
2811 ASSERT_EQ (known_le (ph::make (3, 5, -1), ch::make (4)), N == 1);
2812 ASSERT_EQ (known_le (ph::make (40, -10, 60), ch::make (41)), N <= 2);
2813 ASSERT_FALSE (known_le (ph::make (40, 0, 0), ch::make (-45)));
2814 ASSERT_TRUE (known_le (ph::make (-2, -2, -2), ch::make (-2)));
2815
2816 /* Test known_le (C, T). */
2817 ASSERT_EQ (known_le (ch::make (2), ph::make (3, 5, -1)), N <= 2);
2818 ASSERT_EQ (known_le (ch::make (15), ph::make (40, -10, 60)), N == 1);
2819 ASSERT_FALSE (known_le (ch::make (18), ph::make (-18, 0, 0)));
2820 ASSERT_EQ (known_le (ch::make (-2), ph::make (-2, -2, -2)), N == 1);
2821
2822 /* Test known_le (T, T). */
2823 ASSERT_EQ (known_le (ph::make (-3, -5, -1),
2824 ph::make (-3, 4, -2)), N <= 2);
2825 ASSERT_EQ (known_le (ph::make (-3, 0, 100),
2826 ph::make (-3, -6, 0)), N == 1);
2827 ASSERT_TRUE (known_le (ph::make (-3, 4, 0),
2828 ph::make (-3, 5, 1)));
2829 }
2830
2831 /* Test ordered_p for signed C. */
2832
2833 template<unsigned int N, typename C, typename T>
2834 static void
2835 test_signed_ordered_p ()
2836 {
2837 typedef coeff_helper<C> ch;
2838 typedef poly_helper<T> ph;
2839
2840 /* Test ordered_p (T, C). */
2841 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (4)), N == 1);
2842 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (3)), N <= 2);
2843 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (2)), N <= 2);
2844 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (41)), N <= 2);
2845 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (40)), N <= 2);
2846 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (39)), N == 1);
2847 ASSERT_EQ (ordered_p (ph::make (4, -4, -4), ch::make (0)), N == 1);
2848 ASSERT_EQ (ordered_p (ph::make (4, 0, -4), ch::make (0)), N <= 2);
2849 ASSERT_EQ (ordered_p (ph::make (4, 4, -4), ch::make (0)), N <= 2);
2850 ASSERT_EQ (ordered_p (ph::make (-4, 4, 4), ch::make (0)), N == 1);
2851 ASSERT_EQ (ordered_p (ph::make (-4, 0, 4), ch::make (0)), N <= 2);
2852 ASSERT_EQ (ordered_p (ph::make (-4, -4, 4), ch::make (0)), N <= 2);
2853
2854 /* Test ordered_p (C, T). */
2855 ASSERT_EQ (ordered_p (ch::make (4), ph::make (3, 5, -1)), N == 1);
2856 ASSERT_EQ (ordered_p (ch::make (3), ph::make (3, 5, -1)), N <= 2);
2857 ASSERT_EQ (ordered_p (ch::make (2), ph::make (3, 5, -1)), N <= 2);
2858 ASSERT_EQ (ordered_p (ch::make (41), ph::make (40, -10, 60)), N <= 2);
2859 ASSERT_EQ (ordered_p (ch::make (40), ph::make (40, -10, 60)), N <= 2);
2860 ASSERT_EQ (ordered_p (ch::make (39), ph::make (40, -10, 60)), N == 1);
2861 ASSERT_EQ (ordered_p (ch::make (0), ph::make (4, -4, -4)), N == 1);
2862 ASSERT_EQ (ordered_p (ch::make (0), ph::make (4, 0, -4)), N <= 2);
2863 ASSERT_EQ (ordered_p (ch::make (0), ph::make (4, 4, -4)), N <= 2);
2864 ASSERT_EQ (ordered_p (ch::make (0), ph::make (-4, 4, 4)), N == 1);
2865 ASSERT_EQ (ordered_p (ch::make (0), ph::make (-4, 0, 4)), N <= 2);
2866 ASSERT_EQ (ordered_p (ch::make (0), ph::make (-4, -4, 4)), N <= 2);
2867 }
2868
2869 /* Test ordered_min for signed C. */
2870
2871 template<unsigned int N, typename C, typename T>
2872 static void
2873 test_signed_ordered_min ()
2874 {
2875 typedef coeff_helper<C> ch;
2876 typedef poly_helper<T> ph;
2877
2878 /* Test ordered_min (T, C). */
2879 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, -12, -14), ch::make (5)),
2880 ph::make (4, -12, -14));
2881
2882 /* Test ordered_min (C, T). */
2883 ASSERT_KNOWN_EQ (ordered_min (ch::make (9), ph::make (9, -90, -77)),
2884 ph::make (9, -90, -77));
2885
2886 /* Test ordered_min (T, T). */
2887 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 9, 17), ph::make (4, -1, 17)),
2888 ph::make (4, -1, 17));
2889 }
2890
2891 /* Test ordered_max for signed C. */
2892
2893 template<unsigned int N, typename C, typename T>
2894 static void
2895 test_signed_ordered_max ()
2896 {
2897 typedef coeff_helper<C> ch;
2898 typedef poly_helper<T> ph;
2899
2900 /* Test ordered_max (T, C). */
2901 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, -12, -14), ch::make (5)),
2902 ch::make (5));
2903
2904 /* Test ordered_max (C, T). */
2905 ASSERT_KNOWN_EQ (ordered_max (ch::make (9), ph::make (9, -90, -77)),
2906 ch::make (9));
2907
2908 /* Test ordered_max (T, T). */
2909 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 9, 17), ph::make (4, -1, 17)),
2910 ph::make (4, 9, 17));
2911 }
2912
2913 /* Test lower_bound for signed C. */
2914
2915 template<unsigned int N, typename C, typename T>
2916 static void
2917 test_signed_lower_bound ()
2918 {
2919 typedef coeff_helper<C> ch;
2920 typedef poly_helper<T> ph;
2921
2922 /* Test lower_bound (T, C). */
2923 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ch::make (5)),
2924 ph::make (4, -1, 0));
2925 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ch::make (-11)),
2926 ph::make (-11, 0, -14));
2927
2928 /* Test lower_bound (C, T). */
2929 ASSERT_KNOWN_EQ (lower_bound (ch::make (5), ph::make (4, -1, 3)),
2930 ph::make (4, -1, 0));
2931 ASSERT_KNOWN_EQ (lower_bound (ch::make (-11), ph::make (6, 5, -14)),
2932 ph::make (-11, 0, -14));
2933
2934 /* Test lower_bound (T, T). */
2935 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
2936 ph::make (4, -1, -2));
2937 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
2938 ph::make (-11, 4, -14));
2939 }
2940
2941 /* Test upper_bound for signed C. */
2942
2943 template<unsigned int N, typename C, typename T>
2944 static void
2945 test_signed_upper_bound ()
2946 {
2947 typedef coeff_helper<C> ch;
2948 typedef poly_helper<T> ph;
2949
2950 /* Test upper_bound (T, C). */
2951 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ch::make (5)),
2952 ph::make (5, 0, 3));
2953 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ch::make (-11)),
2954 ph::make (6, 5, 0));
2955
2956 /* Test upper_bound (C, T). */
2957 ASSERT_KNOWN_EQ (upper_bound (ch::make (5), ph::make (4, -1, 3)),
2958 ph::make (5, 0, 3));
2959 ASSERT_KNOWN_EQ (upper_bound (ch::make (-11), ph::make (6, 5, -14)),
2960 ph::make (6, 5, 0));
2961
2962 /* Test upper_bound (T, T). */
2963 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
2964 ph::make (5, 7, 3));
2965 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
2966 ph::make (6, 5, 3));
2967 }
2968
2969 /* Test constant_multiple_p for signed C. */
2970
2971 template<unsigned int N, typename C, typename T>
2972 static void
2973 test_signed_constant_multiple_p ()
2974 {
2975 typedef poly_helper<T> ph;
2976
2977 /* Test constant_multiple_p (T, C). */
2978 C const_multiple;
2979 ASSERT_TRUE (constant_multiple_p (ph::make (-45, 0, 0), 9,
2980 &const_multiple));
2981 ASSERT_EQ (const_multiple, -5);
2982 ASSERT_TRUE (constant_multiple_p (ph::make (63, 0, 0), -7,
2983 &const_multiple));
2984 ASSERT_EQ (const_multiple, -9);
2985 ASSERT_FALSE (constant_multiple_p (ph::make (-121, 0, 0), -12,
2986 &const_multiple));
2987 ASSERT_TRUE (constant_multiple_p (ph::make (-120, 0, 0), -12,
2988 &const_multiple));
2989 ASSERT_EQ (const_multiple, 10);
2990 ASSERT_FALSE (constant_multiple_p (ph::make (-119, 0, 0), -12,
2991 &const_multiple));
2992 ASSERT_EQ (constant_multiple_p (ph::make (-120, -23, 12), 12,
2993 &const_multiple), N == 1);
2994 if (N == 1)
2995 ASSERT_EQ (const_multiple, -10);
2996
2997 /* Test constant_multiple_p (C, T). */
2998 ASSERT_TRUE (constant_multiple_p (-45, ph::make (9, 0, 0),
2999 &const_multiple));
3000 ASSERT_EQ (const_multiple, -5);
3001 ASSERT_TRUE (constant_multiple_p (63, ph::make (-7, 0, 0),
3002 &const_multiple));
3003 ASSERT_EQ (const_multiple, -9);
3004 ASSERT_FALSE (constant_multiple_p (-121, ph::make (-12, 0, 0),
3005 &const_multiple));
3006 ASSERT_TRUE (constant_multiple_p (-120, ph::make (-12, 0, 0),
3007 &const_multiple));
3008 ASSERT_EQ (const_multiple, 10);
3009 ASSERT_FALSE (constant_multiple_p (-119, ph::make (-12, 0, 0),
3010 &const_multiple));
3011 ASSERT_EQ (constant_multiple_p (-120, ph::make (12, 10, 6),
3012 &const_multiple), N == 1);
3013 if (N == 1)
3014 ASSERT_EQ (const_multiple, -10);
3015
3016 ASSERT_TRUE (constant_multiple_p (ph::make (-40, 80, -200),
3017 ph::make (2, -4, 10),
3018 &const_multiple));
3019 ASSERT_EQ (const_multiple, -20);
3020 ASSERT_EQ (constant_multiple_p (ph::make (-20, 40, 100),
3021 ph::make (2, -4, 10),
3022 &const_multiple), N <= 2);
3023 ASSERT_EQ (const_multiple, N <= 2 ? -10 : -20);
3024 ASSERT_EQ (constant_multiple_p (ph::make (-10, -20, -50),
3025 ph::make (2, -4, 10),
3026 &const_multiple), N == 1);
3027 ASSERT_EQ (const_multiple, N == 1 ? -5 : N == 2 ? -10 : -20);
3028 ASSERT_FALSE (constant_multiple_p (ph::make (-31, 0, 0),
3029 ph::make (-6, 0, 0),
3030 &const_multiple));
3031 ASSERT_TRUE (constant_multiple_p (ph::make (-30, 0, 0),
3032 ph::make (-6, 0, 0),
3033 &const_multiple));
3034 ASSERT_EQ (const_multiple, 5);
3035 ASSERT_FALSE (constant_multiple_p (ph::make (-29, 0, 0),
3036 ph::make (-6, 0, 0),
3037 &const_multiple));
3038 }
3039
3040 /* Test multiple_p for signed C. */
3041
3042 template<unsigned int N, typename C, typename T>
3043 static void
3044 test_signed_multiple_p ()
3045 {
3046 typedef poly_helper<T> ph;
3047
3048 /* Test multiple_p (T, C). */
3049 ASSERT_TRUE (multiple_p (ph::make (-45, 36, 0), 9));
3050 ASSERT_TRUE (multiple_p (ph::make (63, 0, -14), -7));
3051 ASSERT_FALSE (multiple_p (ph::make (-121, 0, 0), -12));
3052 ASSERT_TRUE (multiple_p (ph::make (-120, 0, 0), -12));
3053 ASSERT_FALSE (multiple_p (ph::make (-119, 0, 0), -12));
3054 ASSERT_TRUE (multiple_p (ph::make (-120, -24, 12), 12));
3055 ASSERT_EQ (multiple_p (ph::make (-120, -24, 11), 12), N <= 2);
3056 ASSERT_EQ (multiple_p (ph::make (-120, -23, 12), 12), N == 1);
3057
3058 /* Test multiple_p (C, T). */
3059 ASSERT_TRUE (multiple_p (-45, ph::make (9, 0, 0)));
3060 ASSERT_TRUE (multiple_p (63, ph::make (-7, 0, 0)));
3061 ASSERT_FALSE (multiple_p (-121, ph::make (-12, 0, 0)));
3062 ASSERT_TRUE (multiple_p (-120, ph::make (-12, 0, 0)));
3063 ASSERT_FALSE (multiple_p (-119, ph::make (-12, 0, 0)));
3064 ASSERT_EQ (multiple_p (-120, ph::make (12, 10, 6)), N == 1);
3065
3066 /* Test multiple_p (T, T). */
3067 ASSERT_TRUE (multiple_p (ph::make (-40, 80, -200),
3068 ph::make (2, -4, 10)));
3069 ASSERT_EQ (multiple_p (ph::make (-20, 40, 100),
3070 ph::make (2, -4, 10)), N <= 2);
3071 ASSERT_EQ (multiple_p (ph::make (-10, -20, -50),
3072 ph::make (2, -4, 10)), N == 1);
3073 ASSERT_FALSE (multiple_p (ph::make (-31, 0, 0),
3074 ph::make (-6, 0, 0)));
3075 ASSERT_TRUE (multiple_p (ph::make (-30, 0, 0),
3076 ph::make (-6, 0, 0)));
3077 ASSERT_FALSE (multiple_p (ph::make (-29, 0, 0),
3078 ph::make (-6, 0, 0)));
3079 }
3080
3081 /* Test the 3-operand form of multiple_p for signed C. */
3082
3083 template<unsigned int N, typename C, typename T>
3084 static void
3085 test_signed_multiple_p_with_result ()
3086 {
3087 typedef coeff_helper<C> ch;
3088 typedef poly_helper<T> ph;
3089
3090 /* Test multiple_p (T, C) -> T. */
3091 T multiple;
3092 ASSERT_TRUE (multiple_p (ph::make (-45, 36, 0), 9, &multiple));
3093 ASSERT_KNOWN_EQ (multiple, ph::make (-5, 4, 0));
3094 ASSERT_TRUE (multiple_p (ph::make (63, 0, -14), -7, &multiple));
3095 ASSERT_KNOWN_EQ (multiple, ph::make (-9, 0, 2));
3096 ASSERT_FALSE (multiple_p (ph::make (-121, 0, 0), -12, &multiple));
3097 ASSERT_TRUE (multiple_p (ph::make (-120, 0, 0), -12, &multiple));
3098 ASSERT_KNOWN_EQ (multiple, ch::make (10));
3099 ASSERT_FALSE (multiple_p (ph::make (-119, 0, 0), -12, &multiple));
3100 ASSERT_TRUE (multiple_p (ph::make (-120, -24, 12), 12, &multiple));
3101 ASSERT_KNOWN_EQ (multiple, ph::make (-10, -2, 1));
3102 ASSERT_EQ (multiple_p (ph::make (-120, -24, 11), 12, &multiple), N <= 2);
3103 if (N <= 2)
3104 ASSERT_KNOWN_EQ (multiple, ph::make (-10, -2, 0));
3105 ASSERT_EQ (multiple_p (ph::make (-120, -23, 12), 12, &multiple), N == 1);
3106 if (N == 1)
3107 ASSERT_KNOWN_EQ (multiple, ch::make (-10));
3108
3109 /* Test multiple_p (C, T) -> T. */
3110 ASSERT_TRUE (multiple_p (-45, ph::make (9, 0, 0), &multiple));
3111 ASSERT_KNOWN_EQ (multiple, ch::make (-5));
3112 ASSERT_TRUE (multiple_p (63, ph::make (-7, 0, 0), &multiple));
3113 ASSERT_KNOWN_EQ (multiple, ch::make (-9));
3114 ASSERT_FALSE (multiple_p (-121, ph::make (-12, 0, 0), &multiple));
3115 ASSERT_TRUE (multiple_p (-120, ph::make (-12, 0, 0), &multiple));
3116 ASSERT_KNOWN_EQ (multiple, ch::make (10));
3117 ASSERT_FALSE (multiple_p (-119, ph::make (-12, 0, 0), &multiple));
3118 ASSERT_EQ (multiple_p (-120, ph::make (12, 10, 6), &multiple), N == 1);
3119 ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? -10 : 10));
3120
3121 /* Test multiple_p (T, T) -> T. */
3122 ASSERT_TRUE (multiple_p (ph::make (-40, 80, -200),
3123 ph::make (2, -4, 10),
3124 &multiple));
3125 ASSERT_KNOWN_EQ (multiple, ch::make (-20));
3126 ASSERT_EQ (multiple_p (ph::make (-20, 40, 100),
3127 ph::make (2, -4, 10),
3128 &multiple), N <= 2);
3129 if (N <= 2)
3130 ASSERT_KNOWN_EQ (multiple, ch::make (-10));
3131 ASSERT_EQ (multiple_p (ph::make (-10, -20, -50),
3132 ph::make (2, -4, 10),
3133 &multiple), N == 1);
3134 if (N == 1)
3135 ASSERT_KNOWN_EQ (multiple, ch::make (-5));
3136 ASSERT_FALSE (multiple_p (ph::make (-31, 0, 0),
3137 ph::make (-6, 0, 0),
3138 &multiple));
3139 ASSERT_TRUE (multiple_p (ph::make (-30, 0, 0),
3140 ph::make (-6, 0, 0),
3141 &multiple));
3142 ASSERT_KNOWN_EQ (multiple, ch::make (5));
3143 ASSERT_FALSE (multiple_p (ph::make (-29, 0, 0),
3144 ph::make (-6, 0, 0),
3145 &multiple));
3146 }
3147
3148 /* Test exact_div for signed C. */
3149
3150 template<unsigned int N, typename C, typename T>
3151 static void
3152 test_signed_exact_div ()
3153 {
3154 typedef coeff_helper<C> ch;
3155 typedef poly_helper<T> ph;
3156
3157 /* Test exact_div (T, C). */
3158 ASSERT_KNOWN_EQ (exact_div (ph::make (-45, 36, 0), 9),
3159 ph::make (-5, 4, 0));
3160 ASSERT_KNOWN_EQ (exact_div (ph::make (63, 0, -14), -7),
3161 ph::make (-9, 0, 2));
3162 ASSERT_KNOWN_EQ (exact_div (ph::make (-120, 0, 0), -12),
3163 ch::make (10));
3164 ASSERT_KNOWN_EQ (exact_div (ph::make (-120, -24, 12), 12),
3165 ph::make (-10, -2, 1));
3166
3167 /* Test exact_div (T, T). */
3168 ASSERT_KNOWN_EQ (exact_div (ph::make (-40, 80, -200),
3169 ph::make (2, -4, 10)),
3170 ch::make (-20));
3171 ASSERT_KNOWN_EQ (exact_div (ph::make (-30, 0, 0),
3172 ph::make (-6, 0, 0)),
3173 ch::make (5));
3174 }
3175
3176 /* Test the form of can_div_trunc_p that returns a constant, for signed C. */
3177
3178 template<unsigned int N, typename C, typename T>
3179 static void
3180 test_signed_can_div_trunc_p_const ()
3181 {
3182 typedef coeff_helper<C> ch;
3183 typedef poly_helper<T> ph;
3184
3185 /* Test can_div_trunc_p (T, C) -> C. */
3186 C const_quot;
3187 ASSERT_TRUE (can_div_trunc_p (ph::make (-31, 0, 0), 10, &const_quot));
3188 ASSERT_KNOWN_EQ (const_quot, -3);
3189 ASSERT_TRUE (can_div_trunc_p (ph::make (-29, 0, 0), 10, &const_quot));
3190 ASSERT_KNOWN_EQ (const_quot, -2);
3191
3192 /* Test can_div_trunc_p (T, T) -> C. */
3193 ASSERT_TRUE (can_div_trunc_p (ph::make (-10, 25, -15),
3194 ph::make (2, -5, 3),
3195 &const_quot));
3196 ASSERT_EQ (const_quot, -5);
3197 /* (-5 + 2x) / (-3 + 2x) != 1 when x == 1. */
3198 ASSERT_EQ (can_div_trunc_p (ph::make (-5, 2, 0),
3199 ph::make (-3, 2, 0),
3200 &const_quot), N == 1);
3201 ASSERT_EQ (const_quot, N == 1 ? 1 : -5);
3202 /* Similarly for the third coefficient. */
3203 ASSERT_EQ (can_div_trunc_p (ph::make (-5, -5, 2),
3204 ph::make (-3, -3, 2),
3205 &const_quot), N <= 2);
3206 ASSERT_EQ (const_quot, N <= 2 ? 1 : -5);
3207 /* (-15 + 3x) / (-12 + 2x) != 1 when x == 7. */
3208 ASSERT_EQ (can_div_trunc_p (ph::make (-15, 3, 0),
3209 ph::make (-12, 2, 0),
3210 &const_quot), N == 1);
3211 ASSERT_EQ (const_quot, N <= 2 ? 1 : -5);
3212 ASSERT_TRUE (can_div_trunc_p (ph::make (-21, -18, -14),
3213 ph::make (5, 4, 3),
3214 &const_quot));
3215 ASSERT_EQ (const_quot, -4);
3216 ASSERT_TRUE (can_div_trunc_p (ph::make (18, 9, 13),
3217 ph::make (-8, -4, -5),
3218 &const_quot));
3219 ASSERT_EQ (const_quot, -2);
3220
3221 /* Test can_div_trunc_p (T, T) -> C, T. */
3222 T rem;
3223 ASSERT_TRUE (can_div_trunc_p (ph::make (-10, 25, -15),
3224 ph::make (2, -5, 3),
3225 &const_quot, &rem));
3226 ASSERT_EQ (const_quot, -5);
3227 ASSERT_KNOWN_EQ (rem, ch::make (0));
3228 /* (-5 + 2x) / (-3 + 2x) != 1 when x == 1. */
3229 ASSERT_EQ (can_div_trunc_p (ph::make (-5, 2, 0),
3230 ph::make (-3, 2, 0),
3231 &const_quot, &rem), N == 1);
3232 ASSERT_KNOWN_EQ (const_quot, N == 1 ? 1 : -5);
3233 if (N == 1)
3234 ASSERT_KNOWN_EQ (rem, ch::make (-2));
3235 /* Similarly for the third coefficient. */
3236 ASSERT_EQ (can_div_trunc_p (ph::make (-5, -5, 2),
3237 ph::make (-3, -3, 2),
3238 &const_quot, &rem), N <= 2);
3239 ASSERT_KNOWN_EQ (const_quot, N <= 2 ? 1 : -5);
3240 if (N <= 2)
3241 ASSERT_KNOWN_EQ (rem, ph::make (-2, -2, 0));
3242 /* (-15 + 3x) / (-12 + 2x) != 1 when x == 7. */
3243 ASSERT_EQ (can_div_trunc_p (ph::make (-15, 3, 0),
3244 ph::make (-12, 2, 0),
3245 &const_quot, &rem), N == 1);
3246 ASSERT_KNOWN_EQ (const_quot, N <= 2 ? 1 : -5);
3247 if (N == 1)
3248 ASSERT_KNOWN_EQ (rem, ch::make (-3));
3249 ASSERT_TRUE (can_div_trunc_p (ph::make (-21, -18, -14),
3250 ph::make (5, 4, 3),
3251 &const_quot, &rem));
3252 ASSERT_EQ (const_quot, -4);
3253 ASSERT_KNOWN_EQ (rem, ph::make (-1, -2, -2));
3254 ASSERT_TRUE (can_div_trunc_p (ph::make (18, 9, 13),
3255 ph::make (-8, -4, -5),
3256 &const_quot, &rem));
3257 ASSERT_EQ (const_quot, -2);
3258 ASSERT_KNOWN_EQ (rem, ph::make (2, 1, 3));
3259 ASSERT_TRUE (can_div_trunc_p (ph::make (-9, -10, -20),
3260 ph::make (-5, -5, -20),
3261 &const_quot, &rem));
3262 ASSERT_EQ (const_quot, C (1));
3263 ASSERT_KNOWN_EQ (rem, ph::make (-4, -5, 0));
3264 ASSERT_EQ (can_div_trunc_p (ph::make (-9, -11, -20),
3265 ph::make (-5, -5, -20),
3266 &const_quot, &rem), N == 1);
3267 if (N == 1)
3268 {
3269 ASSERT_EQ (const_quot, C (1));
3270 ASSERT_KNOWN_EQ (rem, C (-4));
3271 }
3272 ASSERT_TRUE (can_div_trunc_p (ph::make (9, 10, 20),
3273 ph::make (-5, -5, -20),
3274 &const_quot, &rem));
3275 ASSERT_EQ (const_quot, C (-1));
3276 ASSERT_KNOWN_EQ (rem, ph::make (4, 5, 0));
3277 ASSERT_EQ (can_div_trunc_p (ph::make (9, 11, 20),
3278 ph::make (-5, -5, -20),
3279 &const_quot, &rem), N == 1);
3280 if (N == 1)
3281 {
3282 ASSERT_EQ (const_quot, C (-1));
3283 ASSERT_KNOWN_EQ (rem, C (4));
3284 }
3285 ASSERT_TRUE (can_div_trunc_p (ph::make (-9, -10, -20),
3286 ph::make (5, 5, 20),
3287 &const_quot, &rem));
3288 ASSERT_EQ (const_quot, C (-1));
3289 ASSERT_KNOWN_EQ (rem, ph::make (-4, -5, 0));
3290 ASSERT_EQ (can_div_trunc_p (ph::make (-9, -11, -20),
3291 ph::make (5, 5, 20),
3292 &const_quot, &rem), N == 1);
3293 if (N == 1)
3294 {
3295 ASSERT_EQ (const_quot, C (-1));
3296 ASSERT_KNOWN_EQ (rem, C (-4));
3297 }
3298 }
3299
3300 /* Test the form of can_div_trunc_p that returns a poly_int, for signed C. */
3301
3302 template<unsigned int N, typename C, typename T>
3303 static void
3304 test_signed_can_div_trunc_p_poly ()
3305 {
3306 typedef coeff_helper<C> ch;
3307 typedef poly_helper<T> ph;
3308
3309 /* Test can_div_trunc_p (T, C) -> T. */
3310 T quot;
3311 ASSERT_TRUE (can_div_trunc_p (ph::make (-99, 0, 0), 10, &quot));
3312 ASSERT_KNOWN_EQ (quot, ch::make (-9));
3313 ASSERT_TRUE (can_div_trunc_p (ph::make (7, -63, 81), 9, &quot));
3314 ASSERT_KNOWN_EQ (quot, ph::make (0, -7, 9));
3315 ASSERT_TRUE (can_div_trunc_p (ph::make (15, 44, -55), -11, &quot));
3316 ASSERT_KNOWN_EQ (quot, ph::make (-1, -4, 5));
3317 ASSERT_EQ (can_div_trunc_p (ph::make (-63, -24, -17), -8, &quot), N <= 2);
3318 if (N <= 2)
3319 ASSERT_KNOWN_EQ (quot, ph::make (7, 3, 0));
3320 ASSERT_EQ (can_div_trunc_p (ph::make (40, 48, 70), -7, &quot), N == 1);
3321 if (N == 1)
3322 ASSERT_KNOWN_EQ (quot, ch::make (-5));
3323
3324 /* Test can_div_trunc_p (T, C) -> T, C. */
3325 C const_rem;
3326 ASSERT_TRUE (can_div_trunc_p (ph::make (-99, 0, 0), 10,
3327 &quot, &const_rem));
3328 ASSERT_KNOWN_EQ (quot, ch::make (-9));
3329 ASSERT_EQ (const_rem, -9);
3330 ASSERT_TRUE (can_div_trunc_p (ph::make (7, -63, 81), 9,
3331 &quot, &const_rem));
3332 ASSERT_KNOWN_EQ (quot, ph::make (0, -7, 9));
3333 ASSERT_EQ (const_rem, 7);
3334 ASSERT_TRUE (can_div_trunc_p (ph::make (15, 44, -55), -11,
3335 &quot, &const_rem));
3336 ASSERT_KNOWN_EQ (quot, ph::make (-1, -4, 5));
3337 ASSERT_EQ (const_rem, 4);
3338 ASSERT_EQ (can_div_trunc_p (ph::make (-63, -24, -17), -8,
3339 &quot, &const_rem), N <= 2);
3340 if (N <= 2)
3341 {
3342 ASSERT_KNOWN_EQ (quot, ph::make (7, 3, 0));
3343 ASSERT_EQ (const_rem, -7);
3344 }
3345 ASSERT_EQ (can_div_trunc_p (ph::make (40, 48, 70), -7,
3346 &quot, &const_rem), N == 1);
3347 if (N == 1)
3348 {
3349 ASSERT_KNOWN_EQ (quot, ch::make (-5));
3350 ASSERT_EQ (const_rem, 5);
3351 }
3352 }
3353
3354 /* Test can_div_away_from_zero_p for signed C. */
3355
3356 template<unsigned int N, typename C, typename T>
3357 static void
3358 test_signed_can_div_away_from_zero_p ()
3359 {
3360 typedef poly_helper<T> ph;
3361
3362 /* Test can_div_away_from_zero_p (T, T) -> C. */
3363 C const_quot;
3364 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (-10, 25, -15),
3365 ph::make (2, -5, 3),
3366 &const_quot));
3367 ASSERT_EQ (const_quot, -5);
3368 /* (-5 + 2x) / (-3 + 2x) != 1 when x == 1. */
3369 ASSERT_EQ (can_div_away_from_zero_p (ph::make (-5, 2, 0),
3370 ph::make (-3, 2, 0),
3371 &const_quot), N == 1);
3372 ASSERT_EQ (const_quot, N == 1 ? 2 : -5);
3373 /* Similarly for the third coefficient. */
3374 ASSERT_EQ (can_div_away_from_zero_p (ph::make (-5, -5, 2),
3375 ph::make (-3, -3, 2),
3376 &const_quot), N <= 2);
3377 ASSERT_EQ (const_quot, N <= 2 ? 2 : -5);
3378 /* (-15 + 3x) / (-12 + 2x) != 1 when x == 7. */
3379 ASSERT_EQ (can_div_away_from_zero_p (ph::make (-15, 3, 0),
3380 ph::make (-12, 2, 0),
3381 &const_quot), N == 1);
3382 ASSERT_EQ (const_quot, N <= 2 ? 2 : -5);
3383 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (-21, -18, -14),
3384 ph::make (5, 4, 3),
3385 &const_quot));
3386 ASSERT_EQ (const_quot, -5);
3387 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (18, 9, 13),
3388 ph::make (-8, -4, -5),
3389 &const_quot));
3390 ASSERT_EQ (const_quot, -3);
3391 }
3392
3393 /* Test maybe_in_range_p for signed C. */
3394
3395 template<unsigned int N, typename C, typename T>
3396 static void
3397 test_signed_maybe_in_range_p ()
3398 {
3399 typedef coeff_helper<C> ch;
3400 typedef poly_helper<T> ph;
3401
3402 ASSERT_EQ (maybe_in_range_p (ch::make (4),
3403 ph::make (5, 1, -2),
3404 ph::make (-1, -1, -1)), N == 3);
3405 ASSERT_EQ (maybe_in_range_p (ch::make (4),
3406 ph::make (5, -1, 2),
3407 ph::make (-1, -1, -1)), N >= 2);
3408 }
3409
3410 /* Test maybe_le for unsigned C. */
3411
3412 template<unsigned int N, typename C, typename T>
3413 static void
3414 test_unsigned_maybe_le ()
3415 {
3416 typedef coeff_helper<C> ch;
3417 typedef poly_helper<T> ph;
3418
3419 /* Test maybe_le (T, C). */
3420 ASSERT_FALSE (maybe_le (ph::make (3, 5, -1), ch::make (2)));
3421 ASSERT_FALSE (maybe_le (ph::make (40, -10, 60), ch::make (15)));
3422 ASSERT_FALSE (maybe_le (ph::make (-14, 0, 0), ch::make (13)));
3423
3424 /* Test maybe_le (C, T). */
3425 ASSERT_EQ (maybe_le (ch::make (4), ph::make (3, 5, -1)), N >= 2);
3426 ASSERT_EQ (maybe_le (ch::make (41), ph::make (40, -10, 60)), N >= 2);
3427 ASSERT_FALSE (maybe_le (ch::make (-15), ph::make (11, 0, 0)));
3428
3429 /* Test maybe_le (T, T). */
3430 ASSERT_EQ (maybe_le (ph::make (-2, 4, -2),
3431 ph::make (-3, -5, -1)), N >= 2);
3432 ASSERT_EQ (maybe_le (ph::make (-2, -6, 0),
3433 ph::make (-3, 0, 100)), N == 3);
3434 ASSERT_FALSE (maybe_le (ph::make (-2, 5, 1),
3435 ph::make (-3, 4, 0)));
3436 }
3437
3438 /* Test maybe_lt for unsigned C. */
3439
3440 template<unsigned int N, typename C, typename T>
3441 static void
3442 test_unsigned_maybe_lt ()
3443 {
3444 typedef coeff_helper<C> ch;
3445 typedef poly_helper<T> ph;
3446
3447 /* Test maybe_lt (T, C). */
3448 ASSERT_FALSE (maybe_lt (ph::make (3, 5, -1), ch::make (2)));
3449 ASSERT_FALSE (maybe_lt (ph::make (40, -10, 60), ch::make (15)));
3450 ASSERT_FALSE (maybe_lt (ph::make (-18, 0, 0), ch::make (18)));
3451 ASSERT_FALSE (maybe_lt (ph::make (-2, -2, -2), ch::make (-2)));
3452
3453 /* Test maybe_lt (C, T). */
3454 ASSERT_EQ (maybe_lt (ch::make (4), ph::make (3, 5, -1)), N >= 2);
3455 ASSERT_EQ (maybe_lt (ch::make (41), ph::make (40, -10, 60)), N >= 2);
3456 ASSERT_FALSE (maybe_lt (ch::make (-45), ph::make (40, 0, 0)));
3457 ASSERT_EQ (maybe_lt (ch::make (-2), ph::make (-2, -2, -2)), N >= 2);
3458
3459 /* Test maybe_lt (T, T). */
3460 ASSERT_EQ (maybe_lt (ph::make (-3, 4, -2),
3461 ph::make (-3, -5, -1)), N >= 2);
3462 ASSERT_EQ (maybe_lt (ph::make (-3, -6, 0),
3463 ph::make (-3, 0, 100)), N == 3);
3464 ASSERT_FALSE (maybe_lt (ph::make (-3, 5, 1),
3465 ph::make (-3, 4, 0)));
3466 }
3467
3468 /* Test maybe_ge for unsigned C. */
3469
3470 template<unsigned int N, typename C, typename T>
3471 static void
3472 test_unsigned_maybe_ge ()
3473 {
3474 typedef coeff_helper<C> ch;
3475 typedef poly_helper<T> ph;
3476
3477 /* Test maybe_ge (T, C). */
3478 ASSERT_EQ (maybe_ge (ph::make (3, 5, -1), ch::make (4)), N >= 2);
3479 ASSERT_EQ (maybe_ge (ph::make (40, -10, 60), ch::make (41)), N >= 2);
3480 ASSERT_FALSE (maybe_ge (ph::make (11, 0, 0), ch::make (-15)));
3481
3482 /* Test maybe_ge (C, T). */
3483 ASSERT_FALSE (maybe_ge (ch::make (2), ph::make (3, 5, -1)));
3484 ASSERT_FALSE (maybe_ge (ch::make (15), ph::make (40, -10, 60)));
3485 ASSERT_FALSE (maybe_ge (ch::make (13), ph::make (-14, 0, 0)));
3486
3487 /* Test maybe_ge (T, T). */
3488 ASSERT_EQ (maybe_ge (ph::make (-3, -5, -1),
3489 ph::make (-2, 4, -2)), N >= 2);
3490 ASSERT_EQ (maybe_ge (ph::make (-3, 0, 100),
3491 ph::make (-2, -6, 0)), N == 3);
3492 ASSERT_FALSE (maybe_ge (ph::make (-3, 4, 0),
3493 ph::make (-2, 5, 1)));
3494 }
3495
3496 /* Test maybe_gt for unsigned C. */
3497
3498 template<unsigned int N, typename C, typename T>
3499 static void
3500 test_unsigned_maybe_gt ()
3501 {
3502 typedef coeff_helper<C> ch;
3503 typedef poly_helper<T> ph;
3504
3505 /* Test maybe_gt (T, C). */
3506 ASSERT_EQ (maybe_gt (ph::make (3, 5, -1), ch::make (4)), N >= 2);
3507 ASSERT_EQ (maybe_gt (ph::make (40, -10, 60), ch::make (41)), N >= 2);
3508 ASSERT_FALSE (maybe_gt (ph::make (40, 0, 0), ch::make (-45)));
3509 ASSERT_EQ (maybe_gt (ph::make (-2, -2, -2), ch::make (-2)), N >= 2);
3510
3511 /* Test maybe_gt (C, T). */
3512 ASSERT_FALSE (maybe_gt (ch::make (2), ph::make (3, 5, -1)));
3513 ASSERT_FALSE (maybe_gt (ch::make (15), ph::make (40, -10, 60)));
3514 ASSERT_FALSE (maybe_gt (ch::make (18), ph::make (-18, 0, 0)));
3515 ASSERT_FALSE (maybe_gt (ch::make (-2), ph::make (-2, -2, -2)));
3516
3517 /* Test maybe_gt (T, T). */
3518 ASSERT_EQ (maybe_gt (ph::make (-3, -5, -1),
3519 ph::make (-3, 4, -2)), N >= 2);
3520 ASSERT_EQ (maybe_gt (ph::make (-3, 0, 100),
3521 ph::make (-3, -6, 0)), N == 3);
3522 ASSERT_FALSE (maybe_gt (ph::make (-3, 4, 0),
3523 ph::make (-3, 5, 1)));
3524 }
3525
3526 /* Test known_gt for unsigned C. */
3527
3528 template<unsigned int N, typename C, typename T>
3529 static void
3530 test_unsigned_known_gt ()
3531 {
3532 typedef coeff_helper<C> ch;
3533 typedef poly_helper<T> ph;
3534
3535 /* Test known_gt (T, C). */
3536 ASSERT_TRUE (known_gt (ph::make (3, 5, -1), ch::make (2)));
3537 ASSERT_TRUE (known_gt (ph::make (40, -10, 60), ch::make (15)));
3538 ASSERT_TRUE (known_gt (ph::make (-14, 0, 0), ch::make (13)));
3539
3540 /* Test known_gt (C, T). */
3541 ASSERT_EQ (known_gt (ch::make (4), ph::make (3, 5, -1)), N == 1);
3542 ASSERT_EQ (known_gt (ch::make (41), ph::make (40, -10, 60)), N == 1);
3543 ASSERT_TRUE (known_gt (ch::make (-15), ph::make (11, 0, 0)));
3544
3545 /* Test known_gt (T, T). */
3546 ASSERT_EQ (known_gt (ph::make (-2, 4, -2),
3547 ph::make (-3, -5, -1)), N == 1);
3548 ASSERT_EQ (known_gt (ph::make (-2, -6, 0),
3549 ph::make (-3, 0, 100)), N <= 2);
3550 ASSERT_TRUE (known_gt (ph::make (-2, 5, 1),
3551 ph::make (-3, 4, 0)));
3552 }
3553
3554 /* Test known_ge for unsigned C. */
3555
3556 template<unsigned int N, typename C, typename T>
3557 static void
3558 test_unsigned_known_ge ()
3559 {
3560 typedef coeff_helper<C> ch;
3561 typedef poly_helper<T> ph;
3562
3563 /* Test known_ge (T, C). */
3564 ASSERT_TRUE (known_ge (ph::make (3, 5, -1), ch::make (2)));
3565 ASSERT_TRUE (known_ge (ph::make (40, -10, 60), ch::make (15)));
3566 ASSERT_TRUE (known_ge (ph::make (-18, 0, 0), ch::make (18)));
3567 ASSERT_TRUE (known_ge (ph::make (-2, -2, -2), ch::make (-2)));
3568
3569 /* Test known_ge (C, T). */
3570 ASSERT_EQ (known_ge (ch::make (4), ph::make (3, 5, -1)), N == 1);
3571 ASSERT_EQ (known_ge (ch::make (41), ph::make (40, -10, 60)), N == 1);
3572 ASSERT_TRUE (known_ge (ch::make (-45), ph::make (40, 0, 0)));
3573 ASSERT_EQ (known_ge (ch::make (-2), ph::make (-2, -2, -2)), N == 1);
3574
3575 /* Test known_ge (T, T). */
3576 ASSERT_EQ (known_ge (ph::make (-3, 4, -2),
3577 ph::make (-3, -5, -1)), N == 1);
3578 ASSERT_EQ (known_ge (ph::make (-3, -6, 0),
3579 ph::make (-3, 0, 100)), N <= 2);
3580 ASSERT_TRUE (known_ge (ph::make (-3, 5, 1),
3581 ph::make (-3, 4, 0)));
3582 }
3583
3584 /* Test known_lt for unsigned C. */
3585
3586 template<unsigned int N, typename C, typename T>
3587 static void
3588 test_unsigned_known_lt ()
3589 {
3590 typedef coeff_helper<C> ch;
3591 typedef poly_helper<T> ph;
3592
3593 /* Test known_lt (T, C). */
3594 ASSERT_EQ (known_lt (ph::make (3, 5, -1), ch::make (4)), N == 1);
3595 ASSERT_EQ (known_lt (ph::make (40, -10, 60), ch::make (41)), N == 1);
3596 ASSERT_TRUE (known_lt (ph::make (11, 0, 0), ch::make (-15)));
3597
3598 /* Test known_lt (C, T). */
3599 ASSERT_TRUE (known_lt (ch::make (2), ph::make (3, 5, -1)));
3600 ASSERT_TRUE (known_lt (ch::make (15), ph::make (40, -10, 60)));
3601 ASSERT_TRUE (known_lt (ch::make (13), ph::make (-14, 0, 0)));
3602
3603 /* Test known_lt (T, T). */
3604 ASSERT_EQ (known_lt (ph::make (-3, -5, -1),
3605 ph::make (-2, 4, -2)), N == 1);
3606 ASSERT_EQ (known_lt (ph::make (-3, 0, 100),
3607 ph::make (-2, -6, 0)), N <= 2);
3608 ASSERT_TRUE (known_lt (ph::make (-3, 4, 0),
3609 ph::make (-2, 5, 1)));
3610 }
3611
3612 /* Test known_le for unsigned C. */
3613
3614 template<unsigned int N, typename C, typename T>
3615 static void
3616 test_unsigned_known_le ()
3617 {
3618 typedef coeff_helper<C> ch;
3619 typedef poly_helper<T> ph;
3620
3621 /* Test known_le (T, C). */
3622 ASSERT_EQ (known_le (ph::make (3, 5, -1), ch::make (4)), N == 1);
3623 ASSERT_EQ (known_le (ph::make (40, -10, 60), ch::make (41)), N == 1);
3624 ASSERT_TRUE (known_le (ph::make (40, 0, 0), ch::make (-45)));
3625 ASSERT_EQ (known_le (ph::make (-2, -2, -2), ch::make (-2)), N == 1);
3626
3627 /* Test known_le (C, T). */
3628 ASSERT_TRUE (known_le (ch::make (2), ph::make (3, 5, -1)));
3629 ASSERT_TRUE (known_le (ch::make (15), ph::make (40, -10, 60)));
3630 ASSERT_TRUE (known_le (ch::make (18), ph::make (-18, 0, 0)));
3631 ASSERT_TRUE (known_le (ch::make (-2), ph::make (-2, -2, -2)));
3632
3633 /* Test known_le (T, T). */
3634 ASSERT_EQ (known_le (ph::make (-3, -5, -1),
3635 ph::make (-3, 4, -2)), N == 1);
3636 ASSERT_EQ (known_le (ph::make (-3, 0, 100),
3637 ph::make (-3, -6, 0)), N <= 2);
3638 ASSERT_TRUE (known_le (ph::make (-3, 4, 0),
3639 ph::make (-3, 5, 1)));
3640 }
3641
3642 /* Test ordered_p for unsigned C. */
3643
3644 template<unsigned int N, typename C, typename T>
3645 static void
3646 test_unsigned_ordered_p ()
3647 {
3648 typedef coeff_helper<C> ch;
3649 typedef poly_helper<T> ph;
3650
3651 /* Test ordered_p (T, C). */
3652 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (4)), N == 1);
3653 ASSERT_TRUE (ordered_p (ph::make (3, 5, -1), ch::make (3)));
3654 ASSERT_TRUE (ordered_p (ph::make (3, 5, -1), ch::make (2)));
3655 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (41)), N == 1);
3656 ASSERT_TRUE (ordered_p (ph::make (40, -10, 60), ch::make (40)));
3657 ASSERT_TRUE (ordered_p (ph::make (40, -10, 60), ch::make (39)));
3658 ASSERT_TRUE (ordered_p (ph::make (4, -4, -4), ch::make (0)));
3659 ASSERT_TRUE (ordered_p (ph::make (4, 0, -4), ch::make (0)));
3660 ASSERT_TRUE (ordered_p (ph::make (4, 4, -4), ch::make (0)));
3661 ASSERT_TRUE (ordered_p (ph::make (-4, 4, 4), ch::make (0)));
3662 ASSERT_TRUE (ordered_p (ph::make (-4, 0, 4), ch::make (0)));
3663 ASSERT_TRUE (ordered_p (ph::make (-4, -4, 4), ch::make (0)));
3664
3665 /* Test ordered_p (C, T). */
3666 ASSERT_EQ (ordered_p (ch::make (4), ph::make (3, 5, -1)), N == 1);
3667 ASSERT_TRUE (ordered_p (ch::make (3), ph::make (3, 5, -1)));
3668 ASSERT_TRUE (ordered_p (ch::make (2), ph::make (3, 5, -1)));
3669 ASSERT_EQ (ordered_p (ch::make (41), ph::make (40, -10, 60)), N == 1);
3670 ASSERT_TRUE (ordered_p (ch::make (40), ph::make (40, -10, 60)));
3671 ASSERT_TRUE (ordered_p (ch::make (39), ph::make (40, -10, 60)));
3672 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, -4, -4)));
3673 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 0, -4)));
3674 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 4, -4)));
3675 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, 4, 4)));
3676 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, 0, 4)));
3677 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, -4, 4)));
3678 }
3679
3680 /* Test ordered_min for unsigned C. */
3681
3682 template<unsigned int N, typename C, typename T>
3683 static void
3684 test_unsigned_ordered_min ()
3685 {
3686 typedef coeff_helper<C> ch;
3687 typedef poly_helper<T> ph;
3688
3689 /* Test ordered_min (T, C). */
3690 ASSERT_KNOWN_EQ (ordered_min (ph::make (5, -12, -14), ch::make (5)),
3691 ch::make (5));
3692
3693 /* Test ordered_min (C, T). */
3694 ASSERT_KNOWN_EQ (ordered_min (ch::make (9), ph::make (9, -90, -77)),
3695 ch::make (9));
3696
3697 /* Test ordered_min (T, T). */
3698 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 9, 17), ph::make (4, -1, 17)),
3699 ph::make (4, 9, 17));
3700 }
3701
3702 /* Test ordered_max for unsigned C. */
3703
3704 template<unsigned int N, typename C, typename T>
3705 static void
3706 test_unsigned_ordered_max ()
3707 {
3708 typedef coeff_helper<C> ch;
3709 typedef poly_helper<T> ph;
3710
3711 /* Test ordered_max (T, C). */
3712 ASSERT_KNOWN_EQ (ordered_max (ph::make (5, -12, -14), ch::make (5)),
3713 ph::make (5, -12, -14));
3714
3715 /* Test ordered_max (C, T). */
3716 ASSERT_KNOWN_EQ (ordered_max (ch::make (9), ph::make (9, -90, -77)),
3717 ph::make (9, -90, -77));
3718
3719 /* Test ordered_max (T, T). */
3720 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 9, 17), ph::make (4, -1, 17)),
3721 ph::make (4, -1, 17));
3722 }
3723
3724 /* Test lower_bound for unsigned C. */
3725
3726 template<unsigned int N, typename C, typename T>
3727 static void
3728 test_unsigned_lower_bound ()
3729 {
3730 typedef coeff_helper<C> ch;
3731 typedef poly_helper<T> ph;
3732
3733 /* Test lower_bound (T, C). */
3734 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ch::make (5)),
3735 ch::make (4));
3736 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ch::make (-11)),
3737 ch::make (6));
3738
3739 /* Test lower_bound (C, T). */
3740 ASSERT_KNOWN_EQ (lower_bound (ch::make (5), ph::make (4, -1, 3)),
3741 ch::make (4));
3742 ASSERT_KNOWN_EQ (lower_bound (ch::make (-11), ph::make (6, 5, -14)),
3743 ch::make (6));
3744
3745 /* Test lower_bound (T, T). */
3746 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
3747 ph::make (4, 7, 3));
3748 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
3749 ph::make (6, 4, 3));
3750 }
3751
3752 /* Test upper_bound for unsigned C. */
3753
3754 template<unsigned int N, typename C, typename T>
3755 static void
3756 test_unsigned_upper_bound ()
3757 {
3758 typedef coeff_helper<C> ch;
3759 typedef poly_helper<T> ph;
3760
3761 /* Test upper_bound (T, C). */
3762 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ch::make (5)),
3763 ph::make (5, -1, 3));
3764 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ch::make (-11)),
3765 ph::make (-11, 5, -14));
3766
3767 /* Test upper_bound (C, T). */
3768 ASSERT_KNOWN_EQ (upper_bound (ch::make (5), ph::make (4, -1, 3)),
3769 ph::make (5, -1, 3));
3770 ASSERT_KNOWN_EQ (upper_bound (ch::make (-11), ph::make (6, 5, -14)),
3771 ph::make (-11, 5, -14));
3772
3773 /* Test upper_bound (T, T). */
3774 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
3775 ph::make (5, -1, -2));
3776 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
3777 ph::make (-11, 5, -14));
3778 }
3779
3780 /* Test maybe_in_range_p for unsigned C. */
3781
3782 template<unsigned int N, typename C, typename T>
3783 static void
3784 test_unsigned_maybe_in_range_p ()
3785 {
3786 typedef coeff_helper<C> ch;
3787 typedef poly_helper<T> ph;
3788
3789 /* Unknown size for N == 1. */
3790 ASSERT_TRUE (maybe_in_range_p (ch::make (-1),
3791 ch::make (0),
3792 ph::make (-1, -1, -1)));
3793 /* Unknown size for all N. */
3794 ASSERT_TRUE (maybe_in_range_p (ph::make (-1, -1, -1),
3795 ch::make (0),
3796 ch::make (-1)));
3797 /* Unknown size for N == 1. */
3798 ASSERT_EQ (maybe_in_range_p (ph::make (-1, -1, -1),
3799 ch::make (0),
3800 ph::make (-1, -1, -1)), N == 1);
3801 ASSERT_EQ (maybe_in_range_p (ch::make (-2),
3802 ch::make (0),
3803 ph::make (-2, -2, -2)), N >= 2);
3804 ASSERT_FALSE (maybe_in_range_p (ph::make (-2, -2, -2),
3805 ch::make (0),
3806 ch::make (-2)));
3807 ASSERT_FALSE (maybe_in_range_p (ph::make (-2, -2, -2),
3808 ch::make (0),
3809 ph::make (-2, -2, -2)));
3810 ASSERT_TRUE (maybe_in_range_p (ph::make (-2, -2, -2),
3811 ch::make (1),
3812 ph::make (-2, -2, -2)));
3813 ASSERT_TRUE (maybe_in_range_p (ph::make (-2, -2, -2),
3814 ch::make (1),
3815 ch::make (-2)));
3816 }
3817
3818 /* Test known_in_range_p for unsigned C. */
3819
3820 template<unsigned int N, typename C, typename T>
3821 static void
3822 test_unsigned_known_in_range_p ()
3823 {
3824 typedef coeff_helper<C> ch;
3825 typedef poly_helper<T> ph;
3826
3827 ASSERT_FALSE (known_in_range_p (ch::make (4),
3828 ph::make (5, 1, 2),
3829 ch::make (-2)));
3830 ASSERT_TRUE (known_in_range_p (ph::make (6, 1, 2),
3831 ph::make (5, 1, 2),
3832 ch::make (-2)));
3833 ASSERT_TRUE (known_in_range_p (ph::make (6, 1, 2),
3834 ph::make (5, 1, 2),
3835 ph::make (-2, -2, -2)));
3836 }
3837
3838 /* Test things that work for poly_int-based types T, given that the
3839 coefficient type C is a primitive integer type. N is the number of
3840 coefficients in C */
3841
3842 template<unsigned int N, typename C, typename T>
3843 static void
3844 test_hwi ()
3845 {
3846 typedef coeff_helper<C> ch;
3847 typedef poly_helper<T> ph;
3848
3849 /* Test coeff_gcd. */
3850 ASSERT_EQ (coeff_gcd (ph::make (30, 45, 10)),
3851 N == 1 ? 30 : N == 2 ? 15 : 5);
3852 ASSERT_EQ (coeff_gcd (ph::make (0, 18, 21)),
3853 N == 1 ? 0 : N == 2 ? 18 : 3);
3854 ASSERT_EQ (coeff_gcd (ph::make (0, 0, 101)),
3855 N <= 2 ? 0 : 101);
3856 ASSERT_EQ (coeff_gcd (ph::make (21, 0, 28)),
3857 N <= 2 ? 21 : 7);
3858 ASSERT_EQ (coeff_gcd (ph::make (100, 175, 0)),
3859 N == 1 ? 100 : 25);
3860
3861 /* Test common_multiple (T, C). */
3862 ASSERT_KNOWN_EQ (common_multiple (ph::make (8, 24, 16), 6),
3863 ph::make (24, 72, 48));
3864 ASSERT_KNOWN_EQ (common_multiple (ph::make (30, 0, 0), 45),
3865 ch::make (90));
3866 if (N >= 2)
3867 ASSERT_KNOWN_EQ (common_multiple (ph::make (18, 15, 0), 12),
3868 ph::make (72, 60, 0));
3869 if (N == 3)
3870 ASSERT_KNOWN_EQ (common_multiple (ph::make (18, 15, 4), 12),
3871 ph::make (216, 180, 48));
3872
3873 /* Test common_multiple (C, T). */
3874 ASSERT_KNOWN_EQ (common_multiple (6, ph::make (8, 24, 16)),
3875 ph::make (24, 72, 48));
3876 ASSERT_KNOWN_EQ (common_multiple (45, ph::make (30, 0, 0)),
3877 ch::make (90));
3878 if (N >= 2)
3879 ASSERT_KNOWN_EQ (common_multiple (12, ph::make (18, 15, 0)),
3880 ph::make (72, 60, 0));
3881 if (N == 3)
3882 ASSERT_KNOWN_EQ (common_multiple (12, ph::make (18, 15, 4)),
3883 ph::make (216, 180, 48));
3884
3885 /* Test force_common_multiple. */
3886 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (30, 0, 0),
3887 ph::make (25, 0, 0)),
3888 ph::make (150, 0, 0));
3889 if (N >= 2)
3890 {
3891 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (16, 24, 0),
3892 ph::make (24, 36, 0)),
3893 ph::make (48, 72, 0));
3894 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (16, 24, 0),
3895 ph::make (12, 0, 0)),
3896 ph::make (48, 72, 0));
3897 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (15, 0, 0),
3898 ph::make (21, 9, 0)),
3899 ph::make (105, 45, 0));
3900 }
3901 if (N == 3)
3902 {
3903 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (33, 99, 66),
3904 ph::make (22, 66, 44)),
3905 ph::make (66, 198, 132));
3906 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (30, 0, 45),
3907 ph::make (12, 0, 18)),
3908 ph::make (60, 0, 90));
3909 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (40, 0, 50),
3910 ph::make (8, 0, 0)),
3911 ph::make (160, 0, 200));
3912 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (6, 0, 0),
3913 ph::make (10, 0, 15)),
3914 ph::make (60, 0, 90));
3915 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (20, 40, 30),
3916 ph::make (15, 0, 0)),
3917 ph::make (60, 120, 90));
3918 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (9, 0, 0),
3919 ph::make (90, 81, 27)),
3920 ph::make (90, 81, 27));
3921 }
3922 }
3923
3924 /* Test poly_int<N, C>::to_shwi, using in-range source coefficient value
3925 SRCV (equal to DESTV) and adding DELTA to get an out-of-range value. */
3926
3927 template<unsigned int N, typename C>
3928 static void
3929 test_to_shwi (const C &srcv, int delta, HOST_WIDE_INT destv)
3930 {
3931 typedef poly_helper< poly_int<N, HOST_WIDE_INT> > ps64h;
3932 typedef poly_int<N, C> T;
3933 typedef poly_helper<T> ph;
3934 poly_int<N, HOST_WIDE_INT> shwi;
3935
3936 /* Test in-range T::to_shwi. */
3937 ASSERT_TRUE (ph::make (srcv,
3938 srcv - delta,
3939 srcv - delta * 2).to_shwi (&shwi));
3940 ASSERT_KNOWN_EQ (shwi, ps64h::make (destv,
3941 destv - delta,
3942 destv - delta * 2));
3943
3944 /* Test partially in-range T::to_shwi. */
3945 ASSERT_EQ (ph::make (srcv,
3946 srcv + delta,
3947 srcv + delta * 2).to_shwi (&shwi), N == 1);
3948 if (N == 1)
3949 ASSERT_KNOWN_EQ (shwi, destv);
3950 ASSERT_EQ (ph::make (srcv - delta,
3951 srcv,
3952 srcv + delta).to_shwi (&shwi), N <= 2);
3953 if (N <= 2)
3954 ASSERT_KNOWN_EQ (shwi, ps64h::make (destv - delta,
3955 destv,
3956 destv /* ignored */));
3957
3958 /* Test fully out-of-range T::to_shwi. */
3959 ASSERT_FALSE (ph::make (srcv + delta, srcv, srcv).to_shwi (&shwi));
3960 }
3961
3962 /* Test poly_int<N, C>::to_uhwi, using in-range source coefficient value
3963 SRCV (equal to DESTV) and adding DELTA to get an out-of-range value. */
3964
3965 template<unsigned int N, typename C>
3966 static void
3967 test_to_uhwi (const C &srcv, int delta, unsigned HOST_WIDE_INT destv)
3968 {
3969 typedef poly_helper< poly_int<N, unsigned HOST_WIDE_INT> > pu64h;
3970 typedef poly_int<N, C> T;
3971 typedef poly_helper<T> ph;
3972 poly_int<N, unsigned HOST_WIDE_INT> uhwi;
3973
3974 /* Test in-range T::to_uhwi. */
3975 ASSERT_TRUE (ph::make (srcv,
3976 srcv - delta,
3977 srcv - delta * 2).to_uhwi (&uhwi));
3978 ASSERT_KNOWN_EQ (uhwi, pu64h::make (destv,
3979 destv - delta,
3980 destv - delta * 2));
3981
3982 /* Test partially in-range T::to_uhwi. */
3983 ASSERT_EQ (ph::make (srcv,
3984 srcv + delta,
3985 srcv + delta * 2).to_uhwi (&uhwi), N == 1);
3986 if (N == 1)
3987 ASSERT_KNOWN_EQ (uhwi, destv);
3988 ASSERT_EQ (ph::make (srcv - delta,
3989 srcv,
3990 srcv + delta).to_uhwi (&uhwi), N <= 2);
3991 if (N <= 2)
3992 ASSERT_KNOWN_EQ (uhwi, pu64h::make (destv - delta,
3993 destv,
3994 destv /* ignored */));
3995
3996 /* Test fully out-of-range T::to_uhwi. */
3997 ASSERT_FALSE (ph::make (srcv + delta, srcv, srcv).to_uhwi (&uhwi));
3998 }
3999
4000 /* Test poly_int<N, C>::force_shwi and poly_int<N, C>::force_uhwi, given
4001 that MASK66 has the low 66 bits set and the rest clear. */
4002
4003 template<unsigned int N, typename C>
4004 static void
4005 test_force_hwi (const C &mask66)
4006 {
4007 typedef poly_helper< poly_int<N, HOST_WIDE_INT> > ps64h;
4008 typedef poly_helper< poly_int<N, unsigned HOST_WIDE_INT> > pu64h;
4009 typedef poly_int<N, C> T;
4010 typedef poly_helper<T> ph;
4011 poly_int<N, HOST_WIDE_INT> shwi;
4012 poly_int<N, unsigned HOST_WIDE_INT> uhwi;
4013
4014 C mask65 = wi::arshift (mask66, 1);
4015 C mask64 = wi::arshift (mask66, 2);
4016 C mask63 = wi::arshift (mask66, 3);
4017 C mask62 = wi::arshift (mask66, 4);
4018 C mask61 = wi::arshift (mask66, 5);
4019
4020 /* Test force_shwi. */
4021 ASSERT_KNOWN_EQ (ph::make (mask66, mask65, mask64).force_shwi (),
4022 ps64h::make (HOST_WIDE_INT_M1,
4023 HOST_WIDE_INT_M1,
4024 HOST_WIDE_INT_M1));
4025 ASSERT_KNOWN_EQ (ph::make (mask65, mask64, mask63).force_shwi (),
4026 ps64h::make (HOST_WIDE_INT_M1,
4027 HOST_WIDE_INT_M1,
4028 HOST_WIDE_INT_MAX));
4029 ASSERT_KNOWN_EQ (ph::make (mask64, mask63, mask62).force_shwi (),
4030 ps64h::make (HOST_WIDE_INT_M1,
4031 HOST_WIDE_INT_MAX,
4032 HOST_WIDE_INT_MAX / 2));
4033 ASSERT_KNOWN_EQ (ph::make (mask63, mask62, mask61).force_shwi (),
4034 ps64h::make (HOST_WIDE_INT_MAX,
4035 HOST_WIDE_INT_MAX / 2,
4036 HOST_WIDE_INT_MAX / 4));
4037
4038 /* Test force_uhwi. */
4039 ASSERT_KNOWN_EQ (ph::make (mask66, mask65, mask64).force_uhwi (),
4040 pu64h::make (HOST_WIDE_INT_M1U,
4041 HOST_WIDE_INT_M1U,
4042 HOST_WIDE_INT_M1U));
4043 ASSERT_KNOWN_EQ (ph::make (mask65, mask64, mask63).force_uhwi (),
4044 pu64h::make (HOST_WIDE_INT_M1U,
4045 HOST_WIDE_INT_M1U,
4046 HOST_WIDE_INT_M1U >> 1));
4047 ASSERT_KNOWN_EQ (ph::make (mask64, mask63, mask62).force_uhwi (),
4048 pu64h::make (HOST_WIDE_INT_M1U,
4049 HOST_WIDE_INT_M1U >> 1,
4050 HOST_WIDE_INT_M1U >> 2));
4051 ASSERT_KNOWN_EQ (ph::make (mask63, mask62, mask61).force_uhwi (),
4052 pu64h::make (HOST_WIDE_INT_M1U >> 1,
4053 HOST_WIDE_INT_M1U >> 2,
4054 HOST_WIDE_INT_M1U >> 3));
4055 }
4056
4057 /* Test poly_int<N, wide_int>::from. */
4058
4059 template<unsigned int N>
4060 static void
4061 test_wide_int_from ()
4062 {
4063 typedef poly_helper< poly_int<N, unsigned char> > pu8h;
4064 typedef poly_int<N, wide_int> T;
4065 typedef poly_helper<T> ph;
4066
4067 /* Test narrowing cases of T::from. */
4068 T p_8_3_1 = ph::make (wi::uhwi (8, 3),
4069 wi::uhwi (3, 3),
4070 wi::uhwi (1, 3));
4071 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 3, SIGNED),
4072 p_8_3_1);
4073 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 3, UNSIGNED),
4074 p_8_3_1);
4075
4076 /* Test equal-sized cases of T::from. */
4077 T p_f8_23_81 = ph::make (wi::uhwi (0xf8, 8),
4078 wi::uhwi (0x23, 8),
4079 wi::uhwi (0x81, 8));
4080 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 8, SIGNED),
4081 p_f8_23_81);
4082 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 8, UNSIGNED),
4083 p_f8_23_81);
4084
4085 /* Test widening cases of T::from. */
4086 T p_fff8_0023_ff81 = ph::make (wi::uhwi (0xfff8, 16),
4087 wi::uhwi (0x0023, 16),
4088 wi::uhwi (0xff81, 16));
4089 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 16, SIGNED),
4090 p_fff8_0023_ff81);
4091 T p_00f8_0023_0081 = ph::make (wi::uhwi (0xf8, 16),
4092 wi::uhwi (0x23, 16),
4093 wi::uhwi (0x81, 16));
4094 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 16, UNSIGNED),
4095 p_00f8_0023_0081);
4096 }
4097
4098 /* Test wi::sext for poly_int<N, wide_int>. */
4099
4100 template<unsigned int N>
4101 static void
4102 test_wide_int_sext ()
4103 {
4104 typedef poly_int<N, wide_int> T;
4105 typedef poly_helper<T> ph;
4106
4107 ASSERT_KNOWN_EQ (wi::sext (ph::make (wi::shwi (16, 12),
4108 wi::shwi (63, 12),
4109 wi::shwi (14, 12)), 5),
4110 ph::make (wi::shwi (-16, 12),
4111 wi::shwi (-1, 12),
4112 wi::shwi (14, 12)));
4113 ASSERT_KNOWN_EQ (wi::sext (ph::make (wi::shwi (1024, 12),
4114 wi::shwi (1023, 12),
4115 wi::shwi (1200, 12)), 11),
4116 ph::make (wi::shwi (-1024, 12),
4117 wi::shwi (1023, 12),
4118 wi::shwi (-848, 12)));
4119 }
4120
4121 /* Test wi::zext for poly_int<N, wide_int>. */
4122
4123 template<unsigned int N>
4124 static void
4125 test_wide_int_zext ()
4126 {
4127 typedef poly_int<N, wide_int> T;
4128 typedef poly_helper<T> ph;
4129
4130 ASSERT_KNOWN_EQ (wi::zext (ph::make (wi::uhwi (16, 12),
4131 wi::uhwi (63, 12),
4132 wi::uhwi (14, 12)), 5),
4133 ph::make (wi::uhwi (16, 12),
4134 wi::uhwi (31, 12),
4135 wi::uhwi (14, 12)));
4136 ASSERT_KNOWN_EQ (wi::zext (ph::make (wi::uhwi (1024, 12),
4137 wi::uhwi (1023, 12),
4138 wi::uhwi (3248, 12)), 11),
4139 ph::make (wi::uhwi (1024, 12),
4140 wi::uhwi (1023, 12),
4141 wi::uhwi (1200, 12)));
4142 }
4143
4144 /* Test wi::add for poly_int<N, wide_int>. */
4145
4146 template<unsigned int N>
4147 static void
4148 test_wide_int_add ()
4149 {
4150 typedef poly_int<N, wide_int> T;
4151 typedef poly_helper<T> ph;
4152
4153 wi::overflow_type overflow;
4154 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::uhwi (15, 4),
4155 wi::uhwi (4, 4),
4156 wi::uhwi (2, 4)),
4157 ph::make (wi::uhwi (1, 4),
4158 wi::uhwi (0, 4),
4159 wi::uhwi (0, 4)),
4160 UNSIGNED, &overflow),
4161 ph::make (wi::uhwi (0, 4),
4162 wi::uhwi (4, 4),
4163 wi::uhwi (2, 4)));
4164 ASSERT_TRUE ((bool)overflow);
4165 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::uhwi (30, 5),
4166 wi::uhwi (6, 5),
4167 wi::uhwi (11, 5)),
4168 ph::make (wi::uhwi (1, 5),
4169 wi::uhwi (26, 5),
4170 wi::uhwi (19, 5)),
4171 UNSIGNED, &overflow),
4172 ph::make (wi::uhwi (31, 5),
4173 wi::uhwi (0, 5),
4174 wi::uhwi (30, 5)));
4175 ASSERT_EQ ((bool)overflow, N >= 2);
4176 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::uhwi (1, 6),
4177 wi::uhwi (63, 6),
4178 wi::uhwi (50, 6)),
4179 ph::make (wi::uhwi (61, 6),
4180 wi::uhwi (0, 6),
4181 wi::uhwi (50, 6)),
4182 UNSIGNED, &overflow),
4183 ph::make (wi::uhwi (62, 6),
4184 wi::uhwi (63, 6),
4185 wi::uhwi (36, 6)));
4186 ASSERT_EQ ((bool)overflow, N == 3);
4187
4188 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::shwi (7, 4),
4189 wi::shwi (7, 4),
4190 wi::shwi (-8, 4)),
4191 ph::make (wi::shwi (1, 4),
4192 wi::shwi (0, 4),
4193 wi::shwi (0, 4)),
4194 SIGNED, &overflow),
4195 ph::make (wi::shwi (-8, 4),
4196 wi::shwi (7, 4),
4197 wi::shwi (-8, 4)));
4198 ASSERT_TRUE ((bool)overflow);
4199 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::shwi (-1, 5),
4200 wi::shwi (6, 5),
4201 wi::shwi (11, 5)),
4202 ph::make (wi::shwi (15, 5),
4203 wi::shwi (11, 5),
4204 wi::shwi (-15, 5)),
4205 SIGNED, &overflow),
4206 ph::make (wi::shwi (14, 5),
4207 wi::shwi (-15, 5),
4208 wi::shwi (-4, 5)));
4209 ASSERT_EQ ((bool)overflow, N >= 2);
4210 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::shwi (4, 6),
4211 wi::shwi (0, 6),
4212 wi::shwi (-1, 6)),
4213 ph::make (wi::shwi (-32, 6),
4214 wi::shwi (-32, 6),
4215 wi::shwi (-32, 6)),
4216 SIGNED, &overflow),
4217 ph::make (wi::shwi (-28, 6),
4218 wi::shwi (-32, 6),
4219 wi::shwi (31, 6)));
4220 ASSERT_EQ ((bool)overflow, N == 3);
4221 }
4222
4223 /* Test wi::sub for poly_int<N, wide_int>. */
4224
4225 template<unsigned int N>
4226 static void
4227 test_wide_int_sub ()
4228 {
4229 typedef poly_int<N, wide_int> T;
4230 typedef poly_helper<T> ph;
4231
4232 wi::overflow_type overflow;
4233 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::uhwi (0, 4),
4234 wi::uhwi (4, 4),
4235 wi::uhwi (2, 4)),
4236 ph::make (wi::uhwi (1, 4),
4237 wi::uhwi (0, 4),
4238 wi::uhwi (0, 4)),
4239 UNSIGNED, &overflow),
4240 ph::make (wi::uhwi (15, 4),
4241 wi::uhwi (4, 4),
4242 wi::uhwi (2, 4)));
4243 ASSERT_TRUE ((bool)overflow);
4244 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::uhwi (30, 5),
4245 wi::uhwi (29, 5),
4246 wi::uhwi (11, 5)),
4247 ph::make (wi::uhwi (1, 5),
4248 wi::uhwi (31, 5),
4249 wi::uhwi (9, 5)),
4250 UNSIGNED, &overflow),
4251 ph::make (wi::uhwi (29, 5),
4252 wi::uhwi (30, 5),
4253 wi::uhwi (2, 5)));
4254 ASSERT_EQ ((bool)overflow, N >= 2);
4255 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::uhwi (0, 6),
4256 wi::uhwi (63, 6),
4257 wi::uhwi (0, 6)),
4258 ph::make (wi::uhwi (0, 6),
4259 wi::uhwi (0, 6),
4260 wi::uhwi (52, 6)),
4261 UNSIGNED, &overflow),
4262 ph::make (wi::uhwi (0, 6),
4263 wi::uhwi (63, 6),
4264 wi::uhwi (12, 6)));
4265 ASSERT_EQ ((bool)overflow, N == 3);
4266
4267 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::shwi (-8, 4),
4268 wi::shwi (5, 4),
4269 wi::shwi (-7, 4)),
4270 ph::make (wi::shwi (1, 4),
4271 wi::shwi (0, 4),
4272 wi::shwi (0, 4)),
4273 SIGNED, &overflow),
4274 ph::make (wi::shwi (7, 4),
4275 wi::shwi (5, 4),
4276 wi::shwi (-7, 4)));
4277 ASSERT_TRUE ((bool)overflow);
4278 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::shwi (-1, 5),
4279 wi::shwi (-7, 5),
4280 wi::shwi (0, 5)),
4281 ph::make (wi::shwi (15, 5),
4282 wi::shwi (11, 5),
4283 wi::shwi (-15, 5)),
4284 SIGNED, &overflow),
4285 ph::make (wi::shwi (-16, 5),
4286 wi::shwi (14, 5),
4287 wi::shwi (15, 5)));
4288 ASSERT_EQ ((bool)overflow, N >= 2);
4289 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::shwi (-32, 6),
4290 wi::shwi (-1, 6),
4291 wi::shwi (0, 6)),
4292 ph::make (wi::shwi (-32, 6),
4293 wi::shwi (-32, 6),
4294 wi::shwi (-32, 6)),
4295 SIGNED, &overflow),
4296 ph::make (wi::shwi (0, 6),
4297 wi::shwi (31, 6),
4298 wi::shwi (-32, 6)));
4299 ASSERT_EQ ((bool)overflow, N == 3);
4300 }
4301
4302 /* Test wi::mul for poly_int<N, wide_int>. */
4303
4304 template<unsigned int N>
4305 static void
4306 test_wide_int_mul ()
4307 {
4308 typedef poly_int<N, wide_int> T;
4309 typedef poly_helper<T> ph;
4310
4311 wi::overflow_type overflow;
4312 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::uhwi (4, 4),
4313 wi::uhwi (3, 4),
4314 wi::uhwi (2, 4)), 4,
4315 UNSIGNED, &overflow),
4316 ph::make (wi::uhwi (0, 4),
4317 wi::uhwi (12, 4),
4318 wi::uhwi (8, 4)));
4319 ASSERT_TRUE ((bool)overflow);
4320 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::uhwi (15, 5),
4321 wi::uhwi (31, 5),
4322 wi::uhwi (7, 5)), 2,
4323 UNSIGNED, &overflow),
4324 ph::make (wi::uhwi (30, 5),
4325 wi::uhwi (30, 5),
4326 wi::uhwi (14, 5)));
4327 ASSERT_EQ ((bool)overflow, N >= 2);
4328 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::uhwi (1, 6),
4329 wi::uhwi (0, 6),
4330 wi::uhwi (2, 6)), 63,
4331 UNSIGNED, &overflow),
4332 ph::make (wi::uhwi (63, 6),
4333 wi::uhwi (0, 6),
4334 wi::uhwi (62, 6)));
4335 ASSERT_EQ ((bool)overflow, N == 3);
4336
4337 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::shwi (-1, 4),
4338 wi::shwi (1, 4),
4339 wi::shwi (0, 4)), -8,
4340 SIGNED, &overflow),
4341 ph::make (wi::shwi (-8, 4),
4342 wi::shwi (-8, 4),
4343 wi::shwi (0, 4)));
4344 ASSERT_TRUE ((bool)overflow);
4345 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::shwi (2, 5),
4346 wi::shwi (-3, 5),
4347 wi::shwi (1, 5)), 6,
4348 SIGNED, &overflow),
4349 ph::make (wi::shwi (12, 5),
4350 wi::shwi (14, 5),
4351 wi::shwi (6, 5)));
4352 ASSERT_EQ ((bool)overflow, N >= 2);
4353 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::shwi (5, 6),
4354 wi::shwi (-6, 6),
4355 wi::shwi (7, 6)), -5,
4356 SIGNED, &overflow),
4357 ph::make (wi::shwi (-25, 6),
4358 wi::shwi (30, 6),
4359 wi::shwi (29, 6)));
4360 ASSERT_EQ ((bool)overflow, N == 3);
4361 }
4362
4363 /* Test wi::neg for poly_int<N, wide_int>. */
4364
4365 template<unsigned int N>
4366 static void
4367 test_wide_int_neg ()
4368 {
4369 typedef poly_int<N, wide_int> T;
4370 typedef poly_helper<T> ph;
4371
4372 wi::overflow_type overflow;
4373 ASSERT_KNOWN_EQ (wi::neg (ph::make (wi::shwi (-8, 4),
4374 wi::shwi (7, 4),
4375 wi::shwi (-7, 4)), &overflow),
4376 ph::make (wi::shwi (-8, 4),
4377 wi::shwi (-7, 4),
4378 wi::shwi (7, 4)));
4379 ASSERT_TRUE ((bool)overflow);
4380 ASSERT_KNOWN_EQ (wi::neg (ph::make (wi::shwi (-15, 5),
4381 wi::shwi (-16, 5),
4382 wi::shwi (15, 5)), &overflow),
4383 ph::make (wi::shwi (15, 5),
4384 wi::shwi (-16, 5),
4385 wi::shwi (-15, 5)));
4386 ASSERT_EQ ((bool)overflow, N >= 2);
4387 ASSERT_KNOWN_EQ (wi::neg (ph::make (wi::shwi (-28, 6),
4388 wi::shwi (30, 6),
4389 wi::shwi (-32, 6)), &overflow),
4390 ph::make (wi::shwi (28, 6),
4391 wi::shwi (-30, 6),
4392 wi::shwi (-32, 6)));
4393 ASSERT_EQ ((bool)overflow, N == 3);
4394 }
4395
4396 /* Test poly_int<N, C> for things that only make sense when C is an
4397 offset_int or widest_int. */
4398
4399 template<unsigned int N, typename C>
4400 static void
4401 test_fixed_int (void)
4402 {
4403 typedef poly_helper< poly_int<N, int> > pih;
4404 typedef poly_int<N, C> T;
4405 typedef poly_helper<T> ph;
4406
4407 /* Test signed case. */
4408 ASSERT_KNOWN_EQ (T::from (pih::make (-100, 200, -300), SIGNED),
4409 ph::make (-100, 200, -300));
4410 ASSERT_MAYBE_NE (T::from (pih::make (-100, 200, -300), SIGNED),
4411 ph::make (-100U, 200U, -300U));
4412
4413 /* Test unsigned case. */
4414 ASSERT_MAYBE_NE (T::from (pih::make (-100, 200, -300), UNSIGNED),
4415 ph::make (-100, 200, -300));
4416 ASSERT_KNOWN_EQ (T::from (pih::make (-100, 200, -300), UNSIGNED),
4417 ph::make (-100U, 200U, -300U));
4418
4419 C one = 1;
4420 test_to_shwi<N> (-(one << 63), -1, HOST_WIDE_INT_MIN);
4421 test_to_shwi<N> ((one << 63) - 1, 1, HOST_WIDE_INT_MAX);
4422 test_to_uhwi<N> (C (0), -1, 0U);
4423 test_to_uhwi<N> ((one << 64) - 1, 1, HOST_WIDE_INT_M1U);
4424
4425 /* Test force_shwi and force_uhwi. */
4426 test_force_hwi<N> ((one << 66) - 1);
4427 }
4428
4429 /* Test type promotions. */
4430
4431 template<unsigned int N>
4432 static void
4433 test_type_promotions ()
4434 {
4435 typedef poly_helper< poly_int<N, unsigned short> > pu16h;
4436 typedef poly_helper< poly_int<N, HOST_WIDE_INT> > ps64h;
4437 HOST_WIDE_INT mask32 = ~0U;
4438
4439 /* Test that + on unsigned short promotes to HOST_WIDE_INT. */
4440 ASSERT_KNOWN_EQ (pu16h::make (0xffff, 0xfffe, 0xfffd) + 16,
4441 ps64h::make (0x1000f, 0xfffe, 0xfffd));
4442 ASSERT_KNOWN_EQ (32 + pu16h::make (0xffff, 0xfffe, 0xfffd),
4443 ps64h::make (0x1001f, 0xfffe, 0xfffd));
4444 ASSERT_KNOWN_EQ (pu16h::make (0xffff, 0xfffe, 0xfffd)
4445 + pu16h::make (4, 10, 17),
4446 ps64h::make (0x10003, 0x10008, 0x1000e));
4447
4448 /* Test that - on unsigned short promotes to HOST_WIDE_INT. */
4449 ASSERT_KNOWN_EQ (pu16h::make (1, 2, 3) - ~0U,
4450 ps64h::make (-mask32 + 1, 2, 3));
4451 ASSERT_KNOWN_EQ (INT_MIN - pu16h::make (4, 5, 6),
4452 ps64h::make ((HOST_WIDE_INT) INT_MIN - 4, -5, -6));
4453 ASSERT_KNOWN_EQ (pu16h::make (1, 2, 3) - pu16h::make (100, 200, 300),
4454 ps64h::make (-99, -198, -297));
4455
4456 /* Same for unary -. */
4457 ASSERT_KNOWN_EQ (-pu16h::make (0x8000, 0x9000, 0xa000),
4458 ps64h::make (-0x8000, -0x9000, -0xa000));
4459 ASSERT_MAYBE_NE (-pu16h::make (0x8000, 0x9000, 0xa000),
4460 ps64h::make (0x8000, 0x9000, 0xa000));
4461
4462 /* Test that * on unsigned short promotes to HOST_WIDE_INT. */
4463 ASSERT_KNOWN_EQ (pu16h::make (10, 14, 17) * ~0U,
4464 ps64h::make (10 * mask32, 14 * mask32, 17 * mask32));
4465 ASSERT_KNOWN_EQ (-400000 * pu16h::make (10, 14, 17),
4466 ps64h::make (-4000000, -5600000, -6800000));
4467
4468 /* Test that << on unsigned short promotes to HOST_WIDE_INT. */
4469 ASSERT_KNOWN_EQ (pu16h::make (4, 5, 6) << 50,
4470 ps64h::make ((HOST_WIDE_INT) 4 << 50,
4471 (HOST_WIDE_INT) 5 << 50,
4472 (HOST_WIDE_INT) 6 << 50));
4473
4474 /* Test that can_align_up doesn't truncate to the type of the alignment. */
4475 poly_int<N, HOST_WIDE_INT> aligned;
4476 HOST_WIDE_INT a = (HOST_WIDE_INT_1 << 50);
4477 HOST_WIDE_INT b = (HOST_WIDE_INT_1 << 51);
4478 HOST_WIDE_INT c = (HOST_WIDE_INT_1 << 52);
4479 ASSERT_TRUE (can_align_up (ps64h::make (a - 31, b, c), 16U, &aligned));
4480 ASSERT_KNOWN_EQ (aligned, ps64h::make (a - 16, b, c));
4481
4482 /* Likewise for can_align_down. */
4483 ASSERT_TRUE (can_align_down (ps64h::make (a - 31, b, c), 16U, &aligned));
4484 ASSERT_KNOWN_EQ (aligned, ps64h::make (a - 32, b, c));
4485
4486 /* Same for the force_* routines. */
4487 ASSERT_KNOWN_EQ (force_align_up (ps64h::make (a - 31, b, c), 16U),
4488 ps64h::make (a - 16, b, c));
4489 ASSERT_KNOWN_EQ (force_align_down (ps64h::make (a - 31, b, c), 16U),
4490 ps64h::make (a - 32, b, c));
4491
4492 /* Same for the aligned_*_bound routines. */
4493 ASSERT_KNOWN_EQ (aligned_upper_bound (ps64h::make (a - 31, b - 33, c - 55),
4494 16U),
4495 ps64h::make (a - 16, b - 32, c - 48));
4496 ASSERT_KNOWN_EQ (aligned_lower_bound (ps64h::make (a - 31, b - 33, c - 55),
4497 16U),
4498 ps64h::make (a - 32, b - 48, c - 64));
4499 }
4500
4501 /* Test endpoint_representable_p. */
4502
4503 static void
4504 test_endpoint_representable (void)
4505 {
4506 /* True because the size is unknown. */
4507 ASSERT_TRUE (endpoint_representable_p ((unsigned char) 0x80,
4508 (unsigned char) 0xff));
4509 ASSERT_FALSE (endpoint_representable_p ((unsigned char) 0x80,
4510 (unsigned char) 0xfe));
4511 ASSERT_FALSE (endpoint_representable_p ((unsigned char) 0x80,
4512 (unsigned char) 0x80));
4513 ASSERT_TRUE (endpoint_representable_p ((unsigned char) 0x80,
4514 (unsigned char) 0x7f));
4515 ASSERT_FALSE (endpoint_representable_p ((unsigned char) 0x11,
4516 (unsigned char) 0xef));
4517 ASSERT_TRUE (endpoint_representable_p ((unsigned char) 0x11,
4518 (unsigned char) 0xee));
4519
4520 /* True because the size is unknown. */
4521 ASSERT_TRUE (endpoint_representable_p (INT_MAX, -1));
4522 ASSERT_FALSE (endpoint_representable_p (INT_MAX - 100, INT_MAX));
4523 ASSERT_FALSE (endpoint_representable_p (INT_MAX - 100, 101));
4524 ASSERT_TRUE (endpoint_representable_p (INT_MAX - 100, 100));
4525 ASSERT_TRUE (endpoint_representable_p (0, INT_MAX));
4526 ASSERT_TRUE (endpoint_representable_p (INT_MIN, INT_MAX));
4527
4528 /* True because the size is unknown. */
4529 ASSERT_TRUE (endpoint_representable_p (UINT_MAX, -1U));
4530 ASSERT_FALSE (endpoint_representable_p (UINT_MAX - 400, UINT_MAX - 1));
4531 ASSERT_FALSE (endpoint_representable_p (UINT_MAX - 400, 401U));
4532 ASSERT_TRUE (endpoint_representable_p (UINT_MAX - 400, 400U));
4533 }
4534
4535 /* Test wi::shwi with N coefficients. */
4536
4537 template<unsigned int N>
4538 static void
4539 test_shwi ()
4540 {
4541 typedef poly_int<N, wi::hwi_with_prec> T;
4542 typedef poly_helper<T> ph;
4543
4544 poly_int<N, wide_int> mult;
4545 mult = ph::make (wi::shwi (80, 16),
4546 wi::shwi (-10, 16),
4547 wi::shwi (70, 16)) * 3;
4548 ASSERT_KNOWN_EQ (mult, ph::make (wi::shwi (240, 16),
4549 wi::shwi (-30, 16),
4550 wi::shwi (210, 16)));
4551 }
4552
4553 /* Test wi::uhwi with N coefficients. */
4554
4555 template<unsigned int N>
4556 static void
4557 test_uhwi ()
4558 {
4559 typedef poly_int<N, wi::hwi_with_prec> T;
4560 typedef poly_helper<T> ph;
4561
4562 poly_int<N, wide_int> mult;
4563 mult = ph::make (wi::uhwi (80, 16),
4564 wi::uhwi (-10, 16),
4565 wi::uhwi (70, 16)) * 3;
4566 ASSERT_KNOWN_EQ (mult, ph::make (wi::uhwi (240, 16),
4567 wi::uhwi (-30, 16),
4568 wi::uhwi (210, 16)));
4569 }
4570
4571 /* Test multiple_p for non-polynomial T. */
4572
4573 template<typename T>
4574 static void
4575 test_nonpoly_multiple_p ()
4576 {
4577 ASSERT_TRUE (multiple_p (T (6), T (2)));
4578 ASSERT_TRUE (multiple_p (T (6), T (3)));
4579 ASSERT_FALSE (multiple_p (T (6), T (4)));
4580 ASSERT_FALSE (multiple_p (T (7), T (4)));
4581 ASSERT_TRUE (multiple_p (T (8), T (4)));
4582 }
4583
4584 /* Test known_size_p for non-polynomial T. */
4585
4586 template<typename T>
4587 static void
4588 test_nonpoly_known_size_p ()
4589 {
4590 ASSERT_TRUE (known_size_p (T (0)));
4591 ASSERT_TRUE (known_size_p (T (1)));
4592 ASSERT_TRUE (known_size_p (T (2)));
4593 ASSERT_FALSE (known_size_p (T (-1)));
4594 }
4595
4596 /* Test poly-int.h operations on non-polynomial type T. */
4597
4598 template<typename T>
4599 static void
4600 test_nonpoly_type ()
4601 {
4602 test_nonpoly_multiple_p<T> ();
4603 test_nonpoly_known_size_p<T> ();
4604 }
4605
4606 /* Test poly-int.h operations on non-polynomial values. */
4607
4608 static void
4609 test_nonpoly ()
4610 {
4611 test_nonpoly_type<unsigned char> ();
4612 test_nonpoly_type<unsigned short> ();
4613 test_nonpoly_type<int> ();
4614 test_nonpoly_type<unsigned int> ();
4615 test_nonpoly_type<HOST_WIDE_INT> ();
4616 test_nonpoly_type<unsigned HOST_WIDE_INT> ();
4617 test_nonpoly_type<offset_int> ();
4618 test_nonpoly_type<widest_int> ();
4619 }
4620
4621 /* Test things that work for all poly_int-based types T, given that T
4622 has N coefficients of type C. RC is the type to which C promotes
4623 after an operator. */
4624
4625 template<unsigned int N, typename C, typename RC, typename T>
4626 static void
4627 test_general ()
4628 {
4629 test_poly_int_traits<N, C, T> ();
4630 test_constants<N, C, T> ();
4631 test_plus_equals<N, C, T> ();
4632 test_minus_equals<N, C, T> ();
4633 test_times_equals<N, C, T> ();
4634 test_shl_equals<N, C, T> ();
4635 test_is_constant<N, C, T> ();
4636 test_to_constant<N, C, T> ();
4637 test_addition<N, C, T> ();
4638 test_subtraction<N, C, RC, T> ();
4639 test_negation<N, C, RC, T> ();
4640 test_multiplication<N, C, T> ();
4641 test_shift_left<N, C, T> ();
4642 test_maybe_ne<N, C, T> ();
4643 test_known_eq<N, C, T> ();
4644 test_can_align_p<N, C, T> ();
4645 test_can_align_up<N, C, T> ();
4646 test_can_align_down<N, C, T> ();
4647 test_known_equal_after_align_up<N, C, T> ();
4648 test_known_equal_after_align_down<N, C, T> ();
4649 test_force_align_up<N, C, T> ();
4650 test_force_align_down<N, C, T> ();
4651 test_aligned_lower_bound<N, C, T> ();
4652 test_aligned_upper_bound<N, C, T> ();
4653 test_known_misalignment<N, C, T> ();
4654 test_force_get_misalignment<N, C, T> ();
4655 test_known_alignment<N, C, T> ();
4656 test_can_ior_p<N, C, T> ();
4657 test_known_size_p<N, C, T> ();
4658 }
4659
4660 /* Test things that work for poly_int<2, C>, given that C is signed. */
4661
4662 template<typename C>
4663 static void
4664 test_ordered_2 ()
4665 {
4666 test_maybe_eq_2<C> ();
4667 test_known_ne_2<C> ();
4668 }
4669
4670 /* Test things that work for poly_int-based types T, given that the
4671 coefficient type C supports all the normal C operators. N is the
4672 number of coefficients in C and RC is the type to which C promotes
4673 after an operator. */
4674
4675 template<unsigned int N, typename C, typename RC, typename T>
4676 static void
4677 test_ordered ()
4678 {
4679 test_general<N, C, RC, T> ();
4680 test_maybe_le<N, C, T> ();
4681 test_maybe_lt<N, C, T> ();
4682 test_maybe_ge<N, C, T> ();
4683 test_maybe_gt<N, C, T> ();
4684 test_known_gt<N, C, T> ();
4685 test_known_ge<N, C, T> ();
4686 test_known_lt<N, C, T> ();
4687 test_known_le<N, C, T> ();
4688 test_ordered_p<N, C, T> ();
4689 test_ordered_min<N, C, T> ();
4690 test_ordered_max<N, C, T> ();
4691 test_constant_lower_bound<N, C, T> ();
4692 test_lower_bound<N, C, T> ();
4693 test_upper_bound<N, C, T> ();
4694 test_compare_sizes_for_sort<N, C, T> ();
4695 test_force_align_up_and_div<N, C, T> ();
4696 test_force_align_down_and_div<N, C, T> ();
4697 test_constant_multiple_p<N, C, T> ();
4698 test_multiple_p<N, C, T> ();
4699 test_multiple_p_with_result<N, C, T> ();
4700 test_exact_div<N, C, T> ();
4701 test_can_div_trunc_p_const<N, C, T> ();
4702 test_can_div_trunc_p_poly<N, C, T> ();
4703 test_can_div_away_from_zero_p<N, C, T> ();
4704 test_maybe_in_range_p<N, C, T> ();
4705 test_known_in_range_p<N, C, T> ();
4706 test_ranges_maybe_overlap_p<N, C, T> ();
4707 test_ranges_known_overlap_p<N, C, T> ();
4708 test_known_subrange_p<N, C, T> ();
4709 test_coeffs_in_range_p<N, C, T> ();
4710 }
4711
4712 /* Test things that work for poly_int<2, C>, given that C is signed. */
4713
4714 template<typename C>
4715 static void
4716 test_signed_2 ()
4717 {
4718 test_ordered_2<C> ();
4719 test_signed_maybe_eq_2<C> ();
4720 test_signed_known_ne_2<C> ();
4721 }
4722
4723 /* Test things that work for poly_int-based types T, given that the
4724 coefficient type C is signed. N is the number of coefficients in C
4725 and RC is the type to which C promotes after an operator. */
4726
4727 template<unsigned int N, typename C, typename RC, typename T>
4728 static void
4729 test_signed ()
4730 {
4731 test_ordered<N, C, RC, T> ();
4732 test_signed_negation<N, C, RC, T> ();
4733 test_signed_maybe_le<N, C, T> ();
4734 test_signed_maybe_lt<N, C, T> ();
4735 test_signed_maybe_ge<N, C, T> ();
4736 test_signed_maybe_gt<N, C, T> ();
4737 test_signed_known_gt<N, C, T> ();
4738 test_signed_known_ge<N, C, T> ();
4739 test_signed_known_lt<N, C, T> ();
4740 test_signed_known_le<N, C, T> ();
4741 test_signed_ordered_p<N, C, T> ();
4742 test_signed_ordered_min<N, C, T> ();
4743 test_signed_ordered_max<N, C, T> ();
4744 test_signed_lower_bound<N, C, T> ();
4745 test_signed_upper_bound<N, C, T> ();
4746 test_signed_constant_multiple_p<N, C, T> ();
4747 test_signed_multiple_p<N, C, T> ();
4748 test_signed_multiple_p_with_result<N ,C, T> ();
4749 test_signed_exact_div<N, C, T> ();
4750 test_signed_can_div_trunc_p_const<N, C, T> ();
4751 test_signed_can_div_trunc_p_poly<N, C, T> ();
4752 test_signed_can_div_away_from_zero_p<N, C, T> ();
4753 test_signed_maybe_in_range_p<N, C, T> ();
4754 }
4755
4756 /* Test things that work for poly_int-based types T, given that the
4757 coefficient type C is unsigned. N is the number of coefficients in C
4758 and RC is the type to which C promotes after an operator. */
4759
4760 template<unsigned int N, typename C, typename RC, typename T>
4761 static void
4762 test_unsigned ()
4763 {
4764 test_ordered<N, C, RC, T> ();
4765 test_unsigned_maybe_le<N, C, T> ();
4766 test_unsigned_maybe_lt<N, C, T> ();
4767 test_unsigned_maybe_ge<N, C, T> ();
4768 test_unsigned_maybe_gt<N, C, T> ();
4769 test_unsigned_known_gt<N, C, T> ();
4770 test_unsigned_known_ge<N, C, T> ();
4771 test_unsigned_known_lt<N, C, T> ();
4772 test_unsigned_known_le<N, C, T> ();
4773 test_unsigned_ordered_p<N, C, T> ();
4774 test_unsigned_ordered_min<N, C, T> ();
4775 test_unsigned_ordered_max<N, C, T> ();
4776 test_unsigned_lower_bound<N, C, T> ();
4777 test_unsigned_upper_bound<N, C, T> ();
4778 test_unsigned_maybe_in_range_p<N, C, T> ();
4779 test_unsigned_known_in_range_p<N, C, T> ();
4780 }
4781
4782 /* Test things that are specific to coefficients of type wide_int,
4783 using a poly_int with N coefficients. */
4784
4785 template<unsigned int N>
4786 static void
4787 test_wide_int ()
4788 {
4789 test_wide_int_from<N> ();
4790
4791 test_to_shwi<N> (wi::mask (63, true, 77), -1, HOST_WIDE_INT_MIN);
4792 test_to_shwi<N> (wi::mask (63, false, 77), 1, HOST_WIDE_INT_MAX);
4793 test_to_uhwi<N> (wide_int (wi::zero (94)), -1, 0U);
4794 test_to_uhwi<N> (wi::mask (64, false, 94), 1, HOST_WIDE_INT_M1U);
4795
4796 test_force_hwi<N> (wi::mask (66, false, 81));
4797
4798 test_wide_int_sext<N> ();
4799 test_wide_int_zext<N> ();
4800 test_wide_int_add<N> ();
4801 test_wide_int_sub<N> ();
4802 test_wide_int_mul<N> ();
4803 test_wide_int_neg<N> ();
4804 }
4805
4806 /* Run the tests that are common to all coefficient counts N. */
4807
4808 template<unsigned int N>
4809 static void
4810 test_num_coeffs_core ()
4811 {
4812 test_unsigned<N, unsigned short, HOST_WIDE_INT,
4813 poly_int<N, unsigned short> > ();
4814 test_signed<N, HOST_WIDE_INT, HOST_WIDE_INT,
4815 poly_int<N, HOST_WIDE_INT> > ();
4816 test_unsigned<N, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
4817 poly_int<N, unsigned HOST_WIDE_INT> >();
4818
4819 test_general<N, wide_int, wide_int, poly_int<N, wide_int> > ();
4820
4821 test_hwi<N, unsigned short, poly_int<N, unsigned short> > ();
4822 test_hwi<N, HOST_WIDE_INT, poly_int<N, HOST_WIDE_INT> > ();
4823 test_hwi<N, unsigned HOST_WIDE_INT, poly_int<N, unsigned HOST_WIDE_INT> > ();
4824
4825 test_wide_int<N> ();
4826 test_fixed_int<N, offset_int> ();
4827 test_fixed_int<N, widest_int> ();
4828
4829 test_type_promotions<N> ();
4830 test_shwi<N> ();
4831 test_uhwi<N> ();
4832 }
4833
4834 /* Run extra tests for the most important coefficient counts N. */
4835
4836 template<unsigned int N>
4837 static void
4838 test_num_coeffs_extra ()
4839 {
4840 /* Test the most common POD types. */
4841 test_unsigned<N, unsigned short, HOST_WIDE_INT,
4842 poly_int<N, unsigned short> > ();
4843 test_signed<N, HOST_WIDE_INT, HOST_WIDE_INT,
4844 poly_int<N, HOST_WIDE_INT> > ();
4845 test_unsigned<N, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
4846 poly_int<N, unsigned HOST_WIDE_INT> > ();
4847
4848 /* Test some coefficient types that weren't covered in the core tests. */
4849 test_signed<N, int, HOST_WIDE_INT,
4850 poly_int<N, int> > ();
4851 test_signed<N, offset_int, offset_int,
4852 poly_int<N, offset_int> > ();
4853 test_signed<N, widest_int, widest_int,
4854 poly_int<N, widest_int> > ();
4855 }