blob: 0b89acd91cd93bb2d7ea7ce28e99f9938b8058d3 [file] [log] [blame]
/* This file contains templated tests that are then instantiated in
multiple plugin tests, in order to reduce the size of each test. */
#define ASSERT_FALSE(X) gcc_assert (!(X))
#define ASSERT_TRUE(X) gcc_assert (X)
#define ASSERT_EQ(X, Y) gcc_assert ((X) == (Y))
#define ASSERT_KNOWN_EQ(X, Y) gcc_assert (known_eq (X, Y))
#define ASSERT_MAYBE_NE(X, Y) gcc_assert (maybe_ne (X, Y))
/* make (X) converts an X of type int into T, using an arbitrary
precision for wide_int. It passes other types of X through as-is. */
template<typename T>
struct coeff_helper
{
static inline const T &make (const T &x) { return x; }
};
template<>
struct coeff_helper<wide_int>
{
template<typename T>
static inline const T &make (const T &x) { return x; }
static inline wide_int make (int i) { return wi::shwi (i, 77); }
};
/* make (C1, C2, C3) constructs a T using coefficients from C1, C2 and C3,
picking only enough to fill the T. */
template<typename T>
struct poly_helper
{
typedef typename poly_int_traits<T>::coeff_type C;
template<typename T1, typename T2, typename T3>
static T make (const T1 &a, const T2 &b, const T3 &c);
};
template<typename T>
template<typename T1, typename T2, typename T3>
inline T
poly_helper<T>::make (const T1 &a, const T2 &b, const T3 &c)
{
T res;
res = coeff_helper<C>::make (a);
if (poly_int_traits<T>::num_coeffs >= 2)
res.coeffs[1] = coeff_helper<C>::make (b);
if (poly_int_traits<T>::num_coeffs >= 3)
res.coeffs[2] = coeff_helper<C>::make (c);
return res;
}
/* Test the helper, */
static void
test_helper ()
{
typedef poly_helper< poly_int<1, int> > p1;
typedef poly_helper< poly_int<2, int> > p2;
typedef poly_helper< poly_int<3, int> > p3;
ASSERT_MAYBE_NE (p1::make (1, 2, 3), 0);
ASSERT_KNOWN_EQ (p1::make (1, 2, 3) - p1::make (1, 0, 0), 0);
ASSERT_KNOWN_EQ (p1::make (1, 2, 3) - p1::make (1, 2, 0), 0);
ASSERT_KNOWN_EQ (p1::make (1, 2, 3) - p1::make (1, 2, 3), 0);
ASSERT_MAYBE_NE (p2::make (1, 2, 3), 0);
ASSERT_MAYBE_NE (p2::make (1, 2, 3) - p2::make (1, 0, 0), 0);
ASSERT_KNOWN_EQ (p2::make (1, 2, 3) - p2::make (1, 2, 0), 0);
ASSERT_KNOWN_EQ (p2::make (1, 2, 3) - p2::make (1, 2, 3), 0);
ASSERT_MAYBE_NE (p3::make (1, 2, 3), 0);
ASSERT_MAYBE_NE (p3::make (1, 2, 3) - p3::make (1, 0, 0), 0);
ASSERT_MAYBE_NE (p3::make (1, 2, 3) - p3::make (1, 2, 0), 0);
ASSERT_KNOWN_EQ (p3::make (1, 2, 3) - p3::make (1, 2, 3), 0);
}
/* Test poly_coeff_traits. */
static void
test_poly_coeff_traits ()
{
ASSERT_EQ (poly_coeff_traits<unsigned short>::signedness, 0);
ASSERT_EQ (poly_coeff_traits<unsigned short>::max_value, 0xffff);
ASSERT_EQ (poly_coeff_traits<int>::signedness, 1);
ASSERT_EQ (poly_coeff_traits<int>::max_value, INT_MAX);
ASSERT_EQ (poly_coeff_traits<unsigned int>::signedness, 0);
ASSERT_EQ (poly_coeff_traits<unsigned int>::max_value, UINT_MAX);
ASSERT_EQ (poly_coeff_traits<HOST_WIDE_INT>::signedness, 1);
ASSERT_EQ (poly_coeff_traits<HOST_WIDE_INT>::max_value, HOST_WIDE_INT_MAX);
ASSERT_EQ (poly_coeff_traits<unsigned HOST_WIDE_INT>::signedness, 0);
ASSERT_EQ (poly_coeff_traits<unsigned HOST_WIDE_INT>::max_value,
HOST_WIDE_INT_M1U);
ASSERT_EQ (poly_coeff_traits<wide_int>::signedness, -1);
ASSERT_EQ (poly_coeff_traits<offset_int>::signedness, 1);
ASSERT_EQ (poly_coeff_traits<widest_int>::signedness, 1);
}
/* Test poly_int_traits. */
template<unsigned int N, typename C, typename T>
static void
test_poly_int_traits ()
{
/* Check the properties of poly_int_traits<C>. */
ASSERT_FALSE (poly_int_traits<C>::is_poly);
ASSERT_EQ (poly_int_traits<C>::num_coeffs, 1);
ASSERT_EQ ((C *) 0 - (typename poly_int_traits<C>::coeff_type *) 0, 0);
/* Check the properties of poly_int_traits<T>. */
ASSERT_TRUE (poly_int_traits<T>::is_poly);
ASSERT_EQ (poly_int_traits<T>::num_coeffs, N);
ASSERT_EQ ((C *) 0 - (typename poly_int_traits<T>::coeff_type *) 0, 0);
}
/* Test the handling of constants. */
template<unsigned int N, typename C, typename T>
static void
test_constants ()
{
typedef coeff_helper<C> ch;
T zero, one, two;
poly_int<N, unsigned char> two_uc = 2;
/* Test operator = on C. */
zero = ch::make (0);
one = ch::make (1);
two = ch::make (2);
/* Basic tests of known_eq and maybe_ne. */
ASSERT_KNOWN_EQ (zero, ch::make (0));
ASSERT_MAYBE_NE (one, ch::make (0));
ASSERT_MAYBE_NE (two, ch::make (0));
ASSERT_KNOWN_EQ (ch::make (0), zero);
ASSERT_MAYBE_NE (ch::make (0), one);
ASSERT_MAYBE_NE (ch::make (0), two);
ASSERT_KNOWN_EQ (zero, zero);
ASSERT_MAYBE_NE (one, zero);
ASSERT_MAYBE_NE (two, zero);
ASSERT_MAYBE_NE (zero, ch::make (1));
ASSERT_KNOWN_EQ (one, ch::make (1));
ASSERT_MAYBE_NE (two, ch::make (1));
ASSERT_MAYBE_NE (ch::make (1), zero);
ASSERT_KNOWN_EQ (ch::make (1), one);
ASSERT_MAYBE_NE (ch::make (1), two);
ASSERT_MAYBE_NE (zero, one);
ASSERT_KNOWN_EQ (one, one);
ASSERT_MAYBE_NE (two, one);
ASSERT_MAYBE_NE (zero, ch::make (2));
ASSERT_MAYBE_NE (one, ch::make (2));
ASSERT_KNOWN_EQ (two, ch::make (2));
ASSERT_MAYBE_NE (ch::make (2), zero);
ASSERT_MAYBE_NE (ch::make (2), one);
ASSERT_KNOWN_EQ (ch::make (2), two);
ASSERT_MAYBE_NE (zero, two);
ASSERT_MAYBE_NE (one, two);
ASSERT_KNOWN_EQ (two, two);
ASSERT_MAYBE_NE (zero, two_uc);
ASSERT_MAYBE_NE (one, two_uc);
ASSERT_KNOWN_EQ (two, two_uc);
ASSERT_MAYBE_NE (two_uc, zero);
ASSERT_MAYBE_NE (two_uc, one);
ASSERT_KNOWN_EQ (two_uc, two);
}
/* Test operator +=. */
template<unsigned int N, typename C, typename T>
static void
test_plus_equals ()
{
typedef poly_helper<T> ph;
/* Test += on int. */
T add_cm = ph::make (17, 11, 9);
add_cm += 14;
ASSERT_KNOWN_EQ (add_cm, ph::make (31, 11, 9));
/* Test += on T. */
T add_pm = ph::make (100, 44, 11);
add_pm += ph::make (1, 2, 3);
ASSERT_KNOWN_EQ (add_pm, ph::make (101, 46, 14));
}
/* Test operator -=. */
template<unsigned int N, typename C, typename T>
static void
test_minus_equals ()
{
typedef poly_helper<T> ph;
/* Test -= on int. */
T sub_cm = ph::make (82, 13, 61);
sub_cm -= 76;
ASSERT_KNOWN_EQ (sub_cm, ph::make (6, 13, 61));
/* Test -= on T. */
T sub_pm = ph::make (82, 13, 61);
sub_pm -= ph::make (19, 12, 14);
ASSERT_KNOWN_EQ (sub_pm, ph::make (63, 1, 47));
}
/* Test operator *=. */
template<unsigned int N, typename C, typename T>
static void
test_times_equals ()
{
typedef poly_helper<T> ph;
/* Test *= on int. */
T mul_cm = ph::make (11, 22, 33);
mul_cm *= 3;
ASSERT_KNOWN_EQ (mul_cm, ph::make (33, 66, 99));
}
/* Test operator <<=. */
template<unsigned int N, typename C, typename T>
static void
test_shl_equals ()
{
typedef poly_helper<T> ph;
/* Test <<= on int. */
T shl_cm = ph::make (10, 11, 13);
shl_cm <<= 2;
ASSERT_KNOWN_EQ (shl_cm, ph::make (40, 44, 52));
}
/* Test is_constant. */
template<unsigned int N, typename C, typename T>
static void
test_is_constant ()
{
typedef poly_helper<T> ph;
/* Test is_constant without arguments. */
ASSERT_TRUE (ph::make (1, 0, 0).is_constant ());
ASSERT_EQ (ph::make (2, 0, 1).is_constant (), N <= 2);
ASSERT_EQ (ph::make (3, 1, 0).is_constant (), N == 1);
/* Test is_constant with an argument. */
C const_value;
ASSERT_TRUE (ph::make (1, 0, 0).is_constant (&const_value));
ASSERT_EQ (const_value, 1);
ASSERT_EQ (ph::make (2, 0, 1).is_constant (&const_value), N <= 2);
ASSERT_EQ (const_value, N <= 2 ? 2 : 1);
ASSERT_EQ (ph::make (3, 1, 0).is_constant (&const_value), N == 1);
ASSERT_EQ (const_value, 4 - N);
}
/* Test to_constant. */
template<unsigned int N, typename C, typename T>
static void
test_to_constant ()
{
typedef poly_helper<T> ph;
ASSERT_TRUE (ph::make (1, 0, 0).to_constant () == 1);
ASSERT_TRUE (ph::make (111, 0, 0).to_constant () == 111);
}
/* Test addition, both via operators and wi::. */
template<unsigned int N, typename C, typename T>
static void
test_addition ()
{
typedef poly_helper<T> ph;
/* Test +. */
ASSERT_KNOWN_EQ (ph::make (55, 43, 30) + 1,
ph::make (56, 43, 30));
ASSERT_KNOWN_EQ (100 + ph::make (5, 15, 26),
ph::make (105, 15, 26));
ASSERT_KNOWN_EQ (ph::make (7, 100, 41) + ph::make (96, 9, 21),
ph::make (103, 109, 62));
/* Test wi::add. */
ASSERT_KNOWN_EQ (wi::add (ph::make (55, 43, 30), 1),
ph::make (56, 43, 30));
ASSERT_KNOWN_EQ (wi::add (100, ph::make (5, 15, 26)),
ph::make (105, 15, 26));
ASSERT_KNOWN_EQ (wi::add (ph::make (7, 100, 41), ph::make (96, 9, 21)),
ph::make (103, 109, 62));
}
/* Test subtraction, both via operators and wi::. */
template<unsigned int N, typename C, typename RC, typename T>
static void
test_subtraction ()
{
typedef poly_helper<T> ph;
typedef poly_helper< poly_int<N, RC> > rph;
typedef poly_helper< poly_int<N, int> > iph;
/* Test -. Cs with a rank lower than HOST_WIDE_INT promote to
HOST_WIDE_INT; use rph to capture this. */
ASSERT_KNOWN_EQ (ph::make (64, 49, 36) - 42,
rph::make (22, 49, 36));
ASSERT_KNOWN_EQ (11 - ph::make (9, 3, 4),
rph::make (2, -3, -4));
ASSERT_KNOWN_EQ (ph::make (100, 200, 300) - ph::make (99, 197, 305),
rph::make (1, 3, -5));
/* Test wi::sub. Primitive Cs promote to widest_int; use iph to capture
this. */
ASSERT_KNOWN_EQ (wi::sub (ph::make (64, 49, 36), 42),
iph::make (22, 49, 36));
ASSERT_KNOWN_EQ (wi::sub (11, ph::make (9, 3, 4)),
iph::make (2, -3, -4));
ASSERT_KNOWN_EQ (wi::sub (ph::make (100, 200, 300), ph::make (99, 197, 305)),
iph::make (1, 3, -5));
}
/* Test negation, both via operators and wi::. */
template<unsigned int N, typename C, typename RC, typename T>
static void
test_negation ()
{
typedef poly_helper<T> ph;
typedef poly_helper< poly_int<N, RC> > rph;
typedef poly_helper< poly_int<N, int> > iph;
/* Test unary -. */
ASSERT_KNOWN_EQ (-ph::make (10, 20, 30),
rph::make (-10, -20, -30));
/* Test wi::neg. */
ASSERT_KNOWN_EQ (wi::neg (ph::make (10, 20, 30)),
iph::make (-10, -20, -30));
}
/* Test multiplication, both via operators and wi::. */
template<unsigned int N, typename C, typename T>
static void
test_multiplication ()
{
typedef poly_helper<T> ph;
/* Test *. */
ASSERT_KNOWN_EQ (ph::make (5, 20, 25) * 10,
ph::make (50, 200, 250));
ASSERT_KNOWN_EQ (111 * ph::make (7, 6, 5),
ph::make (777, 666, 555));
/* Test wi::mul. */
ASSERT_KNOWN_EQ (wi::mul (ph::make (5, 20, 25), 10),
ph::make (50, 200, 250));
ASSERT_KNOWN_EQ (wi::mul (111, ph::make (7, 6, 5)),
ph::make (777, 666, 555));
}
/* Test shift left, both via operators and wi::. */
template<unsigned int N, typename C, typename T>
static void
test_shift_left ()
{
typedef poly_helper<T> ph;
/* Test <<. */
ASSERT_KNOWN_EQ (ph::make (1, 20, 300) << 4,
ph::make (16, 320, 4800));
/* Test wi::lshift. */
ASSERT_KNOWN_EQ (wi::lshift (ph::make (9, 15, 50), 3),
ph::make (72, 120, 400));
}
/* Test maybe_ne. */
template<unsigned int N, typename C, typename T>
static void
test_maybe_ne ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test maybe_ne (T, C). */
ASSERT_EQ (maybe_ne (ph::make (1, 0, 2), ch::make (1)), N == 3);
ASSERT_EQ (maybe_ne (ph::make (-11, -2, 0), ch::make (-11)), N >= 2);
ASSERT_TRUE (maybe_ne (ph::make (199, 0, 0), ch::make (200)));
/* Test maybe_ne (C, T). */
ASSERT_EQ (maybe_ne (ch::make (-22), ph::make (-22, 0, -1)), N == 3);
ASSERT_EQ (maybe_ne (ch::make (5), ph::make (5, 4, 0)), N >= 2);
ASSERT_TRUE (maybe_ne (ch::make (-3), ph::make (-4, 0, 0)));
/* Test maybe_ne (T, T). */
ASSERT_EQ (maybe_ne (ph::make (1, 3, 5),
ph::make (1, 3, 6)), N == 3);
ASSERT_EQ (maybe_ne (ph::make (1, 3, 5),
ph::make (1, 4, 5)), N >= 2);
ASSERT_TRUE (maybe_ne (ph::make (1, 3, 5),
ph::make (0, 3, 5)));
}
/* Test known_eq. */
template<unsigned int N, typename C, typename T>
static void
test_known_eq ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test known_eq (T, C). */
ASSERT_EQ (known_eq (ph::make (1, 0, 2), ch::make (1)), N <= 2);
ASSERT_EQ (known_eq (ph::make (-11, -2, 0), ch::make (-11)), N == 1);
ASSERT_FALSE (known_eq (ph::make (199, 0, 0), ch::make (200)));
/* Test known_eq (C, T). */
ASSERT_EQ (known_eq (ch::make (-22), ph::make (-22, 0, -1)), N <= 2);
ASSERT_EQ (known_eq (ch::make (5), ph::make (5, 4, 0)), N == 1);
ASSERT_FALSE (known_eq (ch::make (-3), ph::make (-4, 0, 0)));
/* Test known_eq (T, T). */
ASSERT_EQ (known_eq (ph::make (1, 3, 5),
ph::make (1, 3, 6)), N <= 2);
ASSERT_EQ (known_eq (ph::make (1, 3, 5),
ph::make (1, 4, 5)), N == 1);
ASSERT_FALSE (known_eq (ph::make (1, 3, 5),
ph::make (0, 3, 5)));
}
/* Test can_align_p. */
template<unsigned int N, typename C, typename T>
static void
test_can_align_p ()
{
typedef poly_helper<T> ph;
ASSERT_TRUE (can_align_p (ph::make (41, 32, 16), 16));
ASSERT_EQ (can_align_p (ph::make (15, 64, 8), 16), N <= 2);
ASSERT_EQ (can_align_p (ph::make (17, 8, 80), 16), N == 1);
ASSERT_TRUE (can_align_p (ph::make (-39, -64, -32), 32));
ASSERT_EQ (can_align_p (ph::make (-32, -96, -31), 32), N <= 2);
ASSERT_EQ (can_align_p (ph::make (-31, -31, -128), 32), N == 1);
ASSERT_TRUE (can_align_p (ph::make (17, 0, 0), 16));
ASSERT_TRUE (can_align_p (ph::make (16, 0, 0), 16));
ASSERT_TRUE (can_align_p (ph::make (15, 0, 0), 16));
ASSERT_TRUE (can_align_p (ph::make (-17, 0, 0), 16));
ASSERT_TRUE (can_align_p (ph::make (-16, 0, 0), 16));
ASSERT_TRUE (can_align_p (ph::make (-15, 0, 0), 16));
}
/* Test can_align_up. */
template<unsigned int N, typename C, typename T>
static void
test_can_align_up ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
T aligned;
ASSERT_TRUE (can_align_up (ph::make (41, 32, 16), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ph::make (48, 32, 16));
ASSERT_EQ (can_align_up (ph::make (15, 64, 8), 16, &aligned), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (aligned, ph::make (16, 64, 0));
ASSERT_EQ (can_align_up (ph::make (17, 8, 80), 16, &aligned), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (aligned, ch::make (32));
ASSERT_TRUE (can_align_up (ph::make (-39, -64, -32), 32, &aligned));
ASSERT_KNOWN_EQ (aligned, ph::make (-32, -64, -32));
ASSERT_EQ (can_align_up (ph::make (-32, -96, -31), 32, &aligned), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (aligned, ph::make (-32, -96, 0));
ASSERT_EQ (can_align_up (ph::make (-31, -31, -128), 32, &aligned), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (aligned, ch::make (0));
ASSERT_TRUE (can_align_up (ph::make (17, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (32));
ASSERT_TRUE (can_align_up (ph::make (16, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (16));
ASSERT_TRUE (can_align_up (ph::make (15, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (16));
ASSERT_TRUE (can_align_up (ph::make (-17, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (-16));
ASSERT_TRUE (can_align_up (ph::make (-16, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (-16));
ASSERT_TRUE (can_align_up (ph::make (-15, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (0));
}
/* Test can_align_down. */
template<unsigned int N, typename C, typename T>
static void
test_can_align_down ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
T aligned;
ASSERT_TRUE (can_align_down (ph::make (41, 32, 16), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ph::make (32, 32, 16));
ASSERT_EQ (can_align_down (ph::make (15, 64, 8), 16, &aligned), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (aligned, ph::make (0, 64, 0));
ASSERT_EQ (can_align_down (ph::make (17, 8, 80), 16, &aligned), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (aligned, ch::make (16));
ASSERT_TRUE (can_align_down (ph::make (-39, -64, -32), 32, &aligned));
ASSERT_KNOWN_EQ (aligned, ph::make (-64, -64, -32));
ASSERT_EQ (can_align_down (ph::make (-32, -96, -31), 32, &aligned), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (aligned, ph::make (-32, -96, 0));
ASSERT_EQ (can_align_down (ph::make (-31, -31, -128), 32, &aligned), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (aligned, ch::make (-32));
ASSERT_TRUE (can_align_down (ph::make (17, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (16));
ASSERT_TRUE (can_align_down (ph::make (16, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (16));
ASSERT_TRUE (can_align_down (ph::make (15, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (0));
ASSERT_TRUE (can_align_down (ph::make (-17, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (-32));
ASSERT_TRUE (can_align_down (ph::make (-16, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (-16));
ASSERT_TRUE (can_align_down (ph::make (-15, 0, 0), 16, &aligned));
ASSERT_KNOWN_EQ (aligned, ch::make (-16));
}
/* Test known_equal_after_align_up. */
template<unsigned int N, typename C, typename T>
static void
test_known_equal_after_align_up ()
{
typedef poly_helper<T> ph;
ASSERT_EQ (known_equal_after_align_up (ph::make (15, 15, 32),
ph::make (16, 15, 32), 16), N == 1);
ASSERT_EQ (known_equal_after_align_up (ph::make (16, 16, 15),
ph::make (15, 16, 15), 16), N <= 2);
ASSERT_EQ (known_equal_after_align_up (ph::make (15, 16, 32),
ph::make (7, 16, 48), 16), N <= 2);
ASSERT_EQ (known_equal_after_align_up (ph::make (7, 32, 16),
ph::make (15, 48, 16), 16), N == 1);
ASSERT_TRUE (known_equal_after_align_up (ph::make (16, 16, 32),
ph::make (15, 16, 32), 16));
ASSERT_TRUE (known_equal_after_align_up (ph::make (32, 0, 0),
ph::make (31, 0, 0), 16));
ASSERT_TRUE (known_equal_after_align_up (ph::make (32, 0, 0),
ph::make (32, 0, 0), 32));
ASSERT_FALSE (known_equal_after_align_up (ph::make (32, 0, 0),
ph::make (33, 0, 0), 16));
ASSERT_FALSE (known_equal_after_align_up (ph::make (-31, 0, 0),
ph::make (-32, 0, 0), 16));
ASSERT_TRUE (known_equal_after_align_up (ph::make (-32, 0, 0),
ph::make (-32, 0, 0), 32));
ASSERT_TRUE (known_equal_after_align_up (ph::make (-33, 0, 0),
ph::make (-32, 0, 0), 16));
}
/* Test known_equal_after_align_down. */
template<unsigned int N, typename C, typename T>
static void
test_known_equal_after_align_down ()
{
typedef poly_helper<T> ph;
ASSERT_EQ (known_equal_after_align_down (ph::make (17, 15, 32),
ph::make (16, 15, 32), 16), N == 1);
ASSERT_EQ (known_equal_after_align_down (ph::make (16, 16, 15),
ph::make (17, 16, 15), 16), N <= 2);
ASSERT_EQ (known_equal_after_align_down (ph::make (15, 16, 32),
ph::make (7, 16, 48), 16), N <= 2);
ASSERT_EQ (known_equal_after_align_down (ph::make (15, 32, 16),
ph::make (7, 48, 16), 16), N == 1);
ASSERT_TRUE (known_equal_after_align_down (ph::make (16, 16, 32),
ph::make (17, 16, 32), 16));
ASSERT_FALSE (known_equal_after_align_down (ph::make (32, 0, 0),
ph::make (31, 0, 0), 16));
ASSERT_TRUE (known_equal_after_align_down (ph::make (32, 0, 0),
ph::make (32, 0, 0), 32));
ASSERT_TRUE (known_equal_after_align_down (ph::make (32, 0, 0),
ph::make (33, 0, 0), 16));
ASSERT_TRUE (known_equal_after_align_down (ph::make (-31, 0, 0),
ph::make (-32, 0, 0), 16));
ASSERT_TRUE (known_equal_after_align_down (ph::make (-32, 0, 0),
ph::make (-32, 0, 0), 32));
ASSERT_FALSE (known_equal_after_align_down (ph::make (-33, 0, 0),
ph::make (-32, 0, 0), 16));
}
/* Test force_align_up. */
template<unsigned int N, typename C, typename T>
static void
test_force_align_up ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test force_align_up. */
ASSERT_KNOWN_EQ (force_align_up (ph::make (41, 32, 16), 16),
ph::make (48, 32, 16));
ASSERT_KNOWN_EQ (force_align_up (ph::make (-39, -64, -32), 32),
ph::make (-32, -64, -32));
ASSERT_KNOWN_EQ (force_align_up (ph::make (17, 0, 0), 16),
ch::make (32));
ASSERT_KNOWN_EQ (force_align_up (ph::make (16, 0, 0), 16),
ch::make (16));
ASSERT_KNOWN_EQ (force_align_up (ph::make (15, 0, 0), 16),
ch::make (16));
ASSERT_KNOWN_EQ (force_align_up (ph::make (-17, 0, 0), 16),
ch::make (-16));
ASSERT_KNOWN_EQ (force_align_up (ph::make (-16, 0, 0), 16),
ch::make (-16));
ASSERT_KNOWN_EQ (force_align_up (ph::make (-15, 0, 0), 16),
ch::make (0));
}
/* Test force_align_down. */
template<unsigned int N, typename C, typename T>
static void
test_force_align_down ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
ASSERT_KNOWN_EQ (force_align_down (ph::make (41, 32, 16), 16),
ph::make (32, 32, 16));
ASSERT_KNOWN_EQ (force_align_down (ph::make (-39, -64, -32), 32),
ph::make (-64, -64, -32));
ASSERT_KNOWN_EQ (force_align_down (ph::make (17, 0, 0), 16),
ch::make (16));
ASSERT_KNOWN_EQ (force_align_down (ph::make (16, 0, 0), 16),
ch::make (16));
ASSERT_KNOWN_EQ (force_align_down (ph::make (15, 0, 0), 16),
ch::make (0));
ASSERT_KNOWN_EQ (force_align_down (ph::make (-17, 0, 0), 16),
ch::make (-32));
ASSERT_KNOWN_EQ (force_align_down (ph::make (-16, 0, 0), 16),
ch::make (-16));
ASSERT_KNOWN_EQ (force_align_down (ph::make (-15, 0, 0), 16),
ch::make (-16));
}
/* Test aligned_lower_bound. */
template<unsigned int N, typename C, typename T>
static void
test_aligned_lower_bound ()
{
typedef poly_helper<T> ph;
ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (17, 63, 33), 16),
ph::make (16, 48, 32));
ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (11, -33, 64), 32),
ph::make (0, -64, 64));
ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (-9, 16, -31), 8),
ph::make (-16, 16, -32));
ASSERT_KNOWN_EQ (aligned_lower_bound (ph::make (-8, -12, 16), 4),
ph::make (-8, -12, 16));
}
/* Test aligned_upper_bound. */
template<unsigned int N, typename C, typename T>
static void
test_aligned_upper_bound ()
{
typedef poly_helper<T> ph;
ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (17, 63, 33), 16),
ph::make (32, 64, 48));
ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (11, -33, 64), 32),
ph::make (32, -32, 64));
ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (-9, 16, -31), 8),
ph::make (-8, 16, -24));
ASSERT_KNOWN_EQ (aligned_upper_bound (ph::make (-8, -12, 16), 4),
ph::make (-8, -12, 16));
}
/* Test known_misalignment. */
template<unsigned int N, typename C, typename T>
static void
test_known_misalignment ()
{
typedef poly_helper<T> ph;
C misalignment;
ASSERT_TRUE (known_misalignment (ph::make (45, 8, 24), 8, &misalignment));
ASSERT_EQ (misalignment, 5);
ASSERT_EQ (known_misalignment (ph::make (17, 16, 23), 8, &misalignment),
N <= 2);
ASSERT_EQ (misalignment, N <= 2 ? 1 : 5);
ASSERT_EQ (known_misalignment (ph::make (31, 15, 0), 16, &misalignment),
N == 1);
ASSERT_EQ (misalignment, N == 1 ? 15 : N == 2 ? 1 : 5);
ASSERT_TRUE (known_misalignment (ph::make (-45, -8, -24), 8, &misalignment));
ASSERT_EQ (misalignment, 3);
ASSERT_TRUE (known_misalignment (ph::make (-11, 0, 0), 32, &misalignment));
ASSERT_EQ (misalignment, 21);
}
/* Test force_get_misalignment. */
template<unsigned int N, typename C, typename T>
static void
test_force_get_misalignment ()
{
typedef poly_helper<T> ph;
ASSERT_EQ (force_get_misalignment (ph::make (45, 8, 24), 8), 5);
ASSERT_EQ (force_get_misalignment (ph::make (17, 16, 24), 8), 1);
ASSERT_EQ (force_get_misalignment (ph::make (31, -16, 0), 16), 15);
ASSERT_EQ (force_get_misalignment (ph::make (-45, -8, -24), 8), 3);
ASSERT_EQ (force_get_misalignment (ph::make (-11, 0, 0), 32), 21);
}
/* Test known_alignment. */
template<unsigned int N, typename C, typename T>
static void
test_known_alignment ()
{
typedef poly_helper<T> ph;
ASSERT_EQ (known_alignment (ph::make (16, 24, 30)),
N == 1 ? 16 : N == 2 ? 8 : 2);
ASSERT_EQ (known_alignment (ph::make (30, 0, 31)),
N <= 2 ? 2 : 1);
ASSERT_EQ (known_alignment (ph::make (20, 16, 24)), 4);
ASSERT_EQ (known_alignment (ph::make (24, 0, 0)), 8);
ASSERT_EQ (known_alignment (ph::make (0, 0, 0)), 0);
ASSERT_EQ (known_alignment (ph::make (0, 12, 0)),
N == 1 ? 0 : 4);
ASSERT_EQ (known_alignment (ph::make (0, 12, 6)),
N == 1 ? 0 : N == 2 ? 4 : 2);
ASSERT_EQ (known_alignment (ph::make (-40, -80, -12)),
N <= 2 ? 8 : 4);
}
/* Test can_ior_p. */
template<unsigned int N, typename C, typename T>
static void
test_can_ior_p ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
T ior;
ASSERT_TRUE (can_ior_p (ph::make (0x87, 0x60, 0xa0), 0x13, &ior));
ASSERT_KNOWN_EQ (ior, ph::make (0x97, 0x60, 0xa0));
ASSERT_EQ (can_ior_p (ph::make (9, 96, 48), 28, &ior), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (ior, ph::make (29, 96, 0));
ASSERT_EQ (can_ior_p (ph::make (0x81, 0x20, 0), 0x44, &ior), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (ior, ch::make (0xc5));
}
/* Test maybe_eq for poly_int<2, C>. */
template<typename C>
static void
test_maybe_eq_2 ()
{
typedef poly_int<2, C> T;
/* Test maybe_eq (T, C). */
ASSERT_TRUE (maybe_eq (T (1, 4), 41));
ASSERT_FALSE (maybe_eq (T (1, 4), 42));
ASSERT_FALSE (maybe_eq (T (1, 4), 40));
ASSERT_TRUE (maybe_eq (T (1, 4), 1));
ASSERT_FALSE (maybe_eq (T (1, 4), 0));
ASSERT_FALSE (maybe_eq (T (1, 4), 2));
/* Test maybe_eq (C, T). */
ASSERT_TRUE (maybe_eq (20, T (5, 3)));
ASSERT_FALSE (maybe_eq (21, T (5, 3)));
ASSERT_FALSE (maybe_eq (19, T (5, 3)));
ASSERT_TRUE (maybe_eq (5, T (5, 3)));
ASSERT_FALSE (maybe_eq (2, T (5, 3)));
ASSERT_FALSE (maybe_eq (6, T (5, 3)));
/* Test maybe_eq (T, T). */
ASSERT_TRUE (maybe_eq (T (2, 5), T (22, 3)));
ASSERT_FALSE (maybe_eq (T (3, 5), T (22, 3)));
ASSERT_FALSE (maybe_eq (T (2, 5), T (23, 3)));
ASSERT_FALSE (maybe_eq (T (2, 5), T (3, 5)));
ASSERT_TRUE (maybe_eq (T (10, 3), T (19, 0)));
ASSERT_FALSE (maybe_eq (T (10, 3), T (20, 0)));
ASSERT_TRUE (maybe_eq (T (10, 0), T (4, 2)));
ASSERT_FALSE (maybe_eq (T (11, 0), T (4, 2)));
}
/* Test known_ne for poly_int<2, C>. */
template<typename C>
static void
test_known_ne_2 ()
{
typedef poly_int<2, C> T;
/* Test known_ne (T, C). */
ASSERT_FALSE (known_ne (T (1, 4), 41));
ASSERT_TRUE (known_ne (T (1, 4), 42));
ASSERT_TRUE (known_ne (T (1, 4), 40));
ASSERT_FALSE (known_ne (T (1, 4), 1));
ASSERT_TRUE (known_ne (T (1, 4), 0));
ASSERT_TRUE (known_ne (T (1, 4), 2));
/* Test known_ne (C, T). */
ASSERT_FALSE (known_ne (20, T (5, 3)));
ASSERT_TRUE (known_ne (21, T (5, 3)));
ASSERT_TRUE (known_ne (19, T (5, 3)));
ASSERT_FALSE (known_ne (5, T (5, 3)));
ASSERT_TRUE (known_ne (2, T (5, 3)));
ASSERT_TRUE (known_ne (6, T (5, 3)));
/* Test known_ne (T, T). */
ASSERT_FALSE (known_ne (T (2, 5), T (22, 3)));
ASSERT_TRUE (known_ne (T (3, 5), T (22, 3)));
ASSERT_TRUE (known_ne (T (2, 5), T (23, 3)));
ASSERT_TRUE (known_ne (T (2, 5), T (3, 5)));
ASSERT_FALSE (known_ne (T (10, 3), T (19, 0)));
ASSERT_TRUE (known_ne (T (10, 3), T (20, 0)));
ASSERT_FALSE (known_ne (T (10, 0), T (4, 2)));
ASSERT_TRUE (known_ne (T (11, 0), T (4, 2)));
}
/* Test maybe_le for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_maybe_le ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test maybe_le (T, C). */
ASSERT_FALSE (maybe_le (ph::make (7, 5, 4), ch::make (6)));
ASSERT_FALSE (maybe_le (ph::make (7, 0, 0), ch::make (6)));
ASSERT_TRUE (maybe_le (ph::make (60, 1, 2), ch::make (60)));
ASSERT_TRUE (maybe_le (ph::make (60, 0, 0), ch::make (60)));
ASSERT_TRUE (maybe_le (ph::make (30, 9, 4), ch::make (31)));
ASSERT_TRUE (maybe_le (ph::make (30, 0, 0), ch::make (31)));
/* Test maybe_le (C, T). */
ASSERT_TRUE (maybe_le (ch::make (6), ph::make (7, 5, 4)));
ASSERT_TRUE (maybe_le (ch::make (6), ph::make (7, 0, 0)));
ASSERT_TRUE (maybe_le (ch::make (60), ph::make (60, 1, 2)));
ASSERT_TRUE (maybe_le (ch::make (60), ph::make (60, 0, 0)));
ASSERT_EQ (maybe_le (ch::make (31), ph::make (30, 9, 4)), N >= 2);
ASSERT_EQ (maybe_le (ch::make (31), ph::make (30, 0, 4)), N == 3);
ASSERT_FALSE (maybe_le (ch::make (31), ph::make (30, 0, 0)));
/* Test maybe_le (T, T). */
ASSERT_EQ (maybe_le (ph::make (3, 14, 99), ph::make (2, 15, 100)), N >= 2);
ASSERT_EQ (maybe_le (ph::make (3, 14, 99), ph::make (2, 13, 100)), N == 3);
ASSERT_EQ (maybe_le (ph::make (3, 14, 99), ph::make (2, 15, 98)), N >= 2);
ASSERT_FALSE (maybe_le (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (maybe_le (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (maybe_le (ph::make (2, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (maybe_le (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (maybe_le (ph::make (2, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (maybe_le (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (maybe_le (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (maybe_le (ph::make (1, 14, 99), ph::make (2, 13, 98)));
}
/* Test maybe_lt for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_maybe_lt ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test maybe_lt (T, C). */
ASSERT_FALSE (maybe_lt (ph::make (7, 5, 4), ch::make (6)));
ASSERT_FALSE (maybe_lt (ph::make (7, 0, 0), ch::make (6)));
ASSERT_FALSE (maybe_lt (ph::make (60, 1, 2), ch::make (60)));
ASSERT_FALSE (maybe_lt (ph::make (60, 0, 0), ch::make (60)));
ASSERT_TRUE (maybe_lt (ph::make (30, 9, 4), ch::make (31)));
ASSERT_TRUE (maybe_lt (ph::make (30, 0, 0), ch::make (31)));
/* Test maybe_lt (C, T). */
ASSERT_TRUE (maybe_lt (ch::make (6), ph::make (7, 5, 4)));
ASSERT_TRUE (maybe_lt (ch::make (6), ph::make (7, 0, 0)));
ASSERT_EQ (maybe_lt (ch::make (60), ph::make (60, 1, 2)), N >= 2);
ASSERT_EQ (maybe_lt (ch::make (60), ph::make (60, 0, 2)), N == 3);
ASSERT_FALSE (maybe_lt (ch::make (60), ph::make (60, 0, 0)));
ASSERT_EQ (maybe_lt (ch::make (31), ph::make (30, 9, 4)), N >= 2);
ASSERT_EQ (maybe_lt (ch::make (31), ph::make (30, 0, 4)), N == 3);
ASSERT_FALSE (maybe_lt (ch::make (31), ph::make (30, 0, 0)));
/* Test maybe_lt (T, T). */
ASSERT_EQ (maybe_lt (ph::make (3, 14, 99), ph::make (2, 15, 100)), N >= 2);
ASSERT_EQ (maybe_lt (ph::make (3, 14, 99), ph::make (2, 13, 100)), N == 3);
ASSERT_EQ (maybe_lt (ph::make (3, 14, 99), ph::make (2, 15, 98)), N >= 2);
ASSERT_FALSE (maybe_lt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (maybe_lt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_EQ (maybe_lt (ph::make (2, 14, 99), ph::make (2, 15, 100)), N >= 2);
ASSERT_EQ (maybe_lt (ph::make (2, 14, 99), ph::make (2, 13, 100)), N == 3);
ASSERT_EQ (maybe_lt (ph::make (2, 14, 99), ph::make (2, 15, 98)), N >= 2);
ASSERT_FALSE (maybe_lt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (maybe_lt (ph::make (2, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (maybe_lt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (maybe_lt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (maybe_lt (ph::make (1, 14, 99), ph::make (2, 13, 98)));
}
/* Test maybe_ge for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_maybe_ge ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test maybe_ge (T, C). */
ASSERT_TRUE (maybe_ge (ph::make (7, 5, 4), ch::make (6)));
ASSERT_TRUE (maybe_ge (ph::make (7, 0, 0), ch::make (6)));
ASSERT_TRUE (maybe_ge (ph::make (60, 1, 2), ch::make (60)));
ASSERT_TRUE (maybe_ge (ph::make (60, 0, 0), ch::make (60)));
ASSERT_EQ (maybe_ge (ph::make (30, 9, 4), ch::make (31)), N >= 2);
ASSERT_EQ (maybe_ge (ph::make (30, 0, 4), ch::make (31)), N == 3);
ASSERT_FALSE (maybe_ge (ph::make (30, 0, 0), ch::make (31)));
/* Test maybe_ge (C, T). */
ASSERT_FALSE (maybe_ge (ch::make (6), ph::make (7, 5, 4)));
ASSERT_FALSE (maybe_ge (ch::make (6), ph::make (7, 0, 0)));
ASSERT_TRUE (maybe_ge (ch::make (60), ph::make (60, 1, 2)));
ASSERT_TRUE (maybe_ge (ch::make (60), ph::make (60, 0, 0)));
ASSERT_TRUE (maybe_ge (ch::make (31), ph::make (30, 9, 4)));
ASSERT_TRUE (maybe_ge (ch::make (31), ph::make (30, 0, 0)));
/* Test maybe_ge (T, T). */
ASSERT_TRUE (maybe_ge (ph::make (3, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (maybe_ge (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (maybe_ge (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (maybe_ge (ph::make (2, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (maybe_ge (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (maybe_ge (ph::make (2, 14, 99), ph::make (2, 13, 98)));
ASSERT_FALSE (maybe_ge (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (maybe_ge (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (maybe_ge (ph::make (1, 14, 99), ph::make (2, 15, 98)), N == 3);
ASSERT_EQ (maybe_ge (ph::make (1, 14, 99), ph::make (2, 13, 100)), N >= 2);
ASSERT_EQ (maybe_ge (ph::make (1, 14, 99), ph::make (2, 13, 98)), N >= 2);
}
/* Test maybe_gt for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_maybe_gt ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test maybe_gt (T, C). */
ASSERT_TRUE (maybe_gt (ph::make (7, 5, 4), ch::make (6)));
ASSERT_TRUE (maybe_gt (ph::make (7, 0, 0), ch::make (6)));
ASSERT_EQ (maybe_gt (ph::make (60, 1, 2), ch::make (60)), N >= 2);
ASSERT_EQ (maybe_gt (ph::make (60, 0, 2), ch::make (60)), N == 3);
ASSERT_FALSE (maybe_gt (ph::make (60, 0, 0), ch::make (60)));
ASSERT_EQ (maybe_gt (ph::make (30, 9, 4), ch::make (31)), N >= 2);
ASSERT_EQ (maybe_gt (ph::make (30, 0, 4), ch::make (31)), N == 3);
ASSERT_FALSE (maybe_gt (ph::make (30, 0, 0), ch::make (31)));
/* Test maybe_gt (C, T). */
ASSERT_FALSE (maybe_gt (ch::make (6), ph::make (7, 5, 4)));
ASSERT_FALSE (maybe_gt (ch::make (6), ph::make (7, 0, 0)));
ASSERT_FALSE (maybe_gt (ch::make (60), ph::make (60, 1, 2)));
ASSERT_FALSE (maybe_gt (ch::make (60), ph::make (60, 0, 0)));
ASSERT_TRUE (maybe_gt (ch::make (31), ph::make (30, 9, 4)));
ASSERT_TRUE (maybe_gt (ch::make (31), ph::make (30, 0, 0)));
/* Test maybe_gt (T, T). */
ASSERT_TRUE (maybe_gt (ph::make (3, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (maybe_gt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (maybe_gt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_FALSE (maybe_gt (ph::make (2, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (maybe_gt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (maybe_gt (ph::make (2, 14, 99), ph::make (2, 15, 98)), N == 3);
ASSERT_EQ (maybe_gt (ph::make (2, 14, 99), ph::make (2, 13, 100)), N >= 2);
ASSERT_EQ (maybe_gt (ph::make (2, 14, 99), ph::make (2, 13, 98)), N >= 2);
ASSERT_FALSE (maybe_gt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (maybe_gt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (maybe_gt (ph::make (1, 14, 99), ph::make (2, 15, 98)), N == 3);
ASSERT_EQ (maybe_gt (ph::make (1, 14, 99), ph::make (2, 13, 100)), N >= 2);
ASSERT_EQ (maybe_gt (ph::make (1, 14, 99), ph::make (2, 13, 98)), N >= 2);
}
/* Test known_gt for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_known_gt ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test known_gt (T, C). */
ASSERT_TRUE (known_gt (ph::make (7, 5, 4), ch::make (6)));
ASSERT_TRUE (known_gt (ph::make (7, 0, 0), ch::make (6)));
ASSERT_FALSE (known_gt (ph::make (60, 1, 2), ch::make (60)));
ASSERT_FALSE (known_gt (ph::make (60, 0, 0), ch::make (60)));
ASSERT_FALSE (known_gt (ph::make (30, 9, 4), ch::make (31)));
ASSERT_FALSE (known_gt (ph::make (30, 0, 0), ch::make (31)));
/* Test known_gt (C, T). */
ASSERT_FALSE (known_gt (ch::make (6), ph::make (7, 5, 4)));
ASSERT_FALSE (known_gt (ch::make (6), ph::make (7, 0, 0)));
ASSERT_FALSE (known_gt (ch::make (60), ph::make (60, 1, 2)));
ASSERT_FALSE (known_gt (ch::make (60), ph::make (60, 0, 0)));
ASSERT_EQ (known_gt (ch::make (31), ph::make (30, 9, 4)), N == 1);
ASSERT_EQ (known_gt (ch::make (31), ph::make (30, 0, 4)), N <= 2);
ASSERT_TRUE (known_gt (ch::make (31), ph::make (30, 0, 0)));
/* Test known_gt (T, T). */
ASSERT_EQ (known_gt (ph::make (3, 14, 99), ph::make (2, 15, 100)), N == 1);
ASSERT_EQ (known_gt (ph::make (3, 14, 99), ph::make (2, 13, 100)), N <= 2);
ASSERT_EQ (known_gt (ph::make (3, 14, 99), ph::make (2, 15, 98)), N == 1);
ASSERT_TRUE (known_gt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (known_gt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_FALSE (known_gt (ph::make (2, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (known_gt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (known_gt (ph::make (2, 14, 99), ph::make (2, 13, 98)));
ASSERT_FALSE (known_gt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (known_gt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (known_gt (ph::make (1, 14, 99), ph::make (2, 13, 98)));
}
/* Test known_ge for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_known_ge ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test known_ge (T, C). */
ASSERT_TRUE (known_ge (ph::make (7, 5, 4), ch::make (6)));
ASSERT_TRUE (known_ge (ph::make (7, 0, 0), ch::make (6)));
ASSERT_TRUE (known_ge (ph::make (60, 1, 2), ch::make (60)));
ASSERT_TRUE (known_ge (ph::make (60, 0, 0), ch::make (60)));
ASSERT_FALSE (known_ge (ph::make (30, 9, 4), ch::make (31)));
ASSERT_FALSE (known_ge (ph::make (30, 0, 0), ch::make (31)));
/* Test known_ge (C, T). */
ASSERT_FALSE (known_ge (ch::make (6), ph::make (7, 5, 4)));
ASSERT_FALSE (known_ge (ch::make (6), ph::make (7, 0, 0)));
ASSERT_EQ (known_ge (ch::make (60), ph::make (60, 1, 2)), N == 1);
ASSERT_EQ (known_ge (ch::make (60), ph::make (60, 0, 2)), N <= 2);
ASSERT_TRUE (known_ge (ch::make (60), ph::make (60, 0, 0)));
ASSERT_EQ (known_ge (ch::make (31), ph::make (30, 9, 4)), N == 1);
ASSERT_EQ (known_ge (ch::make (31), ph::make (30, 0, 4)), N <= 2);
ASSERT_TRUE (known_ge (ch::make (31), ph::make (30, 0, 0)));
/* Test known_ge (T, T). */
ASSERT_EQ (known_ge (ph::make (3, 14, 99), ph::make (2, 15, 100)), N == 1);
ASSERT_EQ (known_ge (ph::make (3, 14, 99), ph::make (2, 13, 100)), N <= 2);
ASSERT_EQ (known_ge (ph::make (3, 14, 99), ph::make (2, 15, 98)), N == 1);
ASSERT_TRUE (known_ge (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (known_ge (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_EQ (known_ge (ph::make (2, 14, 99), ph::make (2, 15, 100)), N == 1);
ASSERT_EQ (known_ge (ph::make (2, 14, 99), ph::make (2, 13, 100)), N <= 2);
ASSERT_EQ (known_ge (ph::make (2, 14, 99), ph::make (2, 15, 98)), N == 1);
ASSERT_TRUE (known_ge (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (known_ge (ph::make (2, 14, 99), ph::make (2, 13, 98)));
ASSERT_FALSE (known_ge (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (known_ge (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (known_ge (ph::make (1, 14, 99), ph::make (2, 13, 98)));
}
/* Test known_lt for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_known_lt ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test known_lt (T, C). */
ASSERT_FALSE (known_lt (ph::make (7, 5, 4), ch::make (6)));
ASSERT_FALSE (known_lt (ph::make (7, 0, 0), ch::make (6)));
ASSERT_FALSE (known_lt (ph::make (60, 1, 2), ch::make (60)));
ASSERT_FALSE (known_lt (ph::make (60, 0, 0), ch::make (60)));
ASSERT_EQ (known_lt (ph::make (30, 9, 4), ch::make (31)), N == 1);
ASSERT_EQ (known_lt (ph::make (30, 0, 4), ch::make (31)), N <= 2);
ASSERT_TRUE (known_lt (ph::make (30, 0, 0), ch::make (31)));
/* Test known_lt (C, T). */
ASSERT_TRUE (known_lt (ch::make (6), ph::make (7, 5, 4)));
ASSERT_TRUE (known_lt (ch::make (6), ph::make (7, 0, 0)));
ASSERT_FALSE (known_lt (ch::make (60), ph::make (60, 1, 2)));
ASSERT_FALSE (known_lt (ch::make (60), ph::make (60, 0, 0)));
ASSERT_FALSE (known_lt (ch::make (31), ph::make (30, 9, 4)));
ASSERT_FALSE (known_lt (ch::make (31), ph::make (30, 0, 0)));
/* Test known_lt (T, T). */
ASSERT_FALSE (known_lt (ph::make (3, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (known_lt (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (known_lt (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_FALSE (known_lt (ph::make (2, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (known_lt (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (known_lt (ph::make (2, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (known_lt (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (known_lt (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (known_lt (ph::make (1, 14, 99), ph::make (2, 15, 98)), N <= 2);
ASSERT_EQ (known_lt (ph::make (1, 14, 99), ph::make (2, 13, 100)), N == 1);
ASSERT_EQ (known_lt (ph::make (1, 14, 99), ph::make (2, 13, 98)), N == 1);
}
/* Test known_le for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_known_le ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test known_le (T, C). */
ASSERT_FALSE (known_le (ph::make (7, 5, 4), ch::make (6)));
ASSERT_FALSE (known_le (ph::make (7, 0, 0), ch::make (6)));
ASSERT_EQ (known_le (ph::make (60, 1, 2), ch::make (60)), N == 1);
ASSERT_EQ (known_le (ph::make (60, 0, 2), ch::make (60)), N <= 2);
ASSERT_TRUE (known_le (ph::make (60, 0, 0), ch::make (60)));
ASSERT_EQ (known_le (ph::make (30, 9, 4), ch::make (31)), N == 1);
ASSERT_EQ (known_le (ph::make (30, 0, 4), ch::make (31)), N <= 2);
ASSERT_TRUE (known_le (ph::make (30, 0, 0), ch::make (31)));
/* Test known_le (C, T). */
ASSERT_TRUE (known_le (ch::make (6), ph::make (7, 5, 4)));
ASSERT_TRUE (known_le (ch::make (6), ph::make (7, 0, 0)));
ASSERT_TRUE (known_le (ch::make (60), ph::make (60, 1, 2)));
ASSERT_TRUE (known_le (ch::make (60), ph::make (60, 0, 0)));
ASSERT_FALSE (known_le (ch::make (31), ph::make (30, 9, 4)));
ASSERT_FALSE (known_le (ch::make (31), ph::make (30, 0, 0)));
/* Test known_le (T, T). */
ASSERT_FALSE (known_le (ph::make (3, 14, 99), ph::make (2, 15, 100)));
ASSERT_FALSE (known_le (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_FALSE (known_le (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (known_le (ph::make (2, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (known_le (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (known_le (ph::make (2, 14, 99), ph::make (2, 15, 98)), N <= 2);
ASSERT_EQ (known_le (ph::make (2, 14, 99), ph::make (2, 13, 100)), N == 1);
ASSERT_EQ (known_le (ph::make (2, 14, 99), ph::make (2, 13, 98)), N == 1);
ASSERT_TRUE (known_le (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (known_le (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (known_le (ph::make (1, 14, 99), ph::make (2, 15, 98)), N <= 2);
ASSERT_EQ (known_le (ph::make (1, 14, 99), ph::make (2, 13, 100)), N == 1);
ASSERT_EQ (known_le (ph::make (1, 14, 99), ph::make (2, 13, 98)), N == 1);
}
/* Test ordered_p for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_ordered_p ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test ordered_p (T, C). */
ASSERT_EQ (ordered_p (ph::make (4, 1, 2), ch::make (5)), N == 1);
ASSERT_EQ (ordered_p (ph::make (4, 0, 2), ch::make (5)), N <= 2);
ASSERT_TRUE (ordered_p (ph::make (4, 0, 0), ch::make (5)));
ASSERT_TRUE (ordered_p (ph::make (4, 1, 2), ch::make (4)));
ASSERT_TRUE (ordered_p (ph::make (4, 0, 0), ch::make (4)));
ASSERT_TRUE (ordered_p (ph::make (4, 1, 2), ch::make (3)));
ASSERT_TRUE (ordered_p (ph::make (4, 0, 0), ch::make (3)));
ASSERT_TRUE (ordered_p (ph::make (4, 4, 4), ch::make (0)));
ASSERT_TRUE (ordered_p (ph::make (4, 4, 0), ch::make (0)));
ASSERT_TRUE (ordered_p (ph::make (4, 0, 4), ch::make (0)));
ASSERT_TRUE (ordered_p (ph::make (-4, -4, -4), ch::make (0)));
ASSERT_TRUE (ordered_p (ph::make (-4, -4, 0), ch::make (0)));
ASSERT_TRUE (ordered_p (ph::make (-4, 0, -4), ch::make (0)));
/* Test ordered_p (C, T). */
ASSERT_EQ (ordered_p (ch::make (5), ph::make (4, 1, 2)), N == 1);
ASSERT_EQ (ordered_p (ch::make (5), ph::make (4, 0, 2)), N <= 2);
ASSERT_TRUE (ordered_p (ch::make (5), ph::make (4, 0, 0)));
ASSERT_TRUE (ordered_p (ch::make (4), ph::make (4, 1, 2)));
ASSERT_TRUE (ordered_p (ch::make (4), ph::make (4, 0, 0)));
ASSERT_TRUE (ordered_p (ch::make (3), ph::make (4, 1, 2)));
ASSERT_TRUE (ordered_p (ch::make (3), ph::make (4, 0, 0)));
ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 4, 4)));
ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 4, 0)));
ASSERT_TRUE (ordered_p (ch::make (0), ph::make (4, 0, 4)));
ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, -4, -4)));
ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, -4, 0)));
ASSERT_TRUE (ordered_p (ch::make (0), ph::make (-4, 0, -4)));
/* Test ordered_p (T, T). */
ASSERT_EQ (ordered_p (ph::make (3, 14, 99), ph::make (2, 15, 100)), N == 1);
ASSERT_EQ (ordered_p (ph::make (3, 14, 99), ph::make (2, 13, 100)), N <= 2);
ASSERT_EQ (ordered_p (ph::make (3, 14, 99), ph::make (2, 15, 98)), N == 1);
ASSERT_TRUE (ordered_p (ph::make (3, 14, 99), ph::make (2, 14, 99)));
ASSERT_TRUE (ordered_p (ph::make (3, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 14, 100)));
ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 15, 99)));
ASSERT_EQ (ordered_p (ph::make (2, 14, 99), ph::make (2, 13, 100)), N <= 2);
ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (ordered_p (ph::make (2, 14, 99), ph::make (2, 15, 98)), N <= 2);
ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 13, 99)));
ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 14, 98)));
ASSERT_TRUE (ordered_p (ph::make (2, 14, 99), ph::make (2, 13, 98)));
ASSERT_TRUE (ordered_p (ph::make (1, 14, 99), ph::make (2, 15, 100)));
ASSERT_TRUE (ordered_p (ph::make (1, 14, 99), ph::make (2, 14, 99)));
ASSERT_EQ (ordered_p (ph::make (1, 14, 99), ph::make (2, 15, 98)), N <= 2);
ASSERT_EQ (ordered_p (ph::make (1, 14, 99), ph::make (2, 13, 100)), N == 1);
ASSERT_EQ (ordered_p (ph::make (1, 14, 99), ph::make (2, 13, 98)), N == 1);
}
/* Test ordered_min for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_ordered_min ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test ordered_min (T, C). */
ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 0, 0), ch::make (5)),
ch::make (4));
ASSERT_KNOWN_EQ (ordered_min (ph::make (12, 0, 0), ch::make (11)),
ch::make (11));
ASSERT_KNOWN_EQ (ordered_min (ph::make (12, 6, 4), ch::make (11)),
ch::make (11));
/* Test ordered_min (C, T). */
ASSERT_KNOWN_EQ (ordered_min (ch::make (5), ph::make (4, 0, 0)),
ch::make (4));
ASSERT_KNOWN_EQ (ordered_min (ch::make (11), ph::make (12, 0, 0)),
ch::make (11));
ASSERT_KNOWN_EQ (ordered_min (ch::make (11), ph::make (12, 6, 4)),
ch::make (11));
/* Test ordered_min (T, T). */
ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 6, 14), ph::make (5, 6, 19)),
ph::make (4, 6, 14));
ASSERT_KNOWN_EQ (ordered_min (ph::make (4, 9, 17), ph::make (3, 9, 0)),
ph::make (3, 9, 0));
ASSERT_KNOWN_EQ (ordered_min (ph::make (-4, -5, 12), ph::make (-3, -5, 12)),
ph::make (-4, -5, 12));
ASSERT_KNOWN_EQ (ordered_min (ph::make (4, -9, 6), ph::make (4, -8, 6)),
ph::make (4, -9, 6));
ASSERT_KNOWN_EQ (ordered_min (ph::make (5, -1, -14), ph::make (5, -1, -16)),
ph::make (5, -1, -16));
}
/* Test ordered_max for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_ordered_max ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test ordered_max (T, C). */
ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 0, 0), ch::make (5)),
ch::make (5));
ASSERT_KNOWN_EQ (ordered_max (ph::make (12, 0, 0), ch::make (11)),
ch::make (12));
ASSERT_KNOWN_EQ (ordered_max (ph::make (12, 6, 4), ch::make (11)),
ph::make (12, 6, 4));
/* Test ordered_max (C, T). */
ASSERT_KNOWN_EQ (ordered_max (ch::make (5), ph::make (4, 0, 0)),
ch::make (5));
ASSERT_KNOWN_EQ (ordered_max (ch::make (11), ph::make (12, 0, 0)),
ch::make (12));
ASSERT_KNOWN_EQ (ordered_max (ch::make (11), ph::make (12, 6, 4)),
ph::make (12, 6, 4));
/* Test ordered_max (T, T). */
ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 6, 14), ph::make (5, 6, 19)),
ph::make (5, 6, 19));
ASSERT_KNOWN_EQ (ordered_max (ph::make (4, 9, 17), ph::make (3, 9, 0)),
ph::make (4, 9, 17));
ASSERT_KNOWN_EQ (ordered_max (ph::make (-4, -5, 12), ph::make (-3, -5, 12)),
ph::make (-3, -5, 12));
ASSERT_KNOWN_EQ (ordered_max (ph::make (4, -9, 6), ph::make (4, -8, 6)),
ph::make (4, -8, 6));
ASSERT_KNOWN_EQ (ordered_max (ph::make (5, -1, -14), ph::make (5, -1, -16)),
ph::make (5, -1, -14));
}
/* Test constant_lower_bound for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_constant_lower_bound ()
{
typedef poly_helper<T> ph;
ASSERT_EQ (constant_lower_bound (ph::make (4, 1, 2)), 4);
ASSERT_EQ (constant_lower_bound (ph::make (5, 0, 1)), 5);
ASSERT_EQ (constant_lower_bound (ph::make (6, 1, 0)), 6);
ASSERT_EQ (constant_lower_bound (ph::make (7, 0, 0)), 7);
}
/* Test lower_bound for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_lower_bound ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test lower_bound (T, C). */
ASSERT_KNOWN_EQ (lower_bound (ph::make (7, 2, 15), ch::make (4)),
ch::make (4));
ASSERT_KNOWN_EQ (lower_bound (ph::make (100, 5, 50), ch::make (200)),
ch::make (100));
/* Test lower_bound (C, T). */
ASSERT_KNOWN_EQ (lower_bound (ch::make (4), ph::make (7, 2, 15)),
ch::make (4));
ASSERT_KNOWN_EQ (lower_bound (ch::make (200), ph::make (100, 5, 50)),
ch::make (100));
/* Test lower_bound (T, T). */
ASSERT_KNOWN_EQ (lower_bound (ph::make (7, 2, 15), ph::make (5, 19, 14)),
ph::make (5, 2, 14));
ASSERT_KNOWN_EQ (lower_bound (ph::make (100, 5, 50), ph::make (200, 0, 80)),
ph::make (100, 0, 50));
}
/* Test upper_bound for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_upper_bound ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test upper_bound (T, C). */
ASSERT_KNOWN_EQ (upper_bound (ph::make (7, 2, 15), ch::make (4)),
ph::make (7, 2, 15));
ASSERT_KNOWN_EQ (upper_bound (ph::make (100, 5, 50), ch::make (200)),
ph::make (200, 5, 50));
/* Test upper_bound (C, T). */
ASSERT_KNOWN_EQ (upper_bound (ch::make (4), ph::make (7, 2, 15)),
ph::make (7, 2, 15));
ASSERT_KNOWN_EQ (upper_bound (ch::make (200), ph::make (100, 5, 50)),
ph::make (200, 5, 50));
/* Test upper_bound (T, T). */
ASSERT_KNOWN_EQ (upper_bound (ph::make (7, 2, 15), ph::make (5, 19, 14)),
ph::make (7, 19, 15));
ASSERT_KNOWN_EQ (upper_bound (ph::make (100, 5, 50), ph::make (200, 0, 80)),
ph::make (200, 5, 80));
}
/* Test compare_sizes_for_sort for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_compare_sizes_for_sort ()
{
typedef poly_helper<T> ph;
ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 10, 8),
ph::make (7, 9, 11)),
N == 2 ? 1 : -1);
ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 9, 8),
ph::make (7, 9, 11)),
-1);
ASSERT_EQ (compare_sizes_for_sort (ph::make (19, 9, 13),
ph::make (7, 9, 13)),
1);
ASSERT_EQ (compare_sizes_for_sort (ph::make (5, 9, 7),
ph::make (5, 10, 5)),
N == 1 ? 0 : N == 2 ? -1 : 1);
ASSERT_EQ (compare_sizes_for_sort (ph::make (10, 9, 10),
ph::make (10, 9, 6)),
N <= 2 ? 0 : 1);
ASSERT_EQ (compare_sizes_for_sort (ph::make (10, 9, 6),
ph::make (10, 9, 6)),
0);
}
/* Test force_align_up_and_div for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_force_align_up_and_div ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (41, 32, 16), 16),
ph::make (3, 2, 1));
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-39, -64, -32), 32),
ph::make (C (-32) / 32, C (-64) / 32, C (-32) / 32));
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (17, 0, 0), 16),
ch::make (2));
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (16, 0, 0), 16),
ch::make (1));
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (15, 0, 0), 16),
ch::make (1));
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-17, 0, 0), 16),
ch::make (C (-16) / 16));
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-16, 0, 0), 16),
ch::make (C (-16) / 16));
/* For unsigned short C this gives 0x10000 / 16. */
ASSERT_KNOWN_EQ (force_align_up_and_div (ph::make (-15, 0, 0), 16),
ch::make ((C (-1) + 1) / 16));
}
/* Test force_align_down_and_div for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_force_align_down_and_div ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (41, 32, 16), 16),
ph::make (2, 2, 1));
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-39, -64, -32), 32),
ph::make (C (-64) / 32, C (-64) / 32, C (-32) / 32));
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (17, 0, 0), 16),
ch::make (1));
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (16, 0, 0), 16),
ch::make (1));
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (15, 0, 0), 16),
ch::make (0));
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-17, 0, 0), 16),
ch::make (C (-32) / 16));
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-16, 0, 0), 16),
ch::make (C (-16) / 16));
ASSERT_KNOWN_EQ (force_align_down_and_div (ph::make (-15, 0, 0), 16),
ch::make (C (-16) / 16));
}
/* Test constant_multiple_p for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_constant_multiple_p ()
{
typedef poly_helper<T> ph;
/* Test constant_multiple_p (T, C). */
C const_multiple;
ASSERT_TRUE (constant_multiple_p (ph::make (15, 0, 0), 5,
&const_multiple));
ASSERT_EQ (const_multiple, 3);
ASSERT_FALSE (constant_multiple_p (ph::make (16, 0, 0), 5,
&const_multiple));
ASSERT_FALSE (constant_multiple_p (ph::make (14, 5, 5), 5,
&const_multiple));
ASSERT_EQ (constant_multiple_p (ph::make (44, 0, 55), 11,
&const_multiple), N <= 2);
ASSERT_EQ (const_multiple, N <= 2 ? 4 : 3);
ASSERT_EQ (constant_multiple_p (ph::make (30, 30, 0), 6,
&const_multiple), N == 1);
ASSERT_EQ (const_multiple, N == 1 ? 5 : N == 2 ? 4 : 3);
ASSERT_TRUE (constant_multiple_p (ph::make (0, 0, 0), 5,
&const_multiple));
/* Test constant_multiple_p (C, T). */
ASSERT_TRUE (constant_multiple_p (15, ph::make (5, 0, 0),
&const_multiple));
ASSERT_EQ (const_multiple, 3);
ASSERT_FALSE (constant_multiple_p (16, ph::make (5, 0, 0),
&const_multiple));
ASSERT_FALSE (constant_multiple_p (14, ph::make (5, 5, 5),
&const_multiple));
ASSERT_EQ (constant_multiple_p (44, ph::make (11, 0, 4),
&const_multiple), N <= 2);
ASSERT_EQ (const_multiple, N <= 2 ? 4 : 3);
ASSERT_EQ (constant_multiple_p (30, ph::make (6, 6, 6),
&const_multiple), N == 1);
ASSERT_EQ (const_multiple, N == 1 ? 5 : N == 2 ? 4 : 3);
ASSERT_TRUE (constant_multiple_p (0, ph::make (5, 4, 11),
&const_multiple));
ASSERT_EQ (const_multiple, 0);
/* Test constant_multiple_p (T, T). */
ASSERT_TRUE (constant_multiple_p (ph::make (5, 15, 25),
ph::make (1, 3, 5),
&const_multiple));
ASSERT_EQ (const_multiple, 5);
ASSERT_EQ (constant_multiple_p (ph::make (18, 30, 7),
ph::make (6, 10, 2),
&const_multiple), N <= 2);
ASSERT_EQ (const_multiple, N <= 2 ? 3 : 5);
ASSERT_EQ (constant_multiple_p (ph::make (54, 19, 0),
ph::make (9, 3, 0),
&const_multiple), N == 1);
ASSERT_EQ (const_multiple, N == 1 ? 6 : N == 2 ? 3: 5);
ASSERT_TRUE (constant_multiple_p (ph::make (120, 0, 90),
ph::make (12, 0, 9),
&const_multiple));
ASSERT_EQ (const_multiple, 10);
ASSERT_EQ (constant_multiple_p (ph::make (110, 1, 22),
ph::make (10, 0, 2),
&const_multiple), N == 1);
ASSERT_EQ (const_multiple, N == 1 ? 11 : 10);
ASSERT_EQ (constant_multiple_p (ph::make (120, -1, 22),
ph::make (10, 0, 2),
&const_multiple), N == 1);
ASSERT_EQ (const_multiple, N == 1 ? 12 : 10);
ASSERT_EQ (constant_multiple_p (ph::make (130, 0, 26),
ph::make (10, 1, 2),
&const_multiple), N == 1);
ASSERT_EQ (const_multiple, N == 1 ? 13 : 10);
ASSERT_EQ (constant_multiple_p (ph::make (140, 0, 28),
ph::make (10, -1, 2),
&const_multiple), N == 1);
ASSERT_EQ (const_multiple, N == 1 ? 14 : 10);
ASSERT_FALSE (constant_multiple_p (ph::make (89, 0, 0),
ph::make (11, 0, 0),
&const_multiple));
ASSERT_TRUE (constant_multiple_p (ph::make (88, 0, 0),
ph::make (11, 0, 0),
&const_multiple));
ASSERT_EQ (const_multiple, 8);
ASSERT_FALSE (constant_multiple_p (ph::make (87, 0, 0),
ph::make (11, 0, 0),
&const_multiple));
ASSERT_TRUE (constant_multiple_p (ph::make (35, 63, 0),
ph::make (5, 9, 0),
&const_multiple));
ASSERT_EQ (const_multiple, 7);
ASSERT_TRUE (constant_multiple_p (ph::make (0, 0, 0),
ph::make (11, -24, 25),
&const_multiple));
ASSERT_EQ (const_multiple, 0);
}
/* Test multiple_p for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_multiple_p ()
{
typedef poly_helper<T> ph;
/* Test multiple_p (T, C). */
ASSERT_TRUE (multiple_p (ph::make (15, 0, 0), 5));
ASSERT_FALSE (multiple_p (ph::make (16, 0, 0), 5));
ASSERT_FALSE (multiple_p (ph::make (14, 5, 5), 5));
ASSERT_TRUE (multiple_p (ph::make (44, 0, 55), 11));
ASSERT_TRUE (multiple_p (ph::make (30, 30, 0), 6));
ASSERT_TRUE (multiple_p (ph::make (30, 35, 45), 5));
ASSERT_EQ (multiple_p (ph::make (30, 35, 44), 5), N <= 2);
ASSERT_EQ (multiple_p (ph::make (30, 34, 45), 5), N == 1);
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0), 5));
/* Test multiple_p (C, T). */
ASSERT_TRUE (multiple_p (15, ph::make (5, 0, 0)));
ASSERT_FALSE (multiple_p (16, ph::make (5, 0, 0)));
ASSERT_FALSE (multiple_p (14, ph::make (5, 5, 5)));
ASSERT_EQ (multiple_p (44, ph::make (11, 0, 4)), N <= 2);
ASSERT_EQ (multiple_p (30, ph::make (6, 6, 6)), N == 1);
ASSERT_TRUE (multiple_p (0, ph::make (5, 4, 11)));
/* Test multiple_p (T, T). */
ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
ph::make (5, 0, 0)));
ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
ph::make (5, 0, 0)));
ASSERT_FALSE (multiple_p (ph::make (14, 5, 5),
ph::make (5, 0, 0)));
ASSERT_TRUE (multiple_p (ph::make (44, 0, 55),
ph::make (11, 0, 0)));
ASSERT_TRUE (multiple_p (ph::make (30, 30, 0),
ph::make (6, 0, 0)));
ASSERT_TRUE (multiple_p (ph::make (30, 35, 45),
ph::make (5, 0, 0)));
ASSERT_EQ (multiple_p (ph::make (30, 35, 44),
ph::make (5, 0, 0)), N <= 2);
ASSERT_EQ (multiple_p (ph::make (30, 34, 45),
ph::make (5, 0, 0)), N == 1);
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
ph::make (5, 0, 0)));
ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
ph::make (5, 0, 0)));
ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
ph::make (5, 0, 0)));
ASSERT_FALSE (multiple_p (ph::make (14, 0, 0),
ph::make (5, 5, 5)));
ASSERT_EQ (multiple_p (ph::make (44, 0, 0),
ph::make (11, 0, 4)), N <= 2);
ASSERT_EQ (multiple_p (ph::make (30, 0, 0),
ph::make (6, 6, 6)), N == 1);
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
ph::make (5, 4, 11)));
ASSERT_TRUE (multiple_p (ph::make (5, 15, 25),
ph::make (1, 3, 5)));
ASSERT_EQ (multiple_p (ph::make (18, 30, 7),
ph::make (6, 10, 2)), N <= 2);
ASSERT_EQ (multiple_p (ph::make (54, 19, 0),
ph::make (9, 3, 0)), N == 1);
ASSERT_TRUE (multiple_p (ph::make (120, 0, 90),
ph::make (12, 0, 9)));
ASSERT_EQ (multiple_p (ph::make (110, 1, 22),
ph::make (10, 0, 2)), N == 1);
ASSERT_EQ (multiple_p (ph::make (120, -1, 22),
ph::make (10, 0, 2)), N == 1);
ASSERT_EQ (multiple_p (ph::make (130, 0, 26),
ph::make (10, 1, 2)), N == 1);
ASSERT_EQ (multiple_p (ph::make (140, 0, 28),
ph::make (10, -1, 2)), N == 1);
ASSERT_FALSE (multiple_p (ph::make (89, 0, 0),
ph::make (11, 0, 0)));
ASSERT_TRUE (multiple_p (ph::make (88, 0, 0),
ph::make (11, 0, 0)));
ASSERT_FALSE (multiple_p (ph::make (87, 0, 0),
ph::make (11, 0, 0)));
ASSERT_TRUE (multiple_p (ph::make (35, 63, 0),
ph::make (5, 9, 0)));
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
ph::make (11, -24, 25)));
}
/* Test the 3-operand form of multiple_p for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_multiple_p_with_result ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test multiple_p (T, C) -> T. */
T multiple;
ASSERT_TRUE (multiple_p (ph::make (15, 0, 0), 5, &multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (3));
ASSERT_FALSE (multiple_p (ph::make (16, 0, 0), 5, &multiple));
ASSERT_FALSE (multiple_p (ph::make (14, 5, 5), 5, &multiple));
ASSERT_TRUE (multiple_p (ph::make (44, 0, 55), 11, &multiple));
ASSERT_KNOWN_EQ (multiple, ph::make (4, 0, 5));
ASSERT_TRUE (multiple_p (ph::make (30, 30, 0), 6, &multiple));
ASSERT_KNOWN_EQ (multiple, ph::make (5, 5, 0));
ASSERT_TRUE (multiple_p (ph::make (30, 35, 45), 5, &multiple));
ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 9));
ASSERT_EQ (multiple_p (ph::make (30, 35, 44), 5, &multiple), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 0));
ASSERT_EQ (multiple_p (ph::make (30, 34, 45), 5, &multiple), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (multiple, ch::make (6));
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0), 5, &multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (0));
/* Test multiple_p (C, T) -> T. */
ASSERT_TRUE (multiple_p (15, ph::make (5, 0, 0), &multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (3));
ASSERT_FALSE (multiple_p (16, ph::make (5, 0, 0), &multiple));
ASSERT_FALSE (multiple_p (14, ph::make (5, 5, 5), &multiple));
ASSERT_EQ (multiple_p (44, ph::make (11, 0, 4), &multiple), N <= 2);
ASSERT_KNOWN_EQ (multiple, ch::make (N <= 2 ? 4 : 3));
ASSERT_EQ (multiple_p (30, ph::make (6, 6, 6), &multiple), N == 1);
ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 5 : N == 2 ? 4 : 3));
ASSERT_TRUE (multiple_p (0, ph::make (5, 4, 11), &multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (0));
/* Test multiple_p (T, T) -> T. */
ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
ph::make (5, 0, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (3));
ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
ph::make (5, 0, 0),
&multiple));
ASSERT_FALSE (multiple_p (ph::make (14, 5, 5),
ph::make (5, 0, 0),
&multiple));
ASSERT_TRUE (multiple_p (ph::make (44, 0, 55),
ph::make (11, 0, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ph::make (4, 0, 5));
ASSERT_TRUE (multiple_p (ph::make (30, 30, 0),
ph::make (6, 0, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ph::make (5, 5, 0));
ASSERT_TRUE (multiple_p (ph::make (30, 35, 45),
ph::make (5, 0, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 9));
ASSERT_EQ (multiple_p (ph::make (30, 35, 44),
ph::make (5, 0, 0),
&multiple), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (multiple, ph::make (6, 7, 0));
ASSERT_EQ (multiple_p (ph::make (30, 34, 45),
ph::make (5, 0, 0),
&multiple), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (multiple, ch::make (6));
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
ph::make (5, 0, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (0));
ASSERT_TRUE (multiple_p (ph::make (15, 0, 0),
ph::make (5, 0, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (3));
ASSERT_FALSE (multiple_p (ph::make (16, 0, 0),
ph::make (5, 0, 0),
&multiple));
ASSERT_FALSE (multiple_p (ph::make (14, 0, 0),
ph::make (5, 5, 5),
&multiple));
ASSERT_EQ (multiple_p (ph::make (44, 0, 0),
ph::make (11, 0, 4),
&multiple), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (multiple, ch::make (4));
ASSERT_EQ (multiple_p (ph::make (30, 0, 0),
ph::make (6, 6, 6),
&multiple), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (multiple, ch::make (5));
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
ph::make (5, 4, 11),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (0));
ASSERT_TRUE (multiple_p (ph::make (5, 15, 25),
ph::make (1, 3, 5),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (5));
ASSERT_EQ (multiple_p (ph::make (18, 30, 7),
ph::make (6, 10, 2),
&multiple), N <= 2);
if (N <= 2)
ASSERT_KNOWN_EQ (multiple, ch::make (3));
ASSERT_EQ (multiple_p (ph::make (54, 19, 0),
ph::make (9, 3, 0),
&multiple), N == 1);
if (N == 1)
ASSERT_KNOWN_EQ (multiple, ch::make (6));
ASSERT_TRUE (multiple_p (ph::make (120, 0, 90),
ph::make (12, 0, 9),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (10));
ASSERT_EQ (multiple_p (ph::make (110, 1, 22),
ph::make (10, 0, 2),
&multiple), N == 1);
ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 11 : 10));
ASSERT_EQ (multiple_p (ph::make (120, -1, 22),
ph::make (10, 0, 2),
&multiple), N == 1);
ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 12 : 10));
ASSERT_EQ (multiple_p (ph::make (130, 0, 26),
ph::make (10, 1, 2),
&multiple), N == 1);
ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 13 : 10));
ASSERT_EQ (multiple_p (ph::make (140, 0, 28),
ph::make (10, -1, 2),
&multiple), N == 1);
ASSERT_KNOWN_EQ (multiple, ch::make (N == 1 ? 14 : 10));
ASSERT_FALSE (multiple_p (ph::make (89, 0, 0),
ph::make (11, 0, 0),
&multiple));
ASSERT_TRUE (multiple_p (ph::make (88, 0, 0),
ph::make (11, 0, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (8));
ASSERT_FALSE (multiple_p (ph::make (87, 0, 0),
ph::make (11, 0, 0),
&multiple));
ASSERT_TRUE (multiple_p (ph::make (35, 63, 0),
ph::make (5, 9, 0),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (7));
ASSERT_TRUE (multiple_p (ph::make (0, 0, 0),
ph::make (11, -24, 25),
&multiple));
ASSERT_KNOWN_EQ (multiple, ch::make (0));
}
/* Test exact_div for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_exact_div ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test exact_div (T, C). */
ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0), 5),
ch::make (3));
ASSERT_KNOWN_EQ (exact_div (ph::make (44, 0, 55), 11),
ph::make (4, 0, 5));
ASSERT_KNOWN_EQ (exact_div (ph::make (30, 30, 0), 6),
ph::make (5, 5, 0));
ASSERT_KNOWN_EQ (exact_div (ph::make (30, 35, 45), 5),
ph::make (6, 7, 9));
ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0), 5),
ch::make (0));
/* Test exact_div (T, T). */
ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0),
ph::make (5, 0, 0)),
ch::make (3));
ASSERT_KNOWN_EQ (exact_div (ph::make (44, 0, 55),
ph::make (11, 0, 0)),
ph::make (4, 0, 5));
ASSERT_KNOWN_EQ (exact_div (ph::make (30, 30, 0),
ph::make (6, 0, 0)),
ph::make (5, 5, 0));
ASSERT_KNOWN_EQ (exact_div (ph::make (30, 35, 45),
ph::make (5, 0, 0)),
ph::make (6, 7, 9));
ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
ph::make (5, 0, 0)),
ch::make (0));
ASSERT_KNOWN_EQ (exact_div (ph::make (15, 0, 0),
ph::make (5, 0, 0)),
ch::make (3));
ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
ph::make (5, 4, 11)),
ch::make (0));
ASSERT_KNOWN_EQ (exact_div (ph::make (5, 15, 25),
ph::make (1, 3, 5)),
ch::make (5));
ASSERT_KNOWN_EQ (exact_div (ph::make (120, 0, 90),
ph::make (12, 0, 9)),
ch::make (10));
ASSERT_KNOWN_EQ (exact_div (ph::make (88, 0, 0),
ph::make (11, 0, 0)),
ch::make (8));
ASSERT_KNOWN_EQ (exact_div (ph::make (35, 63, 0),
ph::make (5, 9, 0)),
ch::make (7));
ASSERT_KNOWN_EQ (exact_div (ph::make (0, 0, 0),
ph::make (11, -24, 25)),
ch::make (0));
}
/* Test the form of can_div_trunc_p that returns a constant quotient,
for both signed and unsigned C. */
template<unsigned int N, typename C, typename T>
static void
test_can_div_trunc_p_const ()
{
typedef coeff_helper<C> ch;
typedef poly_helper<T> ph;
/* Test can_div_trunc_p (T, C) -> C. */
C const_quot;
ASSERT_TRUE (can_div_trunc_p (ph::make (22, 0, 0), 5, &const_quot));
ASSERT_KNOWN_EQ (const_quot, C (4));
ASSERT_EQ (can_div_trunc_p (ph::make (44, 0, 1), 5, &const_quot), N <= 2);
ASSERT_KNOWN_EQ (const_quot, C (N <= 2 ? 8 : 4));
ASSERT_EQ (can_div_trunc_p (ph::make (88, 1, 0), 5, &const_quot), N == 1);
ASSERT_KNOWN_EQ (const_quot, C (N == 1 ? 17 : N == 2 ? 8 : 4));
ASSERT_TRUE (can_div_trunc_p (ph::make (20, 0, 0), 5, &const_quot));
ASSERT_KNOWN_EQ (const_quot, C (4));
ASSERT_TRUE (can_div_trunc_p (ph::make (19, 0, 0), 5, &const_quot));
ASSERT_KNOWN_EQ (const_quot, C (3));
/* Test can_div_trunc_p (T, T) -> C. */
ASSERT_TRUE (can_div_trunc_p (ph::make (8, 44, 28),
ph::make (2, 11, 7),
&const_quot));
ASSERT_EQ (const_quot, C (4));
ASSERT_TRUE (can_div_trunc_p (ph::make (9, 23, 30),
ph::make (4, 8, 12),
&const_quot));
ASSERT_EQ (const_quot, C (2));
ASSERT_EQ (can_div_trunc_p (ph::make (15, 25, 40),
ph::make (4, 8, 10),
&const_quot), N <= 2);
ASSERT_EQ (const_quot, C (N <= 2 ? 3 : 2));
ASSERT_EQ (can_div_trunc_p (ph::make (43, 79, 80),
ph::make (4, 8, 10),
&const_quot), N == 1);
ASSERT_EQ (const_quot, C (N == 1 ? 10 : N == 2 ? 3 : 2));
ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 5),
ph::make (4, 5, 6),
&const_quot));
ASSERT_EQ (const_quot, C (0));
ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 6),
ph::make (4, 5, 6),
&const_quot));
ASSERT_EQ (const_quot, C (0));
ASSERT_TRUE (can_div_trunc_p (ph::make (3, 5, 5),
ph::make (4, 5, 6),
&const_quot));
ASSERT_EQ (const_quot, C (0));
ASSERT_EQ (can_div_trunc_p (ph::make (3, 4, 7),
ph::make (4, 5, 6),
&const_quot), N <= 2);
ASSERT_EQ (const_quot, C (0));
ASSERT_EQ (can_div_trunc_p (ph::make (3, 6, 0),
ph::make (4, 5, 6),
&const_quot), N == 1);
ASSERT_EQ (const_quot, C (0));
ASSERT_TRUE (can_div_trunc_p (ph::make (56, 0, 11),
ph::make (11, 0, 2),
&const_quot));
ASSERT_EQ (const_quot, C (5));
ASSERT_EQ (can_div_trunc_p (ph::make (66, 1, 12),
ph::make (11, 0, 2),
&const_quot), N == 1);
ASSERT_EQ (const_quot, C (N == 1 ? 6 : 5));
ASSERT_EQ (can_div_trunc_p (ph::make (77, -1, 14),
ph::make (11, 0, 2),
&const_quot), N == 1);
ASSERT_EQ (const_quot, C (N == 1 ? 7 : 5));
ASSERT_TRUE (can_div_trunc_p (ph::make (89, 0, 0),
ph::make (11, 0, 0),
&const_quot));
ASSERT_EQ (const_quot, C (8));
ASSERT_EQ (can_div_trunc_p (ph::make (101, 0, 1),
ph::make (11, 0, 0),
&const_quot), N <= 2);
ASSERT_EQ (const_quot, C (N <= 2 ? 9 : 8));
ASSERT_TRUE (can_div_trunc_p (ph::make (0, 0, 0),
ph::make (4, 5, 6),
&const_quot));
ASSERT_EQ (const_quot, C (0));
/* Test can_div_trunc_p (T, T) -> C, T. */
T rem;
ASSERT_TRUE (can_div_trunc_p (ph::make (8, 44, 28),
ph::make (2, 11, 7),
&const_quot, &rem));
ASSERT_EQ (const_quot, C (4));
ASSERT_KNOWN_EQ (rem, ch::make (0));
ASSERT_TRUE (can_div_trunc_p (ph::make (9, 23, 30),
ph::make (4, 8, 12),
&const_quot, &rem));
ASSERT_EQ (const_quot, C (2));
ASSERT_KNOWN_EQ (rem, ph::make (1, 7, 6));
ASSERT_EQ (can_div_trunc_p (ph::make (15, 25, 40),
ph::make (4, 8, 10),
&const_quot, &rem), N <= 2);
ASSERT_EQ (const_quot, C (N <= 2 ? 3 : 2));
if (N <= 2)
ASSERT_KNOWN_EQ (rem, ph::make (3, 1, 0));
ASSERT_EQ (can_div_trunc_p (ph::make (43, 79, 80),
ph::make (4, 8, 10),
&const_quot, &rem), N == 1);
ASSERT_EQ (const_quot, C (N == 1 ? 10 : N == 2 ? 3 : 2));
if (N == 1)
ASSERT_KNOWN_EQ (rem, ch::make (3));
ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 5),
ph::make (4, 5, 6),
&const_quot, &rem));
ASSERT_EQ (const_quot, C (0));
ASSERT_KNOWN_EQ (rem, ph::make (3, 4, 5));
ASSERT_TRUE (can_div_trunc_p (ph::make (3, 4, 6),
ph::make (4, 5, 6),
&const_quot, &rem));
ASSERT_EQ (const_quot, C (0));
ASSERT_KNOWN_EQ (rem, ph::make (3, 4, 6));
ASSERT_TRUE (can_div_trunc_p (ph::make (3, 5, 5),
ph::make (4, 5, 6),
&const_quot, &rem));
ASSERT_EQ (const_quot, C (0));
ASSERT_KNOWN_EQ (rem, ph::make (3, 5, 5));
ASSERT_TRUE (can_div_trunc_p (ph::make (56, 0, 11),
ph::make (11, 0, 2),
&const_quot, &rem));
ASSERT_EQ (const_quot, C (5));
ASSERT_KNOWN_EQ (rem, ph::make (1, 0, 1));
ASSERT_EQ (can_div_trunc_p (ph::make (66, 1, 12),
ph::make (11, 0, 2),
&const_quot, &rem), N == 1);
ASSERT_EQ (const_quot, C (N == 1 ? 6 : 5));
if (N == 1)
ASSERT_KNOWN_EQ (rem, ch::make (0));
ASSERT_EQ (can_div_trunc_p (ph::make (77, -1, 14),
ph::make (11, 0, 2),
&const_quot, &rem), N == 1);
ASSERT_EQ (const_quot, C (N == 1 ? 7 : 5));
if (N == 1)
ASSERT_KNOWN_EQ (rem, ch::make (0));
ASSERT_TRUE (can_div_trunc_p (ph::make (89, 0, 0),
ph::make (11, 0, 0),
&const_quot, &rem));
ASSERT_EQ (const_quot, C (8));
ASSERT_KNOWN_EQ (rem, ch::make (1));
ASSERT_EQ (can_div_trunc_p (ph::make (101, 0, 1),
ph::make (11, 0, 0),
&const_quot, &rem), N <= 2);
ASSERT_EQ (const_quot, C (N <= 2 ? 9 : 8));
if (N <= 2)
ASSERT_KNOWN_EQ (rem, ch::make (2));
ASSERT_TRUE (can_div_trunc_p (ph::make (0, 0, 0),