Closed yb303 closed 5 years ago
Thanks but I need more information. Can you please share your test program (or use case)?
Its just for convenience. Like people normally divide any int type by another. Say an int loop iterator divide by uint size of something
I guess it's not always possible to promote in this case. The dividend type can be promoted to a wider type and change signed/unsigned but the divisor cannot.
Dividing any type by another type usually works like this:
int64_t a = 12345;
int32_t b = 2;
// 1) b is automatically promoted to int64_t
// 2) the division a / b is calculated
a = a / b;
However this is not easily possible using libdivide because libdivide first has to generate a divider that only works for a given type (e.g. a libdivide unsigned divider cannot divide a signed integer). Hence the only way to implement your requested feature would be using:
int64_t a = 12345;
int32_t b = 2;
libdivide::divider<int32_t> div(b);
// 1) We need to promote libdivide::divider<int32_t> to libdivide::divider<int64_t>
// 2) Compute the division a / libdivide::divider<int64_t>
a = a / div;
Even if it was possible to automatically promote any libdivide divider to the correct type it would be a very bad idea because generating a libdivide divider is very slow (up to 3 times slower than integer division). For this reason I suggest to leave everything as is and close this issue.
Yeah, of course promoting the divisor is out of the question. I was actually thinking maybe signed and unsigned division can be merged into one and then sign can be promoted. But this does not help with int64 / int32 so IMHO not worth the effort if it cannot properly cover the entire scope of promotion.
Currently gcc is not happy with dividing (some type) by divider.
operator/ and co need more overloads or something more concise.