3 ms·
> The Magic Power of 2: Division Is Slowaloo Is LLVM not smart enough to optimize this?
by floatboth 7y ago
> The Magic Power of 2: Division Is Slowaloo
Is LLVM not smart enough to optimize this?
- BeeOnRope 7y agoYes, for constant divisors. However, for signed division, the C semantics (round towards zero) are different than the semantics when you apply an arithmetic shift (round towards negative infinity). If you are fine with the latter behavior explicit shifts remove several extraneous instructions dealing with the difference.
- caf 7y agoOr you can do the division in unsigned types - reasonable for something like an array index.