In HalideIR source code:
Expr IntImm::make(Type t, int64_t value) {
internal_assert(t.is_int() && t.is_scalar())
<< “IntImm must be a scalar Int\n”;
internal_assert(t.bits() == 8 || t.bits() == 16 || t.bits() == 32 || t.bits() == 64)
<< “IntImm must be 8, 16, 32, or 64-bit\n”;
// Normalize the value by dropping the high bits
value <<= (64 - t.bits());
// Then sign-extending to get them back
value >>= (64 - t.bits());
std::shared_ptr<IntImm> node = std::make_shared<IntImm>();
node->type = t;
node->value = value;
return Expr(node);
}
if value is -1 , value <<= (64 - t.bits()) will cause a runtime error.
image
can I modify the code like this:
value =(uint64_t) value << (64 - t.bits());