13 #ifndef MLIR_SUPPORT_MATHEXTRAS_H_ 14 #define MLIR_SUPPORT_MATHEXTRAS_H_ 17 #include "llvm/ADT/APInt.h" 23 inline int64_t
ceilDiv(int64_t lhs, int64_t rhs) {
26 int64_t x = (rhs > 0) ? -1 : 1;
27 return ((lhs != 0) && (lhs > 0) == (rhs > 0)) ? ((lhs + x) / rhs) + 1
33 inline int64_t
floorDiv(int64_t lhs, int64_t rhs) {
36 int64_t x = (rhs < 0) ? 1 : -1;
37 return ((lhs != 0) && ((lhs < 0) != (rhs < 0))) ? -((-lhs + x) / rhs) - 1
45 inline int64_t
mod(int64_t lhs, int64_t rhs) {
47 return lhs % rhs < 0 ? lhs % rhs + rhs : lhs % rhs;
51 inline int64_t
lcm(int64_t a, int64_t b) {
54 int64_t
lcm = (x * y) / llvm::GreatestCommonDivisor64(x, y);
55 assert((lcm >= a && lcm >= b) &&
"LCM overflow");
60 #endif // MLIR_SUPPORT_MATHEXTRAS_H_ TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
int64_t lcm(int64_t a, int64_t b)
Returns the least common multiple of 'a' and 'b'.
int64_t floorDiv(int64_t lhs, int64_t rhs)
Returns the result of MLIR's floordiv operation on constants.
int64_t ceilDiv(int64_t lhs, int64_t rhs)
Returns the result of MLIR's ceildiv operation on constants.
int64_t mod(int64_t lhs, int64_t rhs)
Returns MLIR's mod operation on constants.
SlowMPInt abs(const SlowMPInt &x)
Redeclarations of friend declarations above to make it discoverable by lookups.