@sgrechanik-h @tqchen @yzhliu
My understanding is that TVM 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. This seems like a bug to me unless I’m missing something. If I get confirmation on this bug, I’ll open an issue and send a PR in Github.
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;
}
}