1 /* This file contains templated tests that are then instantiated in
2 multiple plugin tests, in order to reduce the size of each test. */
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))
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. */
15 static inline const T
&make (const T
&x
) { return x
; }
19 struct coeff_helper
<wide_int
>
22 static inline const T
&make (const T
&x
) { return x
; }
23 static inline wide_int
make (int i
) { return wi::shwi (i
, 77); }
26 /* make (C1, C2, C3) constructs a T using coefficients from C1, C2 and C3,
27 picking only enough to fill the T. */
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
);
37 template<typename T1
, typename T2
, typename T3
>
39 poly_helper
<T
>::make (const T1
&a
, const T2
&b
, const T3
&c
)
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
);
50 /* Test the helper, */
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
;
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);
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);
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);
75 /* Test poly_coeff_traits. */
78 test_poly_coeff_traits ()
80 ASSERT_EQ (poly_coeff_traits
<unsigned short>::signedness
, 0);
81 ASSERT_EQ (poly_coeff_traits
<unsigned short>::max_value
, 0xffff);
83 ASSERT_EQ (poly_coeff_traits
<int>::signedness
, 1);
84 ASSERT_EQ (poly_coeff_traits
<int>::max_value
, INT_MAX
);
86 ASSERT_EQ (poly_coeff_traits
<unsigned int>::signedness
, 0);
87 ASSERT_EQ (poly_coeff_traits
<unsigned int>::max_value
, UINT_MAX
);
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
);
92 ASSERT_EQ (poly_coeff_traits
<unsigned HOST_WIDE_INT
>::signedness
, 0);
93 ASSERT_EQ (poly_coeff_traits
<unsigned HOST_WIDE_INT
>::max_value
,
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);
101 /* Test poly_int_traits. */
103 template<unsigned int N
, typename C
, typename T
>
105 test_poly_int_traits ()
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);
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);
118 /* Test the handling of constants. */
120 template<unsigned int N
, typename C
, typename T
>
124 typedef coeff_helper
<C
> ch
;
126 poly_int
<N
, unsigned char> two_uc
= 2;
128 /* Test operator = on C. */
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
);
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
);
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
);
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
);
172 /* Test operator +=. */
174 template<unsigned int N
, typename C
, typename T
>
178 typedef poly_helper
<T
> ph
;
180 /* Test += on int. */
181 T add_cm
= ph::make (17, 11, 9);
183 ASSERT_KNOWN_EQ (add_cm
, ph::make (31, 11, 9));
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));
191 /* Test operator -=. */
193 template<unsigned int N
, typename C
, typename T
>
197 typedef poly_helper
<T
> ph
;
199 /* Test -= on int. */
200 T sub_cm
= ph::make (82, 13, 61);
202 ASSERT_KNOWN_EQ (sub_cm
, ph::make (6, 13, 61));
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));
210 /* Test operator *=. */
212 template<unsigned int N
, typename C
, typename T
>
216 typedef poly_helper
<T
> ph
;
218 /* Test *= on int. */
219 T mul_cm
= ph::make (11, 22, 33);
221 ASSERT_KNOWN_EQ (mul_cm
, ph::make (33, 66, 99));
224 /* Test operator <<=. */
226 template<unsigned int N
, typename C
, typename T
>
230 typedef poly_helper
<T
> ph
;
232 /* Test <<= on int. */
233 T shl_cm
= ph::make (10, 11, 13);
235 ASSERT_KNOWN_EQ (shl_cm
, ph::make (40, 44, 52));
238 /* Test is_constant. */
240 template<unsigned int N
, typename C
, typename T
>
244 typedef poly_helper
<T
> ph
;
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);
251 /* Test is_constant with an argument. */
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
);
261 /* Test to_constant. */
263 template<unsigned int N
, typename C
, typename T
>
267 typedef poly_helper
<T
> ph
;
269 ASSERT_TRUE (ph::make (1, 0, 0).to_constant () == 1);
270 ASSERT_TRUE (ph::make (111, 0, 0).to_constant () == 111);
273 /* Test addition, both via operators and wi::. */
275 template<unsigned int N
, typename C
, typename T
>
279 typedef poly_helper
<T
> ph
;
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));
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));
298 /* Test subtraction, both via operators and wi::. */
300 template<unsigned int N
, typename C
, typename RC
, typename T
>
304 typedef poly_helper
<T
> ph
;
305 typedef poly_helper
< poly_int
<N
, RC
> > rph
;
306 typedef poly_helper
< poly_int
<N
, int> > iph
;
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));
317 /* Test wi::sub. Primitive Cs promote to widest_int; use iph to capture
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));
327 /* Test negation, both via operators and wi::. */
329 template<unsigned int N
, typename C
, typename RC
, typename T
>
333 typedef poly_helper
<T
> ph
;
334 typedef poly_helper
< poly_int
<N
, RC
> > rph
;
335 typedef poly_helper
< poly_int
<N
, int> > iph
;
338 ASSERT_KNOWN_EQ (-ph::make (10, 20, 30),
339 rph::make (-10, -20, -30));
342 ASSERT_KNOWN_EQ (wi::neg (ph::make (10, 20, 30)),
343 iph::make (-10, -20, -30));
346 /* Test multiplication, both via operators and wi::. */
348 template<unsigned int N
, typename C
, typename T
>
350 test_multiplication ()
352 typedef poly_helper
<T
> ph
;
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));
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));
367 /* Test shift left, both via operators and wi::. */
369 template<unsigned int N
, typename C
, typename T
>
373 typedef poly_helper
<T
> ph
;
376 ASSERT_KNOWN_EQ (ph::make (1, 20, 300) << 4,
377 ph::make (16, 320, 4800));
379 /* Test wi::lshift. */
380 ASSERT_KNOWN_EQ (wi::lshift (ph::make (9, 15, 50), 3),
381 ph::make (72, 120, 400));
386 template<unsigned int N
, typename C
, typename T
>
390 typedef coeff_helper
<C
> ch
;
391 typedef poly_helper
<T
> ph
;
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)));
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)));
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)));
414 template<unsigned int N
, typename C
, typename T
>
418 typedef coeff_helper
<C
> ch
;
419 typedef poly_helper
<T
> ph
;
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)));
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)));
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)));
440 /* Test can_align_p. */
442 template<unsigned int N
, typename C
, typename T
>
446 typedef poly_helper
<T
> ph
;
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));
462 /* Test can_align_up. */
464 template<unsigned int N
, typename C
, typename T
>
468 typedef coeff_helper
<C
> ch
;
469 typedef poly_helper
<T
> ph
;
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);
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);
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);
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);
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));
502 /* Test can_align_down. */
504 template<unsigned int N
, typename C
, typename T
>
506 test_can_align_down ()
508 typedef coeff_helper
<C
> ch
;
509 typedef poly_helper
<T
> ph
;
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);
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);
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);
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);
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));
542 /* Test known_equal_after_align_up. */
544 template<unsigned int N
, typename C
, typename T
>
546 test_known_equal_after_align_up ()
548 typedef poly_helper
<T
> ph
;
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));
574 /* Test known_equal_after_align_down. */
576 template<unsigned int N
, typename C
, typename T
>
578 test_known_equal_after_align_down ()
580 typedef poly_helper
<T
> ph
;
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));
606 /* Test force_align_up. */
608 template<unsigned int N
, typename C
, typename T
>
610 test_force_align_up ()
612 typedef coeff_helper
<C
> ch
;
613 typedef poly_helper
<T
> ph
;
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),
622 ASSERT_KNOWN_EQ (force_align_up (ph::make (16, 0, 0), 16),
624 ASSERT_KNOWN_EQ (force_align_up (ph::make (15, 0, 0), 16),
626 ASSERT_KNOWN_EQ (force_align_up (ph::make (-17, 0, 0), 16),
628 ASSERT_KNOWN_EQ (force_align_up (ph::make (-16, 0, 0), 16),
630 ASSERT_KNOWN_EQ (force_align_up (ph::make (-15, 0, 0), 16),
634 /* Test force_align_down. */
636 template<unsigned int N
, typename C
, typename T
>
638 test_force_align_down ()
640 typedef coeff_helper
<C
> ch
;
641 typedef poly_helper
<T
> ph
;
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),
649 ASSERT_KNOWN_EQ (force_align_down (ph::make (16, 0, 0), 16),
651 ASSERT_KNOWN_EQ (force_align_down (ph::make (15, 0, 0), 16),
653 ASSERT_KNOWN_EQ (force_align_down (ph::make (-17, 0, 0), 16),
655 ASSERT_KNOWN_EQ (force_align_down (ph::make (-16, 0, 0), 16),
657 ASSERT_KNOWN_EQ (force_align_down (ph::make (-15, 0, 0), 16),
661 /* Test aligned_lower_bound. */
663 template<unsigned int N
, typename C
, typename T
>
665 test_aligned_lower_bound ()
667 typedef poly_helper
<T
> ph
;
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));
679 /* Test aligned_upper_bound. */
681 template<unsigned int N
, typename C
, typename T
>
683 test_aligned_upper_bound ()
685 typedef poly_helper
<T
> ph
;
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));
697 /* Test known_misalignment. */
699 template<unsigned int N
, typename C
, typename T
>
701 test_known_misalignment ()
703 typedef poly_helper
<T
> ph
;
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
),
710 ASSERT_EQ (misalignment
, N
<= 2 ? 1 : 5);
711 ASSERT_EQ (known_misalignment (ph::make (31, 15, 0), 16, &misalignment
),
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);
720 /* Test force_get_misalignment. */
722 template<unsigned int N
, typename C
, typename T
>
724 test_force_get_misalignment ()
726 typedef poly_helper
<T
> ph
;
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);
735 /* Test known_alignment. */
737 template<unsigned int N
, typename C
, typename T
>
739 test_known_alignment ()
741 typedef poly_helper
<T
> ph
;
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)),
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)),
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)),
758 /* Test can_ior_p. */
760 template<unsigned int N
, typename C
, typename T
>
764 typedef coeff_helper
<C
> ch
;
765 typedef poly_helper
<T
> ph
;
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);
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);
775 ASSERT_KNOWN_EQ (ior
, ch::make (0xc5));
778 /* Test maybe_eq for poly_int<2, C>. */
784 typedef poly_int
<2, C
> T
;
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));
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)));
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)));
813 /* Test known_ne for poly_int<2, C>. */
819 typedef poly_int
<2, C
> T
;
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));
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)));
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)));
848 /* Test maybe_le for both signed and unsigned C. */
850 template<unsigned int N
, typename C
, typename T
>
854 typedef coeff_helper
<C
> ch
;
855 typedef poly_helper
<T
> ph
;
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)));
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)));
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)));
888 /* Test maybe_lt for both signed and unsigned C. */
890 template<unsigned int N
, typename C
, typename T
>
894 typedef coeff_helper
<C
> ch
;
895 typedef poly_helper
<T
> ph
;
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)));
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)));
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)));
931 /* Test maybe_ge for both signed and unsigned C. */
933 template<unsigned int N
, typename C
, typename T
>
937 typedef coeff_helper
<C
> ch
;
938 typedef poly_helper
<T
> ph
;
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)));
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)));
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);
971 /* Test maybe_gt for both signed and unsigned C. */
973 template<unsigned int N
, typename C
, typename T
>
977 typedef coeff_helper
<C
> ch
;
978 typedef poly_helper
<T
> ph
;
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)));
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)));
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);
1014 /* Test known_gt for both signed and unsigned C. */
1016 template<unsigned int N
, typename C
, typename T
>
1020 typedef coeff_helper
<C
> ch
;
1021 typedef poly_helper
<T
> ph
;
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)));
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)));
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)));
1054 /* Test known_ge for both signed and unsigned C. */
1056 template<unsigned int N
, typename C
, typename T
>
1060 typedef coeff_helper
<C
> ch
;
1061 typedef poly_helper
<T
> ph
;
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)));
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)));
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)));
1097 /* Test known_lt for both signed and unsigned C. */
1099 template<unsigned int N
, typename C
, typename T
>
1103 typedef coeff_helper
<C
> ch
;
1104 typedef poly_helper
<T
> ph
;
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)));
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)));
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);
1137 /* Test known_le for both signed and unsigned C. */
1139 template<unsigned int N
, typename C
, typename T
>
1143 typedef coeff_helper
<C
> ch
;
1144 typedef poly_helper
<T
> ph
;
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)));
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)));
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);
1180 /* Test ordered_p for both signed and unsigned C. */
1182 template<unsigned int N
, typename C
, typename T
>
1186 typedef coeff_helper
<C
> ch
;
1187 typedef poly_helper
<T
> ph
;
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)));
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)));
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);
1241 /* Test ordered_min for both signed and unsigned C. */
1243 template<unsigned int N
, typename C
, typename T
>
1247 typedef coeff_helper
<C
> ch
;
1248 typedef poly_helper
<T
> ph
;
1250 /* Test ordered_min (T, C). */
1251 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 0, 0), ch::make (5)),
1253 ASSERT_KNOWN_EQ (ordered_min (ph::make (12, 0, 0), ch::make (11)),
1255 ASSERT_KNOWN_EQ (ordered_min (ph::make (12, 6, 4), ch::make (11)),
1258 /* Test ordered_min (C, T). */
1259 ASSERT_KNOWN_EQ (ordered_min (ch::make (5), ph::make (4, 0, 0)),
1261 ASSERT_KNOWN_EQ (ordered_min (ch::make (11), ph::make (12, 0, 0)),
1263 ASSERT_KNOWN_EQ (ordered_min (ch::make (11), ph::make (12, 6, 4)),
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));
1279 /* Test ordered_max for both signed and unsigned C. */
1281 template<unsigned int N
, typename C
, typename T
>
1285 typedef coeff_helper
<C
> ch
;
1286 typedef poly_helper
<T
> ph
;
1288 /* Test ordered_max (T, C). */
1289 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 0, 0), ch::make (5)),
1291 ASSERT_KNOWN_EQ (ordered_max (ph::make (12, 0, 0), ch::make (11)),
1293 ASSERT_KNOWN_EQ (ordered_max (ph::make (12, 6, 4), ch::make (11)),
1294 ph::make (12, 6, 4));
1296 /* Test ordered_max (C, T). */
1297 ASSERT_KNOWN_EQ (ordered_max (ch::make (5), ph::make (4, 0, 0)),
1299 ASSERT_KNOWN_EQ (ordered_max (ch::make (11), ph::make (12, 0, 0)),
1301 ASSERT_KNOWN_EQ (ordered_max (ch::make (11), ph::make (12, 6, 4)),
1302 ph::make (12, 6, 4));
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));
1317 /* Test constant_lower_bound for both signed and unsigned C. */
1319 template<unsigned int N
, typename C
, typename T
>
1321 test_constant_lower_bound ()
1323 typedef poly_helper
<T
> ph
;
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);
1331 /* Test lower_bound for both signed and unsigned C. */
1333 template<unsigned int N
, typename C
, typename T
>
1337 typedef coeff_helper
<C
> ch
;
1338 typedef poly_helper
<T
> ph
;
1340 /* Test lower_bound (T, C). */
1341 ASSERT_KNOWN_EQ (lower_bound (ph::make (7, 2, 15), ch::make (4)),
1343 ASSERT_KNOWN_EQ (lower_bound (ph::make (100, 5, 50), ch::make (200)),
1346 /* Test lower_bound (C, T). */
1347 ASSERT_KNOWN_EQ (lower_bound (ch::make (4), ph::make (7, 2, 15)),
1349 ASSERT_KNOWN_EQ (lower_bound (ch::make (200), ph::make (100, 5, 50)),
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));
1359 /* Test upper_bound for both signed and unsigned C. */
1361 template<unsigned int N
, typename C
, typename T
>
1365 typedef coeff_helper
<C
> ch
;
1366 typedef poly_helper
<T
> ph
;
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));
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));
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));
1387 /* Test compare_sizes_for_sort for both signed and unsigned C. */
1389 template<unsigned int N
, typename C
, typename T
>
1391 test_compare_sizes_for_sort ()
1393 typedef poly_helper
<T
> ph
;
1395 ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 10, 8),
1396 ph::make (7, 9, 11)),
1398 ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 9, 8),
1399 ph::make (7, 9, 11)),
1401 ASSERT_EQ (compare_sizes_for_sort (ph::make (19, 9, 13),
1402 ph::make (7, 9, 13)),
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)),
1410 ASSERT_EQ (compare_sizes_for_sort (ph::make (10, 9, 6),
1411 ph::make (10, 9, 6)),
1415 /* Test force_align_up_and_div for both signed and unsigned C. */
1417 template<unsigned int N
, typename C
, typename T
>
1419 test_force_align_up_and_div ()
1421 typedef coeff_helper
<C
> ch
;
1422 typedef poly_helper
<T
> ph
;
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),
1430 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (16, 0, 0), 16),
1432 ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (15, 0, 0), 16),
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));
1443 /* Test force_align_down_and_div for both signed and unsigned C. */
1445 template<unsigned int N
, typename C
, typename T
>
1447 test_force_align_down_and_div ()
1449 typedef coeff_helper
<C
> ch
;
1450 typedef poly_helper
<T
> ph
;
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),
1458 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (16, 0, 0), 16),
1460 ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (15, 0, 0), 16),
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));
1470 /* Test constant_multiple_p for both signed and unsigned C. */
1472 template<unsigned int N
, typename C
, typename T
>
1474 test_constant_multiple_p ()
1476 typedef poly_helper
<T
> ph
;
1478 /* Test constant_multiple_p (T, C). */
1480 ASSERT_TRUE (constant_multiple_p (ph::make (15, 0, 0), 5,
1482 ASSERT_EQ (const_multiple
, 3);
1483 ASSERT_FALSE (constant_multiple_p (ph::make (16, 0, 0), 5,
1485 ASSERT_FALSE (constant_multiple_p (ph::make (14, 5, 5), 5,
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,
1496 /* Test constant_multiple_p (C, T). */
1497 ASSERT_TRUE (constant_multiple_p (15, ph::make (5, 0, 0),
1499 ASSERT_EQ (const_multiple
, 3);
1500 ASSERT_FALSE (constant_multiple_p (16, ph::make (5, 0, 0),
1502 ASSERT_FALSE (constant_multiple_p (14, ph::make (5, 5, 5),
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),
1512 ASSERT_EQ (const_multiple
, 0);
1514 /* Test constant_multiple_p (T, T). */
1515 ASSERT_TRUE (constant_multiple_p (ph::make (5, 15, 25),
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),
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),
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),
1550 ASSERT_TRUE (constant_multiple_p (ph::make (88, 0, 0),
1551 ph::make (11, 0, 0),
1553 ASSERT_EQ (const_multiple
, 8);
1554 ASSERT_FALSE (constant_multiple_p (ph::make (87, 0, 0),
1555 ph::make (11, 0, 0),
1557 ASSERT_TRUE (constant_multiple_p (ph::make (35, 63, 0),
1560 ASSERT_EQ (const_multiple
, 7);
1561 ASSERT_TRUE (constant_multiple_p (ph::make (0, 0, 0),
1562 ph::make (11, -24, 25),
1564 ASSERT_EQ (const_multiple
, 0);
1567 /* Test multiple_p for both signed and unsigned C. */
1569 template<unsigned int N
, typename C
, typename T
>
1573 typedef poly_helper
<T
> ph
;
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));
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)));
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)));
1653 /* Test the 3-operand form of multiple_p for both signed and unsigned C. */
1655 template<unsigned int N
, typename C
, typename T
>
1657 test_multiple_p_with_result ()
1659 typedef coeff_helper
<C
> ch
;
1660 typedef poly_helper
<T
> ph
;
1662 /* Test multiple_p (T, C) -> T. */
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);
1676 ASSERT_KNOWN_EQ (multiple
, ph::make (6, 7, 0));
1677 ASSERT_EQ (multiple_p (ph::make (30, 34, 45), 5, &multiple
), 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));
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));
1695 /* Test multiple_p (T, T) -> T. */
1696 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
1699 ASSERT_KNOWN_EQ (multiple
, ch::make (3));
1700 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
1703 ASSERT_FALSE (multiple_p (ph::make (14, 5, 5),
1706 ASSERT_TRUE (multiple_p (ph::make (44, 0, 55),
1707 ph::make (11, 0, 0),
1709 ASSERT_KNOWN_EQ (multiple
, ph::make (4, 0, 5));
1710 ASSERT_TRUE (multiple_p (ph::make (30, 30, 0),
1713 ASSERT_KNOWN_EQ (multiple
, ph::make (5, 5, 0));
1714 ASSERT_TRUE (multiple_p (ph::make (30, 35, 45),
1717 ASSERT_KNOWN_EQ (multiple
, ph::make (6, 7, 9));
1718 ASSERT_EQ (multiple_p (ph::make (30, 35, 44),
1720 &multiple
), N
<= 2);
1722 ASSERT_KNOWN_EQ (multiple
, ph::make (6, 7, 0));
1723 ASSERT_EQ (multiple_p (ph::make (30, 34, 45),
1725 &multiple
), N
== 1);
1727 ASSERT_KNOWN_EQ (multiple
, ch::make (6));
1728 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1731 ASSERT_KNOWN_EQ (multiple
, ch::make (0));
1732 ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
1735 ASSERT_KNOWN_EQ (multiple
, ch::make (3));
1736 ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
1739 ASSERT_FALSE (multiple_p (ph::make (14, 0, 0),
1742 ASSERT_EQ (multiple_p (ph::make (44, 0, 0),
1743 ph::make (11, 0, 4),
1744 &multiple
), N
<= 2);
1746 ASSERT_KNOWN_EQ (multiple
, ch::make (4));
1747 ASSERT_EQ (multiple_p (ph::make (30, 0, 0),
1749 &multiple
), 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),
1755 ASSERT_KNOWN_EQ (multiple
, ch::make (0));
1756 ASSERT_TRUE (multiple_p (ph::make (5, 15, 25),
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);
1764 ASSERT_KNOWN_EQ (multiple
, ch::make (3));
1765 ASSERT_EQ (multiple_p (ph::make (54, 19, 0),
1767 &multiple
), 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),
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),
1793 ASSERT_TRUE (multiple_p (ph::make (88, 0, 0),
1794 ph::make (11, 0, 0),
1796 ASSERT_KNOWN_EQ (multiple
, ch::make (8));
1797 ASSERT_FALSE (multiple_p (ph::make (87, 0, 0),
1798 ph::make (11, 0, 0),
1800 ASSERT_TRUE (multiple_p (ph::make (35, 63, 0),
1803 ASSERT_KNOWN_EQ (multiple
, ch::make (7));
1804 ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
1805 ph::make (11, -24, 25),
1807 ASSERT_KNOWN_EQ (multiple
, ch::make (0));
1810 /* Test exact_div for both signed and unsigned C. */
1812 template<unsigned int N
, typename C
, typename T
>
1816 typedef coeff_helper
<C
> ch
;
1817 typedef poly_helper
<T
> ph
;
1819 /* Test exact_div (T, C). */
1820 ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0), 5),
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),
1831 /* Test exact_div (T, T). */
1832 ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0),
1833 ph::make (5, 0, 0)),
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)),
1847 ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0),
1848 ph::make (5, 0, 0)),
1850 ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
1851 ph::make (5, 4, 11)),
1853 ASSERT_KNOWN_EQ (exact_div (ph::make (5, 15, 25),
1854 ph::make (1, 3, 5)),
1856 ASSERT_KNOWN_EQ (exact_div (ph::make (120, 0, 90),
1857 ph::make (12, 0, 9)),
1859 ASSERT_KNOWN_EQ (exact_div (ph::make (88, 0, 0),
1860 ph::make (11, 0, 0)),
1862 ASSERT_KNOWN_EQ (exact_div (ph::make (35, 63, 0),
1863 ph::make (5, 9, 0)),
1865 ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
1866 ph::make (11, -24, 25)),
1870 /* Test the form of can_div_trunc_p that returns a constant quotient,
1871 for both signed and unsigned C. */
1873 template<unsigned int N
, typename C
, typename T
>
1875 test_can_div_trunc_p_const ()
1877 typedef coeff_helper
<C
> ch
;
1878 typedef poly_helper
<T
> ph
;
1880 /* Test can_div_trunc_p (T, C) -> C. */
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));
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),
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),
1901 ASSERT_EQ (const_quot
, C (2));
1902 ASSERT_EQ (can_div_trunc_p (ph::make (15, 25, 40),
1903 ph::make (4, 8, 10),
1904 &const_quot
), N
<= 2);
1905 ASSERT_EQ (const_quot
, C (N
<= 2 ? 3 : 2));
1906 ASSERT_EQ (can_div_trunc_p (ph::make (43, 79, 80),
1907 ph::make (4, 8, 10),
1908 &const_quot
), N
== 1);
1909 ASSERT_EQ (const_quot
, C (N
== 1 ? 10 : N
== 2 ? 3 : 2));
1910 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 5),
1913 ASSERT_EQ (const_quot
, C (0));
1914 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 6),
1917 ASSERT_EQ (const_quot
, C (0));
1918 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 5, 5),
1921 ASSERT_EQ (const_quot
, C (0));
1922 ASSERT_EQ (can_div_trunc_p (ph::make (3, 4, 7),
1924 &const_quot
), N
<= 2);
1925 ASSERT_EQ (const_quot
, C (0));
1926 ASSERT_EQ (can_div_trunc_p (ph::make (3, 6, 0),
1928 &const_quot
), N
== 1);
1929 ASSERT_EQ (const_quot
, C (0));
1930 ASSERT_TRUE (can_div_trunc_p (ph::make (56, 0, 11),
1931 ph::make (11, 0, 2),
1933 ASSERT_EQ (const_quot
, C (5));
1934 ASSERT_EQ (can_div_trunc_p (ph::make (66, 1, 12),
1935 ph::make (11, 0, 2),
1936 &const_quot
), N
== 1);
1937 ASSERT_EQ (const_quot
, C (N
== 1 ? 6 : 5));
1938 ASSERT_EQ (can_div_trunc_p (ph::make (77, -1, 14),
1939 ph::make (11, 0, 2),
1940 &const_quot
), N
== 1);
1941 ASSERT_EQ (const_quot
, C (N
== 1 ? 7 : 5));
1942 ASSERT_TRUE (can_div_trunc_p (ph::make (89, 0, 0),
1943 ph::make (11, 0, 0),
1945 ASSERT_EQ (const_quot
, C (8));
1946 ASSERT_EQ (can_div_trunc_p (ph::make (101, 0, 1),
1947 ph::make (11, 0, 0),
1948 &const_quot
), N
<= 2);
1949 ASSERT_EQ (const_quot
, C (N
<= 2 ? 9 : 8));
1950 ASSERT_TRUE (can_div_trunc_p (ph::make (0, 0, 0),
1953 ASSERT_EQ (const_quot
, C (0));
1955 /* Test can_div_trunc_p (T, T) -> C, T. */
1957 ASSERT_TRUE (can_div_trunc_p (ph::make (8, 44, 28),
1958 ph::make (2, 11, 7),
1959 &const_quot
, &rem
));
1960 ASSERT_EQ (const_quot
, C (4));
1961 ASSERT_KNOWN_EQ (rem
, ch::make (0));
1962 ASSERT_TRUE (can_div_trunc_p (ph::make (9, 23, 30),
1963 ph::make (4, 8, 12),
1964 &const_quot
, &rem
));
1965 ASSERT_EQ (const_quot
, C (2));
1966 ASSERT_KNOWN_EQ (rem
, ph::make (1, 7, 6));
1967 ASSERT_EQ (can_div_trunc_p (ph::make (15, 25, 40),
1968 ph::make (4, 8, 10),
1969 &const_quot
, &rem
), N
<= 2);
1970 ASSERT_EQ (const_quot
, C (N
<= 2 ? 3 : 2));
1972 ASSERT_KNOWN_EQ (rem
, ph::make (3, 1, 0));
1973 ASSERT_EQ (can_div_trunc_p (ph::make (43, 79, 80),
1974 ph::make (4, 8, 10),
1975 &const_quot
, &rem
), N
== 1);
1976 ASSERT_EQ (const_quot
, C (N
== 1 ? 10 : N
== 2 ? 3 : 2));
1978 ASSERT_KNOWN_EQ (rem
, ch::make (3));
1979 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 5),
1981 &const_quot
, &rem
));
1982 ASSERT_EQ (const_quot
, C (0));
1983 ASSERT_KNOWN_EQ (rem
, ph::make (3, 4, 5));
1984 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 6),
1986 &const_quot
, &rem
));
1987 ASSERT_EQ (const_quot
, C (0));
1988 ASSERT_KNOWN_EQ (rem
, ph::make (3, 4, 6));
1989 ASSERT_TRUE (can_div_trunc_p (ph::make (3, 5, 5),
1991 &const_quot
, &rem
));
1992 ASSERT_EQ (const_quot
, C (0));
1993 ASSERT_KNOWN_EQ (rem
, ph::make (3, 5, 5));
1994 ASSERT_TRUE (can_div_trunc_p (ph::make (56, 0, 11),
1995 ph::make (11, 0, 2),
1996 &const_quot
, &rem
));
1997 ASSERT_EQ (const_quot
, C (5));
1998 ASSERT_KNOWN_EQ (rem
, ph::make (1, 0, 1));
1999 ASSERT_EQ (can_div_trunc_p (ph::make (66, 1, 12),
2000 ph::make (11, 0, 2),
2001 &const_quot
, &rem
), N
== 1);
2002 ASSERT_EQ (const_quot
, C (N
== 1 ? 6 : 5));
2004 ASSERT_KNOWN_EQ (rem
, ch::make (0));
2005 ASSERT_EQ (can_div_trunc_p (ph::make (77, -1, 14),
2006 ph::make (11, 0, 2),
2007 &const_quot
, &rem
), N
== 1);
2008 ASSERT_EQ (const_quot
, C (N
== 1 ? 7 : 5));
2010 ASSERT_KNOWN_EQ (rem
, ch::make (0));
2011 ASSERT_TRUE (can_div_trunc_p (ph::make (89, 0, 0),
2012 ph::make (11, 0, 0),
2013 &const_quot
, &rem
));
2014 ASSERT_EQ (const_quot
, C (8));
2015 ASSERT_KNOWN_EQ (rem
, ch::make (1));
2016 ASSERT_EQ (can_div_trunc_p (ph::make (101, 0, 1),
2017 ph::make (11, 0, 0),
2018 &const_quot
, &rem
), N
<= 2);
2019 ASSERT_EQ (const_quot
, C (N
<= 2 ? 9 : 8));
2021 ASSERT_KNOWN_EQ (rem
, ch::make (2));
2022 ASSERT_TRUE (can_div_trunc_p (ph::make (0, 0, 0),
2024 &const_quot
, &rem
));
2025 ASSERT_EQ (const_quot
, C (0));
2026 ASSERT_KNOWN_EQ (rem
, ch::make (0));
2029 /* Test the form of can_div_trunc_p that returns a polynomail quotient,
2030 for both signed and unsigned C. */
2032 template<unsigned int N
, typename C
, typename T
>
2034 test_can_div_trunc_p_poly ()
2036 typedef coeff_helper
<C
> ch
;
2037 typedef poly_helper
<T
> ph
;
2039 /* Test can_div_trunc_p (T, C) -> T. */
2041 ASSERT_TRUE (can_div_trunc_p (ph::make (22, 0, 0), 5, "
));
2042 ASSERT_KNOWN_EQ (quot
, ch::make (4));
2043 ASSERT_TRUE (can_div_trunc_p (ph::make (45, 40, 24), 4, "
));
2044 ASSERT_KNOWN_EQ (quot
, ph::make (11, 10, 6));
2045 ASSERT_EQ (can_div_trunc_p (ph::make (13, 18, 19), 6, "
), N
<= 2);
2047 ASSERT_KNOWN_EQ (quot
, ph::make (2, 3, 0));
2048 ASSERT_EQ (can_div_trunc_p (ph::make (55, 11, 10), 10, "
), N
== 1);
2050 ASSERT_KNOWN_EQ (quot
, ch::make (5));
2052 /* Test can_div_trunc_p (T, C) -> T, C. */
2054 ASSERT_TRUE (can_div_trunc_p (ph::make (22, 0, 0), 5,
2055 "
, &const_rem
));
2056 ASSERT_KNOWN_EQ (quot
, ch::make (4));
2057 ASSERT_EQ (const_rem
, C (2));
2058 ASSERT_TRUE (can_div_trunc_p (ph::make (45, 40, 24), 4,
2059 "
, &const_rem
));
2060 ASSERT_KNOWN_EQ (quot
, ph::make (11, 10, 6));
2061 ASSERT_EQ (const_rem
, C (1));
2062 ASSERT_EQ (can_div_trunc_p (ph::make (13, 18, 19), 6,
2063 "
, &const_rem
), N
<= 2);
2066 ASSERT_KNOWN_EQ (quot
, ph::make (2, 3, 0));
2067 ASSERT_EQ (const_rem
, C (1));
2069 ASSERT_EQ (can_div_trunc_p (ph::make (55, 11, 10), 10,
2070 "
, &const_rem
), N
== 1);
2073 ASSERT_KNOWN_EQ (quot
, ch::make (5));
2074 ASSERT_EQ (const_rem
, C (5));
2078 /* Test can_div_away_from_zero_p for both signed and unsigned C. */
2080 template<unsigned int N
, typename C
, typename T
>
2082 test_can_div_away_from_zero_p ()
2084 typedef poly_helper
<T
> ph
;
2086 /* Test can_div_away_from_zero_p (T, T) -> C. */
2088 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (8, 44, 28),
2089 ph::make (2, 11, 7),
2091 ASSERT_EQ (const_quot
, C (4));
2092 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (9, 23, 30),
2093 ph::make (4, 8, 12),
2095 ASSERT_EQ (const_quot
, C (3));
2096 ASSERT_EQ (can_div_away_from_zero_p (ph::make (15, 25, 40),
2097 ph::make (4, 8, 10),
2098 &const_quot
), N
<= 2);
2099 ASSERT_EQ (const_quot
, C (N
<= 2 ? 4 : 3));
2100 ASSERT_EQ (can_div_away_from_zero_p (ph::make (43, 79, 80),
2101 ph::make (4, 8, 10),
2102 &const_quot
), N
== 1);
2103 ASSERT_EQ (const_quot
, C (N
== 1 ? 11 : N
== 2 ? 4 : 3));
2104 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (3, 4, 5),
2107 ASSERT_EQ (const_quot
, C (1));
2108 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (3, 4, 6),
2111 ASSERT_EQ (const_quot
, C (1));
2112 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (3, 5, 5),
2115 ASSERT_EQ (const_quot
, C (1));
2116 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (56, 0, 11),
2117 ph::make (11, 0, 2),
2119 ASSERT_EQ (const_quot
, C (6));
2120 ASSERT_EQ (can_div_away_from_zero_p (ph::make (66, 1, 12),
2121 ph::make (11, 0, 2),
2122 &const_quot
), N
== 1);
2123 ASSERT_EQ (const_quot
, C (6));
2124 ASSERT_EQ (can_div_away_from_zero_p (ph::make (77, -1, 14),
2125 ph::make (11, 0, 2),
2126 &const_quot
), N
== 1);
2127 ASSERT_EQ (const_quot
, C (N
== 1 ? 7 : 6));
2128 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (89, 0, 0),
2129 ph::make (11, 0, 0),
2131 ASSERT_EQ (const_quot
, C (9));
2132 ASSERT_EQ (can_div_away_from_zero_p (ph::make (101, 0, 1),
2133 ph::make (11, 0, 0),
2134 &const_quot
), N
<= 2);
2135 ASSERT_EQ (const_quot
, C (N
<= 2 ? 10 : 9));
2136 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (0, 0, 0),
2139 ASSERT_EQ (const_quot
, C (0));
2142 /* Test known_size_p. */
2144 template<unsigned int N
, typename C
, typename T
>
2146 test_known_size_p ()
2148 typedef poly_helper
<T
> ph
;
2150 ASSERT_EQ (known_size_p (ph::make (-1, 0, -1)), N
== 3);
2151 ASSERT_EQ (known_size_p (ph::make (-1, -1, 0)), N
>= 2);
2152 ASSERT_EQ (known_size_p (ph::make (-1, -1, -1)), N
>= 2);
2153 ASSERT_FALSE (known_size_p (ph::make (-1, 0, 0)));
2154 ASSERT_TRUE (known_size_p (ph::make (0, 0, 0)));
2155 ASSERT_TRUE (known_size_p (ph::make (1, 0, 0)));
2158 /* Test maybe_in_range_p for both signed and unsigned C. */
2160 template<unsigned int N
, typename C
, typename T
>
2162 test_maybe_in_range_p ()
2164 typedef coeff_helper
<C
> ch
;
2165 typedef poly_helper
<T
> ph
;
2167 ASSERT_FALSE (maybe_in_range_p (ch::make (4),
2170 ASSERT_FALSE (maybe_in_range_p (ph::make (4, 0, 0),
2173 ASSERT_FALSE (maybe_in_range_p (ph::make (4, 1, 2),
2176 ASSERT_TRUE (maybe_in_range_p (ph::make (5, 1, 2),
2179 ASSERT_EQ (maybe_in_range_p (ph::make (4, 0, 3),
2181 ch::make (-1)), N
== 3);
2182 ASSERT_EQ (maybe_in_range_p (ph::make (4, 2, 0),
2184 ch::make (-1)), N
>= 2);
2185 ASSERT_TRUE (maybe_in_range_p (ph::make (500, 100, 200),
2188 ASSERT_EQ (maybe_in_range_p (ph::make (6, 1, 0),
2190 ch::make (1)), N
== 3);
2191 ASSERT_EQ (maybe_in_range_p (ph::make (6, 0, 1),
2193 ch::make (1)), N
>= 2);
2194 ASSERT_FALSE (maybe_in_range_p (ph::make (14, 1, 2),
2197 ASSERT_FALSE (maybe_in_range_p (ph::make (14, 1, 2),
2199 ph::make (9, 1, 2)));
2200 ASSERT_FALSE (maybe_in_range_p (ph::make (15, 15, 17),
2201 ph::make (8, 10, 11),
2202 ph::make (7, 5, 6)));
2203 ASSERT_EQ (maybe_in_range_p (ph::make (15, 15, 16),
2204 ph::make (8, 10, 11),
2205 ph::make (7, 5, 6)), N
== 3);
2206 ASSERT_EQ (maybe_in_range_p (ph::make (15, 14, 17),
2207 ph::make (8, 10, 11),
2208 ph::make (7, 5, 6)), N
>= 2);
2209 ASSERT_TRUE (maybe_in_range_p (ph::make (6, 100, 1000),
2210 ph::make (5, 10, 11),
2211 ph::make (2, 1, 2)));
2212 ASSERT_FALSE (maybe_in_range_p (ph::make (6, 8, 2),
2215 ASSERT_EQ (maybe_in_range_p (ph::make (6, 8, 1),
2217 ph::make (0, 1, 2)), N
== 3);
2220 /* Test known_in_range_p for both signed and unsigned C. */
2222 template<unsigned int N
, typename C
, typename T
>
2224 test_known_in_range_p ()
2226 typedef coeff_helper
<C
> ch
;
2227 typedef poly_helper
<T
> ph
;
2229 ASSERT_FALSE (known_in_range_p (ch::make (4),
2232 ASSERT_FALSE (known_in_range_p (ph::make (5, 1, 2),
2235 ASSERT_FALSE (known_in_range_p (ph::make (6, 2, 3),
2238 ASSERT_FALSE (known_in_range_p (ph::make (6, 1, 0),
2241 ASSERT_FALSE (known_in_range_p (ph::make (6, 0, 1),
2244 ASSERT_EQ (known_in_range_p (ph::make (6, 1, 0),
2246 ch::make (2)), N
<= 2);
2247 ASSERT_EQ (known_in_range_p (ph::make (6, 0, 1),
2249 ch::make (2)), N
== 1);
2250 ASSERT_TRUE (known_in_range_p (ph::make (6, 4, 5),
2252 ph::make (2, 3, 3)));
2253 ASSERT_EQ (known_in_range_p (ph::make (6, 4, 6),
2255 ph::make (2, 3, 3)), N
<= 2);
2256 ASSERT_EQ (known_in_range_p (ph::make (6, 5, 5),
2258 ph::make (2, 3, 3)), N
== 1);
2259 ASSERT_FALSE (known_in_range_p (ph::make (6, 8, 2),
2262 ASSERT_FALSE (known_in_range_p (ph::make (6, 8, 1),
2264 ph::make (0, 1, 2)));
2267 /* Test ranges_maybe_overlap_p for both signed and unsigned C. */
2269 template<unsigned int N
, typename C
, typename T
>
2271 test_ranges_maybe_overlap_p ()
2273 typedef coeff_helper
<C
> ch
;
2274 typedef poly_helper
<T
> ph
;
2276 ASSERT_TRUE (ranges_maybe_overlap_p (ph::make (4, 1, 2),
2278 ph::make (500, 3, 5),
2280 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (100, 1, 5),
2282 ph::make (50, 1, 5),
2284 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (100, 1, 5),
2286 ph::make (50, 0, 6),
2287 ch::make (50)), N
== 3);
2288 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (100, 1, 5),
2290 ph::make (50, 2, 0),
2291 ch::make (50)), N
>= 2);
2292 ASSERT_TRUE (ranges_maybe_overlap_p (ph::make (500, 3, 5),
2296 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (50, 1, 5),
2298 ph::make (100, 1, 5),
2300 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (10, 2, 3),
2303 ph::make (20, 30, 40)));
2304 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (10, 2, 3),
2307 ph::make (20, 30, 40)), N
>= 2);
2308 ASSERT_FALSE (ranges_maybe_overlap_p (ch::make (0),
2309 ph::make (20, 30, 40),
2310 ph::make (10, 2, 3),
2312 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (0, 1, 1),
2313 ph::make (20, 30, 40),
2314 ph::make (10, 2, 3),
2315 ph::make (0, 1, 0)), N
>= 2);
2316 ASSERT_TRUE (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2317 ph::make (2, 6, 20),
2320 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2321 ph::make (2, 6, 20),
2323 ph::make (2, 10, 15)));
2324 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2325 ph::make (2, 6, 20),
2327 ph::make (0, 0, 16)), N
== 3);
2328 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (8, 10, 15),
2329 ph::make (2, 6, 20),
2331 ph::make (0, 11, 0)), N
>= 2);
2332 ASSERT_FALSE (ranges_maybe_overlap_p (ph::make (80, 4, 5),
2333 ph::make (10, 6, 7),
2334 ph::make (100, 10, 12),
2335 ph::make (20, 1, 2)));
2336 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (80, 4, 5),
2337 ph::make (10, 6, 7),
2338 ph::make (100, 10, 11),
2339 ph::make (0, 0, 2)), N
== 3);
2340 ASSERT_EQ (ranges_maybe_overlap_p (ph::make (80, 5, 5),
2342 ph::make (100, 10, 12),
2343 ph::make (20, 1, 2)), N
>= 2);
2346 /* Test ranges_known_overlap_p for both signed and unsigned C. */
2348 template<unsigned int N
, typename C
, typename T
>
2350 test_ranges_known_overlap_p ()
2352 typedef coeff_helper
<C
> ch
;
2353 typedef poly_helper
<T
> ph
;
2355 ASSERT_FALSE (ranges_known_overlap_p (ph::make (5, 1, 2),
2359 ASSERT_FALSE (ranges_known_overlap_p (ch::make (9),
2363 ASSERT_FALSE (ranges_known_overlap_p (ph::make (10, 2, 3),
2366 ph::make (20, 30, 40)));
2367 ASSERT_FALSE (ranges_known_overlap_p (ph::make (10, 2, 3),
2370 ph::make (20, 30, 40)));
2371 ASSERT_FALSE (ranges_known_overlap_p (ch::make (0),
2372 ph::make (20, 30, 40),
2373 ph::make (10, 2, 3),
2375 ASSERT_FALSE (ranges_known_overlap_p (ph::make (0, 1, 1),
2376 ph::make (20, 30, 40),
2377 ph::make (10, 2, 3),
2378 ph::make (0, 1, 0)));
2379 ASSERT_EQ (ranges_known_overlap_p (ph::make (5, 1, 2),
2382 ch::make (2)), N
== 1);
2383 ASSERT_TRUE (ranges_known_overlap_p (ph::make (5, 1, 2),
2387 ASSERT_TRUE (ranges_known_overlap_p (ch::make (9),
2391 ASSERT_FALSE (ranges_known_overlap_p (ph::make (10, 11, 12),
2392 ph::make (20, 30, 40),
2395 ASSERT_TRUE (ranges_known_overlap_p (ph::make (10, 11, 12),
2396 ph::make (20, 30, 40),
2397 ph::make (29, 41, 52),
2399 ASSERT_EQ (ranges_known_overlap_p (ph::make (10, 11, 12),
2400 ph::make (20, 30, 40),
2401 ph::make (29, 41, 53),
2402 ch::make (1)), N
<= 2);
2403 ASSERT_EQ (ranges_known_overlap_p (ph::make (10, 11, 12),
2404 ph::make (20, 30, 40),
2405 ph::make (29, 42, 52),
2406 ch::make (1)), N
== 1);
2407 ASSERT_TRUE (ranges_known_overlap_p (ph::make (29, 41, 52),
2409 ph::make (10, 11, 12),
2410 ph::make (20, 30, 40)));
2411 ASSERT_EQ (ranges_known_overlap_p (ph::make (29, 41, 53),
2413 ph::make (10, 11, 12),
2414 ph::make (20, 30, 40)), N
<= 2);
2415 ASSERT_EQ (ranges_known_overlap_p (ph::make (29, 42, 52),
2417 ph::make (10, 11, 12),
2418 ph::make (20, 30, 40)), N
== 1);
2419 ASSERT_TRUE (ranges_known_overlap_p (ph::make (10, 0, 20),
2421 ph::make (7, 3, 20),
2422 ph::make (4, 4, 4)));
2425 /* Test known_subrange_p for both signed and unsigned C. */
2427 template<unsigned int N
, typename C
, typename T
>
2429 test_known_subrange_p ()
2431 typedef coeff_helper
<C
> ch
;
2432 typedef poly_helper
<T
> ph
;
2434 ASSERT_FALSE (known_subrange_p (ph::make (5, 1, 2),
2437 ph::make (2, 2, 2)));
2438 ASSERT_FALSE (known_subrange_p (ph::make (5, 2, 3),
2442 ASSERT_FALSE (known_subrange_p (ph::make (6, 2, 3),
2445 ph::make (3, 4, 11)));
2446 ASSERT_TRUE (known_subrange_p (ph::make (6, 2, 3),
2449 ph::make (3, 4, 11)));
2450 ASSERT_FALSE (known_subrange_p (ph::make (6, 2, 3),
2453 ph::make (2, 4, 11)));
2454 ASSERT_TRUE (known_subrange_p (ph::make (10, 20, 30),
2456 ph::make (9, 19, 29),
2457 ph::make (6, 7, 8)));
2458 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 31),
2460 ph::make (9, 19, 29),
2461 ph::make (6, 7, 8)), N
<= 2);
2462 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 30),
2464 ph::make (9, 19, 29),
2465 ph::make (6, 7, 8)), N
== 1);
2466 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 30),
2468 ph::make (9, 18, 29),
2469 ph::make (6, 7, 8)), N
== 1);
2470 ASSERT_EQ (known_subrange_p (ph::make (10, 20, 30),
2472 ph::make (9, 19, 29),
2473 ph::make (6, 6, 8)), N
== 1);
2476 /* Test coeffs_in_range_p for both signed and unsigned C. */
2478 template<unsigned int N
, typename C
, typename T
>
2480 test_coeffs_in_range_p (void)
2482 typedef coeff_helper
<C
> ch
;
2483 typedef poly_helper
<T
> ph
;
2485 ASSERT_TRUE (coeffs_in_range_p (ph::make (10, 20, 30), 10, 30));
2486 ASSERT_EQ (coeffs_in_range_p (ph::make (1, 10, 19), 0, 11), N
<= 2);
2487 ASSERT_EQ (coeffs_in_range_p (ph::make (100, 1, 102), 10, 100), N
== 1);
2488 ASSERT_FALSE (coeffs_in_range_p (ph::make (10, 11, 12), 7, 9));
2489 ASSERT_FALSE (coeffs_in_range_p (ph::make (10, 11, 12), 13, 15));
2492 /* Test maybe_eq for poly_int<2, C>, given that C is signed. */
2494 template<typename C
>
2496 test_signed_maybe_eq_2 ()
2498 typedef poly_int
<2, C
> T
;
2500 /* Test maybe_eq (T, C). */
2501 ASSERT_TRUE (maybe_eq (T (4, -4), 0));
2502 ASSERT_FALSE (maybe_eq (T (4, -4), 1));
2503 ASSERT_TRUE (maybe_eq (T (4, -4), 4));
2504 ASSERT_FALSE (maybe_eq (T (4, -4), 8));
2505 ASSERT_TRUE (maybe_eq (T (4, -4), -4));
2506 ASSERT_FALSE (maybe_eq (T (4, -4), -3));
2508 /* Test maybe_eq (C, T). */
2509 ASSERT_FALSE (maybe_eq (0, T (4, -3)));
2510 ASSERT_TRUE (maybe_eq (1, T (4, -3)));
2511 ASSERT_TRUE (maybe_eq (4, T (4, -3)));
2512 ASSERT_FALSE (maybe_eq (7, T (4, -3)));
2513 ASSERT_FALSE (maybe_eq (T (4, -3), -3));
2514 ASSERT_TRUE (maybe_eq (T (4, -3), -2));
2516 /* Test maybe_eq (T, T). */
2517 ASSERT_TRUE (maybe_eq (T (0, 3), T (6, 1)));
2518 ASSERT_FALSE (maybe_eq (T (0, -3), T (6, 1)));
2519 ASSERT_FALSE (maybe_eq (T (0, 3), T (7, 1)));
2520 ASSERT_TRUE (maybe_eq (T (-3, 4), T (7, -1)));
2521 ASSERT_FALSE (maybe_eq (T (-3, 4), T (6, -1)));
2524 /* Test known_ne for poly_int<2, C>, given that C is signed. */
2526 template<typename C
>
2528 test_signed_known_ne_2 ()
2530 typedef poly_int
<2, C
> T
;
2532 /* Test known_ne (T, C). */
2533 ASSERT_FALSE (known_ne (T (4, -4), 0));
2534 ASSERT_TRUE (known_ne (T (4, -4), 1));
2535 ASSERT_FALSE (known_ne (T (4, -4), 4));
2536 ASSERT_TRUE (known_ne (T (4, -4), 8));
2537 ASSERT_FALSE (known_ne (T (4, -4), -4));
2538 ASSERT_TRUE (known_ne (T (4, -4), -3));
2540 /* Test known_ne (C, T). */
2541 ASSERT_TRUE (known_ne (0, T (4, -3)));
2542 ASSERT_FALSE (known_ne (1, T (4, -3)));
2543 ASSERT_FALSE (known_ne (4, T (4, -3)));
2544 ASSERT_TRUE (known_ne (7, T (4, -3)));
2545 ASSERT_TRUE (known_ne (T (4, -3), -3));
2546 ASSERT_FALSE (known_ne (T (4, -3), -2));
2548 /* Test known_ne (T, T). */
2549 ASSERT_FALSE (known_ne (T (0, 3), T (6, 1)));
2550 ASSERT_TRUE (known_ne (T (0, -3), T (6, 1)));
2551 ASSERT_TRUE (known_ne (T (0, 3), T (7, 1)));
2552 ASSERT_FALSE (known_ne (T (-3, 4), T (7, -1)));
2553 ASSERT_TRUE (known_ne (T (-3, 4), T (6, -1)));
2556 /* Test negation for signed C, both via operators and wi::. */
2558 template<unsigned int N
, typename C
, typename RC
, typename T
>
2560 test_signed_negation ()
2562 typedef poly_helper
<T
> ph
;
2563 typedef poly_helper
< poly_int
<N
, RC
> > rph
;
2564 typedef poly_helper
< poly_int
<N
, int> > iph
;
2567 ASSERT_KNOWN_EQ (-ph::make (-11, 22, -33),
2568 rph::make (11, -22, 33));
2571 ASSERT_KNOWN_EQ (wi::neg (ph::make (-11, 22, -33)),
2572 iph::make (11, -22, 33));
2575 /* Test maybe_le for signed C. */
2577 template<unsigned int N
, typename C
, typename T
>
2579 test_signed_maybe_le ()
2581 typedef coeff_helper
<C
> ch
;
2582 typedef poly_helper
<T
> ph
;
2584 /* Test maybe_le (T, C). */
2585 ASSERT_EQ (maybe_le (ph::make (3, 5, -1), ch::make (2)), N
== 3);
2586 ASSERT_EQ (maybe_le (ph::make (40, -10, 60), ch::make (15)), N
>= 2);
2587 ASSERT_TRUE (maybe_le (ph::make (-14, 0, 0), ch::make (13)));
2589 /* Test maybe_le (C, T). */
2590 ASSERT_EQ (maybe_le (ch::make (4), ph::make (3, 5, -1)), N
>= 2);
2591 ASSERT_EQ (maybe_le (ch::make (41), ph::make (40, -10, 60)), N
== 3);
2592 ASSERT_TRUE (maybe_le (ch::make (-15), ph::make (11, 0, 0)));
2594 /* Test maybe_le (T, T). */
2595 ASSERT_EQ (maybe_le (ph::make (-2, 4, -2),
2596 ph::make (-3, -5, -1)), N
== 3);
2597 ASSERT_EQ (maybe_le (ph::make (-2, -6, 0),
2598 ph::make (-3, 0, 100)), N
>= 2);
2599 ASSERT_FALSE (maybe_le (ph::make (-2, 5, 1),
2600 ph::make (-3, 4, 0)));
2603 /* Test maybe_lt for signed C. */
2605 template<unsigned int N
, typename C
, typename T
>
2607 test_signed_maybe_lt ()
2609 typedef coeff_helper
<C
> ch
;
2610 typedef poly_helper
<T
> ph
;
2612 /* Test maybe_lt (T, C). */
2613 ASSERT_EQ (maybe_lt (ph::make (3, 5, -1), ch::make (2)), N
== 3);
2614 ASSERT_EQ (maybe_lt (ph::make (40, -10, 60), ch::make (15)), N
>= 2);
2615 ASSERT_TRUE (maybe_lt (ph::make (-18, 0, 0), ch::make (18)));
2616 ASSERT_EQ (maybe_lt (ph::make (-2, -2, -2), ch::make (-2)), N
>= 2);
2618 /* Test maybe_lt (C, T). */
2619 ASSERT_EQ (maybe_lt (ch::make (4), ph::make (3, 5, -1)), N
>= 2);
2620 ASSERT_EQ (maybe_lt (ch::make (41), ph::make (40, -10, 60)), N
== 3);
2621 ASSERT_TRUE (maybe_lt (ch::make (-45), ph::make (40, 0, 0)));
2622 ASSERT_FALSE (maybe_lt (ch::make (-2), ph::make (-2, -2, -2)));
2624 /* Test maybe_lt (T, T). */
2625 ASSERT_EQ (maybe_lt (ph::make (-3, 4, -2),
2626 ph::make (-3, -5, -1)), N
== 3);
2627 ASSERT_EQ (maybe_lt (ph::make (-3, -6, 0),
2628 ph::make (-3, 0, 100)), N
>= 2);
2629 ASSERT_FALSE (maybe_lt (ph::make (-3, 5, 1),
2630 ph::make (-3, 4, 0)));
2633 /* Test maybe_ge for signed C. */
2635 template<unsigned int N
, typename C
, typename T
>
2637 test_signed_maybe_ge ()
2639 typedef coeff_helper
<C
> ch
;
2640 typedef poly_helper
<T
> ph
;
2642 /* Test maybe_ge (T, C). */
2643 ASSERT_EQ (maybe_ge (ph::make (3, 5, -1), ch::make (4)), N
>= 2);
2644 ASSERT_EQ (maybe_ge (ph::make (40, -10, 60), ch::make (41)), N
== 3);
2645 ASSERT_TRUE (maybe_ge (ph::make (11, 0, 0), ch::make (-15)));
2647 /* Test maybe_ge (C, T). */
2648 ASSERT_EQ (maybe_ge (ch::make (2), ph::make (3, 5, -1)), N
== 3);
2649 ASSERT_EQ (maybe_ge (ch::make (15), ph::make (40, -10, 60)), N
>= 2);
2650 ASSERT_TRUE (maybe_ge (ch::make (13), ph::make (-14, 0, 0)));
2652 /* Test maybe_ge (T, T). */
2653 ASSERT_EQ (maybe_ge (ph::make (-3, -5, -1),
2654 ph::make (-2, 4, -2)), N
== 3);
2655 ASSERT_EQ (maybe_ge (ph::make (-3, 0, 100),
2656 ph::make (-2, -6, 0)), N
>= 2);
2657 ASSERT_FALSE (maybe_ge (ph::make (-3, 4, 0),
2658 ph::make (-2, 5, 1)));
2661 /* Test maybe_gt for signed C. */
2663 template<unsigned int N
, typename C
, typename T
>
2665 test_signed_maybe_gt ()
2667 typedef coeff_helper
<C
> ch
;
2668 typedef poly_helper
<T
> ph
;
2670 /* Test maybe_gt (T, C). */
2671 ASSERT_EQ (maybe_gt (ph::make (3, 5, -1), ch::make (4)), N
>= 2);
2672 ASSERT_EQ (maybe_gt (ph::make (40, -10, 60), ch::make (41)), N
== 3);
2673 ASSERT_TRUE (maybe_gt (ph::make (40, 0, 0), ch::make (-45)));
2674 ASSERT_FALSE (maybe_gt (ph::make (-2, -2, -2), ch::make (-2)));
2676 /* Test maybe_gt (C, T). */
2677 ASSERT_EQ (maybe_gt (ch::make (2), ph::make (3, 5, -1)), N
== 3);
2678 ASSERT_EQ (maybe_gt (ch::make (15), ph::make (40, -10, 60)), N
>= 2);
2679 ASSERT_TRUE (maybe_gt (ch::make (18), ph::make (-18, 0, 0)));
2680 ASSERT_EQ (maybe_gt (ch::make (-2), ph::make (-2, -2, -2)), N
>= 2);
2682 /* Test maybe_gt (T, T). */
2683 ASSERT_EQ (maybe_gt (ph::make (-3, -5, -1),
2684 ph::make (-3, 4, -2)), N
== 3);
2685 ASSERT_EQ (maybe_gt (ph::make (-3, 0, 100),
2686 ph::make (-3, -6, 0)), N
>= 2);
2687 ASSERT_FALSE (maybe_gt (ph::make (-3, 4, 0),
2688 ph::make (-3, 5, 1)));
2691 /* Test known_gt for signed C. */
2693 template<unsigned int N
, typename C
, typename T
>
2695 test_signed_known_gt ()
2697 typedef coeff_helper
<C
> ch
;
2698 typedef poly_helper
<T
> ph
;
2700 /* Test known_gt (T, C). */
2701 ASSERT_EQ (known_gt (ph::make (3, 5, -1), ch::make (2)), N
<= 2);
2702 ASSERT_EQ (known_gt (ph::make (40, -10, 60), ch::make (15)), N
== 1);
2703 ASSERT_FALSE (known_gt (ph::make (-14, 0, 0), ch::make (13)));
2705 /* Test known_gt (C, T). */
2706 ASSERT_EQ (known_gt (ch::make (4), ph::make (3, 5, -1)), N
== 1);
2707 ASSERT_EQ (known_gt (ch::make (41), ph::make (40, -10, 60)), N
<= 2);
2708 ASSERT_FALSE (known_gt (ch::make (-15), ph::make (11, 0, 0)));
2710 /* Test known_gt (T, T). */
2711 ASSERT_EQ (known_gt (ph::make (-2, 4, -2),
2712 ph::make (-3, -5, -1)), N
<= 2);
2713 ASSERT_EQ (known_gt (ph::make (-2, -6, 0),
2714 ph::make (-3, 0, 100)), N
== 1);
2715 ASSERT_TRUE (known_gt (ph::make (-2, 5, 1),
2716 ph::make (-3, 4, 0)));
2719 /* Test known_ge for signed C. */
2721 template<unsigned int N
, typename C
, typename T
>
2723 test_signed_known_ge ()
2725 typedef coeff_helper
<C
> ch
;
2726 typedef poly_helper
<T
> ph
;
2728 /* Test known_ge (T, C). */
2729 ASSERT_EQ (known_ge (ph::make (3, 5, -1), ch::make (2)), N
<= 2);
2730 ASSERT_EQ (known_ge (ph::make (40, -10, 60), ch::make (15)), N
== 1);
2731 ASSERT_FALSE (known_ge (ph::make (-18, 0, 0), ch::make (18)));
2732 ASSERT_EQ (known_ge (ph::make (-2, -2, -2), ch::make (-2)), N
== 1);
2734 /* Test known_ge (C, T). */
2735 ASSERT_EQ (known_ge (ch::make (4), ph::make (3, 5, -1)), N
== 1);
2736 ASSERT_EQ (known_ge (ch::make (41), ph::make (40, -10, 60)), N
<= 2);
2737 ASSERT_FALSE (known_ge (ch::make (-45), ph::make (40, 0, 0)));
2738 ASSERT_TRUE (known_ge (ch::make (-2), ph::make (-2, -2, -2)));
2740 /* Test known_ge (T, T). */
2741 ASSERT_EQ (known_ge (ph::make (-3, 4, -2),
2742 ph::make (-3, -5, -1)), N
<= 2);
2743 ASSERT_EQ (known_ge (ph::make (-3, -6, 0),
2744 ph::make (-3, 0, 100)), N
== 1);
2745 ASSERT_TRUE (known_ge (ph::make (-3, 5, 1),
2746 ph::make (-3, 4, 0)));
2749 /* Test known_lt for signed C. */
2751 template<unsigned int N
, typename C
, typename T
>
2753 test_signed_known_lt ()
2755 typedef coeff_helper
<C
> ch
;
2756 typedef poly_helper
<T
> ph
;
2758 /* Test known_lt (T, C). */
2759 ASSERT_EQ (known_lt (ph::make (3, 5, -1), ch::make (4)), N
== 1);
2760 ASSERT_EQ (known_lt (ph::make (40, -10, 60), ch::make (41)), N
<= 2);
2761 ASSERT_FALSE (known_lt (ph::make (11, 0, 0), ch::make (-15)));
2763 /* Test known_lt (C, T). */
2764 ASSERT_EQ (known_lt (ch::make (2), ph::make (3, 5, -1)), N
<= 2);
2765 ASSERT_EQ (known_lt (ch::make (15), ph::make (40, -10, 60)), N
== 1);
2766 ASSERT_FALSE (known_lt (ch::make (13), ph::make (-14, 0, 0)));
2768 /* Test known_lt (T, T). */
2769 ASSERT_EQ (known_lt (ph::make (-3, -5, -1),
2770 ph::make (-2, 4, -2)), N
<= 2);
2771 ASSERT_EQ (known_lt (ph::make (-3, 0, 100),
2772 ph::make (-2, -6, 0)), N
== 1);
2773 ASSERT_TRUE (known_lt (ph::make (-3, 4, 0),
2774 ph::make (-2, 5, 1)));
2777 /* Test known_le for signed C. */
2779 template<unsigned int N
, typename C
, typename T
>
2781 test_signed_known_le ()
2783 typedef coeff_helper
<C
> ch
;
2784 typedef poly_helper
<T
> ph
;
2786 /* Test known_le (T, C). */
2787 ASSERT_EQ (known_le (ph::make (3, 5, -1), ch::make (4)), N
== 1);
2788 ASSERT_EQ (known_le (ph::make (40, -10, 60), ch::make (41)), N
<= 2);
2789 ASSERT_FALSE (known_le (ph::make (40, 0, 0), ch::make (-45)));
2790 ASSERT_TRUE (known_le (ph::make (-2, -2, -2), ch::make (-2)));
2792 /* Test known_le (C, T). */
2793 ASSERT_EQ (known_le (ch::make (2), ph::make (3, 5, -1)), N
<= 2);
2794 ASSERT_EQ (known_le (ch::make (15), ph::make (40, -10, 60)), N
== 1);
2795 ASSERT_FALSE (known_le (ch::make (18), ph::make (-18, 0, 0)));
2796 ASSERT_EQ (known_le (ch::make (-2), ph::make (-2, -2, -2)), N
== 1);
2798 /* Test known_le (T, T). */
2799 ASSERT_EQ (known_le (ph::make (-3, -5, -1),
2800 ph::make (-3, 4, -2)), N
<= 2);
2801 ASSERT_EQ (known_le (ph::make (-3, 0, 100),
2802 ph::make (-3, -6, 0)), N
== 1);
2803 ASSERT_TRUE (known_le (ph::make (-3, 4, 0),
2804 ph::make (-3, 5, 1)));
2807 /* Test ordered_p for signed C. */
2809 template<unsigned int N
, typename C
, typename T
>
2811 test_signed_ordered_p ()
2813 typedef coeff_helper
<C
> ch
;
2814 typedef poly_helper
<T
> ph
;
2816 /* Test ordered_p (T, C). */
2817 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (4)), N
== 1);
2818 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (3)), N
<= 2);
2819 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (2)), N
<= 2);
2820 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (41)), N
<= 2);
2821 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (40)), N
<= 2);
2822 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (39)), N
== 1);
2823 ASSERT_EQ (ordered_p (ph::make (4, -4, -4), ch::make (0)), N
== 1);
2824 ASSERT_EQ (ordered_p (ph::make (4, 0, -4), ch::make (0)), N
<= 2);
2825 ASSERT_EQ (ordered_p (ph::make (4, 4, -4), ch::make (0)), N
<= 2);
2826 ASSERT_EQ (ordered_p (ph::make (-4, 4, 4), ch::make (0)), N
== 1);
2827 ASSERT_EQ (ordered_p (ph::make (-4, 0, 4), ch::make (0)), N
<= 2);
2828 ASSERT_EQ (ordered_p (ph::make (-4, -4, 4), ch::make (0)), N
<= 2);
2830 /* Test ordered_p (C, T). */
2831 ASSERT_EQ (ordered_p (ch::make (4), ph::make (3, 5, -1)), N
== 1);
2832 ASSERT_EQ (ordered_p (ch::make (3), ph::make (3, 5, -1)), N
<= 2);
2833 ASSERT_EQ (ordered_p (ch::make (2), ph::make (3, 5, -1)), N
<= 2);
2834 ASSERT_EQ (ordered_p (ch::make (41), ph::make (40, -10, 60)), N
<= 2);
2835 ASSERT_EQ (ordered_p (ch::make (40), ph::make (40, -10, 60)), N
<= 2);
2836 ASSERT_EQ (ordered_p (ch::make (39), ph::make (40, -10, 60)), N
== 1);
2837 ASSERT_EQ (ordered_p (ch::make (0), ph::make (4, -4, -4)), N
== 1);
2838 ASSERT_EQ (ordered_p (ch::make (0), ph::make (4, 0, -4)), N
<= 2);
2839 ASSERT_EQ (ordered_p (ch::make (0), ph::make (4, 4, -4)), N
<= 2);
2840 ASSERT_EQ (ordered_p (ch::make (0), ph::make (-4, 4, 4)), N
== 1);
2841 ASSERT_EQ (ordered_p (ch::make (0), ph::make (-4, 0, 4)), N
<= 2);
2842 ASSERT_EQ (ordered_p (ch::make (0), ph::make (-4, -4, 4)), N
<= 2);
2845 /* Test ordered_min for signed C. */
2847 template<unsigned int N
, typename C
, typename T
>
2849 test_signed_ordered_min ()
2851 typedef coeff_helper
<C
> ch
;
2852 typedef poly_helper
<T
> ph
;
2854 /* Test ordered_min (T, C). */
2855 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, -12, -14), ch::make (5)),
2856 ph::make (4, -12, -14));
2858 /* Test ordered_min (C, T). */
2859 ASSERT_KNOWN_EQ (ordered_min (ch::make (9), ph::make (9, -90, -77)),
2860 ph::make (9, -90, -77));
2862 /* Test ordered_min (T, T). */
2863 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 9, 17), ph::make (4, -1, 17)),
2864 ph::make (4, -1, 17));
2867 /* Test ordered_max for signed C. */
2869 template<unsigned int N
, typename C
, typename T
>
2871 test_signed_ordered_max ()
2873 typedef coeff_helper
<C
> ch
;
2874 typedef poly_helper
<T
> ph
;
2876 /* Test ordered_max (T, C). */
2877 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, -12, -14), ch::make (5)),
2880 /* Test ordered_max (C, T). */
2881 ASSERT_KNOWN_EQ (ordered_max (ch::make (9), ph::make (9, -90, -77)),
2884 /* Test ordered_max (T, T). */
2885 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 9, 17), ph::make (4, -1, 17)),
2886 ph::make (4, 9, 17));
2889 /* Test lower_bound for signed C. */
2891 template<unsigned int N
, typename C
, typename T
>
2893 test_signed_lower_bound ()
2895 typedef coeff_helper
<C
> ch
;
2896 typedef poly_helper
<T
> ph
;
2898 /* Test lower_bound (T, C). */
2899 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ch::make (5)),
2900 ph::make (4, -1, 0));
2901 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ch::make (-11)),
2902 ph::make (-11, 0, -14));
2904 /* Test lower_bound (C, T). */
2905 ASSERT_KNOWN_EQ (lower_bound (ch::make (5), ph::make (4, -1, 3)),
2906 ph::make (4, -1, 0));
2907 ASSERT_KNOWN_EQ (lower_bound (ch::make (-11), ph::make (6, 5, -14)),
2908 ph::make (-11, 0, -14));
2910 /* Test lower_bound (T, T). */
2911 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
2912 ph::make (4, -1, -2));
2913 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
2914 ph::make (-11, 4, -14));
2917 /* Test upper_bound for signed C. */
2919 template<unsigned int N
, typename C
, typename T
>
2921 test_signed_upper_bound ()
2923 typedef coeff_helper
<C
> ch
;
2924 typedef poly_helper
<T
> ph
;
2926 /* Test upper_bound (T, C). */
2927 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ch::make (5)),
2928 ph::make (5, 0, 3));
2929 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ch::make (-11)),
2930 ph::make (6, 5, 0));
2932 /* Test upper_bound (C, T). */
2933 ASSERT_KNOWN_EQ (upper_bound (ch::make (5), ph::make (4, -1, 3)),
2934 ph::make (5, 0, 3));
2935 ASSERT_KNOWN_EQ (upper_bound (ch::make (-11), ph::make (6, 5, -14)),
2936 ph::make (6, 5, 0));
2938 /* Test upper_bound (T, T). */
2939 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
2940 ph::make (5, 7, 3));
2941 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
2942 ph::make (6, 5, 3));
2945 /* Test constant_multiple_p for signed C. */
2947 template<unsigned int N
, typename C
, typename T
>
2949 test_signed_constant_multiple_p ()
2951 typedef poly_helper
<T
> ph
;
2953 /* Test constant_multiple_p (T, C). */
2955 ASSERT_TRUE (constant_multiple_p (ph::make (-45, 0, 0), 9,
2957 ASSERT_EQ (const_multiple
, -5);
2958 ASSERT_TRUE (constant_multiple_p (ph::make (63, 0, 0), -7,
2960 ASSERT_EQ (const_multiple
, -9);
2961 ASSERT_FALSE (constant_multiple_p (ph::make (-121, 0, 0), -12,
2963 ASSERT_TRUE (constant_multiple_p (ph::make (-120, 0, 0), -12,
2965 ASSERT_EQ (const_multiple
, 10);
2966 ASSERT_FALSE (constant_multiple_p (ph::make (-119, 0, 0), -12,
2968 ASSERT_EQ (constant_multiple_p (ph::make (-120, -23, 12), 12,
2969 &const_multiple
), N
== 1);
2971 ASSERT_EQ (const_multiple
, -10);
2973 /* Test constant_multiple_p (C, T). */
2974 ASSERT_TRUE (constant_multiple_p (-45, ph::make (9, 0, 0),
2976 ASSERT_EQ (const_multiple
, -5);
2977 ASSERT_TRUE (constant_multiple_p (63, ph::make (-7, 0, 0),
2979 ASSERT_EQ (const_multiple
, -9);
2980 ASSERT_FALSE (constant_multiple_p (-121, ph::make (-12, 0, 0),
2982 ASSERT_TRUE (constant_multiple_p (-120, ph::make (-12, 0, 0),
2984 ASSERT_EQ (const_multiple
, 10);
2985 ASSERT_FALSE (constant_multiple_p (-119, ph::make (-12, 0, 0),
2987 ASSERT_EQ (constant_multiple_p (-120, ph::make (12, 10, 6),
2988 &const_multiple
), N
== 1);
2990 ASSERT_EQ (const_multiple
, -10);
2992 ASSERT_TRUE (constant_multiple_p (ph::make (-40, 80, -200),
2993 ph::make (2, -4, 10),
2995 ASSERT_EQ (const_multiple
, -20);
2996 ASSERT_EQ (constant_multiple_p (ph::make (-20, 40, 100),
2997 ph::make (2, -4, 10),
2998 &const_multiple
), N
<= 2);
2999 ASSERT_EQ (const_multiple
, N
<= 2 ? -10 : -20);
3000 ASSERT_EQ (constant_multiple_p (ph::make (-10, -20, -50),
3001 ph::make (2, -4, 10),
3002 &const_multiple
), N
== 1);
3003 ASSERT_EQ (const_multiple
, N
== 1 ? -5 : N
== 2 ? -10 : -20);
3004 ASSERT_FALSE (constant_multiple_p (ph::make (-31, 0, 0),
3005 ph::make (-6, 0, 0),
3007 ASSERT_TRUE (constant_multiple_p (ph::make (-30, 0, 0),
3008 ph::make (-6, 0, 0),
3010 ASSERT_EQ (const_multiple
, 5);
3011 ASSERT_FALSE (constant_multiple_p (ph::make (-29, 0, 0),
3012 ph::make (-6, 0, 0),
3016 /* Test multiple_p for signed C. */
3018 template<unsigned int N
, typename C
, typename T
>
3020 test_signed_multiple_p ()
3022 typedef poly_helper
<T
> ph
;
3024 /* Test multiple_p (T, C). */
3025 ASSERT_TRUE (multiple_p (ph::make (-45, 36, 0), 9));
3026 ASSERT_TRUE (multiple_p (ph::make (63, 0, -14), -7));
3027 ASSERT_FALSE (multiple_p (ph::make (-121, 0, 0), -12));
3028 ASSERT_TRUE (multiple_p (ph::make (-120, 0, 0), -12));
3029 ASSERT_FALSE (multiple_p (ph::make (-119, 0, 0), -12));
3030 ASSERT_TRUE (multiple_p (ph::make (-120, -24, 12), 12));
3031 ASSERT_EQ (multiple_p (ph::make (-120, -24, 11), 12), N
<= 2);
3032 ASSERT_EQ (multiple_p (ph::make (-120, -23, 12), 12), N
== 1);
3034 /* Test multiple_p (C, T). */
3035 ASSERT_TRUE (multiple_p (-45, ph::make (9, 0, 0)));
3036 ASSERT_TRUE (multiple_p (63, ph::make (-7, 0, 0)));
3037 ASSERT_FALSE (multiple_p (-121, ph::make (-12, 0, 0)));
3038 ASSERT_TRUE (multiple_p (-120, ph::make (-12, 0, 0)));
3039 ASSERT_FALSE (multiple_p (-119, ph::make (-12, 0, 0)));
3040 ASSERT_EQ (multiple_p (-120, ph::make (12, 10, 6)), N
== 1);
3042 /* Test multiple_p (T, T). */
3043 ASSERT_TRUE (multiple_p (ph::make (-40, 80, -200),
3044 ph::make (2, -4, 10)));
3045 ASSERT_EQ (multiple_p (ph::make (-20, 40, 100),
3046 ph::make (2, -4, 10)), N
<= 2);
3047 ASSERT_EQ (multiple_p (ph::make (-10, -20, -50),
3048 ph::make (2, -4, 10)), N
== 1);
3049 ASSERT_FALSE (multiple_p (ph::make (-31, 0, 0),
3050 ph::make (-6, 0, 0)));
3051 ASSERT_TRUE (multiple_p (ph::make (-30, 0, 0),
3052 ph::make (-6, 0, 0)));
3053 ASSERT_FALSE (multiple_p (ph::make (-29, 0, 0),
3054 ph::make (-6, 0, 0)));
3057 /* Test the 3-operand form of multiple_p for signed C. */
3059 template<unsigned int N
, typename C
, typename T
>
3061 test_signed_multiple_p_with_result ()
3063 typedef coeff_helper
<C
> ch
;
3064 typedef poly_helper
<T
> ph
;
3066 /* Test multiple_p (T, C) -> T. */
3068 ASSERT_TRUE (multiple_p (ph::make (-45, 36, 0), 9, &multiple
));
3069 ASSERT_KNOWN_EQ (multiple
, ph::make (-5, 4, 0));
3070 ASSERT_TRUE (multiple_p (ph::make (63, 0, -14), -7, &multiple
));
3071 ASSERT_KNOWN_EQ (multiple
, ph::make (-9, 0, 2));
3072 ASSERT_FALSE (multiple_p (ph::make (-121, 0, 0), -12, &multiple
));
3073 ASSERT_TRUE (multiple_p (ph::make (-120, 0, 0), -12, &multiple
));
3074 ASSERT_KNOWN_EQ (multiple
, ch::make (10));
3075 ASSERT_FALSE (multiple_p (ph::make (-119, 0, 0), -12, &multiple
));
3076 ASSERT_TRUE (multiple_p (ph::make (-120, -24, 12), 12, &multiple
));
3077 ASSERT_KNOWN_EQ (multiple
, ph::make (-10, -2, 1));
3078 ASSERT_EQ (multiple_p (ph::make (-120, -24, 11), 12, &multiple
), N
<= 2);
3080 ASSERT_KNOWN_EQ (multiple
, ph::make (-10, -2, 0));
3081 ASSERT_EQ (multiple_p (ph::make (-120, -23, 12), 12, &multiple
), N
== 1);
3083 ASSERT_KNOWN_EQ (multiple
, ch::make (-10));
3085 /* Test multiple_p (C, T) -> T. */
3086 ASSERT_TRUE (multiple_p (-45, ph::make (9, 0, 0), &multiple
));
3087 ASSERT_KNOWN_EQ (multiple
, ch::make (-5));
3088 ASSERT_TRUE (multiple_p (63, ph::make (-7, 0, 0), &multiple
));
3089 ASSERT_KNOWN_EQ (multiple
, ch::make (-9));
3090 ASSERT_FALSE (multiple_p (-121, ph::make (-12, 0, 0), &multiple
));
3091 ASSERT_TRUE (multiple_p (-120, ph::make (-12, 0, 0), &multiple
));
3092 ASSERT_KNOWN_EQ (multiple
, ch::make (10));
3093 ASSERT_FALSE (multiple_p (-119, ph::make (-12, 0, 0), &multiple
));
3094 ASSERT_EQ (multiple_p (-120, ph::make (12, 10, 6), &multiple
), N
== 1);
3095 ASSERT_KNOWN_EQ (multiple
, ch::make (N
== 1 ? -10 : 10));
3097 /* Test multiple_p (T, T) -> T. */
3098 ASSERT_TRUE (multiple_p (ph::make (-40, 80, -200),
3099 ph::make (2, -4, 10),
3101 ASSERT_KNOWN_EQ (multiple
, ch::make (-20));
3102 ASSERT_EQ (multiple_p (ph::make (-20, 40, 100),
3103 ph::make (2, -4, 10),
3104 &multiple
), N
<= 2);
3106 ASSERT_KNOWN_EQ (multiple
, ch::make (-10));
3107 ASSERT_EQ (multiple_p (ph::make (-10, -20, -50),
3108 ph::make (2, -4, 10),
3109 &multiple
), N
== 1);
3111 ASSERT_KNOWN_EQ (multiple
, ch::make (-5));
3112 ASSERT_FALSE (multiple_p (ph::make (-31, 0, 0),
3113 ph::make (-6, 0, 0),
3115 ASSERT_TRUE (multiple_p (ph::make (-30, 0, 0),
3116 ph::make (-6, 0, 0),
3118 ASSERT_KNOWN_EQ (multiple
, ch::make (5));
3119 ASSERT_FALSE (multiple_p (ph::make (-29, 0, 0),
3120 ph::make (-6, 0, 0),
3124 /* Test exact_div for signed C. */
3126 template<unsigned int N
, typename C
, typename T
>
3128 test_signed_exact_div ()
3130 typedef coeff_helper
<C
> ch
;
3131 typedef poly_helper
<T
> ph
;
3133 /* Test exact_div (T, C). */
3134 ASSERT_KNOWN_EQ (exact_div (ph::make (-45, 36, 0), 9),
3135 ph::make (-5, 4, 0));
3136 ASSERT_KNOWN_EQ (exact_div (ph::make (63, 0, -14), -7),
3137 ph::make (-9, 0, 2));
3138 ASSERT_KNOWN_EQ (exact_div (ph::make (-120, 0, 0), -12),
3140 ASSERT_KNOWN_EQ (exact_div (ph::make (-120, -24, 12), 12),
3141 ph::make (-10, -2, 1));
3143 /* Test exact_div (T, T). */
3144 ASSERT_KNOWN_EQ (exact_div (ph::make (-40, 80, -200),
3145 ph::make (2, -4, 10)),
3147 ASSERT_KNOWN_EQ (exact_div (ph::make (-30, 0, 0),
3148 ph::make (-6, 0, 0)),
3152 /* Test the form of can_div_trunc_p that returns a constant, for signed C. */
3154 template<unsigned int N
, typename C
, typename T
>
3156 test_signed_can_div_trunc_p_const ()
3158 typedef coeff_helper
<C
> ch
;
3159 typedef poly_helper
<T
> ph
;
3161 /* Test can_div_trunc_p (T, C) -> C. */
3163 ASSERT_TRUE (can_div_trunc_p (ph::make (-31, 0, 0), 10, &const_quot
));
3164 ASSERT_KNOWN_EQ (const_quot
, -3);
3165 ASSERT_TRUE (can_div_trunc_p (ph::make (-29, 0, 0), 10, &const_quot
));
3166 ASSERT_KNOWN_EQ (const_quot
, -2);
3168 /* Test can_div_trunc_p (T, T) -> C. */
3169 ASSERT_TRUE (can_div_trunc_p (ph::make (-10, 25, -15),
3170 ph::make (2, -5, 3),
3172 ASSERT_EQ (const_quot
, -5);
3173 /* (-5 + 2x) / (-3 + 2x) != 1 when x == 1. */
3174 ASSERT_EQ (can_div_trunc_p (ph::make (-5, 2, 0),
3175 ph::make (-3, 2, 0),
3176 &const_quot
), N
== 1);
3177 ASSERT_EQ (const_quot
, N
== 1 ? 1 : -5);
3178 /* Similarly for the third coefficient. */
3179 ASSERT_EQ (can_div_trunc_p (ph::make (-5, -5, 2),
3180 ph::make (-3, -3, 2),
3181 &const_quot
), N
<= 2);
3182 ASSERT_EQ (const_quot
, N
<= 2 ? 1 : -5);
3183 /* (-15 + 3x) / (-12 + 2x) != 1 when x == 7. */
3184 ASSERT_EQ (can_div_trunc_p (ph::make (-15, 3, 0),
3185 ph::make (-12, 2, 0),
3186 &const_quot
), N
== 1);
3187 ASSERT_EQ (const_quot
, N
<= 2 ? 1 : -5);
3188 ASSERT_TRUE (can_div_trunc_p (ph::make (-21, -18, -14),
3191 ASSERT_EQ (const_quot
, -4);
3192 ASSERT_TRUE (can_div_trunc_p (ph::make (18, 9, 13),
3193 ph::make (-8, -4, -5),
3195 ASSERT_EQ (const_quot
, -2);
3197 /* Test can_div_trunc_p (T, T) -> C, T. */
3199 ASSERT_TRUE (can_div_trunc_p (ph::make (-10, 25, -15),
3200 ph::make (2, -5, 3),
3201 &const_quot
, &rem
));
3202 ASSERT_EQ (const_quot
, -5);
3203 ASSERT_KNOWN_EQ (rem
, ch::make (0));
3204 /* (-5 + 2x) / (-3 + 2x) != 1 when x == 1. */
3205 ASSERT_EQ (can_div_trunc_p (ph::make (-5, 2, 0),
3206 ph::make (-3, 2, 0),
3207 &const_quot
, &rem
), N
== 1);
3208 ASSERT_KNOWN_EQ (const_quot
, N
== 1 ? 1 : -5);
3210 ASSERT_KNOWN_EQ (rem
, ch::make (-2));
3211 /* Similarly for the third coefficient. */
3212 ASSERT_EQ (can_div_trunc_p (ph::make (-5, -5, 2),
3213 ph::make (-3, -3, 2),
3214 &const_quot
, &rem
), N
<= 2);
3215 ASSERT_KNOWN_EQ (const_quot
, N
<= 2 ? 1 : -5);
3217 ASSERT_KNOWN_EQ (rem
, ph::make (-2, -2, 0));
3218 /* (-15 + 3x) / (-12 + 2x) != 1 when x == 7. */
3219 ASSERT_EQ (can_div_trunc_p (ph::make (-15, 3, 0),
3220 ph::make (-12, 2, 0),
3221 &const_quot
, &rem
), N
== 1);
3222 ASSERT_KNOWN_EQ (const_quot
, N
<= 2 ? 1 : -5);
3224 ASSERT_KNOWN_EQ (rem
, ch::make (-3));
3225 ASSERT_TRUE (can_div_trunc_p (ph::make (-21, -18, -14),
3227 &const_quot
, &rem
));
3228 ASSERT_EQ (const_quot
, -4);
3229 ASSERT_KNOWN_EQ (rem
, ph::make (-1, -2, -2));
3230 ASSERT_TRUE (can_div_trunc_p (ph::make (18, 9, 13),
3231 ph::make (-8, -4, -5),
3232 &const_quot
, &rem
));
3233 ASSERT_EQ (const_quot
, -2);
3234 ASSERT_KNOWN_EQ (rem
, ph::make (2, 1, 3));
3237 /* Test the form of can_div_trunc_p that returns a poly_int, for signed C. */
3239 template<unsigned int N
, typename C
, typename T
>
3241 test_signed_can_div_trunc_p_poly ()
3243 typedef coeff_helper
<C
> ch
;
3244 typedef poly_helper
<T
> ph
;
3246 /* Test can_div_trunc_p (T, C) -> T. */
3248 ASSERT_TRUE (can_div_trunc_p (ph::make (-99, 0, 0), 10, "
));
3249 ASSERT_KNOWN_EQ (quot
, ch::make (-9));
3250 ASSERT_TRUE (can_div_trunc_p (ph::make (7, -63, 81), 9, "
));
3251 ASSERT_KNOWN_EQ (quot
, ph::make (0, -7, 9));
3252 ASSERT_TRUE (can_div_trunc_p (ph::make (15, 44, -55), -11, "
));
3253 ASSERT_KNOWN_EQ (quot
, ph::make (-1, -4, 5));
3254 ASSERT_EQ (can_div_trunc_p (ph::make (-63, -24, -17), -8, "
), N
<= 2);
3256 ASSERT_KNOWN_EQ (quot
, ph::make (7, 3, 0));
3257 ASSERT_EQ (can_div_trunc_p (ph::make (40, 48, 70), -7, "
), N
== 1);
3259 ASSERT_KNOWN_EQ (quot
, ch::make (-5));
3261 /* Test can_div_trunc_p (T, C) -> T, C. */
3263 ASSERT_TRUE (can_div_trunc_p (ph::make (-99, 0, 0), 10,
3264 "
, &const_rem
));
3265 ASSERT_KNOWN_EQ (quot
, ch::make (-9));
3266 ASSERT_EQ (const_rem
, -9);
3267 ASSERT_TRUE (can_div_trunc_p (ph::make (7, -63, 81), 9,
3268 "
, &const_rem
));
3269 ASSERT_KNOWN_EQ (quot
, ph::make (0, -7, 9));
3270 ASSERT_EQ (const_rem
, 7);
3271 ASSERT_TRUE (can_div_trunc_p (ph::make (15, 44, -55), -11,
3272 "
, &const_rem
));
3273 ASSERT_KNOWN_EQ (quot
, ph::make (-1, -4, 5));
3274 ASSERT_EQ (const_rem
, 4);
3275 ASSERT_EQ (can_div_trunc_p (ph::make (-63, -24, -17), -8,
3276 "
, &const_rem
), N
<= 2);
3279 ASSERT_KNOWN_EQ (quot
, ph::make (7, 3, 0));
3280 ASSERT_EQ (const_rem
, -7);
3282 ASSERT_EQ (can_div_trunc_p (ph::make (40, 48, 70), -7,
3283 "
, &const_rem
), N
== 1);
3286 ASSERT_KNOWN_EQ (quot
, ch::make (-5));
3287 ASSERT_EQ (const_rem
, 5);
3291 /* Test can_div_away_from_zero_p for signed C. */
3293 template<unsigned int N
, typename C
, typename T
>
3295 test_signed_can_div_away_from_zero_p ()
3297 typedef poly_helper
<T
> ph
;
3299 /* Test can_div_away_from_zero_p (T, T) -> C. */
3301 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (-10, 25, -15),
3302 ph::make (2, -5, 3),
3304 ASSERT_EQ (const_quot
, -5);
3305 /* (-5 + 2x) / (-3 + 2x) != 1 when x == 1. */
3306 ASSERT_EQ (can_div_away_from_zero_p (ph::make (-5, 2, 0),
3307 ph::make (-3, 2, 0),
3308 &const_quot
), N
== 1);
3309 ASSERT_EQ (const_quot
, N
== 1 ? 2 : -5);
3310 /* Similarly for the third coefficient. */
3311 ASSERT_EQ (can_div_away_from_zero_p (ph::make (-5, -5, 2),
3312 ph::make (-3, -3, 2),
3313 &const_quot
), N
<= 2);
3314 ASSERT_EQ (const_quot
, N
<= 2 ? 2 : -5);
3315 /* (-15 + 3x) / (-12 + 2x) != 1 when x == 7. */
3316 ASSERT_EQ (can_div_away_from_zero_p (ph::make (-15, 3, 0),
3317 ph::make (-12, 2, 0),
3318 &const_quot
), N
== 1);
3319 ASSERT_EQ (const_quot
, N
<= 2 ? 2 : -5);
3320 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (-21, -18, -14),
3323 ASSERT_EQ (const_quot
, -5);
3324 ASSERT_TRUE (can_div_away_from_zero_p (ph::make (18, 9, 13),
3325 ph::make (-8, -4, -5),
3327 ASSERT_EQ (const_quot
, -3);
3330 /* Test maybe_in_range_p for signed C. */
3332 template<unsigned int N
, typename C
, typename T
>
3334 test_signed_maybe_in_range_p ()
3336 typedef coeff_helper
<C
> ch
;
3337 typedef poly_helper
<T
> ph
;
3339 ASSERT_EQ (maybe_in_range_p (ch::make (4),
3340 ph::make (5, 1, -2),
3341 ph::make (-1, -1, -1)), N
== 3);
3342 ASSERT_EQ (maybe_in_range_p (ch::make (4),
3343 ph::make (5, -1, 2),
3344 ph::make (-1, -1, -1)), N
>= 2);
3347 /* Test maybe_le for unsigned C. */
3349 template<unsigned int N
, typename C
, typename T
>
3351 test_unsigned_maybe_le ()
3353 typedef coeff_helper
<C
> ch
;
3354 typedef poly_helper
<T
> ph
;
3356 /* Test maybe_le (T, C). */
3357 ASSERT_FALSE (maybe_le (ph::make (3, 5, -1), ch::make (2)));
3358 ASSERT_FALSE (maybe_le (ph::make (40, -10, 60), ch::make (15)));
3359 ASSERT_FALSE (maybe_le (ph::make (-14, 0, 0), ch::make (13)));
3361 /* Test maybe_le (C, T). */
3362 ASSERT_EQ (maybe_le (ch::make (4), ph::make (3, 5, -1)), N
>= 2);
3363 ASSERT_EQ (maybe_le (ch::make (41), ph::make (40, -10, 60)), N
>= 2);
3364 ASSERT_FALSE (maybe_le (ch::make (-15), ph::make (11, 0, 0)));
3366 /* Test maybe_le (T, T). */
3367 ASSERT_EQ (maybe_le (ph::make (-2, 4, -2),
3368 ph::make (-3, -5, -1)), N
>= 2);
3369 ASSERT_EQ (maybe_le (ph::make (-2, -6, 0),
3370 ph::make (-3, 0, 100)), N
== 3);
3371 ASSERT_FALSE (maybe_le (ph::make (-2, 5, 1),
3372 ph::make (-3, 4, 0)));
3375 /* Test maybe_lt for unsigned C. */
3377 template<unsigned int N
, typename C
, typename T
>
3379 test_unsigned_maybe_lt ()
3381 typedef coeff_helper
<C
> ch
;
3382 typedef poly_helper
<T
> ph
;
3384 /* Test maybe_lt (T, C). */
3385 ASSERT_FALSE (maybe_lt (ph::make (3, 5, -1), ch::make (2)));
3386 ASSERT_FALSE (maybe_lt (ph::make (40, -10, 60), ch::make (15)));
3387 ASSERT_FALSE (maybe_lt (ph::make (-18, 0, 0), ch::make (18)));
3388 ASSERT_FALSE (maybe_lt (ph::make (-2, -2, -2), ch::make (-2)));
3390 /* Test maybe_lt (C, T). */
3391 ASSERT_EQ (maybe_lt (ch::make (4), ph::make (3, 5, -1)), N
>= 2);
3392 ASSERT_EQ (maybe_lt (ch::make (41), ph::make (40, -10, 60)), N
>= 2);
3393 ASSERT_FALSE (maybe_lt (ch::make (-45), ph::make (40, 0, 0)));
3394 ASSERT_EQ (maybe_lt (ch::make (-2), ph::make (-2, -2, -2)), N
>= 2);
3396 /* Test maybe_lt (T, T). */
3397 ASSERT_EQ (maybe_lt (ph::make (-3, 4, -2),
3398 ph::make (-3, -5, -1)), N
>= 2);
3399 ASSERT_EQ (maybe_lt (ph::make (-3, -6, 0),
3400 ph::make (-3, 0, 100)), N
== 3);
3401 ASSERT_FALSE (maybe_lt (ph::make (-3, 5, 1),
3402 ph::make (-3, 4, 0)));
3405 /* Test maybe_ge for unsigned C. */
3407 template<unsigned int N
, typename C
, typename T
>
3409 test_unsigned_maybe_ge ()
3411 typedef coeff_helper
<C
> ch
;
3412 typedef poly_helper
<T
> ph
;
3414 /* Test maybe_ge (T, C). */
3415 ASSERT_EQ (maybe_ge (ph::make (3, 5, -1), ch::make (4)), N
>= 2);
3416 ASSERT_EQ (maybe_ge (ph::make (40, -10, 60), ch::make (41)), N
>= 2);
3417 ASSERT_FALSE (maybe_ge (ph::make (11, 0, 0), ch::make (-15)));
3419 /* Test maybe_ge (C, T). */
3420 ASSERT_FALSE (maybe_ge (ch::make (2), ph::make (3, 5, -1)));
3421 ASSERT_FALSE (maybe_ge (ch::make (15), ph::make (40, -10, 60)));
3422 ASSERT_FALSE (maybe_ge (ch::make (13), ph::make (-14, 0, 0)));
3424 /* Test maybe_ge (T, T). */
3425 ASSERT_EQ (maybe_ge (ph::make (-3, -5, -1),
3426 ph::make (-2, 4, -2)), N
>= 2);
3427 ASSERT_EQ (maybe_ge (ph::make (-3, 0, 100),
3428 ph::make (-2, -6, 0)), N
== 3);
3429 ASSERT_FALSE (maybe_ge (ph::make (-3, 4, 0),
3430 ph::make (-2, 5, 1)));
3433 /* Test maybe_gt for unsigned C. */
3435 template<unsigned int N
, typename C
, typename T
>
3437 test_unsigned_maybe_gt ()
3439 typedef coeff_helper
<C
> ch
;
3440 typedef poly_helper
<T
> ph
;
3442 /* Test maybe_gt (T, C). */
3443 ASSERT_EQ (maybe_gt (ph::make (3, 5, -1), ch::make (4)), N
>= 2);
3444 ASSERT_EQ (maybe_gt (ph::make (40, -10, 60), ch::make (41)), N
>= 2);
3445 ASSERT_FALSE (maybe_gt (ph::make (40, 0, 0), ch::make (-45)));
3446 ASSERT_EQ (maybe_gt (ph::make (-2, -2, -2), ch::make (-2)), N
>= 2);
3448 /* Test maybe_gt (C, T). */
3449 ASSERT_FALSE (maybe_gt (ch::make (2), ph::make (3, 5, -1)));
3450 ASSERT_FALSE (maybe_gt (ch::make (15), ph::make (40, -10, 60)));
3451 ASSERT_FALSE (maybe_gt (ch::make (18), ph::make (-18, 0, 0)));
3452 ASSERT_FALSE (maybe_gt (ch::make (-2), ph::make (-2, -2, -2)));
3454 /* Test maybe_gt (T, T). */
3455 ASSERT_EQ (maybe_gt (ph::make (-3, -5, -1),
3456 ph::make (-3, 4, -2)), N
>= 2);
3457 ASSERT_EQ (maybe_gt (ph::make (-3, 0, 100),
3458 ph::make (-3, -6, 0)), N
== 3);
3459 ASSERT_FALSE (maybe_gt (ph::make (-3, 4, 0),
3460 ph::make (-3, 5, 1)));
3463 /* Test known_gt for unsigned C. */
3465 template<unsigned int N
, typename C
, typename T
>
3467 test_unsigned_known_gt ()
3469 typedef coeff_helper
<C
> ch
;
3470 typedef poly_helper
<T
> ph
;
3472 /* Test known_gt (T, C). */
3473 ASSERT_TRUE (known_gt (ph::make (3, 5, -1), ch::make (2)));
3474 ASSERT_TRUE (known_gt (ph::make (40, -10, 60), ch::make (15)));
3475 ASSERT_TRUE (known_gt (ph::make (-14, 0, 0), ch::make (13)));
3477 /* Test known_gt (C, T). */
3478 ASSERT_EQ (known_gt (ch::make (4), ph::make (3, 5, -1)), N
== 1);
3479 ASSERT_EQ (known_gt (ch::make (41), ph::make (40, -10, 60)), N
== 1);
3480 ASSERT_TRUE (known_gt (ch::make (-15), ph::make (11, 0, 0)));
3482 /* Test known_gt (T, T). */
3483 ASSERT_EQ (known_gt (ph::make (-2, 4, -2),
3484 ph::make (-3, -5, -1)), N
== 1);
3485 ASSERT_EQ (known_gt (ph::make (-2, -6, 0),
3486 ph::make (-3, 0, 100)), N
<= 2);
3487 ASSERT_TRUE (known_gt (ph::make (-2, 5, 1),
3488 ph::make (-3, 4, 0)));
3491 /* Test known_ge for unsigned C. */
3493 template<unsigned int N
, typename C
, typename T
>
3495 test_unsigned_known_ge ()
3497 typedef coeff_helper
<C
> ch
;
3498 typedef poly_helper
<T
> ph
;
3500 /* Test known_ge (T, C). */
3501 ASSERT_TRUE (known_ge (ph::make (3, 5, -1), ch::make (2)));
3502 ASSERT_TRUE (known_ge (ph::make (40, -10, 60), ch::make (15)));
3503 ASSERT_TRUE (known_ge (ph::make (-18, 0, 0), ch::make (18)));
3504 ASSERT_TRUE (known_ge (ph::make (-2, -2, -2), ch::make (-2)));
3506 /* Test known_ge (C, T). */
3507 ASSERT_EQ (known_ge (ch::make (4), ph::make (3, 5, -1)), N
== 1);
3508 ASSERT_EQ (known_ge (ch::make (41), ph::make (40, -10, 60)), N
== 1);
3509 ASSERT_TRUE (known_ge (ch::make (-45), ph::make (40, 0, 0)));
3510 ASSERT_EQ (known_ge (ch::make (-2), ph::make (-2, -2, -2)), N
== 1);
3512 /* Test known_ge (T, T). */
3513 ASSERT_EQ (known_ge (ph::make (-3, 4, -2),
3514 ph::make (-3, -5, -1)), N
== 1);
3515 ASSERT_EQ (known_ge (ph::make (-3, -6, 0),
3516 ph::make (-3, 0, 100)), N
<= 2);
3517 ASSERT_TRUE (known_ge (ph::make (-3, 5, 1),
3518 ph::make (-3, 4, 0)));
3521 /* Test known_lt for unsigned C. */
3523 template<unsigned int N
, typename C
, typename T
>
3525 test_unsigned_known_lt ()
3527 typedef coeff_helper
<C
> ch
;
3528 typedef poly_helper
<T
> ph
;
3530 /* Test known_lt (T, C). */
3531 ASSERT_EQ (known_lt (ph::make (3, 5, -1), ch::make (4)), N
== 1);
3532 ASSERT_EQ (known_lt (ph::make (40, -10, 60), ch::make (41)), N
== 1);
3533 ASSERT_TRUE (known_lt (ph::make (11, 0, 0), ch::make (-15)));
3535 /* Test known_lt (C, T). */
3536 ASSERT_TRUE (known_lt (ch::make (2), ph::make (3, 5, -1)));
3537 ASSERT_TRUE (known_lt (ch::make (15), ph::make (40, -10, 60)));
3538 ASSERT_TRUE (known_lt (ch::make (13), ph::make (-14, 0, 0)));
3540 /* Test known_lt (T, T). */
3541 ASSERT_EQ (known_lt (ph::make (-3, -5, -1),
3542 ph::make (-2, 4, -2)), N
== 1);
3543 ASSERT_EQ (known_lt (ph::make (-3, 0, 100),
3544 ph::make (-2, -6, 0)), N
<= 2);
3545 ASSERT_TRUE (known_lt (ph::make (-3, 4, 0),
3546 ph::make (-2, 5, 1)));
3549 /* Test known_le for unsigned C. */
3551 template<unsigned int N
, typename C
, typename T
>
3553 test_unsigned_known_le ()
3555 typedef coeff_helper
<C
> ch
;
3556 typedef poly_helper
<T
> ph
;
3558 /* Test known_le (T, C). */
3559 ASSERT_EQ (known_le (ph::make (3, 5, -1), ch::make (4)), N
== 1);
3560 ASSERT_EQ (known_le (ph::make (40, -10, 60), ch::make (41)), N
== 1);
3561 ASSERT_TRUE (known_le (ph::make (40, 0, 0), ch::make (-45)));
3562 ASSERT_EQ (known_le (ph::make (-2, -2, -2), ch::make (-2)), N
== 1);
3564 /* Test known_le (C, T). */
3565 ASSERT_TRUE (known_le (ch::make (2), ph::make (3, 5, -1)));
3566 ASSERT_TRUE (known_le (ch::make (15), ph::make (40, -10, 60)));
3567 ASSERT_TRUE (known_le (ch::make (18), ph::make (-18, 0, 0)));
3568 ASSERT_TRUE (known_le (ch::make (-2), ph::make (-2, -2, -2)));
3570 /* Test known_le (T, T). */
3571 ASSERT_EQ (known_le (ph::make (-3, -5, -1),
3572 ph::make (-3, 4, -2)), N
== 1);
3573 ASSERT_EQ (known_le (ph::make (-3, 0, 100),
3574 ph::make (-3, -6, 0)), N
<= 2);
3575 ASSERT_TRUE (known_le (ph::make (-3, 4, 0),
3576 ph::make (-3, 5, 1)));
3579 /* Test ordered_p for unsigned C. */
3581 template<unsigned int N
, typename C
, typename T
>
3583 test_unsigned_ordered_p ()
3585 typedef coeff_helper
<C
> ch
;
3586 typedef poly_helper
<T
> ph
;
3588 /* Test ordered_p (T, C). */
3589 ASSERT_EQ (ordered_p (ph::make (3, 5, -1), ch::make (4)), N
== 1);
3590 ASSERT_TRUE (ordered_p (ph::make (3, 5, -1), ch::make (3)));
3591 ASSERT_TRUE (ordered_p (ph::make (3, 5, -1), ch::make (2)));
3592 ASSERT_EQ (ordered_p (ph::make (40, -10, 60), ch::make (41)), N
== 1);
3593 ASSERT_TRUE (ordered_p (ph::make (40, -10, 60), ch::make (40)));
3594 ASSERT_TRUE (ordered_p (ph::make (40, -10, 60), ch::make (39)));
3595 ASSERT_TRUE (ordered_p (ph::make (4, -4, -4), ch::make (0)));
3596 ASSERT_TRUE (ordered_p (ph::make (4, 0, -4), ch::make (0)));
3597 ASSERT_TRUE (ordered_p (ph::make (4, 4, -4), ch::make (0)));
3598 ASSERT_TRUE (ordered_p (ph::make (-4, 4, 4), ch::make (0)));
3599 ASSERT_TRUE (ordered_p (ph::make (-4, 0, 4), ch::make (0)));
3600 ASSERT_TRUE (ordered_p (ph::make (-4, -4, 4), ch::make (0)));
3602 /* Test ordered_p (C, T). */
3603 ASSERT_EQ (ordered_p (ch::make (4), ph::make (3, 5, -1)), N
== 1);
3604 ASSERT_TRUE (ordered_p (ch::make (3), ph::make (3, 5, -1)));
3605 ASSERT_TRUE (ordered_p (ch::make (2), ph::make (3, 5, -1)));
3606 ASSERT_EQ (ordered_p (ch::make (41), ph::make (40, -10, 60)), N
== 1);
3607 ASSERT_TRUE (ordered_p (ch::make (40), ph::make (40, -10, 60)));
3608 ASSERT_TRUE (ordered_p (ch::make (39), ph::make (40, -10, 60)));
3609 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, -4, -4)));
3610 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 0, -4)));
3611 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 4, -4)));
3612 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, 4, 4)));
3613 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, 0, 4)));
3614 ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, -4, 4)));
3617 /* Test ordered_min for unsigned C. */
3619 template<unsigned int N
, typename C
, typename T
>
3621 test_unsigned_ordered_min ()
3623 typedef coeff_helper
<C
> ch
;
3624 typedef poly_helper
<T
> ph
;
3626 /* Test ordered_min (T, C). */
3627 ASSERT_KNOWN_EQ (ordered_min (ph::make (5, -12, -14), ch::make (5)),
3630 /* Test ordered_min (C, T). */
3631 ASSERT_KNOWN_EQ (ordered_min (ch::make (9), ph::make (9, -90, -77)),
3634 /* Test ordered_min (T, T). */
3635 ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 9, 17), ph::make (4, -1, 17)),
3636 ph::make (4, 9, 17));
3639 /* Test ordered_max for unsigned C. */
3641 template<unsigned int N
, typename C
, typename T
>
3643 test_unsigned_ordered_max ()
3645 typedef coeff_helper
<C
> ch
;
3646 typedef poly_helper
<T
> ph
;
3648 /* Test ordered_max (T, C). */
3649 ASSERT_KNOWN_EQ (ordered_max (ph::make (5, -12, -14), ch::make (5)),
3650 ph::make (5, -12, -14));
3652 /* Test ordered_max (C, T). */
3653 ASSERT_KNOWN_EQ (ordered_max (ch::make (9), ph::make (9, -90, -77)),
3654 ph::make (9, -90, -77));
3656 /* Test ordered_max (T, T). */
3657 ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 9, 17), ph::make (4, -1, 17)),
3658 ph::make (4, -1, 17));
3661 /* Test lower_bound for unsigned C. */
3663 template<unsigned int N
, typename C
, typename T
>
3665 test_unsigned_lower_bound ()
3667 typedef coeff_helper
<C
> ch
;
3668 typedef poly_helper
<T
> ph
;
3670 /* Test lower_bound (T, C). */
3671 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ch::make (5)),
3673 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ch::make (-11)),
3676 /* Test lower_bound (C, T). */
3677 ASSERT_KNOWN_EQ (lower_bound (ch::make (5), ph::make (4, -1, 3)),
3679 ASSERT_KNOWN_EQ (lower_bound (ch::make (-11), ph::make (6, 5, -14)),
3682 /* Test lower_bound (T, T). */
3683 ASSERT_KNOWN_EQ (lower_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
3684 ph::make (4, 7, 3));
3685 ASSERT_KNOWN_EQ (lower_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
3686 ph::make (6, 4, 3));
3689 /* Test upper_bound for unsigned C. */
3691 template<unsigned int N
, typename C
, typename T
>
3693 test_unsigned_upper_bound ()
3695 typedef coeff_helper
<C
> ch
;
3696 typedef poly_helper
<T
> ph
;
3698 /* Test upper_bound (T, C). */
3699 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ch::make (5)),
3700 ph::make (5, -1, 3));
3701 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ch::make (-11)),
3702 ph::make (-11, 5, -14));
3704 /* Test upper_bound (C, T). */
3705 ASSERT_KNOWN_EQ (upper_bound (ch::make (5), ph::make (4, -1, 3)),
3706 ph::make (5, -1, 3));
3707 ASSERT_KNOWN_EQ (upper_bound (ch::make (-11), ph::make (6, 5, -14)),
3708 ph::make (-11, 5, -14));
3710 /* Test upper_bound (T, T). */
3711 ASSERT_KNOWN_EQ (upper_bound (ph::make (4, -1, 3), ph::make (5, 7, -2)),
3712 ph::make (5, -1, -2));
3713 ASSERT_KNOWN_EQ (upper_bound (ph::make (6, 5, -14), ph::make (-11, 4, 3)),
3714 ph::make (-11, 5, -14));
3717 /* Test maybe_in_range_p for unsigned C. */
3719 template<unsigned int N
, typename C
, typename T
>
3721 test_unsigned_maybe_in_range_p ()
3723 typedef coeff_helper
<C
> ch
;
3724 typedef poly_helper
<T
> ph
;
3726 /* Unknown size for N == 1. */
3727 ASSERT_TRUE (maybe_in_range_p (ch::make (-1),
3729 ph::make (-1, -1, -1)));
3730 /* Unknown size for all N. */
3731 ASSERT_TRUE (maybe_in_range_p (ph::make (-1, -1, -1),
3734 /* Unknown size for N == 1. */
3735 ASSERT_EQ (maybe_in_range_p (ph::make (-1, -1, -1),
3737 ph::make (-1, -1, -1)), N
== 1);
3738 ASSERT_EQ (maybe_in_range_p (ch::make (-2),
3740 ph::make (-2, -2, -2)), N
>= 2);
3741 ASSERT_FALSE (maybe_in_range_p (ph::make (-2, -2, -2),
3744 ASSERT_FALSE (maybe_in_range_p (ph::make (-2, -2, -2),
3746 ph::make (-2, -2, -2)));
3747 ASSERT_TRUE (maybe_in_range_p (ph::make (-2, -2, -2),
3749 ph::make (-2, -2, -2)));
3750 ASSERT_TRUE (maybe_in_range_p (ph::make (-2, -2, -2),
3755 /* Test known_in_range_p for unsigned C. */
3757 template<unsigned int N
, typename C
, typename T
>
3759 test_unsigned_known_in_range_p ()
3761 typedef coeff_helper
<C
> ch
;
3762 typedef poly_helper
<T
> ph
;
3764 ASSERT_FALSE (known_in_range_p (ch::make (4),
3767 ASSERT_TRUE (known_in_range_p (ph::make (6, 1, 2),
3770 ASSERT_TRUE (known_in_range_p (ph::make (6, 1, 2),
3772 ph::make (-2, -2, -2)));
3775 /* Test things that work for poly_int-based types T, given that the
3776 coefficient type C is a primitive integer type. N is the number of
3777 coefficients in C */
3779 template<unsigned int N
, typename C
, typename T
>
3783 typedef coeff_helper
<C
> ch
;
3784 typedef poly_helper
<T
> ph
;
3786 /* Test coeff_gcd. */
3787 ASSERT_EQ (coeff_gcd (ph::make (30, 45, 10)),
3788 N
== 1 ? 30 : N
== 2 ? 15 : 5);
3789 ASSERT_EQ (coeff_gcd (ph::make (0, 18, 21)),
3790 N
== 1 ? 0 : N
== 2 ? 18 : 3);
3791 ASSERT_EQ (coeff_gcd (ph::make (0, 0, 101)),
3793 ASSERT_EQ (coeff_gcd (ph::make (21, 0, 28)),
3795 ASSERT_EQ (coeff_gcd (ph::make (100, 175, 0)),
3798 /* Test common_multiple (T, C). */
3799 ASSERT_KNOWN_EQ (common_multiple (ph::make (8, 24, 16), 6),
3800 ph::make (24, 72, 48));
3801 ASSERT_KNOWN_EQ (common_multiple (ph::make (30, 0, 0), 45),
3804 ASSERT_KNOWN_EQ (common_multiple (ph::make (18, 15, 0), 12),
3805 ph::make (72, 60, 0));
3807 ASSERT_KNOWN_EQ (common_multiple (ph::make (18, 15, 4), 12),
3808 ph::make (216, 180, 48));
3810 /* Test common_multiple (C, T). */
3811 ASSERT_KNOWN_EQ (common_multiple (6, ph::make (8, 24, 16)),
3812 ph::make (24, 72, 48));
3813 ASSERT_KNOWN_EQ (common_multiple (45, ph::make (30, 0, 0)),
3816 ASSERT_KNOWN_EQ (common_multiple (12, ph::make (18, 15, 0)),
3817 ph::make (72, 60, 0));
3819 ASSERT_KNOWN_EQ (common_multiple (12, ph::make (18, 15, 4)),
3820 ph::make (216, 180, 48));
3822 /* Test force_common_multiple. */
3823 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (30, 0, 0),
3824 ph::make (25, 0, 0)),
3825 ph::make (150, 0, 0));
3828 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (16, 24, 0),
3829 ph::make (24, 36, 0)),
3830 ph::make (48, 72, 0));
3831 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (16, 24, 0),
3832 ph::make (12, 0, 0)),
3833 ph::make (48, 72, 0));
3834 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (15, 0, 0),
3835 ph::make (21, 9, 0)),
3836 ph::make (105, 45, 0));
3840 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (33, 99, 66),
3841 ph::make (22, 66, 44)),
3842 ph::make (66, 198, 132));
3843 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (30, 0, 45),
3844 ph::make (12, 0, 18)),
3845 ph::make (60, 0, 90));
3846 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (40, 0, 50),
3847 ph::make (8, 0, 0)),
3848 ph::make (160, 0, 200));
3849 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (6, 0, 0),
3850 ph::make (10, 0, 15)),
3851 ph::make (60, 0, 90));
3852 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (20, 40, 30),
3853 ph::make (15, 0, 0)),
3854 ph::make (60, 120, 90));
3855 ASSERT_KNOWN_EQ (force_common_multiple (ph::make (9, 0, 0),
3856 ph::make (90, 81, 27)),
3857 ph::make (90, 81, 27));
3861 /* Test poly_int<N, C>::to_shwi, using in-range source coefficient value
3862 SRCV (equal to DESTV) and adding DELTA to get an out-of-range value. */
3864 template<unsigned int N
, typename C
>
3866 test_to_shwi (const C
&srcv
, int delta
, HOST_WIDE_INT destv
)
3868 typedef poly_helper
< poly_int
<N
, HOST_WIDE_INT
> > ps64h
;
3869 typedef poly_int
<N
, C
> T
;
3870 typedef poly_helper
<T
> ph
;
3871 poly_int
<N
, HOST_WIDE_INT
> shwi
;
3873 /* Test in-range T::to_shwi. */
3874 ASSERT_TRUE (ph::make (srcv
,
3876 srcv
- delta
* 2).to_shwi (&shwi
));
3877 ASSERT_KNOWN_EQ (shwi
, ps64h::make (destv
,
3879 destv
- delta
* 2));
3881 /* Test partially in-range T::to_shwi. */
3882 ASSERT_EQ (ph::make (srcv
,
3884 srcv
+ delta
* 2).to_shwi (&shwi
), N
== 1);
3886 ASSERT_KNOWN_EQ (shwi
, destv
);
3887 ASSERT_EQ (ph::make (srcv
- delta
,
3889 srcv
+ delta
).to_shwi (&shwi
), N
<= 2);
3891 ASSERT_KNOWN_EQ (shwi
, ps64h::make (destv
- delta
,
3893 destv
/* ignored */));
3895 /* Test fully out-of-range T::to_shwi. */
3896 ASSERT_FALSE (ph::make (srcv
+ delta
, srcv
, srcv
).to_shwi (&shwi
));
3899 /* Test poly_int<N, C>::to_uhwi, using in-range source coefficient value
3900 SRCV (equal to DESTV) and adding DELTA to get an out-of-range value. */
3902 template<unsigned int N
, typename C
>
3904 test_to_uhwi (const C
&srcv
, int delta
, unsigned HOST_WIDE_INT destv
)
3906 typedef poly_helper
< poly_int
<N
, unsigned HOST_WIDE_INT
> > pu64h
;
3907 typedef poly_int
<N
, C
> T
;
3908 typedef poly_helper
<T
> ph
;
3909 poly_int
<N
, unsigned HOST_WIDE_INT
> uhwi
;
3911 /* Test in-range T::to_uhwi. */
3912 ASSERT_TRUE (ph::make (srcv
,
3914 srcv
- delta
* 2).to_uhwi (&uhwi
));
3915 ASSERT_KNOWN_EQ (uhwi
, pu64h::make (destv
,
3917 destv
- delta
* 2));
3919 /* Test partially in-range T::to_uhwi. */
3920 ASSERT_EQ (ph::make (srcv
,
3922 srcv
+ delta
* 2).to_uhwi (&uhwi
), N
== 1);
3924 ASSERT_KNOWN_EQ (uhwi
, destv
);
3925 ASSERT_EQ (ph::make (srcv
- delta
,
3927 srcv
+ delta
).to_uhwi (&uhwi
), N
<= 2);
3929 ASSERT_KNOWN_EQ (uhwi
, pu64h::make (destv
- delta
,
3931 destv
/* ignored */));
3933 /* Test fully out-of-range T::to_uhwi. */
3934 ASSERT_FALSE (ph::make (srcv
+ delta
, srcv
, srcv
).to_uhwi (&uhwi
));
3937 /* Test poly_int<N, C>::force_shwi and poly_int<N, C>::force_uhwi, given
3938 that MASK66 has the low 66 bits set and the rest clear. */
3940 template<unsigned int N
, typename C
>
3942 test_force_hwi (const C
&mask66
)
3944 typedef poly_helper
< poly_int
<N
, HOST_WIDE_INT
> > ps64h
;
3945 typedef poly_helper
< poly_int
<N
, unsigned HOST_WIDE_INT
> > pu64h
;
3946 typedef poly_int
<N
, C
> T
;
3947 typedef poly_helper
<T
> ph
;
3948 poly_int
<N
, HOST_WIDE_INT
> shwi
;
3949 poly_int
<N
, unsigned HOST_WIDE_INT
> uhwi
;
3951 C mask65
= wi::arshift (mask66
, 1);
3952 C mask64
= wi::arshift (mask66
, 2);
3953 C mask63
= wi::arshift (mask66
, 3);
3954 C mask62
= wi::arshift (mask66
, 4);
3955 C mask61
= wi::arshift (mask66
, 5);
3957 /* Test force_shwi. */
3958 ASSERT_KNOWN_EQ (ph::make (mask66
, mask65
, mask64
).force_shwi (),
3959 ps64h::make (HOST_WIDE_INT_M1
,
3962 ASSERT_KNOWN_EQ (ph::make (mask65
, mask64
, mask63
).force_shwi (),
3963 ps64h::make (HOST_WIDE_INT_M1
,
3965 HOST_WIDE_INT_MAX
));
3966 ASSERT_KNOWN_EQ (ph::make (mask64
, mask63
, mask62
).force_shwi (),
3967 ps64h::make (HOST_WIDE_INT_M1
,
3969 HOST_WIDE_INT_MAX
/ 2));
3970 ASSERT_KNOWN_EQ (ph::make (mask63
, mask62
, mask61
).force_shwi (),
3971 ps64h::make (HOST_WIDE_INT_MAX
,
3972 HOST_WIDE_INT_MAX
/ 2,
3973 HOST_WIDE_INT_MAX
/ 4));
3975 /* Test force_uhwi. */
3976 ASSERT_KNOWN_EQ (ph::make (mask66
, mask65
, mask64
).force_uhwi (),
3977 pu64h::make (HOST_WIDE_INT_M1U
,
3979 HOST_WIDE_INT_M1U
));
3980 ASSERT_KNOWN_EQ (ph::make (mask65
, mask64
, mask63
).force_uhwi (),
3981 pu64h::make (HOST_WIDE_INT_M1U
,
3983 HOST_WIDE_INT_M1U
>> 1));
3984 ASSERT_KNOWN_EQ (ph::make (mask64
, mask63
, mask62
).force_uhwi (),
3985 pu64h::make (HOST_WIDE_INT_M1U
,
3986 HOST_WIDE_INT_M1U
>> 1,
3987 HOST_WIDE_INT_M1U
>> 2));
3988 ASSERT_KNOWN_EQ (ph::make (mask63
, mask62
, mask61
).force_uhwi (),
3989 pu64h::make (HOST_WIDE_INT_M1U
>> 1,
3990 HOST_WIDE_INT_M1U
>> 2,
3991 HOST_WIDE_INT_M1U
>> 3));
3994 /* Test poly_int<N, wide_int>::from. */
3996 template<unsigned int N
>
3998 test_wide_int_from ()
4000 typedef poly_helper
< poly_int
<N
, unsigned char> > pu8h
;
4001 typedef poly_int
<N
, wide_int
> T
;
4002 typedef poly_helper
<T
> ph
;
4004 /* Test narrowing cases of T::from. */
4005 T p_8_3_1
= ph::make (wi::uhwi (8, 3),
4008 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 3, SIGNED
),
4010 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 3, UNSIGNED
),
4013 /* Test equal-sized cases of T::from. */
4014 T p_f8_23_81
= ph::make (wi::uhwi (0xf8, 8),
4016 wi::uhwi (0x81, 8));
4017 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 8, SIGNED
),
4019 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 8, UNSIGNED
),
4022 /* Test widening cases of T::from. */
4023 T p_fff8_0023_ff81
= ph::make (wi::uhwi (0xfff8, 16),
4024 wi::uhwi (0x0023, 16),
4025 wi::uhwi (0xff81, 16));
4026 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 16, SIGNED
),
4028 T p_00f8_0023_0081
= ph::make (wi::uhwi (0xf8, 16),
4029 wi::uhwi (0x23, 16),
4030 wi::uhwi (0x81, 16));
4031 ASSERT_KNOWN_EQ (T::from (pu8h::make (0xf8,0x23,0x81), 16, UNSIGNED
),
4035 /* Test wi::sext for poly_int<N, wide_int>. */
4037 template<unsigned int N
>
4039 test_wide_int_sext ()
4041 typedef poly_int
<N
, wide_int
> T
;
4042 typedef poly_helper
<T
> ph
;
4044 ASSERT_KNOWN_EQ (wi::sext (ph::make (wi::shwi (16, 12),
4046 wi::shwi (14, 12)), 5),
4047 ph::make (wi::shwi (-16, 12),
4049 wi::shwi (14, 12)));
4050 ASSERT_KNOWN_EQ (wi::sext (ph::make (wi::shwi (1024, 12),
4051 wi::shwi (1023, 12),
4052 wi::shwi (1200, 12)), 11),
4053 ph::make (wi::shwi (-1024, 12),
4054 wi::shwi (1023, 12),
4055 wi::shwi (-848, 12)));
4058 /* Test wi::zext for poly_int<N, wide_int>. */
4060 template<unsigned int N
>
4062 test_wide_int_zext ()
4064 typedef poly_int
<N
, wide_int
> T
;
4065 typedef poly_helper
<T
> ph
;
4067 ASSERT_KNOWN_EQ (wi::zext (ph::make (wi::uhwi (16, 12),
4069 wi::uhwi (14, 12)), 5),
4070 ph::make (wi::uhwi (16, 12),
4072 wi::uhwi (14, 12)));
4073 ASSERT_KNOWN_EQ (wi::zext (ph::make (wi::uhwi (1024, 12),
4074 wi::uhwi (1023, 12),
4075 wi::uhwi (3248, 12)), 11),
4076 ph::make (wi::uhwi (1024, 12),
4077 wi::uhwi (1023, 12),
4078 wi::uhwi (1200, 12)));
4081 /* Test wi::add for poly_int<N, wide_int>. */
4083 template<unsigned int N
>
4085 test_wide_int_add ()
4087 typedef poly_int
<N
, wide_int
> T
;
4088 typedef poly_helper
<T
> ph
;
4090 wi::overflow_type overflow
;
4091 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::uhwi (15, 4),
4094 ph::make (wi::uhwi (1, 4),
4097 UNSIGNED
, &overflow
),
4098 ph::make (wi::uhwi (0, 4),
4101 ASSERT_TRUE ((bool)overflow
);
4102 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::uhwi (30, 5),
4105 ph::make (wi::uhwi (1, 5),
4108 UNSIGNED
, &overflow
),
4109 ph::make (wi::uhwi (31, 5),
4112 ASSERT_EQ ((bool)overflow
, N
>= 2);
4113 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::uhwi (1, 6),
4116 ph::make (wi::uhwi (61, 6),
4119 UNSIGNED
, &overflow
),
4120 ph::make (wi::uhwi (62, 6),
4123 ASSERT_EQ ((bool)overflow
, N
== 3);
4125 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::shwi (7, 4),
4128 ph::make (wi::shwi (1, 4),
4132 ph::make (wi::shwi (-8, 4),
4135 ASSERT_TRUE ((bool)overflow
);
4136 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::shwi (-1, 5),
4139 ph::make (wi::shwi (15, 5),
4143 ph::make (wi::shwi (14, 5),
4146 ASSERT_EQ ((bool)overflow
, N
>= 2);
4147 ASSERT_KNOWN_EQ (wi::add (ph::make (wi::shwi (4, 6),
4150 ph::make (wi::shwi (-32, 6),
4154 ph::make (wi::shwi (-28, 6),
4157 ASSERT_EQ ((bool)overflow
, N
== 3);
4160 /* Test wi::sub for poly_int<N, wide_int>. */
4162 template<unsigned int N
>
4164 test_wide_int_sub ()
4166 typedef poly_int
<N
, wide_int
> T
;
4167 typedef poly_helper
<T
> ph
;
4169 wi::overflow_type overflow
;
4170 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::uhwi (0, 4),
4173 ph::make (wi::uhwi (1, 4),
4176 UNSIGNED
, &overflow
),
4177 ph::make (wi::uhwi (15, 4),
4180 ASSERT_TRUE ((bool)overflow
);
4181 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::uhwi (30, 5),
4184 ph::make (wi::uhwi (1, 5),
4187 UNSIGNED
, &overflow
),
4188 ph::make (wi::uhwi (29, 5),
4191 ASSERT_EQ ((bool)overflow
, N
>= 2);
4192 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::uhwi (0, 6),
4195 ph::make (wi::uhwi (0, 6),
4198 UNSIGNED
, &overflow
),
4199 ph::make (wi::uhwi (0, 6),
4202 ASSERT_EQ ((bool)overflow
, N
== 3);
4204 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::shwi (-8, 4),
4207 ph::make (wi::shwi (1, 4),
4211 ph::make (wi::shwi (7, 4),
4214 ASSERT_TRUE ((bool)overflow
);
4215 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::shwi (-1, 5),
4218 ph::make (wi::shwi (15, 5),
4222 ph::make (wi::shwi (-16, 5),
4225 ASSERT_EQ ((bool)overflow
, N
>= 2);
4226 ASSERT_KNOWN_EQ (wi::sub (ph::make (wi::shwi (-32, 6),
4229 ph::make (wi::shwi (-32, 6),
4233 ph::make (wi::shwi (0, 6),
4235 wi::shwi (-32, 6)));
4236 ASSERT_EQ ((bool)overflow
, N
== 3);
4239 /* Test wi::mul for poly_int<N, wide_int>. */
4241 template<unsigned int N
>
4243 test_wide_int_mul ()
4245 typedef poly_int
<N
, wide_int
> T
;
4246 typedef poly_helper
<T
> ph
;
4248 wi::overflow_type overflow
;
4249 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::uhwi (4, 4),
4251 wi::uhwi (2, 4)), 4,
4252 UNSIGNED
, &overflow
),
4253 ph::make (wi::uhwi (0, 4),
4256 ASSERT_TRUE ((bool)overflow
);
4257 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::uhwi (15, 5),
4259 wi::uhwi (7, 5)), 2,
4260 UNSIGNED
, &overflow
),
4261 ph::make (wi::uhwi (30, 5),
4264 ASSERT_EQ ((bool)overflow
, N
>= 2);
4265 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::uhwi (1, 6),
4267 wi::uhwi (2, 6)), 63,
4268 UNSIGNED
, &overflow
),
4269 ph::make (wi::uhwi (63, 6),
4272 ASSERT_EQ ((bool)overflow
, N
== 3);
4274 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::shwi (-1, 4),
4276 wi::shwi (0, 4)), -8,
4278 ph::make (wi::shwi (-8, 4),
4281 ASSERT_TRUE ((bool)overflow
);
4282 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::shwi (2, 5),
4284 wi::shwi (1, 5)), 6,
4286 ph::make (wi::shwi (12, 5),
4289 ASSERT_EQ ((bool)overflow
, N
>= 2);
4290 ASSERT_KNOWN_EQ (wi::mul (ph::make (wi::shwi (5, 6),
4292 wi::shwi (7, 6)), -5,
4294 ph::make (wi::shwi (-25, 6),
4297 ASSERT_EQ ((bool)overflow
, N
== 3);
4300 /* Test wi::neg for poly_int<N, wide_int>. */
4302 template<unsigned int N
>
4304 test_wide_int_neg ()
4306 typedef poly_int
<N
, wide_int
> T
;
4307 typedef poly_helper
<T
> ph
;
4309 wi::overflow_type overflow
;
4310 ASSERT_KNOWN_EQ (wi::neg (ph::make (wi::shwi (-8, 4),
4312 wi::shwi (-7, 4)), &overflow
),
4313 ph::make (wi::shwi (-8, 4),
4316 ASSERT_TRUE ((bool)overflow
);
4317 ASSERT_KNOWN_EQ (wi::neg (ph::make (wi::shwi (-15, 5),
4319 wi::shwi (15, 5)), &overflow
),
4320 ph::make (wi::shwi (15, 5),
4322 wi::shwi (-15, 5)));
4323 ASSERT_EQ ((bool)overflow
, N
>= 2);
4324 ASSERT_KNOWN_EQ (wi::neg (ph::make (wi::shwi (-28, 6),
4326 wi::shwi (-32, 6)), &overflow
),
4327 ph::make (wi::shwi (28, 6),
4329 wi::shwi (-32, 6)));
4330 ASSERT_EQ ((bool)overflow
, N
== 3);
4333 /* Test poly_int<N, C> for things that only make sense when C is an
4334 offset_int or widest_int. */
4336 template<unsigned int N
, typename C
>
4338 test_fixed_int (void)
4340 typedef poly_helper
< poly_int
<N
, int> > pih
;
4341 typedef poly_int
<N
, C
> T
;
4342 typedef poly_helper
<T
> ph
;
4344 /* Test signed case. */
4345 ASSERT_KNOWN_EQ (T::from (pih::make (-100, 200, -300), SIGNED
),
4346 ph::make (-100, 200, -300));
4347 ASSERT_MAYBE_NE (T::from (pih::make (-100, 200, -300), SIGNED
),
4348 ph::make (-100U, 200U, -300U));
4350 /* Test unsigned case. */
4351 ASSERT_MAYBE_NE (T::from (pih::make (-100, 200, -300), UNSIGNED
),
4352 ph::make (-100, 200, -300));
4353 ASSERT_KNOWN_EQ (T::from (pih::make (-100, 200, -300), UNSIGNED
),
4354 ph::make (-100U, 200U, -300U));
4357 test_to_shwi
<N
> (-(one
<< 63), -1, HOST_WIDE_INT_MIN
);
4358 test_to_shwi
<N
> ((one
<< 63) - 1, 1, HOST_WIDE_INT_MAX
);
4359 test_to_uhwi
<N
> (C (0), -1, 0U);
4360 test_to_uhwi
<N
> ((one
<< 64) - 1, 1, HOST_WIDE_INT_M1U
);
4362 /* Test force_shwi and force_uhwi. */
4363 test_force_hwi
<N
> ((one
<< 66) - 1);
4366 /* Test type promotions. */
4368 template<unsigned int N
>
4370 test_type_promotions ()
4372 typedef poly_helper
< poly_int
<N
, unsigned short> > pu16h
;
4373 typedef poly_helper
< poly_int
<N
, HOST_WIDE_INT
> > ps64h
;
4374 HOST_WIDE_INT mask32
= ~0U;
4376 /* Test that + on unsigned short promotes to HOST_WIDE_INT. */
4377 ASSERT_KNOWN_EQ (pu16h::make (0xffff, 0xfffe, 0xfffd) + 16,
4378 ps64h::make (0x1000f, 0xfffe, 0xfffd));
4379 ASSERT_KNOWN_EQ (32 + pu16h::make (0xffff, 0xfffe, 0xfffd),
4380 ps64h::make (0x1001f, 0xfffe, 0xfffd));
4381 ASSERT_KNOWN_EQ (pu16h::make (0xffff, 0xfffe, 0xfffd)
4382 + pu16h::make (4, 10, 17),
4383 ps64h::make (0x10003, 0x10008, 0x1000e));
4385 /* Test that - on unsigned short promotes to HOST_WIDE_INT. */
4386 ASSERT_KNOWN_EQ (pu16h::make (1, 2, 3) - ~0U,
4387 ps64h::make (-mask32
+ 1, 2, 3));
4388 ASSERT_KNOWN_EQ (INT_MIN
- pu16h::make (4, 5, 6),
4389 ps64h::make ((HOST_WIDE_INT
) INT_MIN
- 4, -5, -6));
4390 ASSERT_KNOWN_EQ (pu16h::make (1, 2, 3) - pu16h::make (100, 200, 300),
4391 ps64h::make (-99, -198, -297));
4393 /* Same for unary -. */
4394 ASSERT_KNOWN_EQ (-pu16h::make (0x8000, 0x9000, 0xa000),
4395 ps64h::make (-0x8000, -0x9000, -0xa000));
4396 ASSERT_MAYBE_NE (-pu16h::make (0x8000, 0x9000, 0xa000),
4397 ps64h::make (0x8000, 0x9000, 0xa000));
4399 /* Test that * on unsigned short promotes to HOST_WIDE_INT. */
4400 ASSERT_KNOWN_EQ (pu16h::make (10, 14, 17) * ~0U,
4401 ps64h::make (10 * mask32
, 14 * mask32
, 17 * mask32
));
4402 ASSERT_KNOWN_EQ (-400000 * pu16h::make (10, 14, 17),
4403 ps64h::make (-4000000, -5600000, -6800000));
4405 /* Test that << on unsigned short promotes to HOST_WIDE_INT. */
4406 ASSERT_KNOWN_EQ (pu16h::make (4, 5, 6) << 50,
4407 ps64h::make ((HOST_WIDE_INT
) 4 << 50,
4408 (HOST_WIDE_INT
) 5 << 50,
4409 (HOST_WIDE_INT
) 6 << 50));
4411 /* Test that can_align_up doesn't truncate to the type of the alignment. */
4412 poly_int
<N
, HOST_WIDE_INT
> aligned
;
4413 HOST_WIDE_INT a
= (HOST_WIDE_INT_1
<< 50);
4414 HOST_WIDE_INT b
= (HOST_WIDE_INT_1
<< 51);
4415 HOST_WIDE_INT c
= (HOST_WIDE_INT_1
<< 52);
4416 ASSERT_TRUE (can_align_up (ps64h::make (a
- 31, b
, c
), 16U, &aligned
));
4417 ASSERT_KNOWN_EQ (aligned
, ps64h::make (a
- 16, b
, c
));
4419 /* Likewise for can_align_down. */
4420 ASSERT_TRUE (can_align_down (ps64h::make (a
- 31, b
, c
), 16U, &aligned
));
4421 ASSERT_KNOWN_EQ (aligned
, ps64h::make (a
- 32, b
, c
));
4423 /* Same for the force_* routines. */
4424 ASSERT_KNOWN_EQ (force_align_up (ps64h::make (a
- 31, b
, c
), 16U),
4425 ps64h::make (a
- 16, b
, c
));
4426 ASSERT_KNOWN_EQ (force_align_down (ps64h::make (a
- 31, b
, c
), 16U),
4427 ps64h::make (a
- 32, b
, c
));
4429 /* Same for the aligned_*_bound routines. */
4430 ASSERT_KNOWN_EQ (aligned_upper_bound (ps64h::make (a
- 31, b
- 33, c
- 55),
4432 ps64h::make (a
- 16, b
- 32, c
- 48));
4433 ASSERT_KNOWN_EQ (aligned_lower_bound (ps64h::make (a
- 31, b
- 33, c
- 55),
4435 ps64h::make (a
- 32, b
- 48, c
- 64));
4438 /* Test endpoint_representable_p. */
4441 test_endpoint_representable (void)
4443 /* True because the size is unknown. */
4444 ASSERT_TRUE (endpoint_representable_p ((unsigned char) 0x80,
4445 (unsigned char) 0xff));
4446 ASSERT_FALSE (endpoint_representable_p ((unsigned char) 0x80,
4447 (unsigned char) 0xfe));
4448 ASSERT_FALSE (endpoint_representable_p ((unsigned char) 0x80,
4449 (unsigned char) 0x80));
4450 ASSERT_TRUE (endpoint_representable_p ((unsigned char) 0x80,
4451 (unsigned char) 0x7f));
4452 ASSERT_FALSE (endpoint_representable_p ((unsigned char) 0x11,
4453 (unsigned char) 0xef));
4454 ASSERT_TRUE (endpoint_representable_p ((unsigned char) 0x11,
4455 (unsigned char) 0xee));
4457 /* True because the size is unknown. */
4458 ASSERT_TRUE (endpoint_representable_p (INT_MAX
, -1));
4459 ASSERT_FALSE (endpoint_representable_p (INT_MAX
- 100, INT_MAX
));
4460 ASSERT_FALSE (endpoint_representable_p (INT_MAX
- 100, 101));
4461 ASSERT_TRUE (endpoint_representable_p (INT_MAX
- 100, 100));
4462 ASSERT_TRUE (endpoint_representable_p (0, INT_MAX
));
4463 ASSERT_TRUE (endpoint_representable_p (INT_MIN
, INT_MAX
));
4465 /* True because the size is unknown. */
4466 ASSERT_TRUE (endpoint_representable_p (UINT_MAX
, -1U));
4467 ASSERT_FALSE (endpoint_representable_p (UINT_MAX
- 400, UINT_MAX
- 1));
4468 ASSERT_FALSE (endpoint_representable_p (UINT_MAX
- 400, 401U));
4469 ASSERT_TRUE (endpoint_representable_p (UINT_MAX
- 400, 400U));
4472 /* Test wi::shwi with N coefficients. */
4474 template<unsigned int N
>
4478 typedef poly_int
<N
, wi::hwi_with_prec
> T
;
4479 typedef poly_helper
<T
> ph
;
4481 poly_int
<N
, wide_int
> mult
;
4482 mult
= ph::make (wi::shwi (80, 16),
4484 wi::shwi (70, 16)) * 3;
4485 ASSERT_KNOWN_EQ (mult
, ph::make (wi::shwi (240, 16),
4487 wi::shwi (210, 16)));
4490 /* Test wi::uhwi with N coefficients. */
4492 template<unsigned int N
>
4496 typedef poly_int
<N
, wi::hwi_with_prec
> T
;
4497 typedef poly_helper
<T
> ph
;
4499 poly_int
<N
, wide_int
> mult
;
4500 mult
= ph::make (wi::uhwi (80, 16),
4502 wi::uhwi (70, 16)) * 3;
4503 ASSERT_KNOWN_EQ (mult
, ph::make (wi::uhwi (240, 16),
4505 wi::uhwi (210, 16)));
4508 /* Test multiple_p for non-polynomial T. */
4510 template<typename T
>
4512 test_nonpoly_multiple_p ()
4514 ASSERT_TRUE (multiple_p (T (6), T (2)));
4515 ASSERT_TRUE (multiple_p (T (6), T (3)));
4516 ASSERT_FALSE (multiple_p (T (6), T (4)));
4517 ASSERT_FALSE (multiple_p (T (7), T (4)));
4518 ASSERT_TRUE (multiple_p (T (8), T (4)));
4521 /* Test known_size_p for non-polynomial T. */
4523 template<typename T
>
4525 test_nonpoly_known_size_p ()
4527 ASSERT_TRUE (known_size_p (T (0)));
4528 ASSERT_TRUE (known_size_p (T (1)));
4529 ASSERT_TRUE (known_size_p (T (2)));
4530 ASSERT_FALSE (known_size_p (T (-1)));
4533 /* Test poly-int.h operations on non-polynomial type T. */
4535 template<typename T
>
4537 test_nonpoly_type ()
4539 test_nonpoly_multiple_p
<T
> ();
4540 test_nonpoly_known_size_p
<T
> ();
4543 /* Test poly-int.h operations on non-polynomial values. */
4548 test_nonpoly_type
<unsigned char> ();
4549 test_nonpoly_type
<unsigned short> ();
4550 test_nonpoly_type
<int> ();
4551 test_nonpoly_type
<unsigned int> ();
4552 test_nonpoly_type
<HOST_WIDE_INT
> ();
4553 test_nonpoly_type
<unsigned HOST_WIDE_INT
> ();
4554 test_nonpoly_type
<offset_int
> ();
4555 test_nonpoly_type
<widest_int
> ();
4558 /* Test things that work for all poly_int-based types T, given that T
4559 has N coefficients of type C. RC is the type to which C promotes
4560 after an operator. */
4562 template<unsigned int N
, typename C
, typename RC
, typename T
>
4566 test_poly_int_traits
<N
, C
, T
> ();
4567 test_constants
<N
, C
, T
> ();
4568 test_plus_equals
<N
, C
, T
> ();
4569 test_minus_equals
<N
, C
, T
> ();
4570 test_times_equals
<N
, C
, T
> ();
4571 test_shl_equals
<N
, C
, T
> ();
4572 test_is_constant
<N
, C
, T
> ();
4573 test_to_constant
<N
, C
, T
> ();
4574 test_addition
<N
, C
, T
> ();
4575 test_subtraction
<N
, C
, RC
, T
> ();
4576 test_negation
<N
, C
, RC
, T
> ();
4577 test_multiplication
<N
, C
, T
> ();
4578 test_shift_left
<N
, C
, T
> ();
4579 test_maybe_ne
<N
, C
, T
> ();
4580 test_known_eq
<N
, C
, T
> ();
4581 test_can_align_p
<N
, C
, T
> ();
4582 test_can_align_up
<N
, C
, T
> ();
4583 test_can_align_down
<N
, C
, T
> ();
4584 test_known_equal_after_align_up
<N
, C
, T
> ();
4585 test_known_equal_after_align_down
<N
, C
, T
> ();
4586 test_force_align_up
<N
, C
, T
> ();
4587 test_force_align_down
<N
, C
, T
> ();
4588 test_aligned_lower_bound
<N
, C
, T
> ();
4589 test_aligned_upper_bound
<N
, C
, T
> ();
4590 test_known_misalignment
<N
, C
, T
> ();
4591 test_force_get_misalignment
<N
, C
, T
> ();
4592 test_known_alignment
<N
, C
, T
> ();
4593 test_can_ior_p
<N
, C
, T
> ();
4594 test_known_size_p
<N
, C
, T
> ();
4597 /* Test things that work for poly_int<2, C>, given that C is signed. */
4599 template<typename C
>
4603 test_maybe_eq_2
<C
> ();
4604 test_known_ne_2
<C
> ();
4607 /* Test things that work for poly_int-based types T, given that the
4608 coefficient type C supports all the normal C operators. N is the
4609 number of coefficients in C and RC is the type to which C promotes
4610 after an operator. */
4612 template<unsigned int N
, typename C
, typename RC
, typename T
>
4616 test_general
<N
, C
, RC
, T
> ();
4617 test_maybe_le
<N
, C
, T
> ();
4618 test_maybe_lt
<N
, C
, T
> ();
4619 test_maybe_ge
<N
, C
, T
> ();
4620 test_maybe_gt
<N
, C
, T
> ();
4621 test_known_gt
<N
, C
, T
> ();
4622 test_known_ge
<N
, C
, T
> ();
4623 test_known_lt
<N
, C
, T
> ();
4624 test_known_le
<N
, C
, T
> ();
4625 test_ordered_p
<N
, C
, T
> ();
4626 test_ordered_min
<N
, C
, T
> ();
4627 test_ordered_max
<N
, C
, T
> ();
4628 test_constant_lower_bound
<N
, C
, T
> ();
4629 test_lower_bound
<N
, C
, T
> ();
4630 test_upper_bound
<N
, C
, T
> ();
4631 test_compare_sizes_for_sort
<N
, C
, T
> ();
4632 test_force_align_up_and_div
<N
, C
, T
> ();
4633 test_force_align_down_and_div
<N
, C
, T
> ();
4634 test_constant_multiple_p
<N
, C
, T
> ();
4635 test_multiple_p
<N
, C
, T
> ();
4636 test_multiple_p_with_result
<N
, C
, T
> ();
4637 test_exact_div
<N
, C
, T
> ();
4638 test_can_div_trunc_p_const
<N
, C
, T
> ();
4639 test_can_div_trunc_p_poly
<N
, C
, T
> ();
4640 test_can_div_away_from_zero_p
<N
, C
, T
> ();
4641 test_maybe_in_range_p
<N
, C
, T
> ();
4642 test_known_in_range_p
<N
, C
, T
> ();
4643 test_ranges_maybe_overlap_p
<N
, C
, T
> ();
4644 test_ranges_known_overlap_p
<N
, C
, T
> ();
4645 test_known_subrange_p
<N
, C
, T
> ();
4646 test_coeffs_in_range_p
<N
, C
, T
> ();
4649 /* Test things that work for poly_int<2, C>, given that C is signed. */
4651 template<typename C
>
4655 test_ordered_2
<C
> ();
4656 test_signed_maybe_eq_2
<C
> ();
4657 test_signed_known_ne_2
<C
> ();
4660 /* Test things that work for poly_int-based types T, given that the
4661 coefficient type C is signed. N is the number of coefficients in C
4662 and RC is the type to which C promotes after an operator. */
4664 template<unsigned int N
, typename C
, typename RC
, typename T
>
4668 test_ordered
<N
, C
, RC
, T
> ();
4669 test_signed_negation
<N
, C
, RC
, T
> ();
4670 test_signed_maybe_le
<N
, C
, T
> ();
4671 test_signed_maybe_lt
<N
, C
, T
> ();
4672 test_signed_maybe_ge
<N
, C
, T
> ();
4673 test_signed_maybe_gt
<N
, C
, T
> ();
4674 test_signed_known_gt
<N
, C
, T
> ();
4675 test_signed_known_ge
<N
, C
, T
> ();
4676 test_signed_known_lt
<N
, C
, T
> ();
4677 test_signed_known_le
<N
, C
, T
> ();
4678 test_signed_ordered_p
<N
, C
, T
> ();
4679 test_signed_ordered_min
<N
, C
, T
> ();
4680 test_signed_ordered_max
<N
, C
, T
> ();
4681 test_signed_lower_bound
<N
, C
, T
> ();
4682 test_signed_upper_bound
<N
, C
, T
> ();
4683 test_signed_constant_multiple_p
<N
, C
, T
> ();
4684 test_signed_multiple_p
<N
, C
, T
> ();
4685 test_signed_multiple_p_with_result
<N
,C
, T
> ();
4686 test_signed_exact_div
<N
, C
, T
> ();
4687 test_signed_can_div_trunc_p_const
<N
, C
, T
> ();
4688 test_signed_can_div_trunc_p_poly
<N
, C
, T
> ();
4689 test_signed_can_div_away_from_zero_p
<N
, C
, T
> ();
4690 test_signed_maybe_in_range_p
<N
, C
, T
> ();
4693 /* Test things that work for poly_int-based types T, given that the
4694 coefficient type C is unsigned. N is the number of coefficients in C
4695 and RC is the type to which C promotes after an operator. */
4697 template<unsigned int N
, typename C
, typename RC
, typename T
>
4701 test_ordered
<N
, C
, RC
, T
> ();
4702 test_unsigned_maybe_le
<N
, C
, T
> ();
4703 test_unsigned_maybe_lt
<N
, C
, T
> ();
4704 test_unsigned_maybe_ge
<N
, C
, T
> ();
4705 test_unsigned_maybe_gt
<N
, C
, T
> ();
4706 test_unsigned_known_gt
<N
, C
, T
> ();
4707 test_unsigned_known_ge
<N
, C
, T
> ();
4708 test_unsigned_known_lt
<N
, C
, T
> ();
4709 test_unsigned_known_le
<N
, C
, T
> ();
4710 test_unsigned_ordered_p
<N
, C
, T
> ();
4711 test_unsigned_ordered_min
<N
, C
, T
> ();
4712 test_unsigned_ordered_max
<N
, C
, T
> ();
4713 test_unsigned_lower_bound
<N
, C
, T
> ();
4714 test_unsigned_upper_bound
<N
, C
, T
> ();
4715 test_unsigned_maybe_in_range_p
<N
, C
, T
> ();
4716 test_unsigned_known_in_range_p
<N
, C
, T
> ();
4719 /* Test things that are specific to coefficients of type wide_int,
4720 using a poly_int with N coefficients. */
4722 template<unsigned int N
>
4726 test_wide_int_from
<N
> ();
4728 test_to_shwi
<N
> (wi::mask (63, true, 77), -1, HOST_WIDE_INT_MIN
);
4729 test_to_shwi
<N
> (wi::mask (63, false, 77), 1, HOST_WIDE_INT_MAX
);
4730 test_to_uhwi
<N
> (wide_int (wi::zero (94)), -1, 0U);
4731 test_to_uhwi
<N
> (wi::mask (64, false, 94), 1, HOST_WIDE_INT_M1U
);
4733 test_force_hwi
<N
> (wi::mask (66, false, 81));
4735 test_wide_int_sext
<N
> ();
4736 test_wide_int_zext
<N
> ();
4737 test_wide_int_add
<N
> ();
4738 test_wide_int_sub
<N
> ();
4739 test_wide_int_mul
<N
> ();
4740 test_wide_int_neg
<N
> ();
4743 /* Run the tests that are common to all coefficient counts N. */
4745 template<unsigned int N
>
4747 test_num_coeffs_core ()
4749 test_unsigned
<N
, unsigned short, HOST_WIDE_INT
,
4750 poly_int
<N
, unsigned short> > ();
4751 test_signed
<N
, HOST_WIDE_INT
, HOST_WIDE_INT
,
4752 poly_int
<N
, HOST_WIDE_INT
> > ();
4753 test_unsigned
<N
, unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
4754 poly_int
<N
, unsigned HOST_WIDE_INT
> >();
4756 test_general
<N
, wide_int
, wide_int
, poly_int
<N
, wide_int
> > ();
4758 test_hwi
<N
, unsigned short, poly_int
<N
, unsigned short> > ();
4759 test_hwi
<N
, HOST_WIDE_INT
, poly_int
<N
, HOST_WIDE_INT
> > ();
4760 test_hwi
<N
, unsigned HOST_WIDE_INT
, poly_int
<N
, unsigned HOST_WIDE_INT
> > ();
4762 test_wide_int
<N
> ();
4763 test_fixed_int
<N
, offset_int
> ();
4764 test_fixed_int
<N
, widest_int
> ();
4766 test_type_promotions
<N
> ();
4771 /* Run extra tests for the most important coefficient counts N. */
4773 template<unsigned int N
>
4775 test_num_coeffs_extra ()
4777 /* Test the most common POD types. */
4778 test_unsigned
<N
, unsigned short, HOST_WIDE_INT
,
4779 poly_int_pod
<N
, unsigned short> > ();
4780 test_signed
<N
, HOST_WIDE_INT
, HOST_WIDE_INT
,
4781 poly_int_pod
<N
, HOST_WIDE_INT
> > ();
4782 test_unsigned
<N
, unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
4783 poly_int_pod
<N
, unsigned HOST_WIDE_INT
> > ();
4785 /* Test some coefficient types that weren't covered in the core tests. */
4786 test_signed
<N
, int, HOST_WIDE_INT
,
4787 poly_int
<N
, int> > ();
4788 test_signed
<N
, offset_int
, offset_int
,
4789 poly_int
<N
, offset_int
> > ();
4790 test_signed
<N
, widest_int
, widest_int
,
4791 poly_int
<N
, widest_int
> > ();