tvm-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Salem Derisavi via TVM Discuss <>
Subject [TVM Discuss] [Development] Integer constant folding for division and mod
Date Mon, 25 Mar 2019 18:30:37 GMT

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

[Visit Topic](
to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](

Tianqi Chen, UW, Seattle, WA, 98105, United States
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message