@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.

```c++
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;
    }
}
```





---
[Visit 
Topic](https://discuss.tvm.ai/t/integer-constant-folding-for-division-and-mod/2008/1)
 to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.tvm.ai/email/unsubscribe/0510106b08caa85d6bca6615869092ed978b730af4028d80b3f3fce575f074d7).

Tianqi Chen, UW, Seattle, WA, 98105, United States
http://tracking.discuss.tvm.ai/tracking/unsubscribe?msgid=QljN3ixTGk8H98N8u7FCkQ2

Reply via email to