(Pasting the bug report from https://discuss.tvm.ai/t/integer-constant-folding-for-division-and-mod/2008) My understanding is that TVM/HalideIR uses truncated division/mod, unlike Halide that uses Euclidean division/mod. Nevertheless, TVM uses div_imp (imlementation below) to do constant folding for division. Seems like this implementation is coming from Halide source code.
template<typename T>
inline T div_imp(T a, T b) {
Type t = type_of<T>();
if (t.is_int()) {
int64_t q = a / b;
int64_t r = a - q * b;
int64_t bs = b >> (t.bits() - 1);
int64_t rs = r >> (t.bits() - 1);
return (T) (q - (rs & bs) + (rs & ~bs));
} else {
return a / b;
}
}
(Pasting the bug report from https://discuss.tvm.ai/t/integer-constant-folding-for-division-and-mod/2008) My understanding is that TVM/HalideIR uses truncated division/mod, unlike Halide that uses Euclidean division/mod. Nevertheless, TVM uses div_imp (imlementation below) to do constant folding for division. Seems like this implementation is coming from Halide source code.