29#ifndef HAVE_POLY_INT_H
30#define HAVE_POLY_INT_H
32template<
unsigned int N,
typename T>
class poly_int;
65template<typename T, wi::precision_type = wi::int_traits<T>::precision_type>
73 static const int signedness = (
T (0) >=
T (-1));
75 static const T max_value = (signedness
76 ? ((
T (1) << (precision - 2))
77 + ((T (1) << (precision - 2)) - 1))
79 static const int rank =
sizeof (
T) * 2 + !signedness;
81 template<
typename Arg>
90 static const int signedness = -1;
94 template<
typename Arg>
104 static const int signedness = 1;
108 template<
typename Arg>
118 static const int signedness = 1;
122 template<
typename Arg>
127template<
typename T1,
typename T2>
156#define RANK(X) poly_coeff_traits<X>::rank
158 = ((
RANK (T1) <=
RANK (HOST_WIDE_INT)
159 &&
RANK (T2) <=
RANK (HOST_WIDE_INT))
161 : (
RANK (T1) <=
RANK (
unsigned HOST_WIDE_INT)
162 &&
RANK (T2) <=
RANK (
unsigned HOST_WIDE_INT))
169template<
typename T1,
typename T2,
typename T3,
172template<
typename T1,
typename T2,
typename T3>
200template<
unsigned int N,
typename C>
211template<
typename T1,
typename T2 = T1,
214template<
typename T1,
typename T2>
222template<
typename T1,
typename T2,
typename T3,
226template<
typename T1,
typename T2,
typename T3>
234template<
typename T1,
typename T2 = T1,
237template<
typename T1,
typename T2>
256template<
typename T1,
typename T2 = T1,
261template<
typename T1,
typename T2>
271template<
typename T1,
typename T2>
274 typedef unsigned HOST_WIDE_INT
type;
281template<
typename T1,
typename T2>
293#define POLY_POLY_COEFF(C1, C2) typename poly_result<C1, C2>::type
299#define POLY_CONST_COEFF(C1, T2) \
300 POLY_POLY_COEFF (C1, typename if_nonpoly<T2>::type)
303#define CONST_POLY_COEFF(T1, C2) \
304 POLY_POLY_COEFF (typename if_nonpoly<T1>::type, C2)
308#define POLY_POLY_RESULT(N, C1, C2) poly_int<N, POLY_POLY_COEFF (C1, C2)>
312#define POLY_CONST_RESULT(N, C1, T2) poly_int<N, POLY_CONST_COEFF (C1, T2)>
316#define CONST_POLY_RESULT(N, T1, C2) poly_int<N, CONST_POLY_COEFF (T1, C2)>
320#define CONST_CONST_RESULT(N, T1, T2) \
321 POLY_POLY_COEFF (typename if_nonpoly<T1>::type, \
322 typename if_nonpoly<T2>::type)
326#define POLY_CAST(C1, C2) typename poly_result<C1, C2>::cast
330#define POLY_BINARY_COEFF(T1, T2) \
331 typename poly_result<typename poly_int_traits<T1>::coeff_type, \
332 typename poly_int_traits<T2>::coeff_type>::type
336#define POLY_INT_TYPE(T) typename poly_int_traits<T>::int_type
351#define POLY_SET_COEFF(C, RES, I, VALUE) \
352 ((void) (&(RES).coeffs[0] == (C *) (void *) &(RES).coeffs[0]), \
353 wi::int_traits<C>::precision_type == wi::FLEXIBLE_PRECISION \
354 ? (void) ((RES).coeffs[I] = VALUE) \
355 : (void) ((RES).coeffs[I].~C (), new (&(RES).coeffs[I]) C (VALUE)))
359#define MAX_NUM_POLY_INT_COEFFS_BITS 2
376template<
unsigned int N,
typename C>
383 template<
typename Ca>
386 template<
typename ...Cs>
391 template<
typename Ca>
393 template<
typename Ca>
396 template<
typename Ca>
398 template<
typename Ca>
401 template<
typename Ca>
403 template<
typename Ca>
406 template<
typename Ca>
418 template<
typename Ca>
421 template<
typename Ca>
429#if POLY_INT_CONVERSION
436 template<
typename ...Cs>
439 template<
typename C0,
typename ...Cs>
443template<
unsigned int N,
typename C>
448 for (
unsigned int i = 0;
i <
N;
i++)
452template<
unsigned int N,
typename C>
453template<
typename ...Cs>
460template<
unsigned int N,
typename C>
461template<
typename C0,
typename ...Cs>
464 :
poly_int (c0, cs...,
wi::ints_for<C>::zero (c0)) {}
467template<
unsigned int N,
typename C>
468template<
typename ...Cs>
472 template init_cast<Cs>::
type (cs))... } {}
474template<
unsigned int N,
typename C>
479 for (
unsigned int i = 0;
i <
N;
i++)
484template<
unsigned int N,
typename C>
491 for (
unsigned int i = 1;
i <
N;
i++)
496template<
unsigned int N,
typename C>
501 for (
unsigned int i = 0;
i <
N;
i++)
506template<
unsigned int N,
typename C>
511 this->coeffs[0] +=
a;
515template<
unsigned int N,
typename C>
520 for (
unsigned int i = 0;
i <
N;
i++)
525template<
unsigned int N,
typename C>
530 this->coeffs[0] -=
a;
534template<
unsigned int N,
typename C>
539 for (
unsigned int i = 0;
i <
N;
i++)
540 this->coeffs[
i] *=
a;
544template<
unsigned int N,
typename C>
548 for (
unsigned int i = 0;
i <
N;
i++)
549 this->coeffs[
i] <<=
a;
555template<
unsigned int N,
typename C>
560 for (
unsigned int i = 1;
i <
N;
i++)
561 if (this->coeffs[
i] != 0)
569template<
unsigned int N,
typename C>
576 *const_value = this->coeffs[0];
588template<
unsigned int N,
typename C>
593 return this->coeffs[0];
600template<
unsigned int N,
typename C>
607 for (
unsigned int i = 0;
i <
N;
i++)
615template<
unsigned int N,
typename C>
621 for (
unsigned int i = 0;
i <
N;
i++)
630template<
unsigned int N,
typename C>
634 for (
unsigned int i = 0;
i <
N;
i++)
637 for (
unsigned int i = 0;
i <
N;
i++)
638 r->
coeffs[
i] = this->coeffs[
i].to_shwi ();
647template<
unsigned int N,
typename C>
651 for (
unsigned int i = 0;
i <
N;
i++)
654 for (
unsigned int i = 0;
i <
N;
i++)
655 r->coeffs[
i] = this->coeffs[
i].to_uhwi ();
662template<
unsigned int N,
typename C>
667 for (
unsigned int i = 0;
i <
N;
i++)
668 r.
coeffs[
i] = this->coeffs[
i].to_shwi ();
675template<
unsigned int N,
typename C>
680 for (
unsigned int i = 0;
i <
N;
i++)
681 r.
coeffs[
i] = this->coeffs[
i].to_uhwi ();
685#if POLY_INT_CONVERSION
688template<
unsigned int N,
typename C>
693 return this->coeffs[0];
699template<
typename Ca,
typename Cb,
typename Cc>
703 return a >=
b &&
a <= c;
706template<
unsigned int N,
typename Ca,
typename Cb,
typename Cc>
710 for (
unsigned int i = 0;
i <
N;
i++)
711 if (
a.coeffs[
i] <
b ||
a.coeffs[
i] > c)
719template<
unsigned int N>
724 for (
unsigned int i = 0;
i <
N;
i++)
731template<
unsigned int N>
736 for (
unsigned int i = 0;
i <
N;
i++)
743template<
unsigned int N,
typename Ca>
749 for (
unsigned int i = 0;
i <
N;
i++)
756template<
unsigned int N,
typename Ca>
762 for (
unsigned int i = 0;
i <
N;
i++)
768template<
unsigned int N,
typename Ca,
typename Cb>
775 for (
unsigned int i = 0;
i <
N;
i++)
780template<
unsigned int N,
typename Ca,
typename Cb>
789 for (
unsigned int i = 1;
i <
N;
i++)
794template<
unsigned int N,
typename Ca,
typename Cb>
803 for (
unsigned int i = 1;
i <
N;
i++)
811template<
unsigned int N,
typename Ca,
typename Cb>
817 for (
unsigned int i = 0;
i <
N;
i++)
822template<
unsigned int N,
typename Ca,
typename Cb>
829 for (
unsigned int i = 1;
i <
N;
i++)
835template<
unsigned int N,
typename Ca,
typename Cb>
842 for (
unsigned int i = 1;
i <
N;
i++)
848template<
unsigned int N,
typename Ca,
typename Cb>
856 for (
unsigned int i = 1;
i <
N;
i++)
867template<
unsigned int N,
typename Ca,
typename Cb>
874 for (
unsigned int i = 0;
i <
N;
i++)
879template<
unsigned int N,
typename Ca,
typename Cb>
888 for (
unsigned int i = 1;
i <
N;
i++)
893template<
unsigned int N,
typename Ca,
typename Cb>
902 for (
unsigned int i = 1;
i <
N;
i++)
910template<
unsigned int N,
typename Ca,
typename Cb>
916 for (
unsigned int i = 0;
i <
N;
i++)
921template<
unsigned int N,
typename Ca,
typename Cb>
928 for (
unsigned int i = 1;
i <
N;
i++)
934template<
unsigned int N,
typename Ca,
typename Cb>
941 for (
unsigned int i = 1;
i <
N;
i++)
947template<
unsigned int N,
typename Ca,
typename Cb>
955 for (
unsigned int i = 1;
i <
N;
i++)
966template<
unsigned int N,
typename Ca>
973 for (
unsigned int i = 0;
i <
N;
i++)
981template<
unsigned int N,
typename Ca>
987 for (
unsigned int i = 0;
i <
N;
i++)
992template<
unsigned int N,
typename Ca>
999 for (
unsigned int i = 1;
i <
N;
i++)
1009template<
unsigned int N,
typename Ca>
1015 return ~a.coeffs[0];
1018template<
unsigned int N,
typename Ca,
typename Cb>
1025 for (
unsigned int i = 0;
i <
N;
i++)
1030template<
unsigned int N,
typename Ca,
typename Cb>
1037 for (
unsigned int i = 0;
i <
N;
i++)
1045template<
unsigned int N,
typename Ca,
typename Cb>
1051 for (
unsigned int i = 0;
i <
N;
i++)
1056template<
unsigned int N,
typename Ca,
typename Cb>
1062 for (
unsigned int i = 0;
i <
N;
i++)
1067template<
unsigned int N,
typename Ca,
typename Cb>
1075 for (
unsigned int i = 1;
i <
N;
i++)
1085template<
unsigned int N,
typename Ca,
typename Cb>
1092 for (
unsigned int i = 0;
i <
N;
i++)
1100template<
unsigned int N,
typename Ca,
typename Cb>
1106 for (
unsigned int i = 0;
i <
N;
i++)
1114template<
unsigned int N,
typename C>
1119 for (
unsigned int i = 0;
i <
N;
i++)
1128template<
typename Ca,
typename Cb>
1130maybe_eq_2 (
const Ca &a0,
const Ca &a1,
const Cb &b0,
const Cb &b1)
1141 ? b0 <= a0 && (a0 - b0) % (b1 - a1) == 0
1142 : b0 >= a0 && (b0 - a0) % (a1 - b1) == 0);
1149template<
typename Ca,
typename Cb>
1151maybe_eq_2 (
const Ca &a0,
const Ca &a1,
const Cb &
b)
1161 ?
b <= a0 && (a0 -
b) % a1 == 0
1162 :
b >= a0 && (
b - a0) % a1 == 0);
1168template<
unsigned int N,
typename Ca,
typename Cb>
1174 return maybe_eq_2 (
a.coeffs[0],
a.coeffs[1],
b.coeffs[0],
b.coeffs[1]);
1175 return a.coeffs[0] ==
b.coeffs[0];
1178template<
unsigned int N,
typename Ca,
typename Cb>
1184 return maybe_eq_2 (
a.coeffs[0],
a.coeffs[1],
b);
1185 return a.coeffs[0] ==
b;
1188template<
unsigned int N,
typename Ca,
typename Cb>
1194 return maybe_eq_2 (
b.coeffs[0],
b.coeffs[1],
a);
1195 return a ==
b.coeffs[0];
1198template<
typename Ca,
typename Cb>
1200maybe_eq (
const Ca &
a,
const Cb &
b)
1207template<
unsigned int N,
typename Ca,
typename Cb>
1212 for (
unsigned int i = 1;
i <
N;
i++)
1213 if (
a.coeffs[
i] !=
b.coeffs[
i])
1215 return a.coeffs[0] !=
b.coeffs[0];
1218template<
unsigned int N,
typename Ca,
typename Cb>
1223 for (
unsigned int i = 1;
i <
N;
i++)
1224 if (
a.coeffs[
i] != 0)
1226 return a.coeffs[0] !=
b;
1229template<
unsigned int N,
typename Ca,
typename Cb>
1234 for (
unsigned int i = 1;
i <
N;
i++)
1235 if (
b.coeffs[
i] != 0)
1237 return a !=
b.coeffs[0];
1240template<
typename Ca,
typename Cb>
1242maybe_ne (
const Ca &
a,
const Cb &
b)
1248#define known_eq(A, B) (!maybe_ne (A, B))
1251#define known_ne(A, B) (!maybe_eq (A, B))
1256template<
unsigned int N,
typename Ca,
typename Cb>
1261 for (
unsigned int i = 1;
i <
N;
i++)
1262 if (
a.coeffs[
i] <
b.coeffs[
i])
1264 return a.coeffs[0] <=
b.coeffs[0];
1267template<
unsigned int N,
typename Ca,
typename Cb>
1272 for (
unsigned int i = 1;
i <
N;
i++)
1273 if (
a.coeffs[
i] < 0)
1275 return a.coeffs[0] <=
b;
1278template<
unsigned int N,
typename Ca,
typename Cb>
1283 for (
unsigned int i = 1;
i <
N;
i++)
1284 if (
b.coeffs[
i] > 0)
1286 return a <=
b.coeffs[0];
1289template<
typename Ca,
typename Cb>
1291maybe_le (
const Ca &
a,
const Cb &
b)
1298template<
unsigned int N,
typename Ca,
typename Cb>
1303 for (
unsigned int i = 1;
i <
N;
i++)
1304 if (
a.coeffs[
i] <
b.coeffs[
i])
1306 return a.coeffs[0] <
b.coeffs[0];
1309template<
unsigned int N,
typename Ca,
typename Cb>
1314 for (
unsigned int i = 1;
i <
N;
i++)
1315 if (
a.coeffs[
i] < 0)
1317 return a.coeffs[0] <
b;
1320template<
unsigned int N,
typename Ca,
typename Cb>
1325 for (
unsigned int i = 1;
i <
N;
i++)
1326 if (
b.coeffs[
i] > 0)
1328 return a <
b.coeffs[0];
1331template<
typename Ca,
typename Cb>
1333maybe_lt (
const Ca &
a,
const Cb &
b)
1339#define maybe_ge(A, B) maybe_le (B, A)
1342#define maybe_gt(A, B) maybe_lt (B, A)
1345#define known_le(A, B) (!maybe_gt (A, B))
1348#define known_lt(A, B) (!maybe_ge (A, B))
1351#define known_gt(A, B) (!maybe_le (A, B))
1354#define known_ge(A, B) (!maybe_lt (A, B))
1358template<
typename T1,
typename T2>
1360ordered_p (
const T1 &
a,
const T2 &
b)
1374template<
unsigned int N,
typename Ca,
typename Cb>
1388template<
unsigned int N,
typename Ca,
typename Cb>
1402template<
unsigned int N,
typename Ca,
typename Cb>
1422template<
unsigned int N,
typename Ca,
typename Cb>
1436template<
unsigned int N,
typename Ca,
typename Cb>
1450template<
unsigned int N,
typename Ca,
typename Cb>
1467template<
unsigned int N,
typename Ca>
1477template<
unsigned int N,
typename Ca,
typename Cb>
1489template<
unsigned int N,
typename Ca,
typename Cb>
1502template<
unsigned int N,
typename Ca,
typename Cb>
1514 for (
unsigned int i = 1;
i <
N;
i++)
1519template<
unsigned int N,
typename Ca,
typename Cb>
1523 return lower_bound (
b,
a);
1526template<
unsigned int N,
typename Ca,
typename Cb>
1535 for (
unsigned int i = 0;
i <
N;
i++)
1540template<
typename Ca,
typename Cb>
1542lower_bound (
const Ca &
a,
const Cb &
b)
1544 return a <
b ?
a :
b;
1551template<
unsigned int N,
typename Ca,
typename Cb>
1563 for (
unsigned int i = 1;
i <
N;
i++)
1568template<
unsigned int N,
typename Ca,
typename Cb>
1572 return upper_bound (
b,
a);
1575template<
unsigned int N,
typename Ca,
typename Cb>
1584 for (
unsigned int i = 0;
i <
N;
i++)
1592template<
unsigned int N,
typename Ca>
1598 for (
i =
N - 1;
i > 0; --
i)
1599 if (
a.coeffs[
i] != 0)
1603 for (
unsigned int j = 0; j <
i; ++j)
1604 if (
a.coeffs[j] != 0)
1605 r =
gcd (
r, C (
a.coeffs[j]));
1613template<
unsigned int N,
typename Ca,
typename Cb>
1621template<
unsigned int N,
typename Ca,
typename Cb>
1625 return common_multiple (
b,
a);
1636template<
unsigned int N,
typename Ca,
typename Cb>
1640 if (
b.is_constant ())
1641 return common_multiple (
a,
b.coeffs[0]);
1642 if (
a.is_constant ())
1643 return common_multiple (
a.coeffs[0],
b);
1650 for (
unsigned int i = 1;
i <
N; ++
i)
1651 if (
a.coeffs[
i] != ICa (0))
1654 C amul = lcm /
a.coeffs[
i];
1655 C bmul = lcm /
b.coeffs[
i];
1656 for (
unsigned int j = 0; j <
N; ++j)
1674template<
unsigned int N,
typename Ca,
typename Cb>
1678 for (
unsigned int i =
N;
i-- > 0; )
1679 if (
a.coeffs[
i] !=
b.coeffs[
i])
1680 return a.coeffs[
i] <
b.coeffs[
i] ? -1 : 1;
1686template<
unsigned int N,
typename Ca,
typename Cb>
1690 for (
unsigned int i = 1;
i <
N;
i++)
1691 if ((value.
coeffs[
i] & (align - 1)) != 0)
1699template<
unsigned int N,
typename Ca,
typename Cb>
1704 if (!can_align_p (value, align))
1706 *aligned = value + (-value.
coeffs[0] & (align - 1));
1713template<
unsigned int N,
typename Ca,
typename Cb>
1718 if (!can_align_p (value, align))
1720 *aligned = value - (value.
coeffs[0] & (align - 1));
1728template<
unsigned int N,
typename Ca,
typename Cb,
typename Cc>
1736 return (can_align_up (
a, align, &aligned_a)
1737 && can_align_up (
b, align, &aligned_b)
1738 &&
known_eq (aligned_a, aligned_b));
1745template<
unsigned int N,
typename Ca,
typename Cb,
typename Cc>
1753 return (can_align_down (
a, align, &aligned_a)
1754 && can_align_down (
b, align, &aligned_b)
1755 &&
known_eq (aligned_a, aligned_b));
1765template<
unsigned int N,
typename Ca,
typename Cb>
1770 return value + (-value.
coeffs[0] & (align - 1));
1780template<
unsigned int N,
typename Ca,
typename Cb>
1785 return value - (value.
coeffs[0] & (align - 1));
1792template<
unsigned int N,
typename Ca,
typename Cb>
1797 for (
unsigned int i = 0;
i <
N;
i++)
1801 - (value.
coeffs[
i] & (align - 1))));
1809template<
unsigned int N,
typename Ca,
typename Cb>
1814 for (
unsigned int i = 0;
i <
N;
i++)
1816 + (-value.
coeffs[
i] & (align - 1))));
1828template<
unsigned int N,
typename Ca,
typename Cb>
1836 - (value.
coeffs[0] & (align - 1)))
1839 for (
unsigned int i = 1;
i <
N;
i++)
1852template<
unsigned int N,
typename Ca,
typename Cb>
1860 + (-value.
coeffs[0] & (align - 1)))
1863 for (
unsigned int i = 1;
i <
N;
i++)
1872template<
unsigned int N,
typename Ca,
typename Cb,
typename Cm>
1874known_misalignment (
const poly_int<N, Ca> &value, Cb align, Cm *misalign)
1877 if (!can_align_p (value, align))
1879 *misalign = value.
coeffs[0] & (align - 1);
1887template<
unsigned int N,
typename Ca,
typename Cb>
1892 return a.coeffs[0] & (align - 1);
1898template<
unsigned int N,
typename Ca>
1904 for (
unsigned int i = 1;
i <
N; ++
i)
1912template<
unsigned int N,
typename Ca,
typename Cb,
typename Cr>
1920 for (
unsigned int i = 1;
i <
N;
i++)
1921 if ((-(
a.coeffs[
i] & -
a.coeffs[
i]) &
b) != int_type (0))
1924 result->coeffs[0] |=
b;
1931template<
unsigned int N,
typename Ca,
typename Cb,
typename Cm>
1940 if (
NCa (
a.coeffs[0]) % NCb (
b) != 0 || !
a.is_constant ())
1942 *multiple =
NCa (
a.coeffs[0]) / NCb (
b);
1946template<
unsigned int N,
typename Ca,
typename Cb,
typename Cm>
1956 if (
NCa (
a) % NCb (
b.coeffs[0]) != 0
1957 || (
a != int_type (0) && !
b.is_constant ()))
1959 *multiple =
NCa (
a) / NCb (
b.coeffs[0]);
1963template<
unsigned int N,
typename Ca,
typename Cb,
typename Cm>
1974 if (
NCa (
a.coeffs[0]) % NCb (
b.coeffs[0]) != 0)
1977 C
r =
NCa (
a.coeffs[0]) / NCb (
b.coeffs[0]);
1978 for (
unsigned int i = 1;
i <
N; ++
i)
1979 if (
b.coeffs[
i] == ICb (0)
1980 ?
a.coeffs[
i] != ICa (0)
1981 : (
NCa (
a.coeffs[
i]) % NCb (
b.coeffs[
i]) != 0
1982 ||
NCa (
a.coeffs[
i]) / NCb (
b.coeffs[
i]) !=
r))
1991template<
unsigned int N,
typename Ca,
typename Cb>
2000 if (
NCa (
a.coeffs[0]) % NCb (
b) != 0 || !
a.is_constant ())
2005template<
unsigned int N,
typename Ca,
typename Cb>
2015 if (
NCa (
a) % NCb (
b.coeffs[0]) != 0
2016 || (
a != int_type (0) && !
b.is_constant ()))
2021template<
unsigned int N,
typename Ca,
typename Cb>
2031 if (
NCa (
a.coeffs[0]) % NCb (
b.coeffs[0]) != 0)
2034 C
r =
NCa (
a.coeffs[0]) / NCb (
b.coeffs[0]);
2035 for (
unsigned int i = 1;
i <
N; ++
i)
2036 if (
b.coeffs[
i] == ICb (0)
2037 ?
a.coeffs[
i] != ICa (0)
2038 : (
NCa (
a.coeffs[
i]) % NCb (
b.coeffs[
i]) != 0
2039 ||
NCa (
a.coeffs[
i]) / NCb (
b.coeffs[
i]) !=
r))
2047template<
typename Ca,
typename Cb>
2049multiple_p (Ca
a, Cb
b)
2056template<
unsigned int N,
typename Ca,
typename Cb>
2060 for (
unsigned int i = 0;
i <
N; ++
i)
2061 if (
a.coeffs[
i] %
b != 0)
2068template<
unsigned int N,
typename Ca,
typename Cb>
2076 return a %
b.coeffs[0] == 0 && (
a == int_type (0) ||
b.is_constant ());
2082template<
unsigned int N,
typename Ca,
typename Cb>
2086 if (
b.is_constant ())
2087 return multiple_p (
a,
b.coeffs[0]);
2089 return constant_multiple_p (
a,
b, &tmp);
2095template<
typename Ca,
typename Cb,
typename Cm>
2097multiple_p (Ca
a, Cb
b, Cm *multiple)
2108template<
unsigned int N,
typename Ca,
typename Cb,
typename Cm>
2112 if (!multiple_p (
a,
b))
2114 for (
unsigned int i = 0;
i <
N; ++
i)
2122template<
unsigned int N,
typename Ca,
typename Cb,
typename Cm>
2130 if (
a %
b.coeffs[0] != 0 || (
NCa (
a) != 0 && !
b.is_constant ()))
2132 *multiple =
a /
b.coeffs[0];
2140template<
unsigned int N,
typename Ca,
typename Cb,
typename Cm>
2145 if (
b.is_constant ())
2146 return multiple_p (
a,
b.coeffs[0], multiple);
2147 return constant_multiple_p (
a,
b, multiple);
2152template<
unsigned int N,
typename Ca,
typename Cb>
2158 for (
unsigned int i = 0;
i <
N;
i++)
2168template<
unsigned int N,
typename Ca,
typename Cb>
2172 if (
b.is_constant ())
2173 return exact_div (
a,
b.coeffs[0]);
2181 C
r =
NCa (
a.coeffs[0]) / NCb (
b.coeffs[0]);
2182 for (
unsigned int i = 1;
i <
N; ++
i)
2184 ?
a.coeffs[
i] == int_type (0)
2185 : (
a.coeffs[
i] %
b.coeffs[
i] == 0
2186 &&
NCa (
a.coeffs[
i]) / NCb (
b.coeffs[
i]) ==
r));
2199template<
unsigned int N,
typename Ca,
typename Cb,
typename Cq>
2208 Cq q =
NCa (
a.coeffs[0]) / NCb (
b);
2209 if (!
a.is_constant ())
2215template<
unsigned int N,
typename Ca,
typename Cb,
typename Cq>
2227 C q =
NCa (
a.coeffs[0]) / NCb (
b.coeffs[0]);
2274 bool rem_p =
NCa (
a.coeffs[0]) % NCb (
b.coeffs[0]) != 0;
2275 for (
unsigned int i = 1;
i <
N; ++
i)
2277 if (
b.coeffs[
i] == ICb (0))
2280 if (
a.coeffs[
i] != ICa (0))
2289 auto qi =
NCa (
a.coeffs[
i]) / NCb (
b.coeffs[
i]);
2290 auto ri =
NCa (
a.coeffs[
i]) % NCb (
b.coeffs[
i]);
2304 else if (q <= 0 && qi < q && qi + 1 == q)
2306 else if (q >= 0 && qi > q && qi - 1 == q)
2316 if (rem_p && (!ordered_p (
a, ICa (0)) || !ordered_p (
b, ICb (0))))
2325template<
unsigned int N,
typename Ca,
typename Cb,
typename Cq,
typename Cr>
2328 Cq *quotient, Cr *remainder)
2330 if (!can_div_trunc_p (
a,
b, quotient))
2332 *remainder =
a - *quotient *
b;
2344template<
unsigned int N,
typename Ca,
typename Cb,
typename Cq>
2350 for (
unsigned int i = 1;
i <
N; ++
i)
2351 if (
a.coeffs[
i] %
b != 0)
2353 for (
unsigned int i = 0;
i <
N; ++
i)
2360template<
unsigned int N,
typename Ca,
typename Cb,
typename Cq,
typename Cr>
2365 if (!can_div_trunc_p (
a,
b, quotient))
2367 *remainder =
a.coeffs[0] %
b;
2377template<
unsigned int N,
typename Ca,
typename Cb,
typename Cq>
2382 if (
b.is_constant ())
2383 return can_div_trunc_p (
a,
b.coeffs[0], quotient);
2384 if (!can_div_trunc_p (
a,
b, "ient->
coeffs[0]))
2386 for (
unsigned int i = 1;
i <
N; ++
i)
2399template<
unsigned int N,
typename Ca,
typename Cb,
typename Cq>
2404 if (!can_div_trunc_p (
a,
b, quotient))
2406 if (maybe_ne (*quotient *
b,
a))
2407 *quotient += (*quotient < 0 ? -1 : 1);
2414template<
unsigned int N,
typename C>
2422 fprintf (file,
"[");
2423 for (
unsigned int i = 0;
i <
N; ++
i)
2426 fputc (
i ==
N - 1 ?
']' :
',', file);
2434template<
unsigned int N,
typename C>
2445template<
unsigned int N,
typename C>
2453 fprintf (file,
"[");
2454 for (
unsigned int i = 0;
i <
N; ++
i)
2457 fputc (
i ==
N - 1 ?
']' :
',', file);
2479template<
typename T1,
typename T2,
2481 unsigned HOST_WIDE_INT)>
2482struct poly_span_traits
2484 template<
typename T>
2485 static const T &cast (
const T &x) {
return x; }
2488template<
typename T1,
typename T2>
2489struct poly_span_traits<T1, T2, unsigned HOST_WIDE_INT>
2491 template<
typename T>
2493 cast (
const T &x) {
return x; }
2495 template<
unsigned int N,
typename T>
2505known_size_p (
const T &
a)
2514template<
typename T1,
typename T2,
typename T3>
2516maybe_in_range_p (
const T1 &val,
const T2 &pos,
const T3 &size)
2518 typedef poly_span_traits<T1, T2> start_span;
2519 typedef poly_span_traits<T3, T3> size_span;
2522 if (!known_size_p (size))
2526 && maybe_lt (val, pos))
2530 return maybe_lt (start_span::cast (val) - start_span::cast (pos),
2531 size_span::cast (size));
2538template<
typename T1,
typename T2,
typename T3>
2540known_in_range_p (
const T1 &val,
const T2 &pos,
const T3 &size)
2542 typedef poly_span_traits<T1, T2> start_span;
2543 typedef poly_span_traits<T3, T3> size_span;
2544 return (known_size_p (size)
2546 &&
known_lt (start_span::cast (val) - start_span::cast (pos),
2547 size_span::cast (size)));
2554template<
typename T1,
typename T2,
typename T3,
typename T4>
2556ranges_maybe_overlap_p (
const T1 &pos1,
const T2 &size1,
2557 const T3 &pos2,
const T4 &size2)
2559 if (maybe_in_range_p (pos2, pos1, size1))
2561 if (maybe_in_range_p (pos1, pos2, size2))
2570template<
typename T1,
typename T2,
typename T3,
typename T4>
2572ranges_known_overlap_p (
const T1 &pos1,
const T2 &size1,
2573 const T3 &pos2,
const T4 &size2)
2575 typedef poly_span_traits<T1, T3> start_span;
2576 typedef poly_span_traits<T2, T2> size1_span;
2577 typedef poly_span_traits<T4, T4> size2_span;
2590 return (known_size_p (size1)
2591 && known_size_p (size2)
2592 &&
known_lt (start_span::cast (pos2)
2593 - start_span::cast (lower_bound (pos1, pos2)),
2594 size1_span::cast (size1))
2595 &&
known_lt (start_span::cast (pos1)
2596 - start_span::cast (lower_bound (pos1, pos2)),
2597 size2_span::cast (size2)));
2604template<
typename T1,
typename T2,
typename T3,
typename T4>
2606known_subrange_p (
const T1 &pos1,
const T2 &size1,
2607 const T3 &pos2,
const T4 &size2)
2610 typedef poly_span_traits<T1, T3> start_span;
2611 typedef poly_span_traits<T2, T4> size_span;
2614 || known_size_p (size1))
2615 && known_size_p (size2)
2618 &&
known_le (start_span::cast (pos1) - start_span::cast (pos2),
2619 size_span::cast (size2) - size_span::cast (size1)));
2628endpoint_representable_p (
const T &pos,
const T &size)
2630 return (!known_size_p (size)
2634template<
unsigned int N,
typename C>
2639 if (known_size_p (size))
2640 for (
unsigned int i = 0;
i <
N; ++
i)
2646template<
unsigned int N,
typename C>
2652template<
unsigned int N,
typename C>
2658template<
unsigned int N,
typename C>
2664#undef POLY_SET_COEFF
2666#undef POLY_BINARY_COEFF
2667#undef CONST_CONST_RESULT
2668#undef POLY_CONST_RESULT
2669#undef CONST_POLY_RESULT
2670#undef POLY_POLY_RESULT
2671#undef POLY_CONST_COEFF
2672#undef CONST_POLY_COEFF
2673#undef POLY_POLY_COEFF
void gt_pch_nx(bbitmap< N > *)
Definition bbitmap.h:226
void gt_ggc_mx(bbitmap< N > *)
Definition bbitmap.h:220
Definition poly-int.h:378
C to_constant() const
Definition poly-int.h:590
poly_int< N, unsigned HOST_WIDE_INT > force_uhwi() const
Definition poly-int.h:677
bool to_shwi(poly_int< N, HOST_WIDE_INT > *) const
Definition poly-int.h:632
poly_int< N, HOST_WIDE_INT > force_shwi() const
Definition poly-int.h:664
bool is_constant() const
Definition poly-int.h:557
static poly_int< N, C > from(const poly_int< N, Ca > &, signop)
Definition poly-int.h:618
constexpr poly_int(poly_int_hungry, const C0 &, const Cs &...)
poly_int & operator+=(const poly_int< N, Ca > &)
if_lossless< T, C, bool >::type is_constant(T *) const
Definition poly-int.h:572
if_nonpoly< Ca, poly_int >::type & operator*=(const Ca &)
Definition poly-int.h:537
C coeffs[N]
Definition poly-int.h:433
poly_int & operator<<=(unsigned int)
Definition poly-int.h:546
bool to_uhwi(poly_int< N, unsigned HOST_WIDE_INT > *) const
Definition poly-int.h:649
poly_int & operator-=(const poly_int< N, Ca > &)
poly_int(const poly_int< N, Ca > &)
Definition poly-int.h:446
constexpr poly_int(poly_int_full, const Cs &...)
poly_int(const poly_int &)=default
constexpr poly_int(const Cs &...)
static poly_int< N, C > from(const poly_int< N, Ca > &, unsigned int, signop)
Definition poly-int.h:603
poly_int & operator=(const poly_int &)=default
Definition wide-int.h:1967
void(* gt_pointer_operator)(void *, void *, void *)
Definition coretypes.h:473
dump_flags_t operator~(dump_flags_t flags)
Definition dumpfile.h:226
#define CHAR_BIT
Definition genautomata.cc:120
static type_p type(options_p *optsp, bool nested)
Definition gengtype-parse.cc:883
static struct token T
Definition gengtype-parse.cc:45
#define N
Definition gensupport.cc:202
#define INT_MAX
Definition glimits.h:85
HOST_WIDE_INT gcd(HOST_WIDE_INT a, HOST_WIDE_INT b)
Definition hwint.cc:132
HOST_WIDE_INT least_common_multiple(HOST_WIDE_INT a, HOST_WIDE_INT b)
Definition hwint.cc:187
HOST_WIDE_INT sext_hwi(HOST_WIDE_INT src, unsigned int prec)
Definition hwint.h:300
Definition double-int.h:439
poly_int< N, hwi_with_prec > uhwi(const poly_int< N, unsigned HOST_WIDE_INT > &a, unsigned int precision)
Definition poly-int.h:733
poly_int< N, C > r
Definition poly-int.h:748
UNARY_PREDICATE fits_shwi_p(const T &)
UNARY_FUNCTION zext(const T &, unsigned int)
BINARY_FUNCTION sub(const T1 &, const T2 &)
UNARY_FUNCTION neg(const T &)
Ca unsigned int precision
Definition poly-int.h:746
static void accumulate_overflow(overflow_type &, overflow_type)
Definition wide-int.h:4064
Ca & a
Definition poly-int.h:745
UNARY_PREDICATE fits_uhwi_p(const T &)
BINARY_FUNCTION mul(const T1 &, const T2 &)
UNARY_FUNCTION sext(const T &, unsigned int)
SHIFT_FUNCTION lshift(const T1 &, const T2 &)
BINARY_FUNCTION add(const T1 &, const T2 &)
i
Definition poly-int.h:750
overflow_type
Definition wide-int.h:377
poly_int< N, hwi_with_prec > shwi(const poly_int< N, HOST_WIDE_INT > &a, unsigned int precision)
Definition poly-int.h:721
#define POLY_CONST_COEFF(C1, T2)
Definition poly-int.h:299
#define CONST_POLY_COEFF(T1, C2)
Definition poly-int.h:303
#define POLY_SET_COEFF(C, RES, I, VALUE)
Definition poly-int.h:351
#define POLY_POLY_RESULT(N, C1, C2)
Definition poly-int.h:308
poly_int< N, C > r
Definition poly-int.h:774
#define POLY_CAST(C1, C2)
Definition poly-int.h:326
NCa(a.coeffs[i])+b.coeffs[i])
#define POLY_INT_TYPE(T)
Definition poly-int.h:336
i
Definition poly-int.h:776
#define POLY_BINARY_COEFF(T1, T2)
Definition poly-int.h:330
#define POLY_CONST_RESULT(N, C1, T2)
Definition poly-int.h:312
#define CONST_CONST_RESULT(N, T1, T2)
Definition poly-int.h:320
#define RANK(X)
Definition poly-int.h:156
#define POLY_POLY_COEFF(C1, C2)
Definition poly-int.h:293
if_nonpoly< Ca, bool >::type coeffs_in_range_p(const Ca &a, const Cb &b, const Cc &c)
Definition poly-int.h:701
Ca const poly_int< N, Cb > & b
Definition poly-int.h:771
Ca & a
Definition poly-int.h:770
#define CONST_POLY_RESULT(N, T1, C2)
Definition poly-int.h:316
signop
Definition signop.h:28
@ UNSIGNED
Definition signop.h:30
@ SIGNED
Definition signop.h:29
sreal operator<<(const sreal &a, int exp)
Definition sreal.h:187
T3 type
Definition poly-int.h:175
Definition poly-int.h:171
T3 type
Definition poly-int.h:229
Definition poly-int.h:225
T2 type
Definition poly-int.h:217
Definition poly-int.h:213
T2 type
Definition poly-int.h:240
Definition poly-int.h:236
Definition poly-int.h:129
static const int result_kind
Definition poly-int.h:158
static const bool lossless_p
Definition poly-int.h:144
Definition poly-int.h:123
typedef WI_UNARY_RESULT(T) result
int int_type
Definition poly-int.h:116
T type
Definition poly-int.h:82
T int_type
Definition poly-int.h:72
T result
Definition poly-int.h:71
Definition poly-int.h:109
int int_type
Definition poly-int.h:102
typedef WI_UNARY_RESULT(T) result
int int_type
Definition poly-int.h:89
T result
Definition poly-int.h:88
Definition poly-int.h:365
Definition poly-int.h:370
Definition poly-int.h:366
poly_coeff_traits< C >::int_type int_type
Definition poly-int.h:206
C coeff_type
Definition poly-int.h:205
Definition poly-int.h:194
poly_coeff_traits< T >::int_type int_type
Definition poly-int.h:198
static const bool is_poly
Definition poly-int.h:195
T coeff_type
Definition poly-int.h:197
static const unsigned int num_coeffs
Definition poly-int.h:196
type cast
Definition poly-int.h:267
HOST_WIDE_INT type
Definition poly-int.h:264
type cast
Definition poly-int.h:277
unsigned HOST_WIDE_INT type
Definition poly-int.h:274
const T1 & cast
Definition poly-int.h:287
typedef WI_BINARY_RESULT(T1, T2) type
Definition poly-int.h:258
Definition gengtype.h:252
Definition wide-int.h:427
Definition wide-int.h:2043
#define gcc_unreachable()
Definition system.h:841
#define true
Definition system.h:887
#define false
Definition system.h:888
#define MIN(X, Y)
Definition system.h:396
#define STATIC_ASSERT(X)
Definition system.h:864
#define gcc_checking_assert(EXPR)
Definition system.h:821
#define MAX(X, Y)
Definition system.h:397
comp_cost operator+(comp_cost cost1, comp_cost cost2)
Definition tree-ssa-loop-ivopts.cc:269
comp_cost operator-(comp_cost cost1, comp_cost cost2)
Definition tree-ssa-loop-ivopts.cc:282
void print_hex(const wide_int_ref &val, char *buf)
Definition wide-int-print.cc:141
void print_dec(const wide_int_ref &wi, char *buf, signop sgn)
Definition wide-int-print.cc:34
#define WI_BINARY_RESULT(T1, T2)
Definition wide-int.h:289
#define WI_UNARY_RESULT(T)
Definition wide-int.h:315
#define WIDE_INT_MAX_PRECISION
Definition wide-int.h:253