10 #include "llvm/Support/MathExtras.h" 13 using namespace presburger;
14 using namespace detail;
20 SlowMPInt::operator int64_t()
const {
return val.getSExtValue(); }
127 return std::max(a.getBitWidth(), b.getBitWidth());
137 return val.sext(width) == o.val.sext(width);
141 return val.sext(width) != o.val.sext(width);
145 return val.sext(width).sgt(o.val.sext(width));
149 return val.sext(width).slt(o.val.sext(width));
153 return val.sext(width).sle(o.val.sext(width));
157 return val.sext(width).sge(o.val.sext(width));
169 const APInt &a,
const APInt &b,
174 APInt ret = op(a.sext(width), b.sext(width), overflow);
179 ret = op(a.sext(width), b.sext(width), overflow);
180 assert(!overflow &&
"double width should be sufficient to avoid overflow!");
205 return SlowMPInt(llvm::APIntOps::RoundingSDiv(
206 lhs.val.sext(width), rhs.val.sext(width), APInt::Rounding::UP));
212 return SlowMPInt(llvm::APIntOps::RoundingSDiv(
213 lhs.val.sext(width), rhs.val.sext(width), APInt::Rounding::DOWN));
218 assert(rhs >= 1 &&
"mod is only supported for positive divisors!");
219 return lhs % rhs < 0 ? lhs % rhs + rhs : lhs % rhs;
223 assert(a >= 0 && b >= 0 &&
"operands must be non-negative!");
225 return SlowMPInt(llvm::APIntOps::GreatestCommonDivisor(a.val.sext(width),
233 return (x * y) /
gcd(x, y);
238 unsigned width =
std::max(val.getBitWidth(), o.val.getBitWidth());
239 return SlowMPInt(val.sext(width).srem(o.val.sext(width)));
243 if (val.isMinSignedValue()) {
245 APInt ret = val.sext(2 * val.getBitWidth());
Include the generated interface declarations.
bool operator<(const SlowMPInt &o) const
SlowMPInt operator/(const SlowMPInt &a, int64_t b)
SlowMPInt & operator/=(const SlowMPInt &o)
SlowMPInt & operator%=(const SlowMPInt &o)
SlowMPInt operator+(const SlowMPInt &o) const
bool operator<=(const SlowMPInt &a, int64_t b)
SlowMPInt & operator/=(SlowMPInt &a, int64_t b)
SlowMPInt operator/(const SlowMPInt &o) const
bool operator!=(const SlowMPInt &o) const
SlowMPInt operator*(const SlowMPInt &o) const
static unsigned getMaxWidth(const APInt &a, const APInt &b)
SlowMPInt & operator+=(SlowMPInt &a, int64_t b)
Convenience operator overloads for int64_t.
SlowMPInt mod(const SlowMPInt &lhs, const SlowMPInt &rhs)
Returns the remainder of dividing LHS by RHS.
bool operator>(const SlowMPInt &o) const
SlowMPInt lcm(const SlowMPInt &a, const SlowMPInt &b)
Returns the least common multiple of 'a' and 'b'.
llvm::hash_code hash_value(const SlowMPInt &x)
SlowMPInt & operator*=(SlowMPInt &a, int64_t b)
friend llvm::hash_code hash_value(const SlowMPInt &x)
Overload to compute a hash_code for a SlowMPInt value.
bool operator>(const SlowMPInt &a, int64_t b)
SlowMPInt operator-() const
friend SlowMPInt gcd(const SlowMPInt &a, const SlowMPInt &b)
The operands must be non-negative for gcd.
SlowMPInt operator+(const SlowMPInt &a, int64_t b)
SlowMPInt ceilDiv(const SlowMPInt &lhs, const SlowMPInt &rhs)
SlowMPInt & operator-=(const SlowMPInt &o)
bool operator>=(const SlowMPInt &o) const
SlowMPInt gcd(const SlowMPInt &a, const SlowMPInt &b)
APInt runOpWithExpandOnOverflow(const APInt &a, const APInt &b, llvm::function_ref< APInt(const APInt &, const APInt &, bool &overflow)> op)
Arithmetic operators.
bool operator!=(const SlowMPInt &a, int64_t b)
SlowMPInt & operator+=(const SlowMPInt &o)
Assignment operators, preincrement, predecrement.
void print(llvm::raw_ostream &os) const
Printing.
SlowMPInt operator*(const SlowMPInt &a, int64_t b)
SlowMPInt operator%(const SlowMPInt &o) const
This operation cannot overflow.
bool operator<(const SlowMPInt &a, int64_t b)
SlowMPInt operator-(const SlowMPInt &a, int64_t b)
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const SlowMPInt &x)
SlowMPInt & operator-=(SlowMPInt &a, int64_t b)
A simple class providing multi-precision arithmetic.
SlowMPInt abs(const SlowMPInt &x)
Redeclarations of friend declarations above to make it discoverable by lookups.
bool operator==(const SlowMPInt &o) const
Comparison operators.
SlowMPInt & operator=(int64_t val)
friend SlowMPInt abs(const SlowMPInt &x)
Redeclarations of friend declarations above to make it discoverable by lookups.
bool operator<=(const SlowMPInt &o) const
bool operator==(const SlowMPInt &a, int64_t b)
SlowMPInt & operator%=(SlowMPInt &a, int64_t b)
SlowMPInt operator%(const SlowMPInt &a, int64_t b)
bool operator>=(const SlowMPInt &a, int64_t b)
SlowMPInt & operator*=(const SlowMPInt &o)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
SlowMPInt floorDiv(const SlowMPInt &lhs, const SlowMPInt &rhs)